/* ==========================================================================
   Interactive Search Fundamentals — Andrei Moise Brand + Tactile Lab UX
   Tokens sourced from site-andreimoise-ai (#121212 / #0b0b0b / #00c853)
   ========================================================================== */

:root {
  color-scheme: dark;
  --bg: #121212;
  --bg-deep: #090909;
  --card: #0b0b0b;
  --card-2: #141414;
  --fg: #ededed;
  --reading: #d4d4d4;
  --muted: #9a9a9a;
  --line: #242424;
  --line-strong: #343434;

  /* Andrei brand emerald */
  --brand: #00c853;
  --brand-soft: #98fec3;
  --brand-tint: rgba(0, 200, 83, 0.09);
  --brand-glow: rgba(0, 200, 83, 0.22);

  /* Semantic data-viz palette (carried from prose -> math -> canvas -> KPIs) */
  --sem-primary: #00c853;   /* BM25 / valid match / Doc A */
  --sem-secondary: #60a5fa; /* IDF / Doc B / secondary vector */
  --sem-amber: #f59e0b;     /* Ceiling / length norm / invariant */
  --sem-coral: #fb7185;     /* Failure / keyword stuffing / filtered */

  --grid-line: rgba(255, 255, 255, 0.025);
  --font-sans: "Geist", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "Geist Mono", "SFMono-Regular", Consolas, Menlo, ui-monospace, monospace;
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --radius: 4px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --bg-deep: #f8f9fa;
  --card: #ffffff;
  --card-2: #f3f4f6;
  --fg: #111111;
  --reading: #1a1a1a;
  --muted: #4b5563;
  --line: #e5e7eb;
  --line-strong: #cbd5e1;

  --brand: #007a36;
  --brand-soft: #065f46;
  --brand-tint: rgba(0, 122, 54, 0.08);
  --brand-glow: rgba(0, 122, 54, 0.16);

  --sem-primary: #007a36;
  --sem-secondary: #2563eb;
  --sem-amber: #b45309;
  --sem-coral: #be123c;

  --grid-line: rgba(17, 17, 17, 0.045);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  margin: 0;
  background-color: var(--bg);
  background-image:
    linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: 64px 64px;
  color: var(--fg);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  line-height: 1.65;
}

::selection {
  background: var(--fg);
  color: var(--bg);
}

a {
  color: var(--brand);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

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

.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;
}

.sr-only:focus-visible {
  position: fixed;
  top: 16px;
  left: 16px;
  width: auto;
  height: auto;
  padding: 10px 16px;
  clip: auto;
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--brand);
  z-index: 200;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* Reading progress bar */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0%;
  background: var(--brand);
  z-index: 100;
  transition: width 80ms linear;
}

/* Layout shell — two-column desktop (sticky 260px left rail + fluid content) */
.wrap {
  max-width: 1400px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

/* Sticky Left Chapter Rail */
nav.toc {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 28px 20px 24px;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.toc-brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.toc-brand-name {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--fg);
  display: flex;
  align-items: center;
  gap: 8px;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-tint);
  display: inline-block;
  flex-shrink: 0;
}

.toc-brand-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  padding-left: 15px;
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toc-item a {
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: baseline;
  gap: 6px;
  padding: 8px 10px;
  border-left: 2px solid transparent;
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
  transition: color 180ms ease, background-color 180ms ease, border-color 180ms ease;
}

.toc-item a:hover {
  color: var(--fg);
  background: var(--card-2);
}

.toc-item a.active {
  color: var(--fg);
  border-left-color: var(--brand);
  background: var(--brand-tint);
}

.toc-item a.active .toc-sec {
  color: var(--brand);
}

.toc-sec {
  color: var(--muted);
  font-weight: 600;
}

.toc-divider {
  border: 0;
  border-top: 1px dashed var(--line);
  margin: 6px 0;
}

.toc-upcoming-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 2px 10px;
}

.toc-upcoming {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toc-upcoming li {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 6px;
  padding: 5px 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.toc-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.theme-btn {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: border-color 180ms ease, background-color 180ms ease;
}

.theme-btn:hover {
  border-color: var(--brand);
  background: var(--brand-tint);
}

.toc-note {
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
}

/* Mobile top bar (visible < 960px) */
.mobile-bar {
  display: none;
}

/* Main Content Column */
main {
  padding: 48px 56px 120px;
  max-width: 1040px;
  width: 100%;
  min-width: 0;
}

/* Typography */
.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--brand);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

h1 {
  font-size: clamp(2.2rem, 4.4vw, 3.35rem);
  line-height: 1.08;
  letter-spacing: -0.03em;
  font-weight: 700;
  margin: 0 0 18px;
  color: var(--fg);
}

.h1-accent {
  color: var(--brand);
}

h2 {
  font-size: clamp(1.55rem, 2.4vw, 2rem);
  line-height: 1.2;
  letter-spacing: -0.025em;
  font-weight: 650;
  margin: 0 0 14px;
  color: var(--fg);
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.heading-anchor {
  font-family: var(--font-mono);
  font-size: 0.72em;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  padding: 2px 5px;
  border-radius: 3px;
  transition: opacity 150ms ease, color 150ms ease, background-color 150ms ease;
}

h2:hover .heading-anchor,
.heading-anchor:focus-visible {
  opacity: 1;
  color: var(--brand);
  background: var(--brand-tint);
  text-decoration: none;
}

.math-sym {
  text-transform: none;
  font-style: normal;
}

h3 {
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--fg);
  margin: 32px 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

h3::before {
  content: "▸";
  color: var(--brand);
}

p.lead {
  font-size: 1.15rem;
  line-height: 1.65;
  color: var(--reading);
  max-width: 68ch;
  margin: 0 0 24px;
}

p.prose {
  font-size: 1.04rem;
  line-height: 1.72;
  color: var(--reading);
  max-width: 68ch;
  margin: 0 0 16px;
}

.cite {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  background: var(--card-2);
  padding: 1px 6px;
  border-radius: 3px;
  white-space: nowrap;
}

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--fg);
}

