/* ============================================================
   liquid.css — macOS Tahoe "Liquid Glass" integration
   Tuning layer on top of assets/lib/liquid-glass.css
   (dpawlikowski/liquid-glass, MIT — CSS + SVG feTurbulence/
   feDisplacementMap refraction, animated baseFrequency).

   Only sets the --lg-* custom properties the library consumes
   plus a few per-surface overrides (position, overflow, the
   sprite opacity and the menubar edge treatment).
   ============================================================ */

/* Apple's real glass shows no coloured side fringes — the chromatic
   edge lines read as extra borders, so neutralize them site-wide.
   The specular top highlight (::after) stays: that one is Apple's. */
:root {
  --lg-edge-red:  transparent;
  --lg-edge-cyan: transparent;
}

/* ── Theme-aware tint (RGB triplets) & milkiness ──────────────
   macOS 27 Golden Gate ships a system-wide Liquid Glass slider
   (Clear ↔ Tinted). Every surface multiplies its resting opacity
   by --lg-amount, which System Settings → Appearance writes to
   the root element (0.55 clear … 1.5 tinted, default 1).        */
html[data-theme="light"] {
  --lg-tint:           255 255 255;
  --lg-opacity:        calc(0.62 * var(--lg-amount, 1));
  --lg-border-opacity: calc(0.60 * var(--lg-amount, 1));
  --lg-shadow:         var(--glass-shadow);
}
html[data-theme="dark"] {
  --lg-tint:           22 22 26;
  --lg-opacity:        calc(0.60 * var(--lg-amount, 1));
  --lg-border-opacity: calc(0.22 * var(--lg-amount, 1));
  --lg-shadow:         var(--glass-shadow);
}

/* In dark mode the library's hard-coded white inner top highlight
   (inset 0 1px 0 white/0.42) reads as a harsh edge — soften it. */
html[data-theme="dark"] .liquid-glass {
  box-shadow: var(--lg-shadow), inset 0 1px 0 rgb(255 255 255 / 0.08);
}

/* Scene sampled by the refraction sprite (fallback engines, e.g. Chrome).
   JS re-points this whenever the wallpaper changes (setWallpaper). */
:root {
  --lg-scene-background: url("assets/wallpapers/tahoe.jpg");
}

/* The library draws the sprite at 0.82 opacity, which in engines
   WITHOUT live backdrop refraction (Chrome/Firefox) makes the glass
   show a sharp, un-blurred copy of the wallpaper — a "see-through"
   look.  0.38 keeps a clearly visible liquid ripple under the frosted
   milk (Apple's glass always shows the scene bending), while the
   per-surface blur (≤14px) stops it reading as a pasted screenshot. */
.liquid-glass__refraction {
  opacity: 0.38;
}

/* Performance: the animated turbulence is expensive per surface.
   Windows/notifications/menus/widgets use the STATIC filter for their
   sprite (Safari's live-backdrop path keeps the animated one, and its
   sprite is display:none there anyway). */
.window .liquid-glass__refraction,
.notif .liquid-glass__refraction,
#cal-pop .liquid-glass__refraction,
#ctx .liquid-glass__refraction,
.menu-drop .liquid-glass__refraction {
  filter: url(#liquid-glass-filter-static);
}

/* ── Liquid Lens upgrade (js/liquid-lens.js) ─────────────────────
   The lens engine sets --lg-lens inline per element (a geometric
   SDF displacement filter built for that element's exact size and
   corner radii). Feed it into the live backdrop path; where the
   engine can't run an SVG filter through backdrop-filter, the rule
   below never applies and the sprite keeps its turbulence filter.
   The sprite path intentionally keeps the old filters: the sprite
   box is inset -36px, so a map built for the element box would
   stretch over the wrong geometry there. */
@supports (backdrop-filter: url("#liquid-glass-filter")) or (-webkit-backdrop-filter: url("#liquid-glass-filter")) {
  .liquid-glass:not(.liquid-glass--simple) {
    -webkit-backdrop-filter: var(--lg-lens, var(--lg-filter)) blur(var(--lg-blur)) saturate(var(--lg-saturate));
            backdrop-filter: var(--lg-lens, var(--lg-filter)) blur(var(--lg-blur)) saturate(var(--lg-saturate));
  }
}

/* ── Per-surface optical values ──────────────────────────────── */

/* Windows — frosted body, 10px Tahoe corners, milky enough for text.
   Blur stays LOW (Apple's glass refracts, it doesn't frost): the
   per-element lens in js/liquid-lens.js needs visible backdrop
   detail to bend — 30px+ of blur would wash the refraction out. */
.window.liquid-glass {
  position: absolute;               /* guard: .liquid-glass sets relative */
  --lg-radius:   var(--win-radius);
  --lg-blur:     14px;
  --lg-saturate: 180%;
  --lg-opacity:  calc(0.62 * var(--lg-amount, 1));
}

/* Dock — the signature Tahoe pill.
   overflow must stay visible: magnified/bouncing icons and tooltips
   intentionally rise above the pill (real-macOS behaviour). The
   refraction sprite is clipped to the pill shape with clip-path
   instead of relying on overflow:hidden. */
/* Dock — the signature Tahoe pill.
   Measured against real Tahoe screenshots: the pill is far more
   transparent than the other surfaces — the wallpaper's hue reads
   straight through it, with only a thin bright rim.  Milkiness stays
   low; saturation stays high. */
#dock.liquid-glass {
  overflow: visible;
  /* radius tracks Apple's kit ratio (15/36 of icon size) */
  --lg-radius:   calc(var(--dock-size) * 0.42);
  --lg-blur:     12px;
  --lg-saturate: 200%;
  --lg-opacity:  calc(0.26 * var(--lg-amount, 1));
  /* the kit's own 0.5px rim replaces the lib border — no double rim */
  --lg-border-opacity: 0;
}
#dock .liquid-glass__refraction {
  clip-path: inset(36px round calc(var(--dock-size) * 0.42 + 36px)); /* = dock box (sprite inset −36px) */
}
/* The library paints its refraction sprite at z-index 2 and its specular
   ::after at z-index 3 — both ABOVE the dock icons (z 1), which drew a
   hard highlight line across magnified icons.  Real macOS keeps the
   glass *behind* the icons, so drop both layers below them here. */
