/* ==========================================================================
   Layered Glass UI — glass.css
   A material system: page → shell → panel (glow) → card (glass) → well / tray → piece.
   Colors are slots. Change the tokens, keep the recipes.
   MIRROR copy: the house file, unchanged except that the grain is served from /static/glass-grain.svg
   (CSP default-src 'self' forbids inline data URIs). Inter is self-hosted in ds.css.
   ========================================================================== */

/* ---------- 1. Tokens ---------------------------------------------------- */

:root {
  /* Slots — change per project */
  --hero: #f2ec3a;                 /* the one lit surface */
  --glow-1: #e8a227;               /* the hero's light: hero hue, warmer + deeper */
  --glow-2: #ff3b5c;               /* light from a media/image card */
  --glow-3: #3b6bff;
  --accent: #cdf24a;               /* links + the single accent pill */
  --series-1: #5c54e3;
  --series-2: #22c36d;
  --series-3: #fba23f;
  --series-4: #4fb7ee;
  --series-5: #ff5b2b;
  --good: #49d98f;
  --warn: #f6b445;
  --bad: #ff5545;

  /* Neutrals — keep neutral */
  --page: #1f1f20;
  --shell: #19191b;
  --panel: #202022;
  --ink: #121212;                  /* text on bright surfaces */
  --white: #ffffff;
  --text: rgba(255, 255, 255, .96);
  --text-2: rgba(255, 255, 255, .62);
  --text-3: rgba(255, 255, 255, .42);

  /* Glass */
  --glass-hi: rgba(255, 255, 255, .075);
  --glass-lo: rgba(255, 255, 255, .025);
  --glass-ring: rgba(255, 255, 255, .06);
  --glass-edge: rgba(255, 255, 255, .07);
  --glass-blur: 24px;
  --glass-fill: rgba(255, 255, 255, .06);   /* small glass controls */
  --well: rgba(0, 0, 0, .24);
  --tray-ring: rgba(255, 255, 255, .2);
  --hairline: rgba(255, 255, 255, .16);
  --grid-line: rgba(255, 255, 255, .14);

  /* Shape */
  --r-shell: 48px;
  --r-panel: 34px;                 /* = shell radius − shell padding */
  --r-card: 24px;
  --r-well: 16px;
  --r-piece: 12px;
  --r-tray: 20px;
  --tray-pad: 5px;
  --tray-border: 1.5px;

  /* Space */
  --shell-pad: 14px;
  --panel-pad: 28px;
  --card-pad: 24px;
  --gap: 16px;

  /* Type */
  --font: "Inter", "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;

  /* Motion */
  --ease-out: cubic-bezier(.2, .8, .2, 1);
}