/* Semantic inline tags */
.tag-primary { color: var(--sem-primary); font-weight: 600; }
.tag-secondary { color: var(--sem-secondary); font-weight: 600; }
.tag-amber { color: var(--sem-amber); font-weight: 600; }
.tag-coral { color: var(--sem-coral); font-weight: 600; }

/* Sections */
section.chapter {
  padding-top: 64px;
  margin-top: 48px;
  border-top: 1px solid var(--line);
  scroll-margin-top: 28px;
}

section.hero {
  padding-top: 12px;
  margin-top: 0;
  border-top: 0;
  scroll-margin-top: 28px;
}

/* Hero Roadmap Grid */
.roadmap-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 28px 0 24px;
}

.roadmap-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--fg);
  transition: border-color 180ms ease, transform 180ms var(--ease-out-expo), background-color 180ms ease;
}

.roadmap-card:hover {
  border-color: var(--brand);
  background: var(--brand-tint);
  transform: translateY(-2px);
  text-decoration: none;
}

.roadmap-num {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--brand);
  text-transform: uppercase;
}

.roadmap-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
}

.roadmap-desc {
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}

/* HUD Lab Panel (signature interactive instrument frame) */
.lab {
  position: relative;
  margin: 24px 0 28px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px 22px;
}

/* Subtle HUD corner brackets */
.lab::before,
.lab::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  pointer-events: none;
}

.lab::before {
  top: -1px;
  left: -1px;
  border-top: 2px solid var(--brand);
  border-left: 2px solid var(--brand);
}

.lab::after {
  bottom: -1px;
  right: -1px;
  border-bottom: 2px solid var(--brand);
  border-right: 2px solid var(--brand);
}

.lab.lab-caution::before,
.lab.lab-caution::after {
  border-color: var(--sem-coral);
}

.lab-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.lab-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lab-badge {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 2px;
  background: var(--brand-tint);
  color: var(--brand);
  border: 1px solid color-mix(in srgb, var(--brand) 35%, transparent);
}

.lab-badge.coral {
  background: rgba(251, 113, 133, 0.1);
  color: var(--sem-coral);
  border-color: rgba(251, 113, 133, 0.35);
}

.lab-name {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg);
  font-weight: 600;
}

.lab-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}

/* Preset buttons row */
.preset-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.preset-label {
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
  margin-right: 4px;
}

.pill-btn {
  min-height: 38px;
  padding: 7px 12px;
  border-radius: 3px;
  border: 1px solid var(--line-strong);
  background: var(--card-2);
  color: var(--reading);
  font-family: var(--font-mono);
  font-size: 11.5px;
  cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease, color 150ms ease;
}

.pill-btn:hover {
  border-color: var(--brand);
  color: var(--fg);
}

.pill-btn.active,
.pill-btn[aria-pressed="true"] {
  border-color: var(--brand);
  background: var(--brand-tint);
  color: var(--brand-soft, var(--brand));
  font-weight: 600;
}

.pill-btn.adversarial.active,
.pill-btn.adversarial[aria-pressed="true"] {
  border-color: var(--sem-coral);
  background: rgba(251, 113, 133, 0.12);
  color: var(--sem-coral);
}

/* Controls & Sliders */
.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px 20px;
  margin-bottom: 18px;
}

.control {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  transition: opacity 150ms ease;
}

.control.control-disabled {
  opacity: 0.36;
}

.control.control-disabled input[type="range"] {
  cursor: not-allowed;
}

.control-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11.5px;
}

.control-label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.control-val {
  color: var(--fg);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 24px; /* 24px hit area; the visible track is drawn below */
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: var(--slider-track, #5a5a5a);
}
input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: var(--slider-track, #5a5a5a);
}
input[type="range"]:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 4px;
  border-radius: 4px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 2px;
  background: var(--brand);
  border: 2px solid var(--card);
  box-shadow: 0 0 0 1px var(--brand);
  transform: rotate(45deg);
  cursor: grab;
  margin-top: -5px; /* center the 14px thumb on the 4px track */
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 2px;
  background: var(--brand);
  border: 2px solid var(--card);
  box-shadow: 0 0 0 1px var(--brand);
  transform: rotate(45deg);
  cursor: grab;
}

/* Text input for live query */
.query-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.query-input {
  flex: 1 1 260px;
  padding: 9px 12px;
  background: var(--bg-deep);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 13.5px;
}

.query-input:focus {
  border-color: var(--brand);
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

.check-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--card-2);
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--reading);
  cursor: pointer;
  user-select: none;
}

