/* Inside the Machine — instrument panel for a very small brain.
   Palette mirrors src/viz/palette.js; contrast ratios there are measured by
   tests/run.js rather than eyeballed. */

:root {
  --void: #05070d;
  --canvas: #080b14;
  --panel: #0e1421;
  --panel-raised: #141c2c;
  --edge: #1e2a3f;
  --edge-bright: #2c3d59;

  --cyan: #5fd9ef;
  --amber: #ffab52;
  --green: #7ef0b2;
  --pink: #ff6b9d;
  --gold: #ffd166;

  --ink: #eaf1fb;
  --ink-body: #b9c8de;
  --ink-muted: #8fa2bd;
  --ink-faint: #64789a;

  --ui: 'Space Grotesk', 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', ui-monospace, monospace;

  --rail-left: 296px;
  --rail-right: 336px;
  --gap: 1px;
  --radius: 3px;
}
* { box-sizing: border-box; }

/* Elements toggled with the hidden attribute set display themselves (flex,
   inline-flex), which quietly beats the UA rule. Without this, "hidden" buttons
   stay on screen. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--void);
  color: var(--ink-body);
  font-family: var(--ui);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(95, 217, 239, 0.06), transparent 60%),
    radial-gradient(100% 60% at 50% 100%, rgba(255, 171, 82, 0.035), transparent 60%);
  z-index: 0;
}

button, input { font-family: inherit; color: inherit; }
h2, h3 { margin: 0; font-weight: 600; }

/* ── shell ─────────────────────────────────────────────────────────── */
.app {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

/* ── topbar ────────────────────────────────────────────────────────── */
.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto minmax(0, 1fr);
  align-items: center;
  gap: 24px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--edge);
  background: linear-gradient(180deg, rgba(20, 28, 44, 0.55), rgba(8, 11, 20, 0.2));
}

