/* VLSF Lab. Material 3 look shared with guodongsun.com: same blue / slate / purple scheme,
   Google Sans Flex + Roboto Flex, a navigation rail and rounded tonal panes.
   Colours carry meaning everywhere:
   --true  (primary blue)    the sent codeword / a correct decision
   --wrong (outline grey)    the other codewords
   --danger(error red)       an error
   --gamma (tertiary purple) the threshold and the stop-feedback bit
   --data  (teal)            Monte Carlo and exact curves in the charts
   --tie   (amber)           ties
   --accent(primary)         UI accents */

:root {
  --bg: #ECEEF3;
  --pane: #F7F9FF;
  --surface: #F1F3F9;
  --surface-2: #E6E8EE;
  --surface-3: #E0E2E8;
  --text: #181C20;
  --muted: #42474E;
  --faint: #72777F;
  --border: #C2C7CF;
  --grid: #E0E2E8;
  --accent: #2F628C;
  --accent-soft: #CEE5FF;
  --on-accent: #FFFFFF;
  --on-accent-soft: #0F4A73;
  --secondary: #51606F;
  --secondary-soft: #D5E4F7;
  --on-secondary-soft: #3A4857;
  --true: #2F628C;
  --true-soft: #CEE5FF;
  --wrong: #72777F;
  --wrong-soft: #E6E8EE;
  --danger: #BA1A1A;
  --danger-soft: #FFDAD6;
  --gamma: #68587A;
  --gamma-soft: #EFDBFF;
  --data: #006B5F;
  --tie: #7A5900;
  --live-0: #E0E2E8;
  --live-1: #CDD2DA;
  --live-e: #ECEEF3;
  --shadow-rgb: 0 0 0;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1C2024; --pane: #101418; --surface: #181C20; --surface-2: #272A2F; --surface-3: #323539;
    --text: #E0E2E8; --muted: #C2C7CF; --faint: #8C9198; --border: #42474E; --grid: #272A2F;
    --accent: #9BCBFB; --accent-soft: #0F4A73; --on-accent: #003353; --on-accent-soft: #CEE5FF;
    --secondary: #B9C8DA; --secondary-soft: #3A4857; --on-secondary-soft: #D5E4F7;
    --true: #9BCBFB; --true-soft: #0F4A73; --wrong: #8C9198; --wrong-soft: #272A2F;
    --danger: #FFB4AB; --danger-soft: #93000A; --gamma: #D3BFE6; --gamma-soft: #504061;
    --data: #53DBC9; --tie: #F1C04D; --live-0: #2A2E33; --live-1: #383C42; --live-e: #1C2024;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1C2024; --pane: #101418; --surface: #181C20; --surface-2: #272A2F; --surface-3: #323539;
  --text: #E0E2E8; --muted: #C2C7CF; --faint: #8C9198; --border: #42474E; --grid: #272A2F;
  --accent: #9BCBFB; --accent-soft: #0F4A73; --on-accent: #003353; --on-accent-soft: #CEE5FF;
  --secondary: #B9C8DA; --secondary-soft: #3A4857; --on-secondary-soft: #D5E4F7;
  --true: #9BCBFB; --true-soft: #0F4A73; --wrong: #8C9198; --wrong-soft: #272A2F;
  --danger: #FFB4AB; --danger-soft: #93000A; --gamma: #D3BFE6; --gamma-soft: #504061;
  --data: #53DBC9; --tie: #F1C04D; --live-0: #2A2E33; --live-1: #383C42; --live-e: #1C2024;
  color-scheme: dark;
}