.check-pill input {
  accent-color: var(--brand);
  cursor: pointer;
}

/* Paired two-panel stage */
.stage-2col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.stage-pane {
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.pane-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.pane-title {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.pane-badge {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--brand);
  background: var(--brand-tint);
  padding: 2px 7px;
  border-radius: 2px;
}

.canvas-wrap {
  position: relative;
  width: 100%;
}

canvas.viz {
  display: block;
  width: 100%;
  height: 260px;
  border-radius: 2px;
  touch-action: none;
}

canvas.viz.tall {
  height: 290px;
}

canvas.viz.interactive {
  cursor: crosshair;
}

/* KPI Metric Strip */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.kpi {
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.kpi-val {
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  line-height: 1.2;
}

.kpi-val.brand { color: var(--sem-primary); }
.kpi-val.amber { color: var(--sem-amber); }
.kpi-val.coral { color: var(--sem-coral); }
.kpi-val.blue { color: var(--sem-secondary); }

.kpi-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}

/* Formula strip (real KaTeX, never raw Unicode hack) */
.eq-strip {
  margin: 18px 0 22px;
  padding: 16px 20px;
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-left: 3px solid var(--brand);
  border-radius: var(--radius);
  max-width: 100%;
  overflow-x: auto;
}

.eq-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.eq-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--muted);
}

/* Tokenizer & Inverted Index UI (§0.1) */
.token-flow {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.token-step {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.token-step-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.token-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.t-chip {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 3px;
  border: 1px solid var(--line-strong);
  background: var(--card-2);
  color: var(--fg);
}

.t-chip.hit {
  border-color: var(--brand);
  background: var(--brand-tint);
  color: var(--brand);
  font-weight: 600;
}

.t-chip.stop {
  opacity: 0.45;
  text-decoration: line-through;
}

.table-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.postings-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 11.5px;
}

.postings-table th,
.postings-table td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}

.postings-table th {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.postings-table tr.row-hit {
  background: var(--brand-tint);
}

.postings-table tr.row-hit td:first-child {
  color: var(--brand);
  font-weight: 700;
}

/* Ranked document rows (§1, §3) */
.doc-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.doc-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 3px;
  border: 1px solid var(--line);
  background: var(--card);
  transition: border-color 150ms ease, opacity 150ms ease;
}

.doc-row.top-hit {
  border-color: color-mix(in srgb, var(--brand) 55%, transparent);
  background: var(--brand-tint);
}

/* dimmed rows: muted text, dashed border, strike-through (not opacity, which kills contrast) */
.doc-row.filtered-out,
.doc-row.missed {
  border-style: dashed;
}
.doc-row.filtered-out .doc-title,
.doc-row.missed .doc-title { color: var(--muted); text-decoration: line-through; }
.doc-row.filtered-out .doc-bar-fill,
.doc-row.missed .doc-bar-fill,
.doc-row.filtered-out .dual-bar,
.doc-row.missed .dual-bar { opacity: 0.4; }

.doc-rank {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
}

.doc-row.top-hit .doc-rank {
  color: var(--brand);
}

.doc-info {
  min-width: 0;
}

.doc-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-meta {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.doc-bar-track {
  margin-top: 5px;
  height: 4px;
  width: 100%;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}

.doc-bar-fill {
  height: 100%;
  background: var(--brand);
  border-radius: 2px;
  transition: width 180ms var(--ease-out-expo);
}

.doc-score {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.status-pill {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 2px;
  border: 1px solid var(--line);
}

.status-pill.matched {
  color: var(--brand);
  border-color: color-mix(in srgb, var(--brand) 45%, transparent);
  background: var(--brand-tint);
}

.status-pill.filtered {
  color: var(--sem-coral);
  border-color: rgba(251, 113, 133, 0.35);
}

.status-pill.missed {
  color: var(--muted);
}

/* §5 Query Tree & Transform strip */
.query-tree {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.qt-node {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 10px;
  border-radius: 3px;
  border: 1px solid var(--line-strong);
  background: var(--card);
  font-family: var(--font-mono);
}

.qt-node.entity { border-color: var(--sem-primary); background: var(--brand-tint); }
.qt-node.function { border-color: var(--sem-amber); background: rgba(245, 158, 11, 0.1); }
.qt-node.keyword { border-color: var(--sem-secondary); background: rgba(96, 165, 250, 0.1); }
.qt-node.stop { opacity: 0.45; }

.qt-word { font-size: 12.5px; font-weight: 700; color: var(--fg); }
.qt-type { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }

.transform-box {
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--sem-amber);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--fg);
  word-break: break-word;
}

/* §6 SDBN Clickable SERP */
.serp-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--card);
}

.serp-row .doc-title {
  white-space: normal;
  line-height: 1.3;
}

.serp-row.clicked {
  border-color: var(--brand);
  background: var(--brand-tint);
}

.serp-row.skipped {
  border-color: rgba(251, 113, 133, 0.45);
}

/* §9 Draggable NDCG rows */
.ndcg-row {
  display: grid;
  grid-template-columns: 16px 26px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--card);
  cursor: grab;
}

.ndcg-row:active { cursor: grabbing; }
.ndcg-row.drag-over { border-color: var(--brand); background: var(--brand-tint); }
.ndcg-row.outside-k { border-style: dashed; }
.ndcg-row.outside-k .doc-title { color: var(--muted); }

