/* ═══════════════════════════════════════════════════════════════════════════
   THE MACHINE — terminal design system
   Mission-control CRT: near-black surface, phosphor readouts, boxed panels.

   COLOR JOBS ARE KEPT SEPARATE. This is the rule that keeps a dense board
   readable, and it is not a matter of taste:
     · STATUS  (--good/--warn/--alarm) is reserved for gauge bands and lights.
       Never reused as a series color. Always shipped with the band WORD and a
       glyph, never color alone.
     · DIVERGING (--div-pos ↔ --div-neg with a NEUTRAL GRAY midpoint) encodes
       polarity on equilibrium and stance bars. Deliberately cyan/amber, not
       green/red, so it cannot be confused with status.
     · CATEGORICAL (--cat-1..4) is for multi-series detail charts only, assigned
       in fixed order and never cycled. A 5th series folds into "Other".
     · INK carries all text. Text never wears the data color — the colored mark
       beside it carries identity.

   Every color below was machine-validated, not eyeballed:
     categorical  → dataviz validate_palette.js, dark mode, surface #05080a:
                    lightness band / chroma floor / CVD separation /
                    normal-vision floor / contrast — all PASS.
     status + ink → WCAG contrast vs surface (phos 15.1, amber 11.0, alarm 5.8,
                    ink 16.7, ink-2 8.0 — all clear AA text).
   Re-run the validator before changing any of them.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  /* ── surfaces ─────────────────────────────────────────────────────────── */
  --bg:        #05080a;
  --panel:     #0a1216;
  --panel-2:   #0d181c;
  --panel-hi:  #10201f;   /* hover */
  --rule:      #16302b;
  --rule-hi:   #1f4a3f;

  /* ── ink ──────────────────────────────────────────────────────────────── */
  --ink:       #cdf3de;   /* body + values            16.7:1 */
  --ink-2:     #7fae97;   /* labels, axis ticks        8.0:1 */
  --ink-3:     #4d7563;   /* decorative glyphs, rules  3.9:1 — never body text */

  /* ── status (RESERVED — bands and lights only) ────────────────────────── */
  --good:      #33ff88;
  --warn:      #ffb000;
  --alarm:     #ff4136;
  --info:      #4de8ff;
  --good-dim:  #1d7a4a;
  --glow:      rgba(51, 255, 136, .28);

  /* ── diverging (polarity: equilibrium deviation, lever stance) ────────── */
  --div-pos:   #039eb0;   /* cyan  — above balance / easing */
  --div-neg:   #ba7f01;   /* amber — below balance / tightening */
  --div-mid:   #5c6b66;   /* NEUTRAL gray midpoint — never a hue */

  /* ── categorical (detail charts only, fixed order, never cycled) ──────── */
  --cat-1:     #039eb0;
  --cat-2:     #a061ff;
  --cat-3:     #fc0281;
  --cat-4:     #2077ff;

  /* ── type ─────────────────────────────────────────────────────────────── */
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "DejaVu Sans Mono", "Liberation Mono", monospace;

  --gap: 10px;
  --scan-op: .025;
}

/* CRT scanlines are a toggle, not a decree — they cost real legibility on a
   dense table and some people simply cannot read through them. */
:root[data-crt="off"] { --scan-op: 0; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow-x: hidden;               /* the page body never scrolls sideways */
}

/* Faint vignette + phosphor bloom, so the black isn't a flat void. */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(51,255,136,.045), transparent 60%),
    radial-gradient(140% 100% at 50% 110%, rgba(0,0,0,.55), transparent 55%);
  z-index: 1;
}

/* One overlay for the whole page — not per-panel. */
body::after {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 2;
  background: repeating-linear-gradient(
    to bottom,
    rgba(205,243,222, var(--scan-op)) 0 1px,
    transparent 1px 3px
  );
}

::selection { background: rgba(51,255,136,.25); color: #fff; }

:focus-visible {
  outline: 2px solid var(--good);
  outline-offset: 2px;
}

/* ── numerals ──────────────────────────────────────────────────────────────
   Every number on this page repaints on a poll. Without tabular figures the
   digits jitter sideways on each tick, which reads as instability.          */
.num, .val, td.num, .tile-score, .readout {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ═══ layout ══════════════════════════════════════════════════════════════ */

.wrap {
  position: relative;
  z-index: 3;
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 12px 48px;
}

/* ── header ───────────────────────────────────────────────────────────────
   Sticky, and it stays compact: on a phone this strip IS the dashboard.    */
.hdr {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 48px;
  padding: 6px 12px;
  margin: 0 -12px 14px;
  background: rgba(5,8,10,.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--rule);
}

.hdr-brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: .8rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--good);
  text-shadow: 0 0 8px var(--glow);
  white-space: nowrap;
}
.hdr-brand .mark { font-size: 1rem; }
.hdr-spacer { flex: 1 1 auto; }

