/* ENKI-TOKENS-20260807 — the single declaration of every size, colour and rhythm.
 * TOKENS-V2-20261010 (HUD polish pass): the :root block now carries every role the live modules reference
 * (colour roles with rgb triplets, a type scale with a 10.5px floor, radii, the z ladder, motion durations and
 * easings that collapse under Performance = LIGHT and prefers-reduced-motion, one sans stack with fallbacks)
 * and the theme.css-era names as aliases. Status colours take the value the fleet uses most (ok #3ddc97,
 * warn #ffc857, bad #ff5d5d). The primitives below are unchanged.
 * Sir 7 Aug: "optimize everything perfectly responsive good sizes explainable buttons".
 *
 * THE RULE: no component may hardcode a value that exists here. If a size is not in this
 * file, it is not a size — it is an opinion, and opinions are why panels drift.
 *
 * Loaded FIRST, before any module. Additive only: it declares tokens and a small set of
 * shared primitives (.enki-cards, .enki-btn, focus rings). It overrides nothing that
 * already exists, so it cannot break the current HUD.
 */

:root {
  /* ---- SPACING · 4px base scale ------------------------------------------------ */
  --s0: 2px;  --s1: 4px;  --s2: 8px;   --s3: 12px;
  --s4: 16px; --s5: 24px; --s6: 32px;  --s7: 48px;

  /* ---- TYPE · one scale, 10.5px floor (TOKENS-V2-20261010: was 9.5px; the 8 Oct audit
     counted 208 declarations under 10px in live modules - unreadable on phones) ----------
     MICRO IS ONLY EVER A LABEL. It never carries content Sir has to read. */
  --fs-micro: 10.5px;  --ls-wide: .13em;
  --fs-small: 11px;    --fs-sm:   12px;
  --fs-body:  12.5px;  --fs-md:   13px;
  --fs-lead:  14px;    --fs-lg:   16px;
  --fs-value: 18px;    --fs-xl:   20px;
  --fs-title: 22px;    --fs-2xl:  26px;
  --lh-tight: 1.25;
  --lh-body:  1.6;
  /* one sans stack with real fallbacks: the shell's bare "Segoe UI" fell to the browser serif on
     every non-Windows device (232 declarations in 31 live files on 8 Oct) */
  --font-sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
  --font: var(--font-sans);
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, "JetBrains Mono", monospace;
  --mono: var(--font-mono);

  /* ---- COLOUR · semantic, never decorative -------------------------------------
     The live values as of 10 Oct (next/index.html :root + this file) with the roles the modules
     actually use. Status colours take the value the fleet already uses most (ok #3ddc97 27x/7 files,
     warn #ffc857 69x/22 files, bad #ff5d5d 24x/7 files) so one token replaces the literal exactly.
     GOLD IS RESERVED: it costs money, needs approval, or reaches Sir. Nothing else. */
  --bg0:    #01070d;   --bg1: #031824;   --bg2: #06283a;   --solid: #062030;
  --bg:     #04090f;
  --panel:   rgba(8, 20, 30, .42);
  --panel-2: rgba(10, 26, 38, .60);
  --panel2:  rgba(8, 32, 46, .78);
  --line:    rgba(120, 200, 210, .17);
  --line-hi: rgba(120, 200, 210, .36);
  --line2:   rgba(75, 232, 255, .32);

  --txt:   #cfeef4;  --txt-rgb: 207, 238, 244;
  --text:  #d8eef2;
  --dim:   #7fb2ba;
  --faint: #6d939b;        /* lifted from #5c7f86 — the old value failed contrast on panel */
  --txt-quiet: rgba(207, 238, 244, .58);   /* 4.5:1 on a panel: the floor for a readable quiet label */
  --txt-ghost: rgba(207, 238, 244, .42);   /* decoration only, never a label Sir must read */

  --acc:      #4be8ff;  --acc-rgb:      75, 232, 255;  --accg: rgba(75, 232, 255, .15);
  --acc2:     #0fd9b4;  --acc2-rgb:     15, 217, 180;
  --accent:   #19e3c2;  --accent-rgb:   25, 227, 194;
  --acc-soft: #8fd3ff;  --acc-soft-rgb: 143, 211, 255;
  --gold:     #d9b45b;  --gold-rgb:     217, 180, 91;
  --gated:    #c9a05a;  --gated-rgb:    201, 160, 90;
  --gold-soft:#e7c66b;
  --vio:      #b58cff;
  --vio2:     #8b6cf0;  --vio2-rgb:     139, 108, 240;

  --ok:      #3ddc97;   --ok-rgb:   61, 220, 151;
  --warn:    #ffc857;   --warn-rgb: 255, 200, 87;
  --bad:     #ff5d5d;   --bad-rgb:  255, 93, 93;
  --idle:    #6b7f95;
  --unknown: #5c7f86;
  --ink-rgb: 0, 0, 0;   --paper-rgb: 255, 255, 255;

  /* legacy theme.css names (theme.js era) - same palette, so a legacy module that is switched on
     renders in the live colours instead of its own */
  --jt: #19e3c2; --jc: #5ff4ff; --jg: #e7c66b; --jtxt: #cfeef2; --jdim: #5f86a0;
  --blue: #2f7bff; --blue2: #143a86; --gold2: #f4d97f; --blk: #05070e; --blk2: #0a1020; --jb2: rgba(25, 227, 194, .2);

  /* ---- CONTROLS · the fix for "weirdly stretched" ------------------------------
     NO CARD GRID MAY USE 1fr WITHOUT A MAX. --card-max is that max. */
  --ctl-h:    34px;
  --ctl-h-sm: 28px;
  --ctl-h-lg: 42px;
  --touch:    44px;        /* minimum target at compact size — never smaller */
  --r-xs: 4px; --r-sm: 6px; --r-md: 8px; --r-lg: 10px; --r-xl: 12px; --r-2xl: 14px;
  --r-pill: 999px; --r-round: 50%;
  --radius:      var(--r-md);
  --radius-sm:   var(--r-sm);
  --radius-pill: 20px;
  --r:  var(--r-2xl);      /* the shell's panel radius */
  --r2: var(--r-lg);
  --card-min: 220px;
  --card-max: 300px;

  /* ---- ELEVATION + MOTION ------------------------------------------------------
     Durations collapse to 0 under Performance = LIGHT and prefers-reduced-motion (below). */
  --glow:   0 0 8px currentColor;
  --shadow: 0 3px 16px rgba(0, 0, 0, .5);
  --shadow-lg: 0 10px 34px rgba(1, 8, 14, .6);
  --ease-out:    cubic-bezier(.2, .7, .3, 1);
  --ease-in:     cubic-bezier(.4, 0, 1, 1);
  --ease-inout:  cubic-bezier(.4, 0, .2, 1);
  --ease-spring: cubic-bezier(.16, .72, .24, 1);
  --dur-fast:  120ms;
  --dur-base:  180ms;
  --dur-slow:  300ms;
  --dur-enter: 280ms;
  --dur-skel:  1.4s;
  --t-fast: var(--dur-fast) var(--ease-out);
  --t-base: var(--dur-base) var(--ease-out);
  --t-slow: var(--dur-slow) var(--ease-out);

  /* ---- Z-INDEX · UI-GUIDELINES: panels MUST sit above the chrome (99990) -------
     the ladder below is what the live files already stack at; nothing new is invented */
  --z-raise:      10;
  --z-float:      40;
  --z-tray:       9700;
  --z-chrome:     99990;
  --z-chrome-top: 99999;
  --z-overlay:    100000;
  --z-panel:      100200;
  --z-modal:      100500;
  --z-toast:      100800;
}

