/* ============================================================================
   LEGACY→GLASS TOKEN BRIDGE — RUN5 §2.1
   ----------------------------------------------------------------------------
   WHAT: every legacy design token (--bg, --card, --text, --accent, …) is
   redefined here as an alias of the live glass token (--g-*) it corresponds to.

   WHY (v695/v696 findings): ~2000 legacy call sites — the index.html inline
   style block, every js-injected <style> (calendar.js, websites.js, sops.js,
   integrations.js, profile.js…), and sops.css — read legacy tokens whose only
   dark values live in index.html's [data-theme="dark"] block. That block needs
   the attribute stamped, so those surfaces were BLIND to (a) all 12 themes and
   (b) auto-dark (mode "auto" REMOVES data-theme; only glass.css §2's
   @media (prefers-color-scheme: dark) flips anything). Result: white cards and
   invisible text in Ink dark / auto-dark (run4's picker bug, v695's ground
   bug). Aliasing the legacy names to --g-* closes the whole class at once,
   because --g-* already flip per-theme (themes.css) and per-mode (glass.css
   §2/§3) on <html>, and var() resolves at computed-value time down the tree.

   LOAD ORDER (load-bearing — do not move this <link>):
   MUST load AFTER css/themes.css (index.html links it below the themes link,
   ~:5801). Cascade math: the legacy light block (:root, index.html:43) and
   legacy dark block ([data-theme="dark"], index.html:184) are both specificity
   (0,1,0). This file's selector list is also (0,1,0) per selector, so it wins
   over BOTH purely by source order — the inline <style> block precedes the
   stylesheet links. glass.css's own dark block is html[data-theme="dark"]
   (0,1,1) and intentionally outranks us: it sets the --g-* VALUES we point at,
   never the legacy names, so theme/mode flips flow through the aliases.
   The [data-theme="dark"] selector here is belt-and-braces: if any script ever
   stamps data-theme on <body> instead of <html>, the legacy dark block would
   match that subtree — and so do we, still later in order, still winning.

   The legacy definitions at index.html:43-244 stay UNTOUCHED — they are now
   the no-stylesheet fallback if glass/themes/bridge ever fail to load.

   BRIDGE ≠ DONE: this makes legacy surfaces obey the active theme's colors,
   nothing more. Real conversions (§2.2) still replace legacy classes
   surface-by-surface with .glass-2/.g-card/.g-btn/… so structural theme
   traits (Ink borders, Pop ledges, Terra corners, Verde rules) can appear.

   NOT bridged (deliberate):
   - --toast-bg/--toast-text/--toast-error-bg — no g-twin; legacy pair stays.
   - --space-*, --ctl-*, --row-h*, z-ladder, safe-areas, --topbar-h etc. —
     layout, not look; themes must not move layout through the bridge.
   - --radius-pill (999px, universal), --font-mono (no g-twin), font weights,
     type scale — no theme dimension to bridge.
   - literal hexes in legacy CSS (e.g. .crumb-emoji #0b0b0e) — can't bridge a
     hex; filed for the §2.2 sweep.
   ========================================================================= */