.hdr-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .7rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-2);
  white-space: nowrap;
}
.hdr-item .val { color: var(--ink); }

.chip {
  appearance: none;
  min-height: 30px;
  padding: 4px 10px;
  background: var(--panel);
  border: 1px solid var(--rule);
  color: var(--ink-2);
  font: inherit;
  font-size: .66rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  cursor: pointer;
}
.chip:hover { border-color: var(--rule-hi); color: var(--ink); background: var(--panel-hi); }
.chip[aria-pressed="true"], .chip.is-on {
  border-color: var(--good-dim); color: var(--good); background: rgba(51,255,136,.08);
}

/* ── section rule:  ── FORCES ──────────────────────────────────────────── */
.section {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 22px 0 10px;
  font-size: .68rem;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.section::before { content: "──"; color: var(--ink-3); letter-spacing: 0; }
.section::after {
  content: "";
  flex: 1 1 auto;
  height: 0;
  border-top: 1px solid var(--rule);
}

/* ── panel ────────────────────────────────────────────────────────────────
   Corner ticks are drawn with ::before/::after rather than a border image,
   so they scale with the panel and cost nothing.                           */
.panel {
  position: relative;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--rule);
  padding: 12px;
}
.panel::before, .panel::after {
  content: "";
  position: absolute;
  width: 9px; height: 9px;
  border: 1px solid var(--rule-hi);
  pointer-events: none;
}
.panel::before { top: -1px; left: -1px; border-right: 0; border-bottom: 0; }
.panel::after  { bottom: -1px; right: -1px; border-left: 0; border-top: 0; }

.panel-label {
  font-size: .64rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-2);
}

/* ═══ grids ═══════════════════════════════════════════════════════════════
   auto-fit + minmax handles every breakpoint without a media query: forces
   land 4-up on desktop, 2×2 on a large phone, 1-up on a small one.        */
.grid      { display: grid; gap: var(--gap); }
.grid-4    { grid-template-columns: repeat(auto-fit, minmax(198px, 1fr)); }
.grid-3    { grid-template-columns: repeat(auto-fit, minmax(238px, 1fr)); }
.grid-2    { grid-template-columns: repeat(auto-fit, minmax(292px, 1fr)); }

/* ═══ gauge tile ══════════════════════════════════════════════════════════ */

a.tile, .tile {
  display: block;
  text-decoration: none;
  color: inherit;
  min-height: 44px;                  /* touch target */
  transition: border-color .15s, background .15s;
}
a.tile:hover { border-color: var(--rule-hi); background: var(--panel-hi); }

.tile-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.tile-name {
  flex: 1 1 auto;
  font-size: .64rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile-score {
  font-size: 1.9rem;
  line-height: 1.05;
  letter-spacing: -.01em;
  color: var(--ink);
}
.tile-band {
  margin-top: 2px;
  font-size: .68rem;
  letter-spacing: .13em;
  text-transform: uppercase;
}
.tile-spark { margin: 8px 0 6px; height: 30px; width: 100%; display: block; }
.tile-driver {
  font-size: .68rem;
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Trend arrows are a glyph + a word in the aria-label, never color alone. */
.trend { font-size: .7rem; color: var(--ink-2); }
.trend.up   { color: var(--div-pos); }
.trend.down { color: var(--div-neg); }

/* ── status light ─────────────────────────────────────────────────────────
   Paired with a band WORD everywhere it appears.                           */
.light {
  flex: 0 0 auto;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 1px rgba(0,0,0,.6) inset, 0 0 7px currentColor;
}
.s-good     { color: var(--good); }
.s-neutral  { color: var(--ink-3); }
.s-watch    { color: var(--info); }
.s-warn     { color: var(--warn); }
.s-alarm    { color: var(--alarm); }

@media (prefers-reduced-motion: no-preference) {
  .light.blink { animation: blink 1.4s steps(2, jump-none) infinite; }
}
@keyframes blink { 50% { opacity: .28; } }

/* ═══ diverging bar — equilibrium deviation & lever stance ════════════════
   Centered on 0. The midpoint is a neutral gray tick, and the fill grows
   left or right from it, so "how far out of balance" is read as distance
   from the center rather than as a color.                                  */
.dbar {
  position: relative;
  height: 16px;
  margin: 10px 0 6px;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--rule);
}
.dbar::before {                       /* the balance line */
  content: "";
  position: absolute;
  left: 50%; top: -3px; bottom: -3px;
  width: 1px;
  background: var(--div-mid);
}
.dbar-fill {
  position: absolute;
  top: 2px; bottom: 2px;
  background: var(--div-mid);
}
.dbar-fill.pos { background: var(--div-pos); }
.dbar-fill.neg { background: var(--div-neg); }

.dbar-ends {
  display: flex;
  justify-content: space-between;
  font-size: .58rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ═══ meter — lever ammunition ════════════════════════════════════════════
   Segmented, because "how many pulls are left" is a count, not a continuum. */
.meter { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.meter-cells { display: flex; gap: 2px; flex: 1 1 auto; }
.meter-cell {
  flex: 1 1 0;
  height: 12px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--rule);
}
.meter-cell.on { background: currentColor; border-color: currentColor; }
.meter-val { font-size: .74rem; color: var(--ink); min-width: 3.4em; text-align: right; }

/* ═══ hero — market state ═════════════════════════════════════════════════ */
.hero { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.hero-dial { flex: 0 0 auto; width: 150px; height: 104px; }
.hero-body { flex: 1 1 260px; min-width: 0; }

.hero-regime {
  font-size: clamp(1.15rem, 3.4vw, 1.7rem);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--good);
  text-shadow: 0 0 10px var(--glow);   /* glow ONLY on the hero readouts */
  overflow-wrap: anywhere;
}
.hero-sub { margin-top: 4px; font-size: .74rem; color: var(--ink-2); }
.hero-line { margin-top: 8px; color: var(--ink); }

/* Cross-gauge contradictions — the sentences that make the board reason. */
.tension {
  display: flex;
  gap: 8px;
  padding: 6px 0;
  border-top: 1px dotted var(--rule);
  font-size: .8rem;
  color: var(--ink);
}
.tension::before { content: "▸"; color: var(--warn); flex: 0 0 auto; }

/* ═══ tables ══════════════════════════════════════════════════════════════
   Wide content scrolls inside its own box; the page never does.            */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .78rem; white-space: nowrap; }
table.tbl th {
  text-align: left;
  font-size: .6rem;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--ink-2);
  font-weight: 400;
  border-bottom: 1px solid var(--rule);
  padding: 5px 10px 5px 0;
}
table.tbl td { padding: 5px 10px 5px 0; border-bottom: 1px dotted var(--rule); color: var(--ink); }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl tr:hover td { background: rgba(255,255,255,.02); }