.brand { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.brand-line { display: flex; align-items: baseline; gap: 10px; min-width: 0; overflow: hidden; }
.brand-home {
  font-size: 9.5px; letter-spacing: 0.14em; color: var(--ink-faint);
  text-decoration: underline; text-underline-offset: 3px;
  text-decoration-color: rgba(100, 120, 154, 0.4);
  align-self: flex-start; transition: color 0.15s, text-decoration-color 0.15s;
}
.brand-home:hover { color: var(--cyan); text-decoration-color: var(--cyan); }
.brand-mark {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 10px var(--cyan), 0 0 22px rgba(95, 217, 239, 0.45);
  animation: breathe 5.2s ease-in-out infinite;
  align-self: center;
}
@keyframes breathe { 0%, 100% { opacity: 0.5; transform: scale(0.85); } 50% { opacity: 1; transform: scale(1); } }
.brand-name { font-size: 13px; font-weight: 700; letter-spacing: 0.18em; color: var(--ink); }
.brand-sub {
  font-size: 11px; color: var(--ink-faint); letter-spacing: 0.04em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.modes { display: flex; gap: 2px; padding: 2px; border: 1px solid var(--edge); border-radius: var(--radius); }
.mode {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  padding: 7px 22px; font-size: 11px; font-weight: 600; letter-spacing: 0.16em;
  color: var(--ink-muted); border-radius: 2px; transition: color 0.18s, background 0.18s;
}
.mode:hover { color: var(--ink); }
.mode.is-active { color: var(--void); background: var(--cyan); box-shadow: 0 0 18px rgba(95, 217, 239, 0.35); }
.mode[disabled] { opacity: 0.35; cursor: not-allowed; }

/* The way in for anyone who has no idea what they are looking at, so it stays
   on screen at every width rather than living only in the opening sequence. */
.btn-guide {
  flex-direction: row; gap: 7px;
  padding: 7px 14px; letter-spacing: 0.14em;
  border-color: var(--edge-bright); color: var(--ink-muted);
}
.btn-guide:hover:not([disabled]) { color: var(--ink); border-color: var(--cyan); }
.guide-mark {
  display: inline-grid; place-items: center;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--cyan); color: var(--void);
  font-size: 10px; font-weight: 700; letter-spacing: 0;
}
.btn-guide.is-calling .guide-mark { animation: guideNudge 2.4s ease-in-out infinite; }
@keyframes guideNudge {
  0%, 100% { box-shadow: 0 0 0 rgba(95, 217, 239, 0); }
  50% { box-shadow: 0 0 0 4px rgba(95, 217, 239, 0.25); }
}

.readouts { display: flex; justify-content: flex-end; gap: 26px; margin: 0; min-width: 0; }
.readout dt { font-size: 9px; letter-spacing: 0.18em; color: var(--ink-faint); margin-bottom: 3px; }
.readout dd { margin: 0; font-family: var(--mono); font-size: 15px; font-weight: 500; color: var(--ink); }
.readout dd.is-good { color: var(--green); }
.readout dd.flash { animation: flash 0.5s ease-out; }
@keyframes flash { from { color: var(--cyan); text-shadow: 0 0 14px var(--cyan); } }

/* ── stage ─────────────────────────────────────────────────────────── */
.stage {
  display: grid;
  grid-template-columns: var(--rail-left) minmax(0, 1fr) var(--rail-right);
  gap: var(--gap);
  background: var(--edge);
  min-height: 0;
}

.rail {
  background: var(--void);
  display: flex; flex-direction: column; gap: var(--gap);
  min-height: 0; overflow-y: auto; overflow-x: hidden;
  scrollbar-width: thin; scrollbar-color: var(--edge-bright) transparent;
}
.rail::-webkit-scrollbar { width: 6px; }
.rail::-webkit-scrollbar-thumb { background: var(--edge-bright); border-radius: 3px; }

.panel {
  position: relative;
  flex: 0 0 auto;
  background: var(--panel);
  padding: 14px 16px 16px;
  min-height: 0;
}
.panel::after {
  content: ''; position: absolute; inset: 6px auto auto 6px;
  width: 7px; height: 7px;
  border-left: 1px solid var(--edge-bright); border-top: 1px solid var(--edge-bright);
  pointer-events: none;
}
.panel-title {
  font-size: 9.5px; letter-spacing: 0.2em; color: var(--ink-muted);
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  margin-bottom: 12px;
}
.panel-note { font-family: var(--mono); font-size: 10px; color: var(--ink-faint); letter-spacing: 0; }
.panel-context {
  font-family: var(--mono); font-size: 11px; color: var(--ink-faint);
  margin: -6px 0 10px; word-break: break-word;
}
/* The left rail holds one panel at a time; let it fill the column. */
.rail-left > .panel { flex: 1 1 auto; }

.hint { font-size: 12px; line-height: 1.55; color: var(--ink-faint); margin: 0; }

/* ── training examples ─────────────────────────────────────────────── */
.examples { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.example {
  position: relative;
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: linear-gradient(180deg, rgba(20, 28, 44, 0.5), transparent);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
  overflow: hidden;
}
.example:hover { border-color: var(--edge-bright); transform: translateX(2px); }
.example.is-focus { border-color: var(--cyan); box-shadow: 0 0 0 1px rgba(95, 217, 239, 0.25), 0 0 22px rgba(95, 217, 239, 0.12); }
.example.is-locked { opacity: 0.32; pointer-events: none; }
.example-text { font-family: var(--mono); font-size: 12px; color: var(--ink-body); line-height: 1.5; }
.example-blank { color: var(--ink-faint); }
.example-answer { color: var(--green); font-weight: 700; }
.example-meta {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 5px; font-family: var(--mono); font-size: 10px; color: var(--ink-faint);
}
.example-meta .ok { color: var(--green); }
.example-meta .bad { color: var(--pink); }
.example-bar { position: absolute; left: 0; bottom: 0; height: 2px; background: var(--cyan); opacity: 0.75; transition: width 0.4s ease-out; }

.adder summary {
  cursor: pointer; font-size: 11px; letter-spacing: 0.1em; color: var(--ink-muted);
  padding: 6px 0; list-style: none;
}
.adder summary::-webkit-details-marker { display: none; }
.adder summary::before { content: '+ '; color: var(--cyan); }
.adder[open] summary::before { content: '− '; }
.adder form { display: flex; flex-direction: column; gap: 8px; padding-top: 6px; }
.adder label, .known-label { font-size: 9px; letter-spacing: 0.18em; color: var(--ink-faint); display: block; }
.adder input, #ask-input {
  width: 100%; margin-top: 5px; padding: 9px 10px;
  background: var(--canvas); border: 1px solid var(--edge); border-radius: var(--radius);
  font-family: var(--mono); font-size: 12px; color: var(--ink);
}
.adder input:focus, #ask-input:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 1px rgba(95, 217, 239, 0.3); }
.adder .hint { font-size: 11px; }
.hint.is-error { color: var(--pink); }
.hint.is-warning { color: var(--gold); }
.hint em { font-style: normal; color: var(--ink); font-weight: 600; }

/* ── ask mode ──────────────────────────────────────────────────────── */
#ask-form { display: flex; flex-direction: column; gap: 14px; }
#ask-input { margin-top: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chip {
  font-family: var(--mono); font-size: 10px; padding: 3px 7px;
  border: 1px solid var(--edge); border-radius: 2px; color: var(--ink-faint);
  cursor: pointer; transition: color 0.15s, border-color 0.15s;
}
.chip:hover { color: var(--cyan); border-color: var(--cyan); }