:root {
  --brand: "Google Sans Flex", "Google Sans", "Roboto Flex", Roboto, system-ui, sans-serif;
  --font: "Roboto Flex", Roboto, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --mono: "Roboto Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --shape-xs: 4px;
  --shape-sm: 8px;
  --shape-md: 12px;
  --shape-lg: 16px;
  --shape-lg-inc: 20px;
  --shape-xl: 28px;
  --shape-full: 999px;
  --radius: var(--shape-lg-inc);
  --radius-sm: var(--shape-md);
  --elev-1: 0 1px 2px rgb(var(--shadow-rgb) / 0.3), 0 1px 3px 1px rgb(var(--shadow-rgb) / 0.15);
  --elev-2: 0 1px 2px rgb(var(--shadow-rgb) / 0.3), 0 2px 6px 2px rgb(var(--shadow-rgb) / 0.15);
  --elev-3: 0 1px 3px rgb(var(--shadow-rgb) / 0.3), 0 4px 8px 3px rgb(var(--shadow-rgb) / 0.15);
  --shadow: var(--elev-2);
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/20px var(--font);
  letter-spacing: 0.15px;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
sup, sub { line-height: 0; }
strong, b { font-weight: 600; }
h1, h2, h3, h4 { font-family: var(--brand); font-weight: 500; color: var(--text); letter-spacing: 0; }
.num, output { font-family: var(--font); font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--secondary); outline-offset: 2px; border-radius: var(--shape-sm); }

.msr {
  font-family: "Material Symbols Rounded";
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  direction: ltr;
  font-feature-settings: "liga";
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
  user-select: none;
  flex: none;
  width: 24px;
  overflow: hidden;
}

/* ------------------------------------------------------------------ layout */

.app {
  display: grid;
  grid-template-columns: 96px 288px minmax(0, 1fr) 392px;
  grid-template-rows: minmax(0, 1fr);
  grid-template-areas: "top controls stage tutor";
  gap: 12px;
  padding: 12px 12px 12px 0;
  height: 100vh;
}
.app.tutor-hidden { grid-template-columns: 96px 288px minmax(0, 1fr); grid-template-areas: "top controls stage"; }
.app.tutor-hidden .tutor { display: none; }