.ndcg-row .doc-title {
  white-space: normal;
  line-height: 1.3;
}

.drag-grip {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--muted);
  letter-spacing: -2px;
  user-select: none;
  text-align: center;
}

.grade-badge {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 2px;
  border: 1px solid var(--line-strong);
}

.grade-3 { color: var(--sem-primary); border-color: var(--sem-primary); background: var(--brand-tint); }
.grade-2 { color: var(--sem-secondary); border-color: var(--sem-secondary); }
.grade-1 { color: var(--sem-amber); border-color: var(--sem-amber); }
.grade-0 { color: var(--sem-coral); border-color: var(--sem-coral); }

.move-btns {
  display: inline-flex;
  gap: 6px;
}

.mini-btn {
  min-width: 36px;
  min-height: 36px;
  padding: 4px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: var(--card-2);
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
}

.mini-btn:hover:not(:disabled) {
  border-color: var(--brand);
  color: var(--brand);
}

.mini-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Stacked dual-bar inside hybrid rows */
.dual-bar {
  display: flex;
  height: 5px;
  width: 100%;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 5px;
}

.dual-bar-b { background: var(--sem-primary); height: 100%; }
.dual-bar-v { background: var(--sem-secondary); height: 100%; }

/* RAG Abstention Banner */
.rag-status {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--brand);
  background: var(--brand-tint);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg);
  line-height: 1.55;
}

.rag-status.abstain {
  border-color: var(--sem-coral);
  background: rgba(251, 113, 133, 0.1);
}

/* Andrei-style structured explanation lists, walkthroughs, and compact tables */
.explain-list {
  list-style: none;
  margin: 16px 0 22px;
  padding: 6px 16px;
  max-width: 68ch;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--card) 75%, transparent);
}

.explain-list li {
  position: relative;
  padding: 10px 0 10px 20px;
  border-top: 1px solid var(--line);
  font-size: 0.98rem;
  line-height: 1.62;
  color: var(--reading);
}

.explain-list li:first-child {
  border-top: 0;
}

.explain-list li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 18px;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--brand);
}

.explain-term {
  font-weight: 600;
  color: var(--fg);
}

.walkthrough {
  margin: 16px 0 22px;
  padding: 14px 18px 14px 36px;
  max-width: 68ch;
  border-left: 2px solid var(--brand);
  background: color-mix(in srgb, var(--card) 65%, transparent);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.walkthrough li {
  margin: 0 0 8px;
  font-size: 0.96rem;
  line-height: 1.6;
  color: var(--reading);
}

.walkthrough li:last-child {
  margin-bottom: 0;
}

.ref-table-wrap {
  width: 100%;
  max-width: 68ch;
  overflow-x: auto;
  margin: 16px 0 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.ref-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  background: var(--card);
}

.ref-table th,
.ref-table td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--reading);
  vertical-align: top;
}

.ref-table th {
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--bg-deep);
}

.ref-table tr:last-child td {
  border-bottom: 0;
}

/* ColBERT MaxSim Matrix (DEMO 10.1) */
.ms-table th,
.ms-table td {
  text-align: center;
}

.ms-table td.ms-max {
  background: var(--brand-tint);
  color: var(--brand);
  font-weight: 700;
  border: 1px solid color-mix(in srgb, var(--brand) 50%, transparent);
}

.ms-table td.ms-sum {
  color: var(--sem-amber);
  font-weight: 700;
}

/* Extractive QA Token Span Highlighter (DEMO 9.3) */
.qa-tokens {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px;
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.qa-tok {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 7px;
  border-radius: 3px;
  border: 1px solid transparent;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--reading);
}

.qa-tok.in-span {
  border-color: var(--brand);
  background: var(--brand-tint);
  color: var(--fg);
  font-weight: 600;
}

.qa-probs {
  font-size: 11px;
  color: var(--brand);
  min-height: 12px;
}

/* Side-by-side comparison grid inside §4 and §8 labs */
.compare-2col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

@media (max-width: 820px) {
  .compare-2col {
    grid-template-columns: 1fr;
  }
}

/* Collapsible derivations / production notes */
details.deriv {
  margin: 18px 0 22px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--card) 70%, transparent);
  padding: 12px 16px;
}

details.deriv summary {
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

details.deriv summary::before {
  content: "▸";
  color: var(--brand);
  transition: transform 160ms ease;
}

details.deriv[open] summary::before {
  transform: rotate(90deg);
}

details.deriv .deriv-body {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 0.96rem;
  color: var(--reading);
}

details.deriv .deriv-body p {
  margin: 0 0 10px;
}

details.deriv .deriv-body p:last-child {
  margin-bottom: 0;
}

/* Takeaway / Next Chapter Bridge Card */
.takeaway {
  margin-top: 28px;
  padding: 18px 20px;
  background: var(--brand-tint);
  border: 1px solid color-mix(in srgb, var(--brand) 38%, transparent);
  border-radius: var(--radius);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.takeaway-copy {
  flex: 1 1 380px;
}

.takeaway-tag {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--brand);
  margin-bottom: 6px;
}

.takeaway-text {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.55;
  color: var(--fg);
}

.next-link {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 9px 14px;
  border: 1px solid var(--brand);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--brand);
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 150ms ease, color 150ms ease;
}

