/* One theme for the whole product: neutral grey and white, one blue accent, dark and light.
   Tokens live here only. Everything else (sections.css, lab.css, roles.css, mode-*.css,
   voice.css) consumes these variables and never declares a colour of its own. */

@font-face {
  font-family: "MV Plex";
  src: url("/assets/fonts/plex-regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "MV Plex";
  src: url("/assets/fonts/plex-semibold.ttf") format("truetype");
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: "MV Space";
  src: url("/assets/fonts/space-bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

:root {
  color-scheme: dark;
  /* Dark is the default. Surfaces step about 2.5% L each from paper. */
  --paper: oklch(18% 0 0);
  --paper-2: oklch(21% 0 0);
  --paper-3: oklch(23.5% 0 0);
  --paper-4: oklch(26% 0 0);
  --ink: oklch(96% 0 0);
  --muted: oklch(72% 0 0);
  --faint: oklch(64% 0 0);
  --rule: oklch(30% 0 0);
  --rule-strong: oklch(42% 0 0);
  /* The one accent, for borders, indicators and link text. --accent-fill is the same hue,
     darkened only so white text on a filled button clears WCAG AA. Nothing else adds colour. */
  --accent: oklch(62% 0.17 255);
  --accent-fill: oklch(45% 0.17 255);
  --accent-soft: oklch(62% 0.17 255 / 0.4);
  --accent-ink: oklch(99% 0 0);
  --accent-wash: oklch(30% 0.05 255);
  /* Status, on chips only. */
  --success: oklch(72% 0.15 150);
  --warning: oklch(78% 0.14 80);
  --danger: oklch(68% 0.18 25);
  /* Deliberate neutral backdrop for the WebGL stage, where additive holograms must read. */
  --stage: oklch(15% 0 0);

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: "MV Plex", system-ui, sans-serif;
  --display: "MV Space", "MV Plex", sans-serif;

  --ease-out: cubic-bezier(0.2, 0.7, 0.2, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-linear: linear;
  --fast: 120ms;
  --tap: 44px;
  --sidebar: 232px;

  /* Compatibility aliases. The older stylesheets and the WebGL modules were written against
     an amber/magenta palette; these map them onto the one accent and the status colours. */
  --amber: var(--accent);
  --amber-dim: var(--accent-soft);
  --magenta: var(--danger);
  --holo: var(--accent);
  --holo-dim: var(--rule-strong);
  --bg: var(--paper);
  --line: var(--rule);
  --glass: var(--paper-2);
  --tick: var(--rule);
  --ticks: none;
}

:root[data-theme="light"] {
  color-scheme: light;
  --paper: oklch(99% 0 0);
  --paper-2: oklch(97% 0 0);
  --paper-3: oklch(94.5% 0 0);
  --paper-4: oklch(92% 0 0);
  --ink: oklch(20% 0 0);
  --muted: oklch(44% 0 0);
  --faint: oklch(50% 0 0);
  --rule: oklch(87% 0 0);
  --rule-strong: oklch(72% 0 0);
  --accent: oklch(45% 0.17 255);
  --accent-fill: oklch(45% 0.17 255);
  --accent-soft: oklch(45% 0.17 255 / 0.4);
  --accent-ink: oklch(99% 0 0);
  --accent-wash: oklch(94% 0.03 255);
  --success: oklch(44% 0.14 150);
  --warning: oklch(45% 0.12 80);
  --danger: oklch(45% 0.19 25);
  /* A light neutral: in this theme the WebGL composite draws the hologram as ink on the
     stage instead of light added to it, so the stage matches the panels around it. */
  --stage: oklch(90% 0 0);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --paper: oklch(99% 0 0);
    --paper-2: oklch(97% 0 0);
    --paper-3: oklch(94.5% 0 0);
    --paper-4: oklch(92% 0 0);
    --ink: oklch(20% 0 0);
    --muted: oklch(44% 0 0);
    --faint: oklch(50% 0 0);
    --rule: oklch(87% 0 0);
    --rule-strong: oklch(72% 0 0);
    --accent: oklch(45% 0.17 255);
  --accent-fill: oklch(45% 0.17 255);
    --accent-soft: oklch(45% 0.17 255 / 0.4);
    --accent-ink: oklch(99% 0 0);
    --accent-wash: oklch(94% 0.03 255);
    --success: oklch(44% 0.14 150);
    --warning: oklch(45% 0.12 80);
    --danger: oklch(45% 0.19 25);
    --stage: oklch(90% 0 0);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--paper); }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.55 var(--sans);
  overflow-x: clip;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3, h4 { font-style: normal; }
a { color: var(--accent); }

/* ---------- app shell ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100vh;
}
.rail {
  position: sticky; top: 0; align-self: start; height: 100vh;
  display: flex; flex-direction: column; gap: 14px;
  padding: 16px 12px;
  background: var(--paper-2);
  border-right: 1px solid var(--rule);
  overflow-y: auto;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--ink); text-decoration: none;
  font: 700 17px/1 var(--display); letter-spacing: -0.02em;
  min-height: var(--tap); padding: 0 6px;
}
.mark {
  color: var(--ink); font: 600 11px/1 var(--mono); letter-spacing: 0.08em;
  padding: 5px 6px; border: 1px solid var(--rule-strong);
}
.rail-label {
  margin: 0; padding: 0 6px;
  font: 500 10.5px/1.3 var(--mono); letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--muted);
}
.rail-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  min-height: var(--tap); padding: 8px 10px;
  background: none; border: 0; border-left: 2px solid transparent;
  color: var(--muted); font: 500 14px/1.3 var(--sans); text-align: left;
  cursor: pointer;
  transition: color var(--fast) var(--ease-out), background-color var(--fast) var(--ease-out);
}
.nav-item:hover { color: var(--ink); background: var(--paper-3); }
.nav-short { display: none; }
.nav-item[aria-current="true"] {
  color: var(--ink); background: var(--paper-3); border-left-color: var(--accent);
}
.rail-foot { margin-top: auto; display: grid; gap: 8px; }
.rail-foot .ghost { width: 100%; justify-content: center; }
.rail-select { width: 100%; }

/* ---------- content ---------- */
.content { min-width: 0; display: flex; flex-direction: column; }
.content-head {
  position: sticky; top: 0; z-index: 4;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 24px;
  background: var(--paper); border-bottom: 1px solid var(--rule);
}
.content-head h1 { margin: 0; font: 700 20px/1.2 var(--display); letter-spacing: -0.02em; }
.content-head .spacer { margin-left: auto; }
.section-host { flex: 1; min-width: 0; padding: 24px; }
/* minmax(0,1fr): without it a wide table stretches the grid track and the page scrolls sideways. */
.section-host > .sec { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; max-width: 1120px; }
.loading { color: var(--muted); font: 12.5px/1.5 var(--mono); }

/* ---------- controls ---------- */
.ghost, .primary, .btn, .danger-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 10px 14px;
  border-radius: 0; cursor: pointer; white-space: nowrap;
  font: 500 13.5px/1.2 var(--sans); text-decoration: none;
  transition: background-color var(--fast) var(--ease-out), border-color var(--fast) var(--ease-out),
    color var(--fast) var(--ease-out);
}
.ghost { background: var(--paper-2); border: 1px solid var(--rule); color: var(--ink); }
.ghost:hover { background: var(--paper-3); border-color: var(--rule-strong); }
.ghost[aria-pressed="true"], .ghost[aria-expanded="true"] { border-color: var(--accent); }
.primary, .btn.go {
  background: var(--accent-fill); border: 1px solid var(--accent-fill); color: var(--accent-ink);
  font-weight: 600;
}
.primary:hover, .btn.go:hover { background: color-mix(in oklch, var(--accent-fill) 85%, oklch(0% 0 0)); }
.btn { background: var(--paper-3); border: 1px solid var(--rule-strong); color: var(--ink); font-weight: 600; }
.btn:hover { border-color: var(--accent); }
.danger-btn { background: var(--paper-2); border: 1px solid var(--danger); color: var(--danger); }
.danger-btn:hover { background: var(--paper-3); }
button:disabled, select:disabled, .primary:disabled, .btn:disabled {
  opacity: 0.45; cursor: not-allowed;
}
.link {
  background: none; border: 0; color: var(--muted); font: inherit; font-size: 13.5px;
  cursor: pointer; padding: 6px 2px; min-height: 32px;
  text-decoration: underline; text-decoration-color: var(--rule-strong); text-underline-offset: 3px;
}
.link:hover { color: var(--ink); text-decoration-color: var(--ink); }

select, input, textarea {
  background: var(--paper-2); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 0;
  padding: 10px; font: 14px var(--sans); min-height: var(--tap); min-width: 0;
}
textarea { min-height: 72px; }
select:hover, input:hover, textarea:hover { border-color: var(--rule-strong); }

/* Overflow disclosure: the one place secondary actions live. */
.more { border: 1px solid var(--rule); background: var(--paper-2); }
.more > summary {
  min-height: var(--tap); display: flex; align-items: center; padding: 0 14px;
  cursor: pointer; color: var(--muted);
  font: 500 11px/1.3 var(--mono); letter-spacing: 0.12em; text-transform: uppercase;
  list-style: none;
}
.more > summary::-webkit-details-marker { display: none; }
.more > summary::after { content: "+"; margin-left: auto; font-size: 14px; }
.more[open] > summary::after { content: "\2212"; }
.more > summary:hover { color: var(--ink); }
.more[open] > summary { border-bottom: 1px solid var(--rule); }
.more-body { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px; }

.kicker {
  margin: 0 0 8px; text-transform: uppercase; letter-spacing: 0.16em;
  font: 500 10.5px/1.3 var(--mono); color: var(--muted);
}
.badge, .chip, .tag {
  display: inline-block;
  font: 500 10px/1.4 var(--mono); letter-spacing: 0.1em; text-transform: uppercase;
  padding: 4px 7px; border: 1px solid var(--rule-strong); color: var(--muted);
  white-space: nowrap;
}
.badge.good, .tag.pass, .chip.good { color: var(--success); border-color: var(--success); }
.badge.warning, .tag.warn { color: var(--warning); border-color: var(--warning); }
.badge.error, .tag.fail, .chip.bad { color: var(--danger); border-color: var(--danger); }

/* ---------- under 900px: the rail becomes a bottom bar ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail {
    position: fixed; inset: auto 0 0 0; height: auto; z-index: 6;
    flex-direction: row; align-items: center; flex-wrap: wrap; gap: 4px;
    padding: 4px 6px;
    border-right: 0; border-top: 1px solid var(--rule);
    overflow: visible;
  }
  .rail .brand, .rail .rail-label { display: none; }
  .rail-nav { flex-direction: row; flex-wrap: wrap; gap: 2px; flex: 1 1 auto; min-width: 0; }
  .nav-item {
    flex: 1 1 auto; min-width: 0; justify-content: center;
    border-left: 0; border-bottom: 2px solid transparent;
    padding: 4px 6px; font-size: 12.5px; min-height: 40px;
  }
  .nav-item[aria-current="true"] { border-left: 0; border-bottom-color: var(--accent); }
  .nav-long { display: none; }
  .nav-short { display: inline; }
  .rail-foot { margin: 0; display: flex; gap: 4px; flex: 0 0 auto; }
  .rail-foot .ghost, .rail-select { width: auto; padding: 4px 8px; min-height: 40px; font-size: 12.5px; }
  /* --rail-h is the bar's measured height (shell.js); a long NAV wraps to more rows. */
  .content { padding-bottom: calc(var(--rail-h, 100px) + 16px); }
  .content-head { padding: 10px 16px; }
  .section-host { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