/* The top bar is the navigation rail. */
.topbar { grid-area: top; display: flex; min-width: 0; min-height: 0; }
.brand { display: flex; align-items: center; gap: 12px; flex: none; }
.brand-mark { width: 40px; height: 40px; border-radius: var(--shape-md); transition: border-radius 400ms var(--ease-spring); flex: none; }
.brand:hover .brand-mark { border-radius: 20px; }
.brand-mark rect { fill: var(--accent); }
.brand-mark .bm-gamma { stroke: var(--on-accent); opacity: 0.55; stroke-width: 4; stroke-dasharray: 6 5; fill: none; }
.brand-mark .bm-walk { stroke: var(--on-accent); stroke-width: 5; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.brand-name { font-family: var(--brand); font-size: 22px; line-height: 28px; font-weight: 500; white-space: nowrap; }
.brand-sub { font-size: 12px; line-height: 16px; letter-spacing: 0.4px; color: var(--muted); }

.tabs { display: flex; gap: 2px; scrollbar-width: none; min-width: 0; min-height: 0; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button, .rail-btn {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 72px;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  letter-spacing: 0.5px;
  text-align: center;
  cursor: pointer;
}
.rail-icon {
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  width: 56px;
  height: 32px;
  border-radius: var(--shape-full);
  transition: background-color 200ms var(--ease);
}
.rail-icon::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--text);
  opacity: 0;
  transition: opacity 150ms linear;
  z-index: -1;
}
.tabs button:hover .rail-icon::after, .rail-btn:hover .rail-icon::after { opacity: 0.08; }
.tabs button:focus-visible, .rail-btn:focus-visible { outline: none; }
.tabs button:focus-visible .rail-icon, .rail-btn:focus-visible .rail-icon { outline: 3px solid var(--secondary); outline-offset: 2px; }
.tabs button[aria-selected="true"], .rail-btn[aria-pressed="true"] { color: var(--secondary); font-weight: 700; }
.tabs button[aria-selected="true"] .rail-icon, .rail-btn[aria-pressed="true"] .rail-icon { background: var(--secondary-soft); color: var(--on-secondary-soft); }
.tabs button[aria-selected="true"] .msr { font-variation-settings: "FILL" 1, "wght" 500, "GRAD" 0, "opsz" 24; }
.top-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.controls {
  grid-area: controls;
  overflow-y: auto;
  padding: 20px 20px 16px;
  background: var(--pane);
  border-radius: var(--shape-xl);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.stage {
  grid-area: stage;
  overflow-y: auto;
  padding: 28px 32px 48px;
  min-width: 0;
  background: var(--pane);
  border-radius: var(--shape-xl);
  container-type: inline-size;
}
.tab-panel { max-width: 1180px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; }

@media (min-width: 861px) {
  .topbar { flex-direction: column; align-items: center; gap: 32px; padding: 8px 0; }
  .brand-mark { width: 48px; height: 48px; border-radius: var(--shape-lg); }
  .brand:hover .brand-mark { border-radius: 24px; }
  .brand > div { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
  .tabs { flex-direction: column; gap: 12px; overflow-y: auto; flex: 0 1 auto; }
  .tabs button, .rail-btn { width: 80px; min-width: 0; padding: 0; }
  .top-actions { flex-direction: column; gap: 12px; margin-top: auto; }
}

/* ------------------------------------------------------------------ controls */

.ctl-group h2 {
  margin: 0 0 10px;
  font-family: var(--font);
  font-size: 14px;
  line-height: 20px;
  font-weight: 600;
  letter-spacing: 0.1px;
  color: var(--accent);
}
.ctl-group + .ctl-group { padding-top: 14px; border-top: 1px solid var(--border); }
.ctl { display: block; margin-bottom: 12px; }
.ctl-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.ctl-label { color: var(--muted); font-size: 13px; }
.ctl output { font-size: 13px; font-weight: 500; color: var(--text); }

input[type="range"] { width: 100%; accent-color: var(--accent); height: 22px; margin: 0; cursor: pointer; }
input[type="checkbox"] { accent-color: var(--accent); }
.mini input[type="range"] { width: 110px; }
select {
  background: transparent;
  border: 1px solid var(--faint);
  border-radius: var(--shape-sm);
  padding: 4px 8px;
  cursor: pointer;
}
select:hover { border-color: var(--text); }

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--surface-2);
  border-radius: var(--shape-full);
  padding: 3px;
  gap: 2px;
  margin-bottom: 12px;
}
.seg button {
  border: 0;
  background: none;
  border-radius: var(--shape-full);
  padding: 6px 0;
  font-weight: 500;
  font-size: 13px;
  letter-spacing: 0.1px;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 200ms var(--ease);
}
.seg button:hover { color: var(--text); }
.seg button[aria-checked="true"] { background: var(--secondary-soft); color: var(--on-secondary-soft); }

.eps-helper {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  margin: -4px 0 14px;
}

.derived dl { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 5px 10px; font-size: 13px; }
.derived dt { color: var(--muted); }
.derived dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.derived dt.sep, .derived dd.sep { border-top: 1px solid var(--border); padding-top: 6px; margin-top: 2px; }
.derived .k-true { color: var(--true); }
.derived .k-wrong { color: var(--wrong); }
.derived .k-gamma { color: var(--gamma); }

.status { margin-top: auto; display: flex; gap: 8px; align-items: flex-start; font-size: 12px; line-height: 16px; letter-spacing: 0.4px; color: var(--muted); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); margin-top: 4px; flex: none; }
.status.ok .dot { background: var(--data); }
.status.mock .dot { background: var(--tie); }
.status.err .dot { background: var(--danger); }

/* ------------------------------------------------------------------ buttons */