.next-link:hover {
  background: var(--brand);
  color: #071b10;
  text-decoration: none;
}

/* Footer */
footer.page-footer {
  margin-top: 72px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Responsive */
@media (max-width: 960px) {
  .wrap {
    grid-template-columns: 1fr;
  }

  nav.toc {
    display: none;
  }

  .mobile-bar {
    position: sticky;
    top: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px;
    background: color-mix(in srgb, var(--bg) 95%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
  }

  .mobile-jump {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 38px;
    padding: 6px 10px;
    background: var(--card);
    color: var(--fg);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    font-family: var(--font-mono);
    font-size: 11.5px;
  }

  .mobile-bar .theme-btn {
    width: auto;
    min-height: 38px;
    padding: 6px 10px;
    flex-shrink: 0;
  }

  main {
    padding: 28px 20px 80px;
  }

  .roadmap-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stage-2col {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .roadmap-grid {
    grid-template-columns: 1fr;
  }

  .kpi-strip {
    grid-template-columns: 1fr;
  }

  .lab {
    padding: 16px;
  }

  .pill-btn {
    min-height: 42px;
  }

  .mini-btn {
    min-width: 40px;
    min-height: 40px;
  }

  .serp-row {
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 6px 8px;
  }

  .serp-row .doc-title {
    white-space: normal;
  }

  .serp-row .status-pill {
    grid-column: 1 / 2;
    justify-self: start;
    grid-column: 2;
  }

  .serp-row .mini-btn {
    grid-column: 2;
    justify-self: start;
  }

  .ndcg-row {
    grid-template-columns: 16px 24px minmax(0, 1fr);
    gap: 6px 8px;
  }

  .ndcg-row .grade-badge {
    grid-column: 2 / 4;
    justify-self: start;
  }

  .ndcg-row .move-btns {
    grid-column: 2 / 4;
    justify-self: start;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==========================================================================
   Gap-fill labs (Demo 3.2 explain tree, Demo 5.2 spelling, Demo 7.2 autocomplete)
   ========================================================================== */
p.prose.small-note {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--muted);
}

.explain-tree {
  margin: 0;
  padding: 10px 12px;
  min-height: 180px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--reading);
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow-x: auto;
  white-space: pre;
}

.explain-tree .x-num { color: var(--fg); font-weight: 600; }
.explain-tree .x-title { color: var(--sem-amber); }
.explain-tree .x-body { color: var(--sem-secondary); }
.explain-tree .x-phrase { color: var(--sem-primary); }
.explain-tree .x-dim { color: var(--muted); }

.doc-row.selectable { cursor: pointer; }
.doc-row.selectable:hover { border-color: var(--line-strong); }
.doc-row.selectable:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.doc-row.selected { border-color: var(--sem-secondary); box-shadow: inset 3px 0 0 var(--sem-secondary); }

.spell-scroll {
  max-height: 320px;
  overflow-y: auto;
  overflow-x: auto;
}

.postings-table tr.spell-bad td {
  color: var(--sem-coral);
}

.spell-dim {
  color: var(--muted);
  font-size: 0.9rem;
}

.spell-missed {
  margin: 10px 0 0;
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.9;
}

.ac-typed {
  display: block;
  font-family: var(--font-mono);
  color: var(--fg);
}

/* ==========================================================================
   Session-topic labs (Demo 3.3 factors, 4.2 signals log, 6.5 tree, 7.3 blend)
   ========================================================================== */
.lab-legend {
  margin: 4px 0 12px;
  font-size: 0.86rem;
  color: var(--muted);
}
.lab-legend.mono { font-family: var(--font-mono); font-size: 11.5px; }

/* Demo 3.3: stacked contribution bar */
.stack-bar {
  display: flex;
  height: 7px;
  margin-top: 6px;
  border-radius: 2px;
  overflow: hidden;
  background: var(--card-2);
}
.stack-bar span { display: block; height: 100%; }
.seg-text { background: var(--sem-secondary); }
.seg-fresh { background: var(--sem-amber); }
.seg-near { background: var(--sem-primary); }
.seg-pop { background: var(--sem-coral); }
.seg-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  border-radius: 2px;
  vertical-align: middle;
}

/* Demo 4.2: signals log */
.sig-table td { white-space: nowrap; }
.sig-table tr.sig-ctx td { color: var(--muted); }
.sig-table tr.sig-neg td { color: var(--sem-coral); }
.doc-bar-fill.neg { background: var(--sem-coral); }
.doc-score.neg { color: var(--sem-coral); }

/* Demo 6.5: tiny decision tree */
.tree-view {
  margin: 6px 0 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--bg-deep);
  font-size: 0.9rem;
}
.tree-node {
  text-align: center;
  margin-bottom: 8px;
}
.tree-node code, .tree-view [data-node="t"] code { font-size: 12px; }
.tree-view [data-node="t"] { padding: 4px; border-radius: 3px; }
.tree-branches {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.tree-branch {
  padding: 8px;
  border: 1px dashed var(--line-strong);
  border-radius: 3px;
}
.tree-edge {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  text-align: center;
  margin-bottom: 6px;
}
.tree-leaves {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.tree-leaf {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 6px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--card);
  text-align: center;
  transition: border-color 150ms ease, background 150ms ease;
}
.tree-leaf span { font-family: var(--font-mono); font-size: 11px; color: var(--muted); text-transform: uppercase; }
.tree-leaf strong { font-family: var(--font-mono); font-size: 18px; color: var(--fg); }
.tree-leaf small { font-size: 11px; color: var(--muted); }
.tree-view .on-path.tree-leaf,
.tree-view [data-node].on-path:not(.tree-leaf):not(.tree-edge) {
  border-color: var(--brand);
  background: var(--brand-tint);
}
.tree-view .tree-edge.on-path { color: var(--brand); font-weight: 700; }
.tree-view .tree-leaf.on-path strong { color: var(--brand); }

/* Demo 7.3: blend scatter */
.blend-stack {
  display: grid;
  gap: 12px;
}
.blend-svg {
  width: 100%;
  max-width: 520px;
  height: auto;
  display: block;
  margin: 0 auto;
}
.blend-svg .bl-frame { fill: var(--bg-deep); stroke: var(--line); }
.blend-svg .bl-seg { stroke: var(--line-strong); stroke-dasharray: 4 4; stroke-width: 1.5; }
.blend-svg .bl-pt circle { fill: var(--muted); }
.blend-svg .bl-pt text { fill: var(--muted); font-family: var(--font-mono); font-size: 11px; }
.blend-svg .bl-pt.end circle { fill: var(--sem-secondary); }
.blend-svg .bl-pt.end text { fill: var(--fg); }
.blend-svg .bl-pt.blend circle { fill: var(--sem-amber); }
.blend-svg .bl-pt.hit circle { fill: var(--brand); }
.blend-svg .bl-pt.hit text { fill: var(--fg); font-weight: 700; }
.blend-svg .bl-q path { fill: var(--sem-amber); stroke: var(--fg); stroke-width: 1; }

@media (max-width: 600px) {
  .tree-branches, .tree-leaves { grid-template-columns: 1fr; }
}

/* ==========================================================================
   Widget polish (TurboQuant-style): 4 corner brackets, framed plots,
   in-plot hint chips, "do X · watch Y" headers, before → after tiles
   ========================================================================== */
.lab-hint {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 11.5px;
  color: var(--brand);
  opacity: 0.85;
}

/* the two missing corners (top-right, bottom-left) are injected as <i class="cbr"> */
.lab > i.cbr {
  position: absolute;
  width: 10px;
  height: 10px;
  pointer-events: none;
  border: 0 solid var(--brand);
}
.lab > i.cbr.tr { top: -1px; right: -1px; border-top-width: 2px; border-right-width: 2px; }
.lab > i.cbr.bl { bottom: -1px; left: -1px; border-bottom-width: 2px; border-left-width: 2px; }

/* framed plot area */
.canvas-wrap.framed {
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-radius: 2px;
}
.canvas-wrap.framed::before,
.canvas-wrap.framed::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  pointer-events: none;
  border: 0 solid color-mix(in srgb, var(--brand) 55%, transparent);
  z-index: 1;
}
.canvas-wrap.framed::before { top: -1px; left: -1px; border-top-width: 1px; border-left-width: 1px; }
.canvas-wrap.framed::after { bottom: -1px; right: -1px; border-bottom-width: 1px; border-right-width: 1px; }

/* hint chip sitting inside the plot */
.plot-hint {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 2;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand);
  background: color-mix(in srgb, var(--bg-deep) 80%, transparent);
  border: 1px solid color-mix(in srgb, var(--brand) 40%, transparent);
  padding: 3px 8px;
  border-radius: 2px;
  pointer-events: none;
}
.plot-hint.left { right: auto; left: 10px; }