/* ═══ chart shell ═════════════════════════════════════════════════════════ */
.chart-box { position: relative; height: min(42vh, 340px); }
.ranges { display: flex; gap: 4px; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 2px; }
.ranges .chip { scroll-snap-align: start; }

/* ═══ gate ════════════════════════════════════════════════════════════════ */
.gate {
  position: fixed; inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(5,8,10,.97);
}
.gate[hidden] { display: none; }
.gate-box { width: min(420px, 100%); }
.gate-title {
  font-size: .8rem;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--good);
  text-shadow: 0 0 8px var(--glow);
}
.gate-hint { margin: 6px 0 14px; font-size: .74rem; color: var(--ink-2); }

.field {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--rule-hi);
  background: rgba(0,0,0,.4);
  padding: 0 10px;
}
.field::before { content: ">"; color: var(--good); }
.field input {
  flex: 1 1 auto;
  min-height: 44px;
  background: transparent;
  border: 0;
  color: var(--ink);
  font: inherit;
  letter-spacing: .08em;
}
.field input:focus { outline: none; }

.btn {
  appearance: none;
  width: 100%;
  min-height: 44px;
  margin-top: 12px;
  background: rgba(51,255,136,.1);
  border: 1px solid var(--good-dim);
  color: var(--good);
  font: inherit;
  font-size: .74rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  cursor: pointer;
}
.btn:hover:not(:disabled) { background: rgba(51,255,136,.18); }
.btn:disabled { opacity: .5; cursor: default; }

.err { margin-top: 10px; font-size: .74rem; color: var(--alarm); min-height: 1.2em; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: .72rem;
  color: var(--ink-2);
  cursor: pointer;
}
.check input { accent-color: var(--good); width: 16px; height: 16px; }

/* ═══ boot sequence ═══════════════════════════════════════════════════════ */
.boot { font-size: .76rem; color: var(--ink-2); line-height: 1.7; }
.boot .ok { color: var(--good); }
.cursor { display: inline-block; width: .55em; height: 1em; background: var(--good); vertical-align: -.14em; }
@media (prefers-reduced-motion: no-preference) {
  .cursor { animation: blink 1.05s steps(2, jump-none) infinite; }
}

/* ═══ utility ═════════════════════════════════════════════════════════════ */
.muted   { color: var(--ink-2); }
.dim     { color: var(--ink-3); }
.tiny    { font-size: .66rem; letter-spacing: .1em; text-transform: uppercase; }
.stack   { display: grid; gap: var(--gap); }
.row     { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── phone ────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  html, body { font-size: 14px; }
  .wrap { padding: 0 10px 40px; }
  .hdr { gap: 10px; }
  .hdr-brand .full { display: none; }
  .tile-score { font-size: 1.6rem; }
  .hero { gap: 12px; }
  .hero-dial { width: 122px; height: 86px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  body::after { display: none; }        /* scanlines off entirely */
}