.btn {
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  border: 0;
  background: var(--secondary-soft);
  color: var(--on-secondary-soft);
  border-radius: var(--shape-full);
  padding: 6px 18px;
  font-weight: 500;
  font-size: 14px;
  line-height: 20px;
  letter-spacing: 0.1px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-radius 300ms var(--ease-spring), box-shadow 200ms var(--ease);
}
.btn::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: currentColor;
  opacity: 0;
  transition: opacity 150ms linear;
  pointer-events: none;
  z-index: -1;
}
.btn:hover::after { opacity: 0.08; }
.btn:active::after { opacity: 0.12; }
.btn:active { border-radius: var(--shape-md); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:disabled::after { display: none; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:hover { box-shadow: var(--elev-1); }
.btn.ghost { color: var(--accent); background: none; padding-inline: 12px; }
.btn.small { min-height: 28px; padding: 3px 12px; font-size: 13px; }
.icon-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--shape-full);
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 150ms linear;
}
.icon-btn:hover { background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text); }

/* ------------------------------------------------------------------ panels & cards */

.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 4px; }
.panel-head h1 { margin: 0 0 6px; font-size: 28px; line-height: 36px; font-weight: 450; }
.lede { margin: 0; color: var(--muted); max-width: 780px; font-family: var(--brand); font-size: 16px; line-height: 24px; }
.ask { flex: none; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.toolbar .spacer, .spacer { flex: 1; }
.mini { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; cursor: pointer; }
.note { color: var(--muted); font-size: 13px; letter-spacing: 0.25px; }
.badge { font-size: 12px; line-height: 16px; letter-spacing: 0.5px; border-radius: var(--shape-sm); padding: 4px 10px; font-weight: 600; }
.badge.warn { background: var(--gamma-soft); color: var(--gamma); }
.note-bar { background: var(--secondary-soft); color: var(--on-secondary-soft); border-radius: var(--shape-lg); padding: 10px 16px; font-size: 13px; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px 18px;
  position: relative;
  min-width: 0;
}
.tx-guide {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  background: var(--accent-soft);
  color: var(--on-accent-soft);
  border-radius: var(--shape-xl);
  padding: 20px 24px;
}
.tx-guide > div:first-child { flex: 1 1 260px; min-width: 0; }
.tx-guide-progress { font-size: 14px; line-height: 20px; font-weight: 600; letter-spacing: 0.1px; }
.tx-guide h2 { margin: 2px 0 4px; font-size: 22px; line-height: 28px; font-weight: 450; color: inherit; }
.tx-guide p { margin: 0; font-size: 14px; }
.tx-guide .note { color: inherit; opacity: 0.8; }
.tx-guide-actions { display: grid; gap: 4px; text-align: center; }
.tx-guide-actions .btn[aria-disabled="true"] { opacity: 0.6; cursor: default; }

.result-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 18px;
}
.result-summary > div { flex: 1 1 240px; min-width: 0; }
.result-value { margin: 0; font-family: var(--brand); font-size: clamp(18px, 2.2vw, 24px); font-weight: 500; line-height: 1.3; }
.result-detail { margin: 4px 0 0; color: var(--muted); font-size: 14px; letter-spacing: 0.25px; }
.result-summary .ask { white-space: normal; text-align: left; max-width: 100%; }
.tx-result { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 8px; }
.tx-plot h2 { font-size: 18px; line-height: 24px; margin: 0; }
.tx-plot-tools { display: flex; justify-content: space-between; flex-wrap: wrap; align-items: center; gap: 4px 16px; }
.tx-plot-tools .tx-legend { margin: 0; }
#txLivePlot { position: relative; }
.legend-inline .score-swatch { width: 17px; height: 0; border-radius: 0; vertical-align: 3px; border-top: 2px solid; }
.legend-inline .score-swatch.sent { border-color: var(--true); }
.legend-inline .score-swatch.competitor { border-color: var(--danger); border-top-style: dotted; }
.legend-inline .score-swatch.threshold { border-color: var(--gamma); border-top-style: dashed; }
.tx-compare > p { margin: 8px 0; }
.tx-compare-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tx-compare-grid figure { margin: 0; min-width: 0; background: var(--surface-2); border-radius: var(--shape-lg); padding: 10px; }
.tx-compare-grid figcaption { font-size: 13px; font-weight: 600; padding: 0 4px; }
.tx-compare-grid canvas { height: 240px; }
@container (max-width: 620px) {
  .tx-compare-grid { grid-template-columns: 1fr; }
}
.tx-options summary { cursor: pointer; font-weight: 500; font-family: var(--brand); font-size: 16px; }
.tx-options summary::marker { color: var(--accent); }
.tx-options[open] summary { margin-bottom: 10px; }
.settings-head, .mobile-settings, .settings-scrim { display: none; }