.generated { margin-top: 16px; min-height: 60px; }
.generated-label { font-size: 9px; letter-spacing: 0.18em; color: var(--ink-faint); margin-bottom: 8px; }
.generated-text { font-family: var(--mono); font-size: 15px; line-height: 1.7; color: var(--ink); }
.generated-text .prompt-part { color: var(--ink-muted); }
.generated-text .new-token {
  color: var(--cyan); animation: tokenIn 0.4s ease-out;
  display: inline-block;
}
.generated-text .end-token { color: var(--ink-faint); font-size: 11px; letter-spacing: 0.1em; }
@keyframes tokenIn { from { opacity: 0; transform: translateY(-5px); filter: blur(3px); } }
.caret { display: inline-block; width: 7px; height: 15px; background: var(--cyan); vertical-align: -2px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ── sliders ───────────────────────────────────────────────────────── */
.slider { display: block; }
.slider-head { display: flex; align-items: center; gap: 8px; font-size: 9px; letter-spacing: 0.18em; color: var(--ink-faint); }
.slider-head .value { font-family: var(--mono); font-size: 12px; color: var(--cyan); letter-spacing: 0; margin-left: auto; }
.slider-inline .slider-head .value { margin-left: 4px; }
.slider-ends { display: flex; justify-content: space-between; font-size: 9px; letter-spacing: 0.14em; color: var(--ink-faint); margin-top: 2px; }
input[type='range'] {
  -webkit-appearance: none; appearance: none; width: 100%; margin: 9px 0 0;
  height: 2px; background: var(--edge-bright); border-radius: 2px; cursor: pointer;
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none; width: 13px; height: 13px; border-radius: 50%;
  background: var(--cyan); box-shadow: 0 0 12px rgba(95, 217, 239, 0.6); border: 0; cursor: grab;
}
input[type='range']::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%; border: 0;
  background: var(--cyan); box-shadow: 0 0 12px rgba(95, 217, 239, 0.6);
}
.info {
  appearance: none; width: 14px; height: 14px; padding: 0; border-radius: 50%;
  border: 1px solid var(--edge-bright); background: transparent; color: var(--ink-faint);
  font-size: 9px; line-height: 1; cursor: help;
}
.info:hover { color: var(--cyan); border-color: var(--cyan); }

/* ── viewport ──────────────────────────────────────────────────────── */
.viewport {
  position: relative; background: var(--canvas);
  min-width: 0; min-height: 0;
  /* Column, so anything that stops being absolutely positioned on a narrow
     screen stacks under the canvas instead of beside it. */
  display: flex; flex-direction: column;
}
#network { flex: 1 1 auto; width: 100%; min-height: 0; display: block; touch-action: manipulation; }

.phase-chip {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  font-size: 10px; letter-spacing: 0.22em; padding: 6px 16px;
  border: 1px solid currentColor; border-radius: 2px;
  background: rgba(8, 11, 20, 0.85); backdrop-filter: blur(6px);
  animation: chipIn 0.3s ease-out;
}
@keyframes chipIn { from { opacity: 0; transform: translate(-50%, -6px); } }
.phase-chip[data-tone='forward'] { color: var(--cyan); }
.phase-chip[data-tone='backward'] { color: var(--amber); }
.phase-chip[data-tone='loss'] { color: var(--gold); }
.phase-chip[data-tone='update'] { color: var(--pink); }

.narration {
  position: absolute; left: 50%; bottom: 62px; transform: translateX(-50%);
  width: min(560px, calc(100% - 48px));
  text-align: center; pointer-events: none;
}
.narration-text {
  margin: 0 0 14px; font-size: 15px; line-height: 1.6; color: var(--ink);
  text-shadow: 0 2px 18px rgba(5, 7, 13, 0.95);
  animation: narrationIn 0.5s ease-out;
}
@keyframes narrationIn { from { opacity: 0; transform: translateY(8px); filter: blur(4px); } }
.narration .btn { pointer-events: auto; }

.disclaimer {
  position: absolute; left: 0; right: 0; bottom: 10px; margin: 0;
  text-align: center; font-size: 10.5px; color: var(--ink-faint); line-height: 1.5;
  padding: 0 20px;
}
.link {
  appearance: none; border: 0; background: none; padding: 0; cursor: pointer;
  color: var(--cyan); font-size: inherit; text-decoration: underline; text-underline-offset: 3px;
}
.link:hover { color: var(--ink); }

