/* Veilstring UI system: design tokens.
   Every value the screens use lives here, on `.vui` (the UI root). Player options change a handful of inputs
   (--ts text scale, --us UI scale, --hs HUD scale, --ho HUD opacity, data-contrast, data-palette, data-motion, data-distance)
   and everything else is derived from them, so one switch restyles every screen.
   The root sits inside a size container named `vui` (the viewport in the game, the device screen in the lookbook):
   cqi / cqb units and @container queries measure that box, never the browser window. */

.vui-host { container: vui / size; position: relative; overflow: hidden; }

.vui {
  /* ---- inputs (player options) ---- */
  --ts: 1;      /* text scale: 1 .. 2 (Large text sets 1.25; the slider reaches 200%) */
  --us: 1;      /* UI scale: .85 .. 1.3, sizes and spacing of menus */
  --hs: 1;      /* HUD scale: .75 .. 1.4 */
  --ho: .92;    /* HUD opacity: .5 .. 1 (text inside HUD plates never drops below its own floor) */
  --hk: var(--hs);
  --lum: .35;   /* backdrop luminance, 0..1, measured from the live 3D frame (backdrop.js); raises the glass when the Field is bright */
  --sat: 0px; --sab: 0px; --sal: 0px; --sar: 0px;   /* safe-area insets (env() in the game, per-device in the lookbook) */

  /* ---- colour: ink and cream ---- */
  --ink: #07051a; --ink-2: #0e0b26; --ink-3: #18143a;
  --cream: #fff4e0;
  --text: var(--cream);
  --text-2: rgba(255, 244, 224, .80);   /* secondary copy: >= 7:1 on glass-2 over ink */
  --text-3: rgba(255, 244, 224, .72);   /* captions, eyebrows: >= 4.5:1 on glass-2 */
  --line: rgba(255, 244, 224, .18);
  --line-2: rgba(255, 244, 224, .32);

  /* brand accents (the Dawn sun and the Dusk veil) */
  --gold: #ffb35c; --rose: #ff6f9a; --violet: #9d86ff; --cyan: #45d8ff;
  --accent: var(--gold); --on-accent: #1a0f02;

  /* semantic: each pairs a colour with an icon or word, never colour alone */
  --ok: #5ee6a8; --warn: #ffc46b; --danger: #ff7a7a; --info: #8cc4ff;
  --hp: #5ee6a8; --shield: #fff4e0; --xp: #c4b5ff; --credits: #ffd27a; --salvage: #9fe8ff;

  /* teams: the hue AND a shape (Dawn = disc, Dusk = diamond) AND, on bars, a pattern (Dusk is hatched) */
  --dawn: #ffb35c; --dawn-2: #ff8fb0; --dusk: #b3a3ff; --dusk-2: #45d8ff;
  --ally: var(--dawn); --foe: var(--dusk); --me: var(--cream);

  /* ---- glass: three levels, each an ink plate whose alpha rises with the backdrop's brightness ---- */
  --glass-a1: calc(.50 + var(--lum) * .26);
  --glass-a2: calc(.66 + var(--lum) * .22);
  --glass-a3: calc(.82 + var(--lum) * .12);
  --glass-1: rgb(7 5 26 / var(--glass-a1));
  --glass-2: rgb(10 8 32 / var(--glass-a2));
  --glass-3: rgb(10 8 32 / var(--glass-a3));
  --blur-1: blur(10px) saturate(1.2);
  --blur-2: blur(16px) saturate(1.25);
  --blur-3: blur(24px) saturate(1.3);
  /* text over open 3D (titles on the scene, HUD numbers): a two-step shadow that works on bright nebulae */
  --halo: 0 1px 2px rgba(7, 5, 26, .9), 0 0 12px rgba(7, 5, 26, .75), 0 0 28px rgba(7, 5, 26, .5);
  /* edge scrims: a soft darkening only where UI docks, so the middle of the Field stays untouched */
  --scrim-k: calc(.45 + var(--lum) * .35);

  /* ---- elevation ---- */
  --e1: 0 1px 0 rgba(255, 244, 224, .06) inset, 0 6px 18px rgba(0, 0, 0, .28);
  --e2: 0 1px 0 rgba(255, 244, 224, .08) inset, 0 14px 36px rgba(0, 0, 0, .38);
  --e3: 0 1px 0 rgba(255, 244, 224, .10) inset, 0 24px 64px rgba(0, 0, 0, .5);

  /* ---- type: Instrument Serif for display, Manrope for everything read at speed ---- */
  --serif: 'Instrument Serif', Georgia, serif;
  --sans: 'Manrope', 'Segoe UI', system-ui, sans-serif;
  --mono: 'Manrope', system-ui, sans-serif; /* figures use tabular-nums, not a second family */
  --k: calc(var(--ts) * var(--us));
  --fs-xs: calc(clamp(12px, 11px + .25cqi, 13px) * var(--k));       /* eyebrows, keycaps: never under 12 px */
  --fs-sm: calc(clamp(13px, 12px + .3cqi, 15px) * var(--k));        /* captions, secondary */
  --fs-md: calc(clamp(15px, 13.5px + .35cqi, 17px) * var(--k));     /* body, buttons */
  --fs-lg: calc(clamp(17px, 15px + .5cqi, 21px) * var(--k));        /* panel titles */
  /* display sizes are already large: they follow Text size to 130%, body text goes to 200% */
  --kd: calc(min(var(--ts), 1.3) * var(--us));
  --fs-xl: calc(clamp(24px, 19px + 1.2cqi, 34px) * var(--kd));       /* screen titles (serif) */
  --fs-2xl: calc(clamp(34px, 24px + 3cqi, 64px) * var(--kd));        /* names, results (serif) */
  --fs-3xl: calc(clamp(46px, 28px + 5.5cqi, 104px) * var(--kd));     /* brand, Victory (serif) */
  --lh-tight: 1.05; --lh: 1.45; --lh-read: 1.6;
  --track-eyebrow: .16em;

  /* ---- space: a 4 px grid that breathes with the container ---- */
  --s1: calc(4px * var(--us)); --s2: calc(8px * var(--us)); --s3: calc(12px * var(--us)); --s4: calc(16px * var(--us));
  --s5: calc(clamp(20px, 16px + 1cqi, 28px) * var(--us)); --s6: calc(clamp(24px, 18px + 1.6cqi, 40px) * var(--us)); --s7: calc(clamp(32px, 22px + 2.6cqi, 64px) * var(--us));
  --edge: max(var(--s4), calc(12px + 1.2cqi));     /* gutter from the screen edge before safe areas */
  --pt: calc(var(--edge) * .75 + var(--sat)); --pb: calc(var(--edge) * .75 + var(--sab));
  --pl: calc(var(--edge) + var(--sal)); --pr: calc(var(--edge) + var(--sar));

  /* ---- size ---- */
  --tap: max(44px, calc(44px * var(--us)));         /* the smallest thing a finger presses */
  --tap-lg: max(52px, calc(56px * var(--us)));
  --r-sm: 8px; --r-md: 12px; --r-lg: 18px; --r-xl: 26px; --r-pill: 999px;
  --rail: clamp(280px, 26cqi, 380px);              /* a docked side panel */

  /* ---- focus: a cream ring with an ink halo, visible on any Field and on any accent ---- */
  --focus: var(--cream);
  --focus-ring: 0 0 0 2px var(--ink), 0 0 0 5px var(--focus), 0 0 0 8px rgba(7, 5, 26, .7);

  /* ---- motion ---- */
  --t-fast: 120ms; --t-med: 220ms; --t-slow: 420ms; --t-scene: 900ms;
  --ease: cubic-bezier(.2, .8, .2, 1); --ease-in: cubic-bezier(.4, 0, 1, 1);

  font-family: var(--sans); font-size: var(--fs-md); line-height: var(--lh); color: var(--text);
  -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums;
}