.card h3 { margin: 0 0 8px; font-size: 16px; line-height: 24px; font-weight: 500; }
.card-title-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 6px; }
.card-title-row h3 { margin: 0; }
.hint { color: var(--faint); font-family: var(--font); font-size: 12px; line-height: 16px; letter-spacing: 0.4px; font-weight: 400; }
.empty-card { color: var(--muted); grid-column: 1 / -1; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }

canvas { display: block; width: 100%; }
.cv-codebook { height: 168px; }
.cv-walks { height: 340px; }
.cv-md { height: 250px; }
.cv-sm { height: 190px; }
.cv-lg { height: 420px; }
.cv-tree { height: 470px; cursor: crosshair; }

.plot-tip {
  position: absolute;
  pointer-events: none;
  z-index: 5;
  background: var(--surface-3);
  box-shadow: var(--elev-2);
  border-radius: var(--shape-md);
  padding: 8px 12px;
  font-size: 12px;
  line-height: 16px;
  letter-spacing: 0.4px;
  max-width: 280px;
  white-space: nowrap;
}
.plot-tip b { font-weight: 600; }
.plot-tip .mono { font-family: var(--mono); }

.stat {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 18px 16px;
}
.stat .s-label { color: var(--muted); font-size: 13px; letter-spacing: 0.25px; }
.stat .s-value { font-family: var(--brand); font-size: 26px; line-height: 34px; font-weight: 450; font-variant-numeric: tabular-nums; color: var(--accent); margin: 1px 0; }
.stat .s-sub { color: var(--faint); font-size: 12px; line-height: 16px; letter-spacing: 0.4px; }
.stat.good .s-value { color: var(--true); }
.stat.bad .s-value { color: var(--danger); }

.statline { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--muted); margin-top: 6px; }
.statline b { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 500; }
.explain { font-size: 13px; letter-spacing: 0.25px; color: var(--muted); margin: 6px 0 0; }

/* ------------------------------------------------------------------ transmission */

.scrub { display: flex; align-items: center; gap: 12px; }
.scrub span { font-size: 13px; color: var(--muted); min-width: 92px; text-align: right; }
.diagram-card { padding: 8px 12px; }
.diagram { width: 100%; height: auto; display: block; }
.diagram .box { fill: var(--surface-2); stroke: var(--border); }
.diagram .box.active { stroke: var(--accent); }
.diagram .t { fill: var(--text); font: 600 13px var(--font); }
.diagram .s { fill: var(--muted); font: 11.5px var(--font); }
.diagram .v { fill: var(--text); font: 500 15px var(--mono); }
.diagram .wire { stroke: var(--faint); stroke-width: 1.6; fill: none; }
.diagram .fb { stroke: var(--gamma); stroke-width: 1.6; fill: none; stroke-dasharray: 5 4; }
.diagram .fb.on { stroke-dasharray: none; stroke-width: 2.6; }
.diagram .fbbit { font: 500 12px var(--mono); fill: var(--muted); }
.diagram .fbbit.one { fill: var(--gamma); font-weight: 700; }
.diagram .pulse { fill: var(--gamma); }
.diagram .xbit { fill: var(--true); }
.diagram .ybad { fill: var(--danger); }

/* When the stage is narrow (e.g. the tutor is open), the walk plot gets the full width and the
   decoder state becomes a strip below it. */