#dock .liquid-glass__refraction,
#dock.liquid-glass::after {
  z-index: 0;
}

/* Menu bar — thin, airy strip.
   It spans the full screen width, so the chromatic side fringes and
   the white top highlight would sit on the screen edges: keep only
   a hairline below.  Light theme uses a milky bar (dark text needs a
   light backing); dark theme stays airy. */
#menubar.liquid-glass {
  --lg-radius:   0px;
  --lg-blur:     10px;
  --lg-saturate: 200%;
  --lg-opacity:  calc(0.30 * var(--lg-amount, 1));
  --lg-border-opacity: 0.16;
  --lg-shadow:   0 1px 8px rgb(0 0 0 / 0.10);
  border-top-color: transparent;
  border-left-color: transparent;
  border-right-color: transparent;
  box-shadow: 0 1px 10px rgb(0 0 0 / 0.14);
}
html[data-theme="dark"] #menubar.liquid-glass { --lg-opacity: calc(0.24 * var(--lg-amount, 1)); }
#menubar.liquid-glass::after {
  box-shadow: inset 0 -1px rgb(255 255 255 / 0.28);
}
html[data-theme="dark"] #menubar.liquid-glass::after {
  box-shadow: inset 0 -1px rgb(255 255 255 / 0.12);
}

/* Blur discipline (HIG-style "glass refracts, it doesn't frost"):
   every lens surface stays at ≤14px of blur so the per-element
   refraction stays visible. Legibility comes from --lg-opacity
   (the milky tint), not from heavy frosting. */

/* Spotlight panel */
.sp-shell.liquid-glass {
  --lg-radius:   18px;
  --lg-blur:     14px;
  --lg-saturate: 180%;
  --lg-opacity:  calc(0.64 * var(--lg-amount, 1));
}

/* Control Center */
#cc.liquid-glass {
  --lg-radius:   18px;
  --lg-blur:     13px;
  --lg-saturate: 180%;
  --lg-opacity:  calc(0.60 * var(--lg-amount, 1));
}

/* Calendar popover */
#cal-pop.liquid-glass {
  --lg-radius:   14px;
  --lg-blur:     13px;
  --lg-saturate: 180%;
  --lg-opacity:  calc(0.62 * var(--lg-amount, 1));
}

/* Context menu + Apple/app menus.
   The refraction sprite (box inset −36px) is clipped with clip-path
   instead of overflow:hidden, so long menus keep their overflow-y:auto
   scroll from shell.css (radius 8 + 36 = 44). */
#ctx.liquid-glass,
.menu-drop.liquid-glass {
  position: absolute;               /* guard: .liquid-glass sets relative */
  --lg-radius:   var(--card-radius);
  --lg-blur:     12px;
  --lg-saturate: 180%;
  --lg-opacity:  calc(0.68 * var(--lg-amount, 1));
}
#ctx .liquid-glass__refraction,
.menu-drop .liquid-glass__refraction {
  clip-path: inset(36px round 44px);
}
#ctx.liquid-glass { position: fixed; }  /* #ctx guard wins */

/* Notifications */
.notif.liquid-glass {
  --lg-radius:   16px;
  --lg-blur:     13px;
  --lg-saturate: 180%;
  --lg-opacity:  calc(0.66 * var(--lg-amount, 1));
}

/* ── App-icon PNGs (real Apple assets) ───────────────────────── */
.app-png {
  width: 100%;
  height: 100%;
  display: block;
}
.dock-preview .dp-ico img {
  width: 100%;
  height: 100%;
  display: block;
}