/* before → after values inside KPI tiles */
.kpi-val .was {
  color: var(--muted);
  font-size: 0.62em;
  font-weight: 500;
  margin-right: 4px;
}
.kpi-val .arrow {
  color: var(--muted);
  font-size: 0.62em;
  margin-right: 4px;
}

/* chart caption line above a plot (colored like its series) */
.plot-title {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  margin: 0 0 6px;
  color: var(--reading);
}
.plot-title .t-brand { color: var(--sem-primary); }
.plot-title .t-blue { color: var(--sem-secondary); }
.plot-title .t-amber { color: var(--sem-amber); }
.plot-title .t-coral { color: var(--sem-coral); }
.plot-stack { display: grid; gap: 12px; }

/* rebuilt widgets: plot pairs, short plots */
.plot-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 4px 0 12px;
}
.plot-title-gap { margin-top: 6px; }
.plot-title .t-dim { color: var(--muted); font-weight: 400; }
canvas.viz.short { height: 180px; }
@media (max-width: 760px) {
  .plot-pair { grid-template-columns: 1fr; }
}

/* ==========================================================================
   §0 primer grid + live readouts (verdict lines)
   ========================================================================== */
.primer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 10px 0 28px;
}
.primer-cell {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.primer-cell::before,
.primer-cell::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  border: 0 solid var(--brand);
  pointer-events: none;
}
.primer-cell::before { top: -1px; left: -1px; border-top-width: 1px; border-left-width: 1px; }
.primer-cell::after { bottom: -1px; right: -1px; border-bottom-width: 1px; border-right-width: 1px; }
.primer-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--brand);
}
.primer-head { font-weight: 600; font-size: 1rem; line-height: 1.35; color: var(--fg); }
.primer-head span { font-weight: 500; color: var(--muted); }
.primer-text { margin: 0; font-size: 0.9rem; line-height: 1.6; color: var(--reading); }
.primer-controls { display: flex; flex-direction: column; gap: 6px; }
.primer-pills { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.primer-pills > span {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  min-width: 52px;
}
.pill-btn.mini { padding: 3px 9px; font-size: 11px; }
canvas.viz.mini { height: 170px; }

.prim-docs { display: grid; gap: 4px; }
.prim-doc {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 2px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--muted);
}
.prim-doc.hit { border-color: color-mix(in srgb, var(--brand) 55%, transparent); background: var(--brand-tint); color: var(--reading); }
.prim-doc .pid { color: var(--muted); font-size: 11px; }
.prim-doc .pstat { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; }
.prim-doc.hit .pstat { color: var(--brand); }
.prim-doc mark { background: none; padding: 0 1px; font-weight: 700; }
.prim-doc mark.m-a { color: var(--sem-secondary); }
.prim-doc mark.m-b { color: var(--sem-amber); }