/* Performance (enki-perf-mode.js, <html data-perf>) and the OS preference own the motion budget:
   LIGHT and reduced motion run every token-driven transition instantly; FULL and BALANCED keep it. */
html[data-perf="light"], html[data-perf-rm="1"] {
  --dur-fast: 0ms; --dur-base: 0ms; --dur-slow: 0ms; --dur-enter: 0ms; --dur-skel: 0s;
}
@media (prefers-reduced-motion: reduce) {
  :root { --dur-fast: 0ms; --dur-base: 0ms; --dur-slow: 0ms; --dur-enter: 0ms; --dur-skel: 0s; }
}

/* ================================================================================
   RESPONSIVE PRIMITIVE — respond to the CONTAINER, not the viewport.
   The shell already sets .view{container-type:inline-size}; this uses it. The same
   panel lives in a full-width view and a narrow rail — the viewport cannot tell them
   apart, but the container can.
   ================================================================================ */
.enki-cards {
  display: grid;
  gap: var(--s3);
  align-items: start;
  justify-content: start;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-min), 1fr));
}
@container (min-width: 900px) {
  .enki-cards { grid-template-columns: repeat(auto-fill, minmax(240px, var(--card-max))); }
}
@container (max-width: 560px) {
  .enki-cards { grid-template-columns: 1fr; }
}
/* Fallback for any context without container-type (older shells, iframes). */
@supports not (container-type: inline-size) {
  @media (min-width: 1500px) { .enki-cards { grid-template-columns: repeat(auto-fill, minmax(240px, var(--card-max))); } }
  @media (max-width: 640px)  { .enki-cards { grid-template-columns: 1fr; } }
}