/* Hero presets — the whole page re-lights from one attribute */
[data-hero="citrus"] { --hero: #f2ec3a; --glow-1: #e8a227; --accent: #cdf24a; }
[data-hero="ice"]    { --hero: #a9e4ff; --glow-1: #2f7bff; --accent: #9fd8ff; }
[data-hero="coral"]  { --hero: #ff9e80; --glow-1: #ff4f2e; --accent: #ffc2ad; }

/* ---------- 2. Base ------------------------------------------------------ */

.lg-page {
  min-height: 100vh;
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
.lg-page *, .lg-page *::before, .lg-page *::after { box-sizing: border-box; }
/* :where() keeps this reset at zero weight so component colors always win */
:where(.lg-page) :where(button, input, select, textarea) { font: inherit; color: inherit; }
.lg-page :focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.lg-hero :focus-visible { outline-color: var(--ink); }

/* ---------- 3. Shell, rail, panel --------------------------------------- */

.lg-shell {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: var(--shell-pad);
  padding: var(--shell-pad);
  border-radius: var(--r-shell);
  background: var(--shell);
  box-shadow:
    inset 0 0 0 1.5px var(--hairline),
    0 60px 120px -60px rgba(0, 0, 0, .9);
}

.lg-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
}
.lg-rail__group { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.lg-rail__spacer { flex: 1; }
.lg-rail__divider { width: 28px; height: 1px; margin: 6px 0; background: var(--hairline); }

.lg-panel {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-width: 0;
  padding: var(--panel-pad);
  border-radius: var(--r-panel);
  background: var(--panel);
}
/* grain: stops large glows from banding */
.lg-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: .05;
  mix-blend-mode: overlay;
  background-image: url("/static/glass-grain.svg");
}

/* ---------- 4. Light: glow layer ---------------------------------------- */

.lg-glows {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
  border-radius: inherit;
}
.lg-glow {
  position: absolute;
  left: var(--x, 50%);
  top: var(--y, 60%);
  width: var(--w, 60%);
  aspect-ratio: var(--ratio, 1.5);
  translate: -50% -50%;
  border-radius: 50%;
  background: radial-gradient(closest-side, var(--c, var(--glow-1)), transparent);
  opacity: var(--o, .5);
  filter: blur(var(--blur, 90px));
  transition: background .6s ease;
}
.lg-glow--drift { animation: lg-drift var(--drift, 48s) ease-in-out infinite alternate; }
@keyframes lg-drift {
  0%   { transform: translate(0, 0) scale(1); }
  50%  { transform: translate(5%, -4%) scale(1.07); }
  100% { transform: translate(-4%, 3%) scale(.96); }
}

/* ---------- 5. Glass ----------------------------------------------------- */

.lg-card {
  position: relative;
  min-width: 0;
  padding: var(--card-pad);
  border-radius: var(--r-card);
  border: 1px solid var(--glass-ring);
  background: linear-gradient(150deg, var(--glass-hi), var(--glass-lo) 62%);
  box-shadow:
    inset 0 1px 0 var(--glass-edge),
    0 24px 48px -28px rgba(0, 0, 0, .7);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  color: var(--text);
}
.lg-card--interactive { cursor: pointer; transition: border-color .2s, box-shadow .2s; }
.lg-card--interactive:hover {
  border-color: rgba(255, 255, 255, .1);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .12), 0 24px 48px -28px rgba(0, 0, 0, .7);
}

.lg-frost {
  border-radius: calc(var(--r-card) - 8px);
  background: linear-gradient(180deg, rgba(255, 255, 255, .12), rgba(255, 255, 255, .04));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .2), inset 0 0 0 1px rgba(255, 255, 255, .06);
  -webkit-backdrop-filter: blur(22px) saturate(170%);
  backdrop-filter: blur(22px) saturate(170%);
}

/* ---------- 6. Wells, trays, markers ------------------------------------ */

.lg-well {
  position: relative;
  padding: 14px 16px;
  border-radius: var(--r-well);
  background: var(--well);
}
.lg-wells {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.lg-tray {
  display: flex;
  gap: 4px;
  padding: var(--tray-pad);
  border: var(--tray-border) solid var(--tray-ring);
  border-radius: var(--r-tray);
  background: rgba(0, 0, 0, .12);
}
/* concentric: inner = outer − padding − border */
.lg-tray > * { border-radius: calc(var(--r-tray) - var(--tray-pad) - var(--tray-border)); }

/* marker on a well: sits on the left edge */
.lg-marker::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 32%;
  bottom: 32%;
  width: 3px;
  border-radius: 3px;
  background: var(--mk, var(--series-4));
}
/* marker on a stat: colored top half, quiet bottom half */
.lg-stat {
  position: relative;
  padding-left: 14px;
}
.lg-stat::before {
  content: "";
  position: absolute;
  left: 0;
  top: 2px;
  bottom: 2px;
  width: 2px;
  border-radius: 2px;
  background: linear-gradient(var(--mk, var(--series-1)) 0 50%, rgba(255, 255, 255, .22) 50% 100%);
}

/* ---------- 7. Controls -------------------------------------------------- */

.lg-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: filter .15s, background-color .15s, box-shadow .15s;
}
.lg-pill:hover { filter: brightness(1.06); }
.lg-pill:active { filter: brightness(.92); }
.lg-pill--primary { background: var(--white); color: var(--ink); }
.lg-pill--accent { background: var(--accent); color: var(--ink); font-weight: 600; }
.lg-pill--outline {
  background: rgba(0, 0, 0, .18);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18);
}
.lg-pill--outline:hover { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .28); filter: none; }
.lg-pill--block { width: 100%; border-radius: var(--r-well); }

.lg-icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--glass-fill);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06);
  color: var(--text);
  cursor: pointer;
  transition: background-color .15s;
}
.lg-icon-btn:hover { background: rgba(255, 255, 255, .1); }
.lg-icon-btn--ring {
  width: 48px;
  height: 48px;
  background: transparent;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .16);
}
.lg-icon-btn--ring:hover { background: rgba(255, 255, 255, .05); }
.lg-icon-btn[aria-current="page"] { background: var(--white); color: var(--ink); box-shadow: none; }
.lg-icon-btn svg { width: 20px; height: 20px; }

.lg-search {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  background: var(--glass-fill);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06);
  color: var(--text-2);
}
.lg-search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}
.lg-search input::placeholder { color: var(--text-3); }
.lg-search:focus-within { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .22); }

.lg-toggle {
  display: inline-flex;
  gap: 2px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .05);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
}
.lg-toggle button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.lg-toggle button[aria-pressed="true"] { background: rgba(255, 255, 255, .12); color: var(--text); }

.lg-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  font-weight: 500;
  text-decoration: none;
}
.lg-link:hover { text-decoration: underline; text-underline-offset: 3px; }

.lg-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .06);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.lg-dot {
  display: inline-block;
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--dot, var(--series-1));
}

