/* tokens.css — the design system's foundation: type, space, shape, motion, z, derived
   roles + the generated palette hexes. AUTHORED (palettes.css is generated — see tools/).

   Cascade layers are declared here once, in priority order; every system sheet writes into
   one of them, so any UNLAYERED consumer rule beats the whole system by design. This is the
   lift-into-another-project guarantee — override anything without a specificity war.

   Consumer contract: <link tokens.css> + <link components.css> + <script ui.js> (+ sync
   boot.js in <head>, + palettes.js for chip data). Fonts come from Google Fonts and degrade
   to the system stack when the network is unavailable (e.g. opened over file://). */
@layer sg.tokens, sg.layout, sg.components, sg.anim;

@import "palettes.css" layer(sg.tokens);

@layer sg.tokens {
  :root {
    /* ---- type ---- */
    --font-display: 'Bricolage Grotesque', 'Segoe UI', system-ui, sans-serif;
    --font-body: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, monospace;
    --font-eyebrow: var(--font-mono);
    --display-weight: 700;
    --display-tracking: -0.02em;
    --text-xs: 0.75rem;
    --text-sm: 0.85rem;
    --text-base: 1rem;
    --text-md: 1.05rem;
    --text-lg: 1.18rem;
    --text-xl: 1.4rem;
    --text-2xl: 1.85rem;
    --text-3xl: 2.4rem;
    --fs-display: clamp(2.3rem, 6vw, 3.8rem);
    --leading: 1.55;

    /* ---- space (8px base) ---- */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-7: 32px;
    --space-8: 40px;
    --space-9: 48px;
    --space-10: 64px;
    --space-11: 80px;
    --space-12: 96px;

    /* ---- shape ---- */
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --radius-pill: 999px;
    --gutter: clamp(16px, 4vw, 40px);
    --maxw: 1120px;
    --measure: 68ch;

    /* ---- motion (consumed by animations.css + ui.js) ---- */
    --dur-fast: 120ms;
    --dur: 200ms;
    --dur-slow: 320ms;
    --ease-out: cubic-bezier(0.2, 0.7, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

    /* ---- z-index scale ---- */
    --z-nav: 50;
    --nav-h: 64px;   /* sticky nav height — sidebar offset + scroll-padding derive from it */
    --z-menu: 60;
    --z-modal: 100;
    --z-toast: 120;
    --z-bar: 40;      /* sticky now-playing bar / floating pill — under the nav, over page content */

    /* ---- media (overlay text on posters, video and art is always light-on-scrim: media is dark in every theme) ---- */
    --media-ink: #fff;
    --media-bg: #0b0f14;
    --media-scrim: linear-gradient(to top, rgba(8, 11, 16, 0.82), rgba(8, 11, 16, 0.38) 55%, rgba(8, 11, 16, 0));
    /* accent on media: the palette accent lifted for the always-dark media surface (a light theme's dark accent
       is ~1:1 on it); the @supports rule below keeps the hue and floors OKLCH lightness instead of whitening */
    --media-accent: color-mix(in srgb, var(--accent) 45%, var(--media-ink));
    --dur-loop: 1.4s;   /* looping decorative motion (skeleton shimmer, equalizer) — zeroed under reduced motion */

    /* ---- derived roles (reference palette role vars so they follow the theme) ---- */
    --ring: var(--accent);
    --link: var(--accent-2);
    --eyebrow-ink: var(--accent-2);
    --nav-bg: color-mix(in srgb, var(--bg) 82%, transparent);
    --band-bg: var(--bg);
    /* tints mix in oklch: an sRGB mix of a complementary secondary into the bg cancels to grey.
       --tint-base-* is the grey end of each mix (a theme can hue-anchor it — see Vivid neutral below) */
    --tint-base-bg: var(--bg);
    --tint-base-surface: var(--surface);
    --tint-base-surface-2: var(--surface-2);
    /* the hero's and tint band's own grey ends: default to the bg base (a theme can lift them in L) */
    --hero-base-bg: var(--tint-base-bg);
    --band-tint-base-bg: var(--tint-base-bg);
    --footer-bg: color-mix(in oklch, var(--secondary) var(--footer-tint-pct), var(--tint-base-surface-2));
    --hero-bg: linear-gradient(135deg, color-mix(in oklch, var(--accent) var(--hero-accent-pct), var(--hero-base-bg)), color-mix(in oklch, var(--secondary) var(--hero-secondary-pct), var(--hero-base-bg)));
    --band-tint-bg: color-mix(in oklch, var(--secondary) var(--band-tint-pct), var(--band-tint-base-bg));
    --table-head-bg: color-mix(in oklch, var(--secondary) var(--table-head-tint-pct), var(--tint-base-surface-2));
    --sidebar-bg: color-mix(in oklch, var(--secondary) var(--sidebar-tint-pct), var(--tint-base-surface));
    --brand-mark-bg: var(--accent);
    --brand-mark-ink: var(--accent-ink);
  }

  /* ---- elevation + tint strength — theme-scoped (structure, not palette) ----
     light keeps the hero gradient faint (a 16% mix pulls muted hero text under 3:1); darks take it stronger.
     Every .eyebrow's OKLCH lightness is clamped into [l-min, l-max] (components.css) so it clears
     4.5:1 on bg, tint bands and both hero stops: capped dark on light, floored light on the darks. */
  :root {
    --shadow-1: 0 1px 2px rgba(14, 21, 36, 0.06), 0 4px 14px rgba(14, 21, 36, 0.06);
    --shadow-2: 0 10px 30px rgba(14, 21, 36, 0.14), 0 2px 6px rgba(14, 21, 36, 0.08);
    --shadow-3: 0 24px 60px rgba(14, 21, 36, 0.18), 0 6px 18px rgba(14, 21, 36, 0.1);
    --hero-accent-pct: 7%;
    --hero-secondary-pct: 6%;
    --eyebrow-l-min: 0;
    --eyebrow-l-max: 0.5;
    --band-tint-pct: 9%;
    --footer-tint-pct: 8%;
    --table-head-tint-pct: 7%;
    --sidebar-tint-pct: 5%;
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.45);
      --shadow-2: 0 16px 40px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.5);
      --shadow-3: 0 28px 70px rgba(0, 0, 0, 0.6), 0 8px 22px rgba(0, 0, 0, 0.55);
      --hero-accent-pct: 16%;
      --hero-secondary-pct: 14%;
      --eyebrow-l-min: 0.74;
      --eyebrow-l-max: 1;
      --band-divider-lift: 6%;
    }
  }
  :root[data-theme="dark"],
  :root[data-theme="dark-vivid"],
  :root[data-theme="dark-vivid-neutral"] {
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.45);
    --shadow-2: 0 16px 40px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.5);
    --shadow-3: 0 28px 70px rgba(0, 0, 0, 0.6), 0 8px 22px rgba(0, 0, 0, 0.55);
    --hero-accent-pct: 16%;
    --hero-secondary-pct: 14%;
    --eyebrow-l-min: 0.74;
    --eyebrow-l-max: 1;
    --band-divider-lift: 6%;
  }
  /* Vivid neutral keeps its big surfaces GREY (OKLCH C ≲ 0.006, never brown): colour comes from accents,
     stats, card icons and the CTA, not from tinted bands/footer/hero — hence the near-zero strengths. */
  :root[data-theme="dark-vivid-neutral"] {
    --hero-accent-pct: 1.5%;
    --hero-secondary-pct: 0%;
    --band-tint-pct: 1.5%;
    --footer-tint-pct: 1%;
    --table-head-tint-pct: 1%;
    --sidebar-tint-pct: 0%;
  }
  /* Chrome treats the near-grey neutral bases' hue as powerless, so even a 2% mix took the secondary's
     whole hue (juniper's charcoal bands went plum). Re-stating the base through relative colour pins
     its own hue — the palette's grey lean (warm stone or cool slate, set in synth.js) — so the tint
     only nudges chroma and every band/footer/hero stays on that grey. */
  @supports (color: oklch(from red l c h)) {
    :root { --media-accent: oklch(from var(--accent) max(l, 0.78) c h); }
  }
  @supports (color: oklch(from red l c h)) {
    :root[data-theme="dark-vivid-neutral"] {
      --tint-base-bg: oklch(from var(--bg) l c h);
      --tint-base-surface: oklch(from var(--surface) l c h);
      --tint-base-surface-2: oklch(from var(--surface-2) l c h);
      /* with near-zero tints the hero, tint band and page were one flat plane: separate them by LIGHTNESS —
         a white mix lifts L (4% ≈ +0.03 hero, 1.6% ≈ +0.012 tint band) while white's powerless hue leaves the
         pinned grey hue alone and only thins chroma. Tuned on the 8-bit lattice: band 2–2.6%, or any hero
         secondary tint (hence 0% above), rounds ember/olive/moss/fieldstone onto h49 — the brown 30–65° zone */
      --hero-base-bg: color-mix(in oklch, #ffffff 4%, var(--tint-base-bg));
      --band-tint-base-bg: color-mix(in oklch, #ffffff 1.6%, var(--tint-base-bg));
    }
  }
}