/* Three named container sizes — every module honours the same three. */
.enki-compact-only { display: none; }
@container (max-width: 560px) {
  .enki-compact-only { display: revert; }
  .enki-regular-up   { display: none; }
}

/* ================================================================================
   THE CONTROL CONTRACT — a control is not shippable without a word, an explanation,
   a visible state, a settings entry and a keyboard path. These primitives make the
   first, third and fifth free.
   ================================================================================ */
.enki-btn {
  display: inline-flex; align-items: center; gap: var(--s2);
  min-height: var(--ctl-h); padding: 0 var(--s3);
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); color: var(--dim);
  font: 700 var(--fs-micro) / 1 var(--font-mono);
  letter-spacing: var(--ls-wide); text-transform: uppercase;
  cursor: pointer; transition: background var(--t-base), border-color var(--t-base), color var(--t-base);
}
.enki-btn:hover { border-color: var(--line-hi); color: var(--text); background: var(--panel-2); }
.enki-btn[aria-pressed="true"], .enki-btn.is-on { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.enki-btn[disabled], .enki-btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
.enki-btn.is-gated { color: var(--gated); border-color: color-mix(in srgb, var(--gated) 45%, transparent); }

/* STATE IS NEVER COLOUR ALONE — a dot carries shape as well as hue, so it survives
   colour-blindness and a bright room. */
.enki-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--unknown); box-shadow: 0 0 7px currentColor; }
.enki-dot.is-ok      { background: var(--ok); }
.enki-dot.is-warn    { background: var(--warn); border-radius: 2px; }        /* square = warn */
.enki-dot.is-bad     { background: var(--bad);  transform: rotate(45deg); border-radius: 1px; } /* diamond = fail */
.enki-dot.is-unknown { background: transparent; border: 1px solid var(--unknown); box-shadow: none; } /* hollow = unknown */

/* KEYBOARD PATH — visible focus everywhere, always. */
.enki-btn:focus-visible, [data-enki-focusable]:focus-visible, .enki-chip:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-sm);
}

/* Touch targets at compact size — never smaller than a fingertip. */
@container (max-width: 560px) {
  .enki-btn { min-height: var(--touch); padding: 0 var(--s4); }
}

/* ================================================================================
   INCLUSIVE BY DEFAULT — honour the system, don't fight it.
   ================================================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important; scroll-behavior: auto !important;
  }
}
@media (prefers-contrast: more) {
  :root {
    --text: #eefaff; --dim: #b9dde4; --faint: #8fb4bc;
    --line: rgba(150, 220, 230, .38); --line-hi: rgba(150, 220, 230, .6);
    --panel: rgba(8, 20, 30, .8);
  }
}

/* Screen-reader-only text — for controls that show an icon but must still say a word. */
.enki-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Shared label + card primitives so modules stop inventing their own. */
.enki-label { font: 700 var(--fs-micro) / 1 var(--font-mono); letter-spacing: var(--ls-wide);
  text-transform: uppercase; color: var(--dim); }
.enki-card { border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); padding: var(--s3) var(--s3); box-sizing: border-box;
  max-width: 100%; min-height: 78px; display: flex; flex-direction: column; }
.enki-card:hover { border-color: var(--line-hi); background: var(--panel-2); }