@container (max-width: 1040px) {
  .decoder-card { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px 18px; align-items: center; }
  .decoder-card .outcome, .decoder-card .hint { grid-column: 1 / -1; margin: 0; }
}
.decoder-card { display: flex; flex-direction: column; gap: 10px; font-size: 13px; }
.decoder-card .d-row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.decoder-card .d-k { color: var(--muted); }
.decoder-card .d-v { font-variant-numeric: tabular-nums; font-weight: 500; }
.decoder-card .d-v.true { color: var(--true); }
.decoder-card .bar { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; margin-top: 4px; }
.decoder-card .bar span { display: block; height: 100%; background: var(--true); transition: width 0.15s; }
.outcome { border-radius: var(--shape-md); padding: 10px 14px; font-weight: 500; font-size: 13px; }
.outcome.wait { background: var(--surface-2); color: var(--muted); }
.outcome.ok { background: var(--true-soft); color: var(--on-accent-soft); }
.outcome.err { background: var(--danger-soft); color: var(--danger); }
.fb-big { font-family: var(--mono); font-size: 13px; }
.fb-big .one { color: var(--gamma); font-weight: 700; }
.tx-legend, .card-legend { margin: 0 0 6px; }
.narrative { font-size: 14px; line-height: 22px; }
.narrative p { margin: 0 0 6px; }
.narrative p:last-child { margin: 0; }
.narrative .tag { font-weight: 600; }

/* ------------------------------------------------------------------ filtration */

.fx-main { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 12px; align-items: start; }
.fx-side { display: flex; flex-direction: column; gap: 12px; }
.fx-codebook { font-family: var(--mono); font-size: 12px; line-height: 1.7; overflow-x: auto; }
.fx-codebook .row { white-space: nowrap; }
.fx-codebook .lab { color: var(--muted); display: inline-block; width: 2.6em; }
.fx-codebook .row.sent .lab { color: var(--true); font-weight: 600; }
.fx-codebook b { font-weight: 400; padding: 0 1px; border-radius: 3px; }
.fx-codebook b.hit { background: var(--true-soft); color: var(--on-accent-soft); }
.fx-codebook b.miss { background: var(--danger-soft); color: var(--danger); }
.fx-codebook b.era { background: var(--surface-3); color: var(--faint); }
.fx-hover { font-size: 13px; min-height: 120px; }
.fx-hover .prefix { font-family: var(--mono); word-break: break-all; }
.sbar { display: grid; grid-template-columns: 3.2em 1fr 3.6em; gap: 6px; align-items: center; margin: 3px 0; font-size: 12px; }
.sbar .track { position: relative; height: 8px; background: var(--surface-3); border-radius: 4px; }
.sbar .fill { position: absolute; top: 0; bottom: 0; border-radius: 4px; background: var(--wrong); }
.sbar .fill.true { background: var(--true); }
.sbar .gam { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--gamma); }
.sbar .v { font-variant-numeric: tabular-nums; text-align: right; }
.legend-inline { display: inline-flex; gap: 6px 14px; font-size: 12px; line-height: 16px; letter-spacing: 0.4px; color: var(--muted); flex-wrap: wrap; }
.legend-inline i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

/* ------------------------------------------------------------------ limits */