/* ── distribution ──────────────────────────────────────────────────── */
.dist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.dist-row { position: relative; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 2px; overflow: hidden; }
.dist-row .fill { position: absolute; inset: 0 auto 0 0; background: rgba(95, 217, 239, 0.14); transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1); }
.dist-row .token { position: relative; font-family: var(--mono); font-size: 12px; color: var(--ink-body); }
.dist-row .p { position: relative; font-family: var(--mono); font-size: 12px; color: var(--ink-muted); }
.dist-row.is-target .fill { background: rgba(126, 240, 178, 0.16); }
.dist-row.is-target .token, .dist-row.is-target .p { color: var(--green); font-weight: 700; }
.dist-row.is-top .token { color: var(--cyan); }
.dist-row.is-chosen { box-shadow: inset 0 0 0 1px rgba(255, 209, 102, 0.6); }
.dist-row .tag { position: relative; font-size: 8.5px; letter-spacing: 0.14em; color: var(--ink-faint); margin-left: 6px; }

/* ── inspector ─────────────────────────────────────────────────────── */
.panel-inspector { flex: 0 0 auto; }
.inspector-kind { font-size: 9px; letter-spacing: 0.2em; color: var(--cyan); margin-bottom: 6px; }
.inspector-kind[data-kind='weight'] { color: var(--pink); }
.inspector-kind[data-kind='token'] { color: var(--amber); }
.inspector-value { font-family: var(--mono); font-size: 26px; color: var(--ink); line-height: 1.1; margin-bottom: 4px; }
.inspector-where { font-family: var(--mono); font-size: 10.5px; color: var(--ink-faint); margin-bottom: 10px; }
.inspector-copy { font-size: 12px; line-height: 1.6; color: var(--ink-body); margin: 0 0 8px; }
.inspector-meta { display: flex; gap: 14px; font-family: var(--mono); font-size: 10.5px; color: var(--ink-faint); flex-wrap: wrap; }
.inspector-meta b { color: var(--amber); font-weight: 500; }

/* ── loss graph ────────────────────────────────────────────────────── */
.panel-graph { flex: 1 1 auto; min-height: 132px; padding: 0; }
.panel-graph::after { display: none; }
#loss-graph { width: 100%; height: 100%; display: block; }

/* ── controls ──────────────────────────────────────────────────────── */
.controlbar {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 12px 20px; border-top: 1px solid var(--edge);
  background: linear-gradient(0deg, rgba(20, 28, 44, 0.5), transparent);
  flex-wrap: wrap;
}
.controls-main { display: flex; align-items: stretch; gap: 8px; }
.controls-settings { display: flex; align-items: center; gap: 26px; }
.controls-settings .slider { width: 190px; }