/* live readout: label/value pairs + one plain-words verdict */
.readout {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 14px;
  padding: 8px 10px;
  border: 1px dashed var(--line);
  border-radius: 2px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg);
}
.readout .ro b {
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-right: 6px;
}
.readout .ro-verdict {
  flex-basis: 100%;
  font-family: var(--font-sans);
  font-size: 0.86rem;
  line-height: 1.5;
  color: var(--reading);
}
.readout .ro-verdict::before { content: "→ "; color: var(--brand); font-family: var(--font-mono); }
.readout .ro-verdict.warn::before { color: var(--sem-coral); }
@media (max-width: 760px) {
  .primer-grid { grid-template-columns: 1fr; }
}

/* Demo 5.3 SKG bars */
.skg-bars { display: grid; gap: 10px; padding: 10px 2px; }
.skg-row { display: grid; grid-template-columns: 140px 1fr 48px; gap: 10px; align-items: center; }
.skg-lbl { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); }
.skg-track { position: relative; height: 14px; background: var(--card-2); border-radius: 2px; }
.skg-fill { height: 100%; border-radius: 2px; }
.skg-fill.bg { background: var(--sem-secondary); }
.skg-fill.fg { background: var(--sem-amber); }
.skg-chance { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--fg); }
.skg-val { font-family: var(--font-mono); font-size: 11px; color: var(--fg); text-align: right; }
.skg-note { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
@media (max-width: 600px) { .skg-row { grid-template-columns: 100px 1fr 40px; } }

/* Demo 9.5 metrics playground */
.mx-list { display: grid; gap: 4px; }
.mx-row {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--card);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11.5px;
  text-align: left;
  cursor: pointer;
}
.mx-row:hover { border-color: var(--line-strong); }
.mx-row:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.mx-row.good { border-color: color-mix(in srgb, var(--brand) 55%, transparent); background: var(--brand-tint); color: var(--reading); }
.mx-row.good .mx-tag { color: var(--brand); }
.mx-row.past { border-style: dashed; }
.mx-row.past, .mx-row.past * { color: var(--muted); }
.mx-rank { font-weight: 700; }
.mx-tag { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; }
.mx-bars { display: grid; gap: 12px; padding-top: 4px; }
.mx-bar-top { display: flex; justify-content: space-between; font-family: var(--font-mono); font-size: 11.5px; color: var(--reading); margin-bottom: 4px; }
.mx-bar-top b { color: var(--fg); }
.mx-hint { font-size: 0.78rem; color: var(--muted); margin-top: 3px; }


/* ---- Parts: menu labels + dividers between groups of chapters ---- */
.toc-part {
  margin: 12px 0 2px;
  padding: 0 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--brand);
}

.part-divider {
  display: grid;
  gap: 4px;
  margin-top: 88px;
  padding: 22px 24px;
  background: var(--brand-tint);
  border: 1px solid var(--line);
  border-left: 3px solid var(--brand);
  border-radius: var(--radius);
  scroll-margin-top: 28px;
}

.part-num {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--brand);
}

.part-title {
  font-size: 26px;
  font-weight: 650;
  line-height: 1.15;
  color: var(--fg);
}

.part-sub {
  font-size: 14.5px;
  color: var(--muted);
}

.part-divider + section.chapter {
  margin-top: 8px;
  border-top: 0;
  padding-top: 40px;
}

/* ---- 3D labs: bigger left plot ---- */
.plot-pair.lead { grid-template-columns: 1.35fr 1fr; }
canvas.viz.d3 { height: 340px; }
canvas.viz.d3.interactive { cursor: move; }
@media (max-width: 900px) {
  .plot-pair.lead { grid-template-columns: 1fr; }
  canvas.viz.d3 { height: 320px; }
}

/* ---- knowledge graph demo ---- */
canvas.viz.kg { height: 400px; }
@media (max-width: 600px) { canvas.viz.kg { height: 360px; } }