/* ---- couch / TV distance: everything one and a half times larger, focus rings heavier ---- */
.vui[data-distance="tv"] { --us: 1.45; --focus-ring: 0 0 0 3px var(--ink), 0 0 0 7px var(--focus), 0 0 0 11px rgba(7, 5, 26, .7); }

/* ---- high contrast: solid plates, 2 px borders, no translucent text ---- */
.vui[data-contrast="high"] {
  --text-2: #fff4e0; --text-3: #f2e6d0; --line: rgba(255, 244, 224, .7); --line-2: #fff4e0;
  --glass-1: rgb(4 3 16 / .9); --glass-2: rgb(4 3 16 / .94); --glass-3: rgb(4 3 16 / .97);
  --blur-1: none; --blur-2: none; --blur-3: none;
  --dusk: #c9bdff; --ok: #7dffc0; --danger: #ff9a9a; --warn: #ffd27a;
}

/* ---- colour-vision palettes: team hues move to pairs each type can tell apart; shapes and patterns stay ---- */
.vui[data-palette="deuteranopia"], .vui[data-palette="protanopia"] {
  --dawn: #ffb000; --dawn-2: #ffd27a; --dusk: #5aa9ff; --dusk-2: #9fd0ff; --hp: #f2e9d6; --ok: #6ec3ff; --danger: #ff9f1c;
}
.vui[data-palette="protanopia"] { --dawn: #ffc21a; --danger: #ffb000; }
.vui[data-palette="tritanopia"] {
  --dawn: #ff6b8a; --dawn-2: #ffa3b5; --dusk: #2ee6d6; --dusk-2: #9ff5ec; --gold: #ff8a6b; --accent: #ff8a6b; --hp: #2ee6d6; --warn: #ff9a8a; --credits: #ffb3a3;
}

/* ---- reduced motion: no camera drift, no slides; state changes are cross-fades or instant ---- */
.vui[data-motion="reduced"] { --t-fast: 1ms; --t-med: 1ms; --t-slow: 1ms; --t-scene: 1ms; }
@media (prefers-reduced-motion: reduce) { .vui:not([data-motion="full"]) { --t-fast: 1ms; --t-med: 1ms; --t-slow: 1ms; --t-scene: 1ms; } }