.btn {
  appearance: none; cursor: pointer;
  background: var(--panel-raised); border: 1px solid var(--edge-bright);
  border-radius: var(--radius); color: var(--ink-body);
  padding: 9px 16px; font-size: 11px; font-weight: 600; letter-spacing: 0.14em;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  transition: border-color 0.15s, color 0.15s, background 0.15s, transform 0.1s;
}
.btn:hover:not([disabled]) { color: var(--ink); border-color: var(--cyan); }
.btn:active:not([disabled]) { transform: translateY(1px); }
.btn[disabled] { opacity: 0.3; cursor: not-allowed; }
.btn-sub { font-size: 9px; font-weight: 400; letter-spacing: 0.05em; color: var(--ink-faint); text-transform: none; }
.btn-primary {
  background: var(--cyan); border-color: var(--cyan); color: #04121a;
  box-shadow: 0 0 24px rgba(95, 217, 239, 0.28);
}
.btn-primary .btn-sub { color: rgba(4, 18, 26, 0.7); }
.btn-primary:hover:not([disabled]) { background: #7ee6f8; border-color: #7ee6f8; color: #04121a; }
.btn-quiet { background: transparent; border-color: var(--edge); color: var(--ink-faint); }
.btn-train { min-width: 168px; }
.btn.is-calling { animation: callToAction 1.8s ease-in-out infinite; }
@keyframes callToAction {
  0%, 100% { box-shadow: 0 0 24px rgba(95, 217, 239, 0.28); }
  50% { box-shadow: 0 0 40px rgba(95, 217, 239, 0.75); }
}

.speeds { display: flex; gap: 2px; padding: 2px; border: 1px solid var(--edge); border-radius: var(--radius); }
.speed {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  padding: 6px 12px; font-family: var(--mono); font-size: 11px; color: var(--ink-faint); border-radius: 2px;
}
.speed.is-active { background: var(--edge-bright); color: var(--ink); }

/* ── curtain (opening sequence) ────────────────────────────────────── */
.curtain {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  background: radial-gradient(80% 60% at 50% 45%, rgba(12, 18, 30, 0.94), rgba(5, 7, 13, 0.985));
  backdrop-filter: blur(3px);
  transition: opacity 0.6s ease, visibility 0.6s;
}
.curtain[hidden] { display: none; }
.curtain.is-gone { opacity: 0; visibility: hidden; pointer-events: none; }
.curtain-inner { text-align: center; max-width: 620px; padding: 0 28px; }
.curtain-line {
  font-size: clamp(20px, 3.4vw, 34px); font-weight: 500; letter-spacing: 0.01em;
  line-height: 1.4; color: var(--ink); margin: 0 0 30px; min-height: 1.4em;
}
.curtain-line em { font-style: normal; color: var(--cyan); }
.curtain-skip {
  display: block; margin: 26px auto 0; font-size: 11px; color: var(--ink-faint); text-decoration: none;
  letter-spacing: 0.1em;
}
.curtain-skip:hover { color: var(--ink-muted); }

/* ── modal ─────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(5, 7, 13, 0.86); backdrop-filter: blur(4px); padding: 20px; }
.modal[hidden] { display: none; }
.modal-card {
  width: min(760px, 100%); max-height: 90dvh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--edge-bright); border-radius: var(--radius);
  padding: 28px 30px 26px; box-shadow: 0 40px 90px rgba(0, 0, 0, 0.6);
}
.modal-card h2 { font-size: 11px; letter-spacing: 0.3em; color: var(--ink-muted); margin-bottom: 22px; }
.scale-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 26px; }
.scale-col h3 { font-size: 10px; letter-spacing: 0.2em; color: var(--cyan); margin-bottom: 14px; }
.scale-col-large h3 { color: var(--amber); }
.scale-col dl { margin: 0; display: flex; flex-direction: column; gap: 12px; }
.scale-col dl div { display: flex; flex-direction: column; gap: 3px; }
.scale-col dt { font-size: 9px; letter-spacing: 0.16em; color: var(--ink-faint); }
.scale-col dd { margin: 0; font-family: var(--mono); font-size: 14px; color: var(--ink); }
.scale-bar { margin-top: 18px; height: 4px; background: var(--edge); border-radius: 2px; overflow: hidden; }
.scale-bar span { display: block; height: 100%; background: var(--cyan); box-shadow: 0 0 12px var(--cyan); min-width: 2px; }
.scale-bar-full span { width: 100%; background: linear-gradient(90deg, var(--amber), var(--pink)); box-shadow: 0 0 12px rgba(255, 171, 82, 0.5); }
.modal-note { font-size: 12px; line-height: 1.65; color: var(--ink-faint); margin: 26px 0 22px; }

/* ── guide (how it works) ──────────────────────────────────────────── */
/* The card grows with its longest section and stops; stretching it to the
   viewport left short sections floating in an empty pane. */
.guide-card {
  width: min(940px, 100%);
  display: flex; flex-direction: column;
  max-height: min(88dvh, 760px);
  padding: 0;
  overflow: hidden;               /* the panes scroll, not the card */
}
.guide-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 20px;
  padding: 22px 26px 18px; border-bottom: 1px solid var(--edge);
}
.guide-head h2 { margin-bottom: 6px; }
.guide-subtitle { margin: 0; font-size: 12px; color: var(--ink-faint); }
.guide-close { align-self: flex-start; }

.guide-body { display: grid; grid-template-columns: 208px minmax(0, 1fr); min-height: 0; flex: 0 1 auto; }
.guide-nav {
  display: flex; flex-direction: column; gap: 1px;
  padding: 14px 10px; border-right: 1px solid var(--edge);
  overflow-y: auto;
}
.guide-nav button {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  text-align: left; padding: 9px 12px; border-radius: 2px;
  font-family: var(--ui); font-size: 10px; font-weight: 600; letter-spacing: 0.14em;
  color: var(--ink-faint); transition: color 0.15s, background 0.15s;
  display: flex; align-items: baseline; gap: 9px;
}
.guide-nav button:hover { color: var(--ink-body); background: var(--panel-raised); }
.guide-nav button.is-active { color: var(--ink); background: var(--panel-raised); box-shadow: inset 2px 0 0 var(--cyan); }
.guide-nav .n { font-family: var(--mono); font-size: 9px; color: var(--ink-faint); font-weight: 400; }
.guide-nav button.is-active .n { color: var(--cyan); }

.guide-panes { overflow-y: auto; padding: 24px 30px 30px; scrollbar-width: thin; scrollbar-color: var(--edge-bright) transparent; }
.guide-panes::-webkit-scrollbar { width: 7px; }
.guide-panes::-webkit-scrollbar-thumb { background: var(--edge-bright); border-radius: 3px; }
.guide-pane[hidden] { display: none !important; }
.guide-pane h3 {
  font-size: 17px; font-weight: 600; letter-spacing: 0; color: var(--ink);
  margin-bottom: 14px;
}
.guide-pane h4 {
  font-size: 9.5px; letter-spacing: 0.2em; font-weight: 600; color: var(--cyan);
  text-transform: uppercase;
  margin: 26px 0 10px;
}
.guide-pane p { margin: 0 0 12px; font-size: 13.5px; line-height: 1.7; color: var(--ink-body); }
.guide-pane p b, .guide-pane li b, .guide-pane dd b { color: var(--ink); font-weight: 600; }
.guide-pane em { font-style: normal; color: var(--ink); }
.guide-lead { font-size: 15px !important; color: var(--ink) !important; line-height: 1.65 !important; }
.guide-pane kbd {
  font-family: var(--mono); font-size: 11px; color: var(--ink);
  background: var(--panel-raised); border: 1px solid var(--edge-bright); border-radius: 2px;
  padding: 1px 6px;
}