/* ---- one boost, two searches: winners grid ---- */
.b2-grid { display: grid; grid-template-columns: auto 1fr 1fr; gap: 6px; margin: 10px 0 4px; font-family: var(--font-mono); font-size: 12px; }
.b2-head { color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-size: 11.5px; align-self: center; padding: 0 6px; }
.b2-cell { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 2px; background: var(--card); }
.b2-cell b { color: var(--fg); font-weight: 600; }
.b2-cell span { color: var(--muted); font-size: 11px; }
.b2-cell.e { border-color: color-mix(in srgb, var(--sem-secondary) 55%, transparent); }
.b2-cell.g { border-color: color-mix(in srgb, var(--sem-amber) 55%, transparent); }

/* ---- accessibility helpers ---- */
:root { --slider-track: #5a5a5a; }
:root[data-theme="light"] { --slider-track: #64748b; }
@media (max-width: 960px) { html { scroll-padding-top: 76px; } }

/* ---- Go deeper: advanced side notes, closed by default ---- */
details.deeper { margin: 6px 0 22px; border: 1px dashed var(--line-strong); border-radius: var(--radius); background: var(--card); }
details.deeper > summary { cursor: pointer; padding: 10px 14px; font-family: var(--font-mono); font-size: 11.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--brand-soft, var(--brand)); list-style: none; }
details.deeper > summary::-webkit-details-marker { display: none; }
details.deeper > summary::before { content: "+ "; }
details.deeper[open] > summary::before { content: "− "; }
details.deeper > .explain-list { margin: 0; padding: 4px 14px 12px; border: 0; background: transparent; }

/* ---- reading & learning layer ---- */
.lab-link { margin-left: auto; font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 2px; padding: 4px 8px; cursor: pointer; min-height: 26px; }
.lab-link:hover { color: var(--fg); border-color: var(--brand); }
.lab-header { flex-wrap: wrap; }
.read-meta { color: var(--muted); font-weight: 500; }
.toc-item a { position: relative; }
.toc-min { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 10.5px; color: var(--muted); letter-spacing: 0; text-transform: none; }
.toc-item a { padding-right: 34px; }
.resume-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 0 0 18px; padding: 10px 14px; border: 1px solid var(--brand); border-radius: var(--radius); background: var(--brand-tint); font-size: 14px; color: var(--fg); }
.resume-go { font-family: var(--font-mono); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--brand-soft, var(--brand)); font-weight: 600; }
.resume-x { margin-left: auto; background: transparent; border: 0; color: var(--muted); font-size: 16px; cursor: pointer; min-width: 32px; min-height: 32px; }
.try-btn { margin-left: 10px; font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--brand-soft, var(--brand)); background: var(--brand-tint); border: 1px solid color-mix(in srgb, var(--brand) 50%, transparent); border-radius: 2px; padding: 3px 9px; cursor: pointer; min-height: 26px; vertical-align: 1px; white-space: nowrap; }
.try-btn:hover { border-color: var(--brand); }
.walkthrough li.step-on { background: var(--brand-tint); border-radius: 4px; }
.lab.flash { animation: labflash 900ms ease-out; }
@keyframes labflash { 0% { box-shadow: 0 0 0 3px var(--brand); } 100% { box-shadow: 0 0 0 0 transparent; } }
.gloss { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: help; text-decoration: underline dotted color-mix(in srgb, var(--brand) 70%, transparent); text-underline-offset: 3px; text-decoration-thickness: 1.5px; }
.gloss:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.gloss-tip { position: fixed; z-index: 50; padding: 10px 12px; background: var(--card); color: var(--fg); border: 1px solid var(--brand); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,0.35); font-size: 13.5px; line-height: 1.45; display: grid; gap: 4px; pointer-events: none; }
.gloss-tip[hidden] { display: none; }
.gloss-tip b { font-family: var(--font-mono); font-size: 12px; color: var(--brand-soft, var(--brand)); }
.gloss-tip em { font-style: normal; font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.quiz { margin: 28px 0; padding: 18px 20px; border: 1px solid var(--line-strong); border-left: 3px solid var(--sem-amber); border-radius: var(--radius); background: var(--card); }
.quiz-tag { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--sem-amber); margin-bottom: 6px; }
.quiz-q { margin: 0 0 12px; font-weight: 600; color: var(--fg); }
.quiz-opts { display: grid; gap: 8px; }
.quiz-opt { display: flex; gap: 10px; align-items: flex-start; padding: 9px 12px; border: 1px solid var(--line); border-radius: 2px; cursor: pointer; color: var(--reading); }
.quiz-opt input { margin-top: 3px; accent-color: var(--brand); }
.quiz-opt.right { border-color: var(--brand); background: var(--brand-tint); }
.quiz-opt.wrong { border-color: var(--sem-coral); }
.quiz-why { margin: 12px 0 0; color: var(--reading); min-height: 1em; }

/* ---- sources ---- */
section.sources { margin-top: 64px; padding-top: 40px; border-top: 1px solid var(--line); }
section.sources h2 { margin: 0 0 12px; }
.sources-list { margin: 10px 0 0; padding-left: 20px; color: var(--reading); line-height: 1.7; }
.sources-list li { margin-bottom: 8px; }
.sources-list a { color: var(--brand-soft, var(--brand)); }
.page-footer a { color: inherit; text-decoration: underline; }

/* sidebar brand links back to the home page */
.toc-brand-name .home-link { color: inherit; text-decoration: none; }
.toc-brand-name .home-link:hover { color: var(--brand); }
.toc-brand-name .home-link:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