/* ---------- 8. Type ------------------------------------------------------ */

.lg-title { margin: 0; font-size: 24px; font-weight: 600; letter-spacing: -.01em; line-height: 1.2; }
.lg-subtitle { margin: 4px 0 0; color: var(--text-2); font-size: 15px; }
.lg-card-title { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -.005em; line-height: 1.3; }
.lg-label { margin: 0; color: var(--text-2); font-size: 13px; }
.lg-muted { color: var(--text-2); }
.lg-num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  letter-spacing: -.02em;
}
.lg-num--hero { font-size: clamp(30px, 2.5vw, 40px); font-weight: 600; line-height: 1.05; }
.lg-num--stat { font-size: 22px; font-weight: 600; line-height: 1.15; }
.lg-num--row  { font-size: 17px; font-weight: 600; }
.lg-unit { color: var(--text-2); font-weight: 400; letter-spacing: 0; }
.lg-delta { display: inline-flex; align-items: center; gap: 2px; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.lg-delta--good { color: var(--good); }
.lg-delta--bad { color: var(--bad); }

/* ---------- 9. Hero surface --------------------------------------------- */

.lg-hero {
  --hero-ink: var(--ink);
  --hero-ink-2: color-mix(in oklab, var(--ink) 58%, var(--hero));
  --hero-ring: color-mix(in oklab, var(--hero) 84%, #000);
  --hero-raised: color-mix(in oklab, var(--hero) 68%, #fff);
  --hero-sunk: color-mix(in oklab, var(--hero) 92%, #000);
  --hero-pad: 14px;
  position: relative;
  min-width: 0;
  padding: var(--hero-pad);
  border-radius: var(--r-card);
  background: var(--hero);
  color: var(--hero-ink);
  box-shadow: 0 40px 90px -50px color-mix(in oklab, var(--glow-1) 80%, transparent);
  transition: background-color .6s ease;
}
.lg-hero .lg-muted, .lg-hero .lg-label, .lg-hero .lg-subtitle, .lg-hero .lg-unit { color: var(--hero-ink-2); }
.lg-hero__frame {
  padding: 22px 16px 16px;
  border-radius: calc(var(--r-card) - var(--hero-pad) + 4px);
  box-shadow: inset 0 0 0 1px var(--hero-ring);
}
.lg-tile {
  padding: 18px 20px;
  border-radius: var(--r-well);
}
.lg-tile--raised { background: var(--hero-raised); }
.lg-tile--sunk { background: var(--hero-sunk); }
.lg-hero .lg-toggle {
  background: color-mix(in oklab, var(--hero) 78%, #fff);
  box-shadow: inset 0 0 0 1px var(--hero-ring);
}
.lg-hero .lg-toggle button { color: var(--hero-ink-2); }
.lg-hero .lg-toggle button[aria-pressed="true"] {
  background: color-mix(in oklab, var(--hero) 30%, #fff);
  color: var(--hero-ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}

/* ---------- 10. Data marks ---------------------------------------------- */

.lg-hatch {
  background-image: repeating-linear-gradient(135deg, var(--hatch, currentColor) 0 2px, transparent 2px 7px);
}

/* Legend swatches */
.lg-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: currentColor;
}
.lg-swatch--hatch {
  background: repeating-linear-gradient(135deg, currentColor 0 1.5px, transparent 1.5px 3.5px);
  box-shadow: inset 0 0 0 1px currentColor;
}

/* Diverging columns: positive above zero (solid), negative below (hatched) */
.lg-diverge {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  column-gap: 14px;
  row-gap: 10px;
  height: 100%;
  min-height: 240px;
  color: var(--hero-ink, var(--text));
}
.lg-diverge__y {
  position: relative;
  min-width: 34px;
  font-size: 12px;
  color: var(--hero-ink-2, var(--text-3));
  font-variant-numeric: tabular-nums;
}
.lg-diverge__y span { position: absolute; right: 0; translate: 0 -50%; white-space: nowrap; }
.lg-diverge__plot { position: relative; }
.lg-diverge__grid {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  border-top: 1px dashed color-mix(in oklab, currentColor 28%, transparent);
}
.lg-diverge__grid--zero { border-top-style: solid; border-top-color: color-mix(in oklab, currentColor 45%, transparent); }
.lg-diverge__cols {
  position: absolute;
  inset: 0;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 6px;
}
.lg-diverge__col { display: grid; grid-template-rows: 1fr 1fr; min-width: 0; }
.lg-diverge__up, .lg-diverge__down { display: flex; min-height: 0; }
.lg-diverge__up { align-items: flex-end; }
.lg-diverge__down { align-items: flex-start; }
.lg-diverge__pos {
  width: 100%;
  height: calc(var(--v) * 100%);
  border-radius: 14px 14px 0 0;
  background: currentColor;
}
.lg-diverge__neg {
  width: 100%;
  height: calc(var(--v) * 100%);
  border-radius: 0 0 14px 14px;
  background-image: repeating-linear-gradient(135deg, currentColor 0 2px, transparent 2px 6.5px);
}
.lg-diverge__x {
  grid-column: 2;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 6px;
  font-size: 12px;
  color: var(--hero-ink-2, var(--text-3));
  text-align: center;
}

/* Tank gauges: fill rises from the bottom; remainder is hatched */
.lg-tanks { height: 200px; }
.lg-tank {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  background-color: color-mix(in oklab, var(--c) 26%, #0c0c0f);
  background-image: repeating-linear-gradient(135deg, color-mix(in oklab, var(--c) 52%, #0c0c0f) 0 2.5px, transparent 2.5px 9px);
}
.lg-tank__fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  height: calc(var(--fill) * 100%);
  padding: 12px 14px;
  border-radius: inherit;
  background: var(--c);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  text-shadow: 0 1px 1px rgba(0, 0, 0, .15);
}

/* Segmented bar */
.lg-segbar { height: 64px; }
.lg-seg { flex: var(--v) 1 0; min-width: 10px; background: var(--c); }

/* Legend list */
.lg-legend { margin: 0; padding: 0; list-style: none; display: grid; gap: 14px; }
.lg-legend li { display: flex; align-items: center; gap: 12px; }
.lg-legend .lg-legend__value { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- 11. Media card ---------------------------------------------- */

.lg-media {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: 380px;
  border-radius: var(--r-card);
  background: #0b0b0e;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 24px 48px -28px rgba(0, 0, 0, .7);
}
.lg-media { container-type: inline-size; }
.lg-media__art { position: absolute; inset: 0; z-index: -1; }
.lg-media__art svg { width: 100%; height: 100%; display: block; }
/* frosted strip: nested 8px inside the card, concentric corners (from .lg-frost) */
.lg-media__strip {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 18px 20px;
}
@container (max-width: 460px) {
  .lg-media__strip { flex-direction: column; align-items: flex-start; gap: 14px; }
}
/* small frosted chip floating on the art */
.lg-media__chip {
  position: absolute;
  top: 12px;
  left: 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
}

/* ---------- 12. Layout --------------------------------------------------- */

.lg-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px 24px;
  margin-bottom: 26px;
}
.lg-header > :first-child { flex: 1 1 320px; min-width: 0; }
.lg-header__actions { display: flex; align-items: center; gap: 12px; flex: 0 1 auto; min-width: 0; }
.lg-header__actions .lg-search { flex: 0 1 340px; min-width: 180px; }

.lg-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--gap);
}
.lg-span-3 { grid-column: span 3; }
.lg-span-4 { grid-column: span 4; }
.lg-span-6 { grid-column: span 6; }
.lg-span-8 { grid-column: span 8; }
.lg-span-9 { grid-column: span 9; }
.lg-span-12 { grid-column: span 12; }

@media (max-width: 1180px) {
  .lg-span-3, .lg-span-9 { grid-column: span 12; }
  .lg-span-4 { grid-column: span 6; }
  .lg-span-4:last-child { grid-column: span 12; }
}

@media (max-width: 720px) {
  :root { --panel-pad: 16px; --card-pad: 18px; }
  .lg-shell {
    grid-template-columns: minmax(0, 1fr);
    padding: 0;
    gap: 12px;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }
  /* phone: rail becomes a top row with logo, main nav and avatar only */
  .lg-rail { flex-direction: row; justify-content: flex-start; gap: 8px; padding: 4px 4px 0; }
  .lg-rail > * { flex: none; }
  .lg-rail__group { flex-direction: row; gap: 8px; }
  .lg-rail__group--secondary, .lg-rail__divider { display: none; }
  .lg-rail__spacer { flex: 1 1 auto; min-width: 0; }
  .lg-rail .lg-icon-btn--ring { width: 42px; height: 42px; }
  .lg-panel { border-radius: var(--r-card); }
  .lg-span-3, .lg-span-4, .lg-span-6, .lg-span-8, .lg-span-9, .lg-span-4:last-child { grid-column: span 12; }
  .lg-header__actions { width: 100%; flex-wrap: wrap; }
  .lg-header__actions .lg-search { flex: 1 1 100%; }
}

/* ---------- 13. Motion --------------------------------------------------- */

.lg-grow { animation: lg-grow .55s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 35ms); }
.lg-grow--up { transform-origin: 50% 100%; }
.lg-grow--down { transform-origin: 50% 0%; }
@keyframes lg-grow { from { transform: scaleY(0); } }

@media (prefers-reduced-motion: reduce) {
  .lg-page *, .lg-page *::before, .lg-page *::after {
    animation: none !important;
    transition: none !important;
  }
}