.guide-callout {
  border-left: 2px solid var(--cyan);
  background: rgba(95, 217, 239, 0.05);
  padding: 12px 14px; margin: 20px 0 4px !important;
  font-size: 13px !important;
}

.guide-steps { list-style: none; margin: 0; padding: 0; counter-reset: guide; }
.guide-steps li {
  counter-increment: guide;
  position: relative; padding: 0 0 16px 34px;
  font-size: 13.5px; line-height: 1.7; color: var(--ink-body);
}
.guide-steps li::before {
  content: counter(guide);
  position: absolute; left: 0; top: 1px;
  width: 21px; height: 21px; border-radius: 50%;
  display: grid; place-items: center;
  border: 1px solid var(--edge-bright);
  font-family: var(--mono); font-size: 10px; color: var(--ink-faint);
}
.guide-step-name {
  display: block; margin-bottom: 3px;
  font-size: 9.5px; letter-spacing: 0.18em; font-weight: 600; color: var(--ink);
}
.guide-step-name[data-tone='forward'] { color: var(--cyan); }
.guide-step-name[data-tone='backward'] { color: var(--amber); }
.guide-step-name[data-tone='loss'] { color: var(--gold); }
.guide-step-name[data-tone='update'] { color: var(--green); }
.guide-steps-plain li::before { border-color: var(--edge); }

.guide-defs { margin: 0 0 4px; display: flex; flex-direction: column; gap: 12px; }
.guide-defs > div { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 14px; align-items: baseline; }
.guide-defs dt { font-size: 9.5px; letter-spacing: 0.16em; font-weight: 600; color: var(--ink); padding-top: 3px; }
.guide-defs dd { margin: 0; font-size: 13px; line-height: 1.65; color: var(--ink-body); }