.insight-cards { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.insight { background: var(--surface); border-radius: var(--radius); padding: 16px 20px 18px; }
.insight .i-kicker { font-size: 14px; line-height: 20px; letter-spacing: 0.1px; color: var(--accent); font-weight: 600; }
.insight .i-big { font-family: var(--brand); font-size: 28px; line-height: 36px; font-weight: 450; font-variant-numeric: tabular-nums; margin: 4px 0 2px; }
.insight .i-big small { font-family: var(--font); font-size: 13px; color: var(--muted); }
.insight p { margin: 4px 0 0; font-size: 13px; letter-spacing: 0.25px; color: var(--muted); }

/* ------------------------------------------------------------------ prose (theory, tutor) */

.prose { padding: 24px 28px; font-size: 15px; line-height: 24px; max-width: 900px; }
.prose h1 { font-size: 28px; line-height: 36px; font-weight: 450; margin: 0 0 12px; }
.prose h2 { font-size: 22px; line-height: 28px; margin: 28px 0 8px; display: flex; align-items: center; gap: 10px; }
.prose h3 { font-size: 17px; line-height: 24px; margin: 18px 0 6px; }
.prose p { margin: 0 0 12px; }
.prose ul, .prose ol { margin: 0 0 12px; padding-left: 22px; }
.prose li { margin: 4px 0; }
.prose li::marker { color: var(--accent); }
.prose code { font-family: var(--mono); font-size: 0.9em; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
.prose pre { background: var(--surface-2); padding: 12px 16px; border-radius: var(--shape-lg); overflow-x: auto; }
.prose pre code { background: none; padding: 0; }
.prose table { border-collapse: collapse; margin: 8px 0 14px; font-size: 13px; line-height: 20px; display: block; overflow-x: auto; }
.prose th, .prose td { border-bottom: 1px solid var(--border); padding: 8px 12px; text-align: left; vertical-align: top; }
.prose th { color: var(--text); font-weight: 600; border-bottom-color: var(--faint); }
.prose a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.prose a:hover { text-decoration-thickness: 2px; }
.prose blockquote { margin: 0 0 12px; padding: 12px 16px; background: var(--secondary-soft); color: var(--on-secondary-soft); border-radius: var(--shape-lg); }
.prose blockquote p:last-child { margin-bottom: 0; }
.prose .katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.prose h2 .ask-sec { font-family: var(--font); font-size: 13px; font-weight: 500; }

/* ------------------------------------------------------------------ tutor */

.tutor {
  grid-area: tutor;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--pane);
  border-radius: var(--shape-xl);
  overflow: hidden;
}
.tutor-head { display: flex; align-items: center; gap: 6px; padding: 14px 12px 10px 20px; }
.tutor-title { font-family: var(--brand); font-size: 22px; line-height: 28px; font-weight: 500; }
.tutor-sub { font-size: 12px; line-height: 16px; letter-spacing: 0.4px; color: var(--muted); }
.tutor-msgs { flex: 1; overflow-y: auto; padding: 12px 16px 6px; display: flex; flex-direction: column; gap: 12px; }
.tutor-empty { color: var(--muted); font-size: 14px; }
.tutor-empty .te-title { color: var(--text); font-family: var(--brand); font-weight: 500; font-size: 18px; line-height: 24px; margin: 4px 0 6px; }
.chips { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.chip {
  text-align: left;
  border: 1px solid var(--border);
  background: none;
  border-radius: var(--shape-sm);
  padding: 6px 14px;
  min-height: 32px;
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
  letter-spacing: 0.1px;
  cursor: pointer;
  color: var(--muted);
  transition: background-color 150ms linear;
}
.chip:hover { background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text); }

.msg { display: flex; flex-direction: column; gap: 6px; }
.msg.user { align-items: flex-end; }
.msg .bubble { border-radius: var(--shape-lg-inc); padding: 10px 14px; max-width: 100%; font-size: 14px; line-height: 20px; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--accent); color: var(--on-accent); border-bottom-right-radius: var(--shape-xs); max-width: 88%; white-space: pre-wrap; }
.msg.model .bubble { background: var(--surface-2); border-bottom-left-radius: var(--shape-xs); }
.msg.model .bubble.prose { padding: 10px 14px; max-width: none; font-size: 14px; line-height: 22px; }
.msg.model .bubble.prose p:last-child { margin-bottom: 0; }
.msg.model .bubble.prose h1, .msg.model .bubble.prose h2, .msg.model .bubble.prose h3 { font-size: 15px; line-height: 22px; margin: 10px 0 4px; }
.msg.model .bubble.prose code { background: var(--surface-3); }
.msg .err-text { color: var(--danger); font-size: 13px; }
.toolchip {
  align-self: flex-start;
  border: 1px solid var(--border);
  border-radius: var(--shape-md);
  font-size: 12px;
  line-height: 16px;
  max-width: 100%;
}
.toolchip summary { list-style: none; cursor: pointer; padding: 6px 12px; display: flex; gap: 7px; align-items: center; color: var(--muted); }
.toolchip summary::-webkit-details-marker { display: none; }
.toolchip summary .tc-icon { color: var(--accent); }
.toolchip.bad summary .tc-icon { color: var(--danger); }
.toolchip summary .tc-label { color: var(--text); font-weight: 500; }
.toolchip pre { margin: 0; padding: 8px 12px; border-top: 1px solid var(--border); max-height: 220px; overflow: auto; font: 11px/1.45 var(--mono); color: var(--muted); white-space: pre-wrap; word-break: break-all; }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.tutor-context { font-size: 12px; line-height: 16px; letter-spacing: 0.4px; color: var(--faint); padding: 4px 20px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 12px 12px; }
.composer textarea {
  flex: 1;
  resize: none;
  border: 0;
  border-radius: var(--shape-lg-inc);
  padding: 10px 16px;
  background: var(--surface-2);
  max-height: 160px;
  line-height: 20px;
  font-size: 14px;
}
.composer textarea::placeholder { color: var(--faint); }
.composer textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.composer .btn { height: 40px; width: 40px; min-height: 0; padding: 0; }
.scrim { display: none; }