:root, [data-theme="dark"] {           /* one block wins over both legacy definitions */
  --bg-grad-1: var(--g-canvas); --bg-grad-2: var(--g-canvas); --bg-grad-3: var(--g-canvas);
  --bg-solid: var(--g-canvas);
  --bg: var(--g-solid-2);      --bg-2: var(--g-fill-sunken);   --card: var(--g-solid-2);
  --glass: var(--g-fill-2);    --glass-strong: var(--g-fill-1); --glass-border: var(--g-hairline);
  --surface: var(--g-fill-sunken); --surface-2: var(--g-solid-sunken); --surface-60: var(--g-fill-2);
  --hairline: var(--g-hairline); --hairline-strong: var(--g-hairline-strong);
  --shadow-sm: var(--g-e1);    --shadow: var(--g-e2);          --shadow-lg: var(--g-e3);
  --accent: var(--g-accent);   --accent-strong: var(--g-accent-strong); --accent-fill: var(--g-accent-fill);
  --accent-soft: var(--g-accent-soft); --accent-softer: var(--g-accent-softer);
  --text: var(--g-text); --text-2: var(--g-text-2); --text-3: var(--g-text-3); --text-4: var(--g-text-4);
  --text-on-accent: var(--g-text-on-accent); --placeholder: var(--g-placeholder);
  /* v736: --text-on-green / --text-on-red were REFERENCED but never DEFINED. sops.css:218/247/404/462
     hedge `var(--text-on-green, var(--g-text-on-green,#fff))`, so the first hop was always dead and the
     value came from the second — harmless, but it reads at the call site as though the alias exists,
     which is how the next person writes `var(--text-on-red)` bare and silently gets #fff on red.
     Completing the set rather than deleting the hop: --text-on-accent already lives here, and these
     three are the app's ink-on-a-solid-status-fill family. ZERO behaviour change — the alias resolves
     to exactly the token the fallback already reached. */
  --text-on-green: var(--g-text-on-green); --text-on-red: var(--g-text-on-red);
  --row-hover: var(--g-fill-hover); --row-selected: var(--g-fill-sel);
  /* ⚠️ READ THIS BEFORE USING ANY `*-bg` BELOW. It has cost SEVEN shipped bugs.
     ---------------------------------------------------------------------------
     `--X-bg` IS NOT A SOLID COLOUR. In most themes it is `rgba(<the same rgb as
     --X>, .12-.18)` — a translucent TINT of its own ink. That is invisible at the
     call site, which is exactly why this keeps happening:
       V721-2  red pair failed on its own tint
       V721-7  green pair, same shape
       V731-F1 `.ppm-svc-res-bad` shipped `color:var(--red-bg)` on `background:var(--red)`
               -> 1.00:1, literally invisible, in 23 of 24 theme/mode combos
       V732-A  the whole accent family (`--accent-soft`/`--accent-softer`/`--row-selected`)
               -> the SELECTED item was often the lowest-contrast thing on screen
       V733-N1 `background:#fff; color:var(--accent)` on the View-as exit — a LITERAL
               plate, no token in sight; 1.00:1 in cobalt, failing in EVERY dark theme
       V733-N2 `--g-slate-bg` was a tint of `--g-slate`; `.tltl-off` failed 24 of 24
       V734-P1 7 sites painting literal `#fff` on `--g-green`/`--g-red`, 13 of 24 each
     THE RULE (derived v733, WIDENED v734, WORDING CORRECTED v738; see css/themes.css):
       SCOPE: **ANY** plate carrying an ink -- token OR HARD-CODED LITERAL. v734 widened it
       because V733-N1 was a bare `#fff` plate with no token involved, and auditing only
       `--X-bg` tokens would never have found it. Audit literals too.
       A cell VIOLATES when EITHER half is true, measured against every enforced ground:
        (1) ORDER -- the INK's luminance lands BETWEEN the plate's and the ground's, or the
            plate sits AT the ink. That is the geometry where source-over drags the composite
            toward the ink, so the pair spends the ink's whole margin before the ground is
            even considered. Corollary: lowering the alpha can NEVER fix it -- at alpha 0 you
            are left with the bare ink's own margin, which in the accent family was 4.50-4.62,
            i.e. nothing.
        (2) CONTRAST -- the COMPOSITED ink-on-plate misses 4.5:1.
       HEALTHY = the ink is an EXTREME, never the middle value: the plate stays on the ground's
       side of it (between ink and ground, or past the ground), AND the pair clears 4.5.
       ⚠️ This rule used to read "the plate must sit on the FAR side of that ink's luminance
       from every enforced ground." That is INVERTED -- it describes clause (1), the FAILURE --
       and every healthy shipped pair breaks it (ink's lime, pink and amber chips all do).
       Do not restore it. The two-clause test above is what the audits have always computed;
       it was re-derived from shipped data in v738 and validated against 6 known-good pairs and
       3 known-bad (V734-P3's same-hue literal, V733-N1's `#fff` plate, plate == ink). It is the
       test the audits run: `.agents/mission/wave-v738/ink-amber-verify.js:279`.
       SEVERITY, so the next sweep does not report a phantom regression: a cell failing (2) is
       BROKEN TODAY -- fix it. A cell failing ONLY (1) is LATENT: readable at the shipped alpha,
       but the composite crosses the ink at some alpha, so any ground or alpha change lands on
       1.00:1. v738's 1152-cell sweep has 12 of these (studio/dark `--g-amber`, contrast
       5.73-7.92) and counted them 0 LIVE violations -- see sweeps/v738-sweep.md:314. File a
       (1)-only cell as watch; never fix it blind.
     SO: `--X-bg` may TINT a surface. It may NEVER be `color:` on an `--X` plate.
     For ink ON a solid status fill use the token built for it: `--g-text-on-red`,
     `--g-text-on-green`, `--g-text-on-accent` (see css/glass.css:157 and the
     `.g-btn--danger` precedent at css/glass.css:1062). If you are about to write
     `color:var(--X-bg)`, you have found bug number five. */
  --green: var(--g-green); --green-bg: var(--g-green-bg); --amber: var(--g-amber); --amber-bg: var(--g-amber-bg);
  --blue: var(--g-blue); --blue-bg: var(--g-blue-bg); --red: var(--g-red); --red-bg: var(--g-red-bg);
  --purple: var(--g-violet); --purple-bg: var(--g-violet-bg); --slate: var(--g-slate); --slate-bg: var(--g-slate-bg);
  /* --orange/--yellow/--gray have NO g-equivalent; per plan note they collapse
     onto the nearest real pair (amber / slate) instead of staying legacy —
     unbridged they'd show LIGHT values in auto-dark, the exact bug class this
     file exists to close. They were already BANNED in new UI (index.html:90). */
  --orange: var(--g-amber); --orange-bg: var(--g-amber-bg);
  --yellow: var(--g-amber); --yellow-bg: var(--g-amber-bg);
  --gray: var(--g-slate);   --gray-bg: var(--g-slate-bg);
  --scrim: var(--g-scrim); --scrim-strong: var(--g-scrim-strong);
  --scroll-thumb: var(--g-scroll-thumb); --scroll-thumb-hover: var(--g-scroll-thumb-hover);
  /* R6-36 (owner-reported): the legacy scale is a SIZE scale (xs<sm<md), but --g-r-xs/sm/md are a
     ROLE/SHAPE scale — in tahoe/halo/aurora they are 999px because those themes make CONTROLS
     pills. v697 aliased them straight across, so "give me a small corner" started meaning "make me
     a pill": 28% of every box became a circle in those 3 themes (vs 4.4% in Ink), Ads Manager cards
     rendered as ellipses with client names 54px outside the card, and chat bubble tails inverted
     into lobes that swallowed the timestamp. v698's tokenization multiplied it ~4x but did NOT
     create it. Capping at the max any NON-pill theme already ships keeps 9 of 12 themes
     byte-identical and only pulls the 3 pill themes back to a real corner. */
  --radius-lg: var(--g-r-lg); --radius: min(var(--g-r-md), 14px); --radius-md: min(var(--g-r-md), 14px);
  --radius-sm: min(var(--g-r-sm), 12px); --radius-xs: min(var(--g-r-xs), 8px);
  --g-r-tail: min(var(--g-r-xs), 6px);   /* a bubble tail is ALWAYS the sharpest corner — never a pill. A corner that carries MEANING (tail/notch/joined edge) must never read a token a theme may set to 999px. */
  --blur: var(--g-blur-2); --blur-modal: var(--g-blur-scrim);
  --font: var(--g-font); --font-display: var(--g-font-display);
}