.guide-key { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.guide-key li { font-size: 13px; line-height: 1.6; color: var(--ink-body); }
.guide-key .swatch {
  display: inline-block; width: 11px; height: 11px; border-radius: 50%;
  margin-right: 9px; vertical-align: -1px;
}
.swatch[data-tone='forward'] { background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.swatch[data-tone='backward'] { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.swatch[data-tone='negative'] { background: var(--pink); box-shadow: 0 0 8px var(--pink); }
.swatch[data-tone='target'] { background: transparent; border: 2px solid var(--green); }
.swatch[data-tone='loss'] { background: transparent; border: 2px solid var(--gold); }

.guide-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 26px; border-top: 1px solid var(--edge);
}
.guide-progress { font-family: var(--mono); font-size: 10px; color: var(--ink-faint); letter-spacing: 0.1em; }

/* ── pacing: what exists before free play ──────────────────────────── */
/* The lesson is one sentence and one button. Everything else arrives when the
   player is let loose, so the first minute is not a cockpit. The stage lives on
   .app as data-stage, set only by setStage() in app.js. */
.app:not([data-stage='free']) .reveal-free { display: none !important; }

.goal {
  margin: -4px 0 10px; font-size: 11px; letter-spacing: 0.06em; color: var(--ink-muted);
}
.goal b { font-family: var(--mono); font-weight: 500; color: var(--cyan); margin-left: 4px; }
.goal.is-done { color: var(--green); }
.example-note { margin: 6px 0 2px; font-size: 11px; line-height: 1.5; color: var(--gold); }

/* ── never seen ────────────────────────────────────────────────────── */
/* Purple throughout, matching its line on the loss graph (--never-seen mirrors
   PALETTE.heldOut, whose contrast tests/run.js measures). */
:root { --never-seen: #b69cff; }
.never-seen { margin: 4px 0 12px; }
.never-seen-title { color: var(--never-seen); cursor: help; margin-bottom: 8px; }
.never-seen .examples { margin-bottom: 0; }
.example.is-test { border-style: dashed; border-color: rgba(182, 156, 255, 0.35); background: linear-gradient(180deg, rgba(182, 156, 255, 0.06), transparent); }
.example.is-test:hover { border-color: var(--never-seen); }
.example.is-test.is-focus { border-color: var(--never-seen); box-shadow: 0 0 0 1px rgba(182, 156, 255, 0.25), 0 0 22px rgba(182, 156, 255, 0.12); }
.example.is-test .example-bar { background: var(--never-seen); }
.rail-link { display: block; margin: 0 0 12px; font-size: 12px; text-align: left; }

/* ── where the answers come from ───────────────────────────────────── */
.split {
  position: absolute; inset: 0; z-index: 5;
  display: grid; place-items: center; padding: 16px;
  background: rgba(8, 11, 20, 0.84); backdrop-filter: blur(3px);
  animation: splitIn 0.3s ease-out;
}
/* Its own keyframes: chipIn carries the phase chip's translate(-50%), which
   slid this whole overlay in from half off screen. */
@keyframes splitIn { from { opacity: 0; } }
.split-card {
  width: min(540px, 100%); max-height: 100%; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--edge-bright); border-radius: var(--radius);
  padding: 22px 24px; box-shadow: 0 30px 70px rgba(0, 0, 0, 0.55);
  text-align: center;
}
.split-title { margin: 0 0 16px; font-size: 10px; letter-spacing: 0.26em; color: var(--ink-muted); }
.split-sentence { margin: 0 0 14px; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; min-height: 34px; }
.split-word {
  display: inline-block; font-family: var(--mono); font-size: 14px; line-height: 1.2;
  padding: 5px 9px; border: 1px solid var(--edge-bright); border-radius: var(--radius);
  color: var(--ink); background: var(--panel-raised);
}
.split-word.is-ahead { color: transparent; border-style: dashed; border-color: var(--edge); background: transparent; }
.split-word.is-question { color: var(--gold); border-color: var(--gold); box-shadow: 0 0 14px rgba(255, 209, 102, 0.25); }
.split-word.is-answer { color: var(--green); border-color: var(--green); box-shadow: 0 0 14px rgba(126, 240, 178, 0.25); animation: tokenIn 0.35s ease-out; }
.split-word.is-dim { color: var(--ink-faint); border-color: var(--edge); background: transparent; }
.split-caption { margin: 0 0 14px; min-height: 1.6em; font-size: 14px; line-height: 1.6; color: var(--ink); }
.split-caption em { font-style: normal; color: var(--green); }
.split-pairs {
  list-style: none; margin: 0 auto 12px; padding: 0; display: inline-flex; flex-direction: column; gap: 3px;
  text-align: left; font-family: var(--mono); font-size: 12px; color: var(--ink-body);
}
.split-pairs li { animation: tokenIn 0.3s ease-out; }
.split-pairs .blank { color: var(--gold); }
.split-pairs .ans { color: var(--green); font-weight: 700; }
.split-count { margin: 0 0 16px; min-height: 1.4em; font-family: var(--mono); font-size: 12px; color: var(--cyan); }

/* ── from this to a chatbot ────────────────────────────────────────── */
.chatbot-card { width: min(1040px, 100%); }
.chatbot-card h2 { margin-bottom: 12px; }
.chatbot-lead { margin: 0 0 22px; font-size: 15px; line-height: 1.6; color: var(--ink); max-width: 680px; }
.chatbot-stages { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.chatbot-stage {
  border: 1px solid var(--edge); border-top: 2px solid var(--tone, var(--cyan)); border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(20, 28, 44, 0.6), transparent);
  padding: 14px 16px 16px; min-width: 0;
}
.chatbot-stage[data-tone='forward'] { --tone: var(--cyan); }
.chatbot-stage[data-tone='backward'] { --tone: var(--amber); }
.chatbot-stage[data-tone='target'] { --tone: var(--green); }
.chatbot-n { margin: 0 0 4px; font-size: 9.5px; letter-spacing: 0.2em; font-weight: 600; color: var(--tone); }
.chatbot-stage h3 { font-size: 15px; color: var(--ink); margin-bottom: 8px; }
.chatbot-copy { margin: 0 0 10px; font-size: 12.5px; line-height: 1.6; color: var(--ink-body); }
.chatbot-copy:last-child { margin-bottom: 0; }
.demo { margin: 0 0 10px; padding: 9px 11px; border: 1px solid var(--edge); border-radius: var(--radius); background: var(--void); }
.demo-label { margin: 0 0 6px; font-size: 8.5px; letter-spacing: 0.18em; color: var(--ink-faint); }
.demo-line { margin: 0 0 4px; font-family: var(--mono); font-size: 12px; line-height: 1.55; color: var(--ink-body); overflow-wrap: anywhere; }
.demo-line:last-child { margin-bottom: 0; }
.demo-prompt { color: var(--ink); }
.demo-answer { color: var(--green); font-weight: 700; }
.demo-bad { color: var(--pink); }
.demo-who { color: var(--ink-faint); }
.demo-arrow { color: var(--ink-faint); }
.demo .split-word { font-size: 11px; padding: 1px 6px; }
.demo-choice { color: var(--ink-faint); }
.demo-choice.is-picked { color: var(--green); }
.demo-mark { display: inline-block; width: 1.2em; }
.chatbot-loop { margin: 20px 0 0; font-size: 13.5px; color: var(--ink-body); text-align: center; }
.chatbot-loop b { color: var(--ink); font-weight: 600; }

@media (max-width: 980px) {
  .chatbot-stages { grid-template-columns: minmax(0, 1fr); }
}

/* ── tooltip & debug ───────────────────────────────────────────────── */
.tooltip {
  /* width: max-content is load-bearing. A fixed-position box with only a
     max-width shrink-to-fits against the distance to the viewport's right
     edge, so the same text measures 260x73 at left:0 and 94x198 at left:700 —
     and the script has to measure it to decide where to put it. max-content
     makes the size depend on the text alone, whatever the box is sitting on. */
  position: fixed; z-index: 60; pointer-events: none;
  width: max-content; max-width: min(260px, calc(100vw - 24px));
  background: var(--panel-raised); border: 1px solid var(--edge-bright); border-radius: var(--radius);
  padding: 9px 11px; font-size: 11.5px; line-height: 1.55; color: var(--ink-body);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
.tooltip[hidden] { display: none; }

.debug {
  position: fixed; right: 10px; bottom: 10px; z-index: 70; margin: 0;
  background: rgba(5, 7, 13, 0.92); border: 1px solid var(--edge-bright); border-radius: var(--radius);
  padding: 10px 12px; font-family: var(--mono); font-size: 10px; line-height: 1.65; color: var(--ink-muted);
  white-space: pre; pointer-events: none;
}
.debug[hidden] { display: none; }
.debug b { color: var(--cyan); font-weight: 500; }

/* ── responsive ────────────────────────────────────────────────────── */
@media (max-width: 1180px) {
  :root { --rail-left: 250px; --rail-right: 290px; }
  .brand-sub { display: none; }
  .readouts { gap: 18px; }
}

@media (max-width: 980px) {
  html, body { height: auto; }
  .app { height: auto; min-height: 100dvh; }
  .topbar { grid-template-columns: 1fr auto auto; row-gap: 12px; }
  .readouts { grid-column: 1 / -1; justify-content: space-between; gap: 12px; }
  .stage { grid-template-columns: 1fr; }
  .viewport { order: -1; height: auto; }
  #network { flex: 0 0 auto; height: min(60dvh, 500px); }
  .rail { max-height: none; overflow: visible; }
  .panel-graph { height: 150px; }
  .controlbar { position: sticky; bottom: 0; z-index: 10; background: var(--void); }
  .controls-settings { width: 100%; justify-content: space-between; gap: 14px; }
  .controls-settings .slider { width: auto; flex: 1; }
  .scale-grid { grid-template-columns: 1fr; gap: 20px; }

  /* The guide's side nav becomes a scrolling strip above the text. */
  .guide-card { max-height: 92dvh; }
  .guide-body { grid-template-columns: minmax(0, 1fr); }
  .guide-nav {
    flex-direction: row; gap: 4px;
    border-right: 0; border-bottom: 1px solid var(--edge);
    overflow-x: auto; padding: 10px;
  }
  .guide-nav button { white-space: nowrap; box-shadow: none !important; }
  .guide-nav button.is-active { color: var(--void); background: var(--cyan); }
  .guide-nav button.is-active .n { color: rgba(5, 7, 13, 0.65); }
  .guide-panes { padding: 20px 22px 26px; }
  .guide-defs > div { grid-template-columns: minmax(0, 1fr); gap: 4px; }
}

/* Narrow phones: the topbar is what overflows first — the brand name, the mode
   switch and four readouts cannot all keep their natural width. */
@media (max-width: 620px) {
  .topbar { grid-template-columns: minmax(0, 1fr) auto auto; padding: 10px 12px; gap: 10px; }
  /* Only the mark survives — the label is what stops all three fitting. */
  .btn-guide { padding: 7px 9px; font-size: 0; gap: 0; }
  .brand-name { font-size: 10px; letter-spacing: 0.1em; }
  .brand-mark { width: 7px; height: 7px; }
  .mode { padding: 6px 14px; letter-spacing: 0.12em; }
  .readouts {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }
  .readout dt { font-size: 8px; letter-spacing: 0.1em; }
  .readout dd { font-size: 13px; }
  .controlbar { padding: 10px 12px; gap: 12px; }
  .guide-head { padding: 16px 18px 14px; }
  .guide-foot { padding: 12px 18px; }
}

@media (max-width: 560px) {
  .controls-main { flex-wrap: wrap; }
  .btn-train { min-width: 100%; }
  .narration { bottom: auto; top: 50%; transform: translate(-50%, -50%); }
  .disclaimer { position: static; padding: 12px 14px; }
  #network { height: 56dvh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