/* ------------------------------------------------------------------ responsive */

@media (max-width: 1360px) {
  .app, .app.tutor-hidden { grid-template-columns: 96px 264px minmax(0, 1fr); grid-template-areas: "top controls stage"; }
  .tutor {
    position: fixed;
    right: 12px;
    top: 12px;
    bottom: 12px;
    width: min(420px, calc(100vw - 24px));
    z-index: 30;
    box-shadow: var(--elev-3);
  }
  .app:not(.tutor-open) .tutor { display: none; }
  .app.tutor-open .scrim { display: block; position: fixed; inset: 0; background: rgb(0 0 0 / 0.32); z-index: 25; border: 0; }
}

@media (max-width: 980px) {
  .fx-main { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  body { background: var(--pane); }
  .app, .app.tutor-hidden { display: flex; flex-direction: column; gap: 0; padding: 0; height: auto; min-height: 100vh; }
  .topbar { flex-wrap: wrap; align-items: center; padding: 8px 12px 0; gap: 0 12px; }
  .brand { padding: 8px 4px 4px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; padding: 6px 0 10px; }
  .tabs button { white-space: nowrap; }
  .top-actions { margin-left: auto; gap: 4px; }
  .top-actions .rail-label { display: none; }
  .top-actions .rail-icon { width: 40px; height: 40px; }
  .mobile-settings { display: inline-flex; min-height: 32px; padding: 4px 14px; }
  .brand { flex: 1; min-width: 0; }
  .controls { display: none; }
  .app.settings-open .controls {
    display: flex;
    position: fixed;
    z-index: 40;
    inset: 0 0 0 auto;
    width: min(360px, 100%);
    border-radius: var(--shape-xl) 0 0 var(--shape-xl);
    box-shadow: var(--elev-3);
    overscroll-behavior: contain;
  }
  .settings-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
  .settings-head h2 { margin: 0; font-size: 22px; line-height: 28px; }
  .settings-scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgb(0 0 0 / 0.32); border: 0; }
  .tx-compare-grid { grid-template-columns: 1fr; }
  .cv-walks { height: 275px; }
  .tx-plot .card-title-row { flex-wrap: wrap; gap: 4px 12px; }
  .tx-guide-actions { justify-items: start; text-align: left; }
  .scrub span { white-space: nowrap; min-width: auto; }
  .topbar .brand-sub { display: none; }
  .stage { padding: 16px 16px 48px; overflow: visible; border-radius: 0; }
  .panel-head h1 { font-size: 24px; line-height: 32px; }
  .grid-2 { grid-template-columns: 1fr; }
  .panel-head { flex-direction: column; }
  .tutor { inset: 0; width: 100vw; border-radius: 0; }
  .prose { padding: 20px; }
}

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