/* ============================================================
   Pearl — milk-tea study hall
   Dark roast (default) + steamed-milk light theme
   ============================================================ */

:root {
  --roast: #140c08;
  --roast-2: #1e130c;
  --bark: #2a1a12;
  --foam: #f3e7d6;
  --foam-dim: #d9c4a8;
  --milk: #efe2cf;
  --sugar: #c9894a;
  --sugar-bright: #e0a86a;
  --tapioca: #0f0a07;
  --pearl-mint: #8fad9a;
  --pit: #a85a4a;
  --goal: #6f9b78;
  --ink: #f7efe3;
  --ink-soft: rgba(247, 239, 227, 0.72);
  --ink-mute: rgba(247, 239, 227, 0.45);
  --line: rgba(201, 137, 74, 0.28);
  --glass: rgba(42, 26, 18, 0.72);
  --topbar-bg: rgba(20, 12, 8, 0.65);
  --panel-bg: rgba(15, 10, 7, 0.55);
  --eq-bg: rgba(15, 10, 7, 0.6);
  --pearl-dot: #1a100b;
  --steam-glow: rgba(243, 231, 214, 0.08);
  --bg-spot-1: rgba(201, 137, 74, 0.18);
  --bg-spot-2: rgba(143, 173, 154, 0.12);
  --bg-spot-3: rgba(168, 90, 74, 0.08);
  --bg-base-end: #120a06;
  --btn-primary-fg: #140c08;
  --radius: 18px;
  --font-display: "Syne", system-ui, sans-serif;
  --font-body: "Newsreader", Georgia, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --pearl-field-opacity: 0.35;
}

/* Light milk tea — warm off-white foam */
html[data-theme="light"] {
  --roast: #f6efe4;
  --roast-2: #efe6d8;
  --bark: #e8dcc8;
  --foam: #2a1c12;
  --foam-dim: #5c4634;
  --milk: #1f140e;
  --sugar: #b67a3e;
  --sugar-bright: #9a6230;
  --tapioca: #3d2a1c;
  --pearl-mint: #4f6f5c;
  --pit: #a85a4a;
  --goal: #4f7a58;
  --ink: #24180f;
  --ink-soft: rgba(36, 24, 15, 0.78);
  --ink-mute: rgba(36, 24, 15, 0.48);
  --line: rgba(140, 100, 60, 0.28);
  --glass: rgba(255, 250, 242, 0.78);
  --topbar-bg: rgba(246, 239, 228, 0.86);
  --panel-bg: rgba(255, 251, 245, 0.9);
  --eq-bg: rgba(255, 252, 247, 0.95);
  --pearl-dot: rgba(90, 60, 35, 0.18);
  --steam-glow: rgba(201, 137, 74, 0.14);
  --bg-spot-1: rgba(201, 137, 74, 0.16);
  --bg-spot-2: rgba(111, 155, 120, 0.1);
  --bg-spot-3: rgba(168, 90, 74, 0.06);
  --bg-base-end: #f3ebe0;
  --btn-primary-fg: #f7efe3;
  --pearl-field-opacity: 0.45;
}

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

html {
  scroll-behavior: smooth;
  color-scheme: dark;
}

html[data-theme="light"] {
  color-scheme: light;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at 12% -10%, var(--bg-spot-1), transparent 55%),
    radial-gradient(900px 600px at 90% 8%, var(--bg-spot-2), transparent 50%),
    radial-gradient(800px 500px at 70% 100%, var(--bg-spot-3), transparent 45%),
    linear-gradient(165deg, var(--roast) 0%, var(--roast-2) 45%, var(--bg-base-end) 100%);
  font-family: var(--font-body);
  font-size: 1.125rem;
  line-height: 1.65;
  overflow-x: hidden;
  transition: background 0.35s var(--ease), color 0.25s var(--ease);
}

/* floating tapioca field */
.pearl-field {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 0;
  opacity: var(--pearl-field-opacity);
  background-image: radial-gradient(circle at 20% 30%, var(--pearl-dot) 1.5px, transparent 2px),
    radial-gradient(circle at 70% 60%, var(--pearl-dot) 2px, transparent 2.5px),
    radial-gradient(circle at 40% 80%, var(--pearl-dot) 1px, transparent 1.5px),
    radial-gradient(circle at 85% 20%, var(--pearl-dot) 1.5px, transparent 2px);
  background-size: 90px 90px, 140px 140px, 70px 70px, 110px 110px;
  animation: drift 48s linear infinite;
}

.steam {
  pointer-events: none;
  position: fixed;
  top: -10%;
  left: 55%;
  width: 280px;
  height: 280px;
  z-index: 0;
  background: radial-gradient(circle, var(--steam-glow), transparent 65%);
  filter: blur(30px);
  animation: steam 9s ease-in-out infinite;
}

@keyframes drift {
  from { transform: translateY(0); }
  to { transform: translateY(-90px); }
}

@keyframes steam {
  0%, 100% { transform: translate(-10%, 0) scale(1); opacity: 0.5; }
  50% { transform: translate(8%, 18%) scale(1.15); opacity: 0.85; }
}

.topbar,
main,
.site-foot {
  position: relative;
  z-index: 1;
}

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 1.1rem clamp(1.2rem, 4vw, 3rem);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
  background: var(--topbar-bg);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: var(--foam);
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.03em;
  font-size: 1.15rem;
}

.brand-mark {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #3a281c, var(--tapioca));
  box-shadow:
    0 0 0 3px rgba(201, 137, 74, 0.25),
    10px 0 0 -3px #1a100b,
    18px 2px 0 -5px #120c08;
}

.chapter-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem 1.1rem;
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chapter-nav a {
  color: var(--sugar-bright);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.chapter-nav a.active,
.chapter-nav a:hover {
  border-bottom-color: var(--sugar);
}

.chapter-nav .locked {
  color: var(--ink-mute);
  cursor: default;
}

.theme-hint {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--btn-primary-fg);
  background: var(--foam);
  border: none;
  border-radius: 999px;
  padding: 0.55rem 0.95rem;
  cursor: pointer;
  transition: transform 0.25s var(--ease), background 0.25s;
}

.theme-hint:hover {
  transform: translateY(-1px);
  background: var(--sugar-bright);
  color: var(--btn-primary-fg);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-left: 0;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.4rem 0.7rem 0.4rem 0.45rem;
  cursor: pointer;
  transition: border-color 0.25s, background 0.25s, color 0.25s;
}

.theme-toggle:hover {
  border-color: var(--sugar);
  color: var(--foam);
}

.theme-toggle-track {
  width: 34px;
  height: 18px;
  border-radius: 999px;
  background: rgba(201, 137, 74, 0.25);
  border: 1px solid var(--line);
  position: relative;
  flex-shrink: 0;
}

.theme-toggle-thumb {
  position: absolute;
  top: 1px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--sugar-bright);
  transition: transform 0.28s var(--ease);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

html[data-theme="light"] .theme-toggle-thumb {
  transform: translateX(14px);
  background: var(--tapioca);
}

html[data-theme="light"] .theme-toggle-track {
  background: rgba(182, 122, 62, 0.28);
}

html[data-theme="light"] .btn.primary {
  background: var(--tapioca);
  color: #f7efe3;
}

html[data-theme="light"] .btn.primary:hover {
  background: var(--sugar-bright);
  color: #1f140e;
}

html[data-theme="light"] .theme-hint {
  background: var(--tapioca);
  color: #f7efe3;
}

html[data-theme="light"] .theme-hint:hover {
  background: var(--sugar-bright);
  color: #1f140e;
}

html[data-theme="light"] .equation-block,
html[data-theme="light"] .eq-block,
html[data-theme="light"] .bellman-trace,
html[data-theme="light"] .transition-viz,
html[data-theme="light"] .tuple-panel,
html[data-theme="light"] .toc,
html[data-theme="light"] .lab,
html[data-theme="light"] .calc-panel,
html[data-theme="light"] .demo-controls,
html[data-theme="light"] .math-live,
html[data-theme="light"] .grid-wrap,
html[data-theme="light"] .worked-board,
html[data-theme="light"] .abstract,
html[data-theme="light"] .markov-col,
html[data-theme="light"] .loop-stage {
  background: var(--panel-bg);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.65) inset;
}

html[data-theme="light"] .hero-brand {
  background: linear-gradient(120deg, #2a1c12 10%, #9a6230 55%, #4f6f5c 120%);
  -webkit-background-clip: text;
  background-clip: text;
}

html[data-theme="light"] .cup-liquid {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.45) 0%, transparent 18%),
    linear-gradient(165deg, #c9894a 0%, #8a5a32 45%, #5c3a22 100%);
}

html[data-theme="light"] select {
  background: #fffaf2 !important;
  color: var(--ink) !important;
}

/* ---------- layout ---------- */
main {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
  padding-bottom: 6rem;
}

.section {
  padding: 4.5rem 0 1rem;
  border-top: 1px solid transparent;
}

.section + .section {
  border-top-color: var(--line);
  margin-top: 2rem;
}

.section-head {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.section-head .num {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--pearl-mint);
  letter-spacing: 0.12em;
}

.section-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.7rem, 3.4vw, 2.45rem);
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.lesson-tag {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--pearl-mint);
  margin: 0 0 1rem;
}

.prose {
  max-width: 62ch;
}

.prose.narrow {
  max-width: 58ch;
}

.prose p {
  color: var(--ink-soft);
  margin: 0 0 1.15rem;
}

.prose strong {
  color: var(--foam);
  font-weight: 600;
}

.sym {
  font-family: var(--font-mono);
  font-size: 0.92em;
  color: var(--sugar-bright);
}

.caption {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-mute);
  margin-top: 1.25rem;
}

.caption.tight {
  margin-top: 0.75rem;
}

.tight-list {
  color: var(--ink-soft);
  padding-left: 1.2rem;
}

.tight-list li {
  margin-bottom: 0.55rem;
}

.callout {
  border-left: 3px solid var(--sugar);
  padding: 0.35rem 0 0.35rem 1rem;
  color: var(--foam) !important;
  font-style: italic;
}

.equation-block {
  margin: 1.4rem 0;
  padding: 1rem 1.2rem;
  background: rgba(15, 10, 7, 0.55);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow-x: auto;
  color: var(--foam);
}

.inline-math {
  font-family: var(--font-mono);
  font-size: 0.95em;
}

/* ---------- hero ---------- */
.hero {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: clamp(2rem, 5vw, 4rem);
  align-items: end;
  min-height: min(88vh, 820px);
  padding: 3.5rem 0 2rem;
}

.hero-brand {
  display: block;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(3.4rem, 9vw, 6.4rem);
  letter-spacing: -0.055em;
  line-height: 0.92;
  background: linear-gradient(120deg, var(--foam) 10%, var(--sugar-bright) 55%, var(--pearl-mint) 120%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 0.55rem;
}

.hero-line {
  display: block;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2rem, 4.8vw, 3.4rem);
  letter-spacing: -0.04em;
  line-height: 1.05;
  color: var(--milk);
}

.hero h1 {
  margin: 0 0 1.4rem;
}

.hero-lede {
  max-width: 38ch;
  color: var(--ink-soft);
  font-size: 1.2rem;
  margin: 0 0 2rem;
}

.hero-cta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-decoration: none;
  border-radius: 999px;
  padding: 0.85rem 1.25rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.25s var(--ease), background 0.25s, border-color 0.25s, color 0.25s;
}

.btn:hover {
  transform: translateY(-2px);
}

.btn.primary {
  background: var(--foam);
  color: var(--btn-primary-fg);
}

.btn.primary:hover {
  background: var(--sugar-bright);
}

.btn.ghost {
  background: transparent;
  color: var(--foam);
  border-color: var(--line);
}

.btn.ghost:hover {
  border-color: var(--sugar);
  color: var(--sugar-bright);
}

.btn.small {
  padding: 0.55rem 0.9rem;
  font-size: 0.7rem;
}

/* cup visual */
.hero-visual {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 360px;
}

.cup {
  position: relative;
  width: 180px;
  height: 250px;
  animation: floatCup 5.5s ease-in-out infinite;
}

@keyframes floatCup {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-14px) rotate(2deg); }
}

.cup-rim {
  position: absolute;
  top: 18px;
  left: 8px;
  right: 8px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid rgba(243, 231, 214, 0.55);
  background: rgba(243, 231, 214, 0.08);
  z-index: 3;
}

.cup-liquid {
  position: absolute;
  inset: 28px 18px 20px;
  border-radius: 12px 12px 42% 42% / 12px 12px 28% 28%;
  background:
    linear-gradient(180deg, rgba(243, 231, 214, 0.35) 0%, transparent 18%),
    linear-gradient(165deg, #7a4a28 0%, #4a2a16 45%, #2b160e 100%);
  box-shadow: inset 0 -30px 40px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.cup-swirl {
  position: absolute;
  inset: 20% 10% auto;
  height: 40%;
  background: radial-gradient(ellipse at 40% 40%, rgba(224, 168, 106, 0.45), transparent 60%);
  filter: blur(8px);
  animation: swirl 7s ease-in-out infinite;
}

@keyframes swirl {
  0%, 100% { transform: translateX(-6%) rotate(0deg); }
  50% { transform: translateX(8%) rotate(12deg); }
}

.cup-pearls {
  position: absolute;
  inset: auto 12% 10%;
  height: 38%;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-content: end;
  justify-content: center;
}

.cup-pearls i {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 28%, #3c2a1e, #0c0806 70%);
  display: block;
  animation: bob 2.8s ease-in-out infinite;
}

.cup-pearls i:nth-child(odd) { animation-delay: 0.4s; }
.cup-pearls i:nth-child(3n) { animation-delay: 0.9s; width: 12px; height: 12px; }

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.cup-straw {
  position: absolute;
  top: -18px;
  right: 48px;
  width: 10px;
  height: 160px;
  border-radius: 6px;
  background: linear-gradient(90deg, #d9c4a8, #f3e7d6 40%, #b89a78);
  transform: rotate(8deg);
  z-index: 4;
}

.hero-aside {
  position: absolute;
  bottom: 8%;
  right: 4%;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--sugar-bright);
  letter-spacing: 0.08em;
  opacity: 0.85;
}

/* ---------- loop stage ---------- */
.loop-stage {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 2rem;
  padding: 1.4rem;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.loop-node {
  flex: 1 1 120px;
  min-width: 110px;
  padding: 1rem 1.1rem;
  border-radius: 14px;
  background: rgba(15, 10, 7, 0.55);
  border: 1px solid transparent;
  transition: border-color 0.35s, transform 0.35s var(--ease), background 0.35s;
}

.loop-node.wide {
  flex: 1.3 1 160px;
}

.loop-node.active {
  border-color: var(--sugar);
  background: rgba(201, 137, 74, 0.12);
  transform: translateY(-3px);
}

.loop-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-bottom: 0.35rem;
}

.loop-node strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.loop-node small {
  color: var(--ink-mute);
  font-size: 0.85rem;
}

.loop-arrow {
  font-family: var(--font-mono);
  color: var(--sugar);
  opacity: 0.7;
}

.loop-arrow.wrap {
  opacity: 0.45;
}

/* ---------- tuple ---------- */
.tuple-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.65rem;
  margin: 1.75rem 0 1rem;
}

.tuple-card {
  appearance: none;
  text-align: left;
  cursor: pointer;
  padding: 1rem 0.9rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(15, 10, 7, 0.4);
  color: var(--ink);
  transition: border-color 0.25s, background 0.25s, transform 0.25s var(--ease);
}

.tuple-card:hover {
  transform: translateY(-2px);
  border-color: rgba(201, 137, 74, 0.55);
}

.tuple-card.active {
  background: linear-gradient(160deg, rgba(201, 137, 74, 0.22), rgba(15, 10, 7, 0.55));
  border-color: var(--sugar);
}

.tuple-letter {
  display: block;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.8rem;
  letter-spacing: -0.04em;
  color: var(--sugar-bright);
  line-height: 1;
  margin-bottom: 0.35rem;
}

.tuple-name {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

.tuple-panel {
  padding: 1.4rem 1.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--glass);
  min-height: 150px;
}

.tuple-panel h3 {
  margin: 0 0 0.6rem;
  font-family: var(--font-display);
  font-size: 1.25rem;
}

.tuple-panel p {
  margin: 0 0 0.75rem;
  color: var(--ink-soft);
}

.tuple-panel code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--pearl-mint);
}

/* ---------- split / calc ---------- */
.split {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 1.75rem;
  align-items: start;
}

.calc-panel {
  padding: 1.25rem 1.35rem 1.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background:
    linear-gradient(165deg, rgba(42, 26, 18, 0.9), rgba(15, 10, 7, 0.85));
  position: sticky;
  top: 5.5rem;
}

.calc-panel header h3 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: 1.2rem;
}

.calc-panel header p {
  margin: 0 0 1rem;
  color: var(--ink-mute);
  font-size: 0.95rem;
}

.gamma-row,
.slider-label {
  display: grid;
  gap: 0.4rem;
  margin-bottom: 1rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
}

input[type="range"] {
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(201, 137, 74, 0.35), rgba(243, 231, 214, 0.3));
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--sugar-bright);
  cursor: pointer;
  box-shadow: 0 0 0 5px rgba(201, 137, 74, 0.22);
  border: 2px solid rgba(255, 250, 242, 0.88);
}

.reward-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 1rem;
}

.reward-chip {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.4rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--foam);
  cursor: pointer;
}

.reward-chip.active {
  background: rgba(201, 137, 74, 0.2);
  border-color: var(--sugar);
  color: var(--sugar-bright);
}

.math-steps {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.55rem;
}

.math-steps li {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--ink-soft);
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.25);
  border-left: 2px solid rgba(143, 173, 154, 0.5);
  animation: fadeUp 0.35s var(--ease) both;
}

.math-steps li.hidden-step {
  display: none;
}

.math-steps li.hidden-step.show {
  display: block;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.math-total {
  margin-top: 0.9rem;
  padding-top: 0.9rem;
  border-top: 1px dashed var(--line);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--sugar-bright);
}

/* ---------- markov demo ---------- */
.markov-demo {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 2rem;
}

.markov-col {
  padding: 1.2rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--glass);
}

.markov-col h4 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
}

.markov-col > p {
  margin: 0 0 1rem;
  color: var(--ink-mute);
  font-size: 0.95rem;
}

.markov-viz {
  height: 120px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.35);
  position: relative;
  overflow: hidden;
  margin-bottom: 0.75rem;
}

.markov-note {
  font-family: var(--font-mono) !important;
  font-size: 0.72rem !important;
  color: var(--ink-mute) !important;
  margin: 0 !important;
}

.markov-col.bad .markov-note { color: var(--pit) !important; }
.markov-col.good .markov-note { color: var(--goal) !important; }

.ball {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--foam), var(--sugar));
  top: 50%;
  left: 20%;
  margin-top: -9px;
}

.trail {
  position: absolute;
  height: 2px;
  background: rgba(243, 231, 214, 0.2);
  top: 50%;
  left: 10%;
  right: 10%;
}

.vel-arrow {
  position: absolute;
  top: 42%;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--pearl-mint);
}

/* ---------- demo shell ---------- */
.demo-section {
  padding-bottom: 2rem;
}

.demo-shell {
  display: grid;
  grid-template-columns: 220px 1fr 300px;
  gap: 1rem;
  margin-top: 1.5rem;
  align-items: start;
}

.demo-controls,
.math-live {
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--glass);
}

.control-block {
  margin-bottom: 1.1rem;
}

.control-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--pearl-mint);
  margin-bottom: 0.55rem;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 42px);
  grid-template-rows: repeat(2, 42px);
  gap: 0.35rem;
  justify-content: center;
}

.dpad button {
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.3);
  color: var(--foam);
  border-radius: 10px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.dpad button:hover,
.dpad button:focus-visible {
  background: rgba(201, 137, 74, 0.25);
  border-color: var(--sugar);
}

.dpad button[data-action="up"] { grid-column: 2; grid-row: 1; }
.dpad button[data-action="left"] { grid-column: 1; grid-row: 2; }
.dpad button[data-action="down"] { grid-column: 2; grid-row: 2; }
.dpad button[data-action="right"] { grid-column: 3; grid-row: 2; }

.toggle {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
  margin-bottom: 0.75rem;
  cursor: pointer;
}

.toggle input {
  accent-color: var(--sugar);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.stat-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  margin-top: 0.5rem;
}

.stat-strip div {
  padding: 0.55rem 0.6rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
}

.stat-strip span {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

.stat-strip strong {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--sugar-bright);
}

.grid-wrap {
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(42, 26, 18, 0.5), rgba(15, 10, 7, 0.7));
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  margin-bottom: 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-mute);
}

.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 0.3rem;
  vertical-align: middle;
}

.lg.agent { background: var(--sugar-bright); border-radius: 50%; }
.lg.goal { background: var(--goal); }
.lg.pit { background: var(--pit); }
.lg.wall { background: #3a2a22; }
.lg.step { background: rgba(243, 231, 214, 0.2); }

.grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  aspect-ratio: 1;
  max-width: 420px;
  margin: 0 auto;
}

.cell {
  position: relative;
  border-radius: 12px;
  background: rgba(243, 231, 214, 0.09);
  border: 1px solid rgba(243, 231, 214, 0.06);
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--ink-mute);
  transition: transform 0.2s var(--ease), background 0.25s, box-shadow 0.25s;
}

.cell.wall {
  background: repeating-linear-gradient(
    -45deg,
    #2a1c15,
    #2a1c15 4px,
    #221610 4px,
    #221610 8px
  );
  border-color: #3a2a22;
}

.cell.goal {
  background: rgba(111, 155, 120, 0.25);
  border-color: rgba(111, 155, 120, 0.55);
  color: var(--goal);
}

.cell.pit {
  background: rgba(168, 90, 74, 0.25);
  border-color: rgba(168, 90, 74, 0.5);
  color: var(--pit);
}

.cell.agent {
  box-shadow: inset 0 0 0 2px var(--sugar-bright);
}

.cell .agent-dot {
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--foam), var(--sugar));
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  animation: pulseDot 1.8s ease-in-out infinite;
}

@keyframes pulseDot {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.cell.flash {
  animation: cellFlash 0.45s var(--ease);
}

@keyframes cellFlash {
  0% { transform: scale(1); }
  40% { transform: scale(1.04); background: rgba(201, 137, 74, 0.28); }
  100% { transform: scale(1); }
}

.math-live header h3 {
  margin: 0 0 0.25rem;
  font-family: var(--font-display);
  font-size: 1.05rem;
}

.math-live header p {
  margin: 0 0 0.85rem;
  font-size: 0.85rem;
  color: var(--ink-mute);
}

.transition-viz {
  min-height: 120px;
  margin-bottom: 1rem;
  padding: 0.75rem;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.28);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.55;
  color: var(--ink-soft);
}

.transition-viz .empty-hint {
  margin: 0;
  color: var(--ink-mute);
  font-family: var(--font-body);
  font-size: 0.95rem;
}

.transition-viz .hl {
  color: var(--sugar-bright);
}

.episode-log h4,
.g-build h4 {
  margin: 0 0 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--pearl-mint);
}

.episode-log ol {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
  max-height: 180px;
  overflow: auto;
  display: grid;
  gap: 0.35rem;
}

.episode-log li {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-soft);
  padding: 0.35rem 0.45rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
}

.g-formula {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--sugar-bright);
  word-break: break-word;
}

/* ---------- worked / bars ---------- */
.worked-board {
  margin-top: 1.25rem;
  padding: 1.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--glass);
}

.worked-board .btn {
  margin: 0 0.4rem 1rem 0;
}

.worked-board code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--pearl-mint);
}

.bar-chart {
  display: grid;
  gap: 0.55rem;
  margin: 1rem 0 0.5rem;
}

.bar-row {
  display: grid;
  grid-template-columns: 72px 1fr 48px;
  gap: 0.5rem;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-soft);
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(243, 231, 214, 0.08);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--sugar), var(--pearl-mint));
  transition: width 0.4s var(--ease);
}

/* ---------- closing ---------- */
.closing .next-card {
  margin-top: 2rem;
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  align-items: center;
  padding: 1.5rem 1.6rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background:
    linear-gradient(120deg, rgba(143, 173, 154, 0.12), transparent 45%),
    var(--glass);
}

.next-card h3 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: 1.45rem;
}

.next-card p {
  margin: 0;
  color: var(--ink-soft);
}

.next-lock {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-mute);
  white-space: nowrap;
}

.site-foot {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-soft);
}

.site-foot .muted {
  color: var(--ink-mute);
}

.site-foot code {
  color: var(--sugar-bright);
}

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .hero {
    grid-template-columns: 1fr;
    min-height: auto;
    padding-top: 2rem;
  }

  .hero-visual {
    order: -1;
    min-height: 280px;
  }

  .tuple-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .split,
  .markov-demo,
  .demo-shell {
    grid-template-columns: 1fr;
  }

  .calc-panel {
    position: static;
  }

  .chapter-nav {
    display: none;
  }
}

@media (max-width: 560px) {
  .tuple-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .topbar {
    flex-wrap: wrap;
  }
}

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

/* ============================================================
   Book / study-note layer — Wikipedia-like reading chrome
   ============================================================ */

.layout-book {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: clamp(1.5rem, 3vw, 2.75rem);
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding-bottom: 5rem;
  align-items: start;
}

.toc {
  position: sticky;
  top: 4.8rem;
  max-height: calc(100vh - 5.5rem);
  overflow: auto;
  padding: 1rem 0.85rem 1.25rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(15, 10, 7, 0.55);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  line-height: 1.45;
}

.toc-title {
  display: block;
  margin-bottom: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--pearl-mint);
}

.toc ol {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.45rem;
}

.toc a {
  color: var(--ink-mute);
  text-decoration: none;
  display: block;
  padding: 0.2rem 0;
  border-left: 2px solid transparent;
  padding-left: 0.55rem;
  transition: color 0.2s, border-color 0.2s;
}

.toc a:hover,
.toc a.active {
  color: var(--foam);
  border-left-color: var(--sugar);
}

.study-main {
  min-width: 0;
  max-width: 78ch;
}

.study-main .lab .demo-shell,
.study-section.lab-wide .demo-shell {
  max-width: none;
}

.study-section.lab-wide {
  max-width: min(960px, 100%);
}

.chapter-kicker {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--pearl-mint);
  margin: 2.5rem 0 0.75rem;
}

.study-title {
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.2rem, 5vw, 3.6rem);
  letter-spacing: -0.04em;
  line-height: 1.05;
  color: var(--milk);
}

.study-title em {
  font-style: normal;
  background: linear-gradient(120deg, var(--foam), var(--sugar-bright));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.abstract {
  margin: 0 0 2rem;
  padding: 1.1rem 1.25rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(42, 26, 18, 0.55);
  color: var(--ink-soft);
  font-size: 1.05rem;
}

.abstract strong {
  color: var(--foam);
}

.study-section {
  padding: 2.75rem 0 0.5rem;
  border-top: 1px solid var(--line);
  margin-top: 2rem;
}

.study-section:first-of-type {
  border-top: none;
  margin-top: 0;
}

.study-section > h2 {
  margin: 0 0 1.1rem;
  font-family: var(--font-display);
  font-size: clamp(1.45rem, 2.6vw, 1.9rem);
  letter-spacing: -0.03em;
  scroll-margin-top: 5.5rem;
}

.study-section > h3 {
  margin: 2rem 0 0.75rem;
  font-family: var(--font-display);
  font-size: 1.2rem;
  letter-spacing: -0.02em;
  color: var(--foam);
  scroll-margin-top: 5.5rem;
}

.study-section > h4 {
  margin: 1.4rem 0 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sugar-bright);
}

.prose-study {
  color: var(--ink-soft);
}

.prose-study p {
  margin: 0 0 1.15rem;
  max-width: 68ch;
}

.prose-study p.lead {
  font-size: 1.18rem;
  color: var(--foam);
}

.prose-study ul,
.prose-study ol {
  max-width: 68ch;
  margin: 0 0 1.2rem;
  padding-left: 1.25rem;
}

.prose-study li {
  margin-bottom: 0.45rem;
}

.prose-study strong {
  color: var(--foam);
  font-weight: 600;
}

.note-box,
.def-box,
.thm-box,
.remark-box,
.analysis-box {
  margin: 1.35rem 0 1.5rem;
  padding: 1rem 1.15rem 1.1rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  max-width: 70ch;
}

.note-box {
  background: rgba(143, 173, 154, 0.08);
  border-color: rgba(143, 173, 154, 0.35);
}

.def-box {
  background: rgba(201, 137, 74, 0.1);
  border-left: 3px solid var(--sugar);
}

.thm-box {
  background: rgba(15, 10, 7, 0.55);
  border-color: rgba(224, 168, 106, 0.4);
}

.remark-box {
  background: rgba(42, 26, 18, 0.45);
}

.analysis-box {
  background: linear-gradient(160deg, rgba(168, 90, 74, 0.1), rgba(15, 10, 7, 0.4));
}

.box-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 0.45rem;
  color: var(--pearl-mint);
}

.def-box .box-label { color: var(--sugar-bright); }
.thm-box .box-label { color: var(--sugar-bright); }

.note-box p,
.def-box p,
.thm-box p,
.remark-box p,
.analysis-box p {
  margin: 0 0 0.65rem;
  color: var(--ink-soft);
}

.note-box p:last-child,
.def-box p:last-child,
.thm-box p:last-child,
.remark-box p:last-child,
.analysis-box p:last-child {
  margin-bottom: 0;
}

.eq-block {
  margin: 1.25rem 0 1.4rem;
  padding: 1rem 1.1rem;
  background: rgba(15, 10, 7, 0.6);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow-x: auto;
  position: relative;
  max-width: 70ch;
}

.eq-block .eq-tag {
  position: absolute;
  right: 0.75rem;
  top: 0.65rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-mute);
}

.eq-block.tight {
  padding: 0.75rem 1rem;
}

.lab {
  margin: 2rem 0 1rem;
  padding: 1.25rem 1.2rem 1.4rem;
  border-radius: 16px;
  border: 1px dashed rgba(201, 137, 74, 0.45);
  background: rgba(15, 10, 7, 0.4);
  max-width: none;
}

.lab > .lab-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.lab-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
}

.lab-head span {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

.lab > .lab-intro {
  margin: 0 0 1rem;
  color: var(--ink-mute);
  font-size: 0.95rem;
  max-width: 62ch;
}

.see-also {
  margin: 2rem 0;
  padding: 1rem 1.15rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--glass);
  max-width: 70ch;
}

.see-also h4 {
  margin: 0 0 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--pearl-mint);
}

.see-also ul {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--ink-soft);
}

.see-also a {
  color: var(--sugar-bright);
}

.chapter-end {
  margin-top: 3rem;
  padding: 1.5rem;
  border-radius: 16px;
  border: 1px solid var(--line);
  background:
    linear-gradient(120deg, rgba(143, 173, 154, 0.12), transparent 50%),
    var(--glass);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  max-width: 70ch;
}

.chapter-end h3 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
}

.chapter-end p {
  margin: 0;
  color: var(--ink-soft);
}

.hero.compact {
  min-height: auto;
  padding: 2rem 0 0.5rem;
  grid-template-columns: 1fr;
  gap: 0;
}

.hero.compact .hero-visual {
  display: none;
}

.dl-inline {
  display: grid;
  gap: 0.65rem;
  margin: 1rem 0 1.4rem;
  max-width: 70ch;
}

.dl-inline div {
  display: grid;
  grid-template-columns: 3.2rem 1fr;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.22);
}

.dl-inline dt {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--sugar-bright);
  font-size: 1.15rem;
}

.dl-inline dd {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.98rem;
}

.value-heat {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  max-width: 360px;
  margin: 0.75rem 0;
}

.value-heat .vcell {
  aspect-ratio: 1;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  border: 1px solid rgba(243, 231, 214, 0.12);
  background: rgba(243, 231, 214, 0.08);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
  color: var(--foam);
}

.bellman-trace {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.55;
  color: var(--ink-soft);
  background: rgba(0, 0, 0, 0.3);
  border-radius: 10px;
  padding: 0.75rem;
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
}

@media (max-width: 900px) {
  .layout-book {
    grid-template-columns: 1fr;
  }
  .toc {
    position: static;
    max-height: none;
    display: grid;
    grid-template-columns: 1fr;
  }
  .toc ol {
    grid-template-columns: 1fr 1fr;
  }
}

/* ============================================================
   Shared lab grids (was duplicated via runtime injection)
   ============================================================ */

.dp-grid {
  display: grid;
  gap: 5px;
  max-width: 420px;
}

.dp-cell {
  border-radius: 10px;
  border: 1px solid rgba(243, 231, 214, 0.12);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-family: var(--font-mono);
  min-height: 52px;
  background: rgba(243, 231, 214, 0.09);
}

.dp-cell.wall {
  background: repeating-linear-gradient(
    -45deg,
    #2a1c15,
    #2a1c15 4px,
    #221610 4px,
    #221610 8px
  );
  color: var(--ink-mute);
  font-size: 0.55rem;
}

.dp-cell.cliff {
  background: rgba(168, 90, 74, 0.45) !important;
}

.dp-cell.goal {
  background: rgba(111, 155, 120, 0.4) !important;
}

.dp-cell.start {
  outline: 1px solid rgba(224, 168, 106, 0.5);
}

.dp-v {
  font-size: 0.65rem;
  color: var(--foam);
}

.dp-a {
  font-size: 0.85rem;
  color: var(--sugar-bright);
  line-height: 1;
}

#tdGrid.dp-grid,
#qlGrid.dp-grid,
#qlGridTgt.dp-grid {
  max-width: 560px;
}

#pgGrid.dp-grid,
#trpoGrid.dp-grid,
#ppoGrid.dp-grid,
#valueHeat.dp-grid {
  grid-template-columns: repeat(4, 1fr);
  aspect-ratio: 1;
  max-width: 360px;
}

.tuple-card:focus-visible,
.btn:focus-visible,
.dpad button:focus-visible,
.reward-chip:focus-visible,
.vq-tab:focus-visible,
.vq-cell:focus-visible {
  outline: 2px solid var(--sugar-bright);
  outline-offset: 2px;
}

/* ============================================================
   V / Q visual studio (Chapter 02)
   ============================================================ */

.vq-studio {
  max-width: none;
}

.vq-mode-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.85rem;
}

.vq-tab {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.03em;
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.2s var(--ease), border-color 0.2s, color 0.2s;
}

.vq-tab:hover {
  border-color: var(--sugar);
  color: var(--foam);
}

.vq-tab.active {
  background: rgba(201, 137, 74, 0.22);
  border-color: var(--sugar);
  color: var(--sugar-bright);
}

.vq-split {
  align-items: start;
}

.vq-grid-wrap {
  padding: 0.35rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.12);
  max-width: 380px;
}

.vq-grid {
  display: grid;
  gap: 5px;
}

.vq-cell {
  aspect-ratio: 1;
  min-height: 64px;
  border-radius: 10px;
  border: 1px solid rgba(243, 231, 214, 0.12);
  background: rgba(243, 231, 214, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 0.2rem;
  cursor: pointer;
  font-family: var(--font-mono);
  color: var(--foam);
  transition: outline 0.2s, transform 0.2s var(--ease);
}

.vq-cell:hover {
  transform: translateY(-1px);
}

.vq-cell.selected {
  outline: 2px solid var(--sugar-bright);
  outline-offset: 1px;
}

.vq-cell.goal {
  color: var(--pearl-mint);
}

.vq-main {
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.1;
}

.vq-sub {
  font-size: 0.55rem;
  color: var(--ink-mute);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.vq-q-cross {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  width: 100%;
  height: 100%;
  gap: 1px;
  font-size: 0.52rem;
}

.vq-q-arm {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  padding: 1px;
  line-height: 1.1;
  color: var(--ink-soft);
}

.vq-q-arm.best {
  background: rgba(201, 137, 74, 0.28);
  color: var(--sugar-bright);
  font-weight: 600;
}

.vq-q-arm:nth-child(1) { grid-column: 2; grid-row: 1; }
.vq-q-arm:nth-child(2) { grid-column: 3; grid-row: 2; }
.vq-q-arm:nth-child(3) { grid-column: 2; grid-row: 3; }
.vq-q-arm:nth-child(4) { grid-column: 1; grid-row: 2; }

.vq-q-arrow {
  font-size: 0.85rem;
  line-height: 1;
}

.vq-q-val {
  font-size: 0.5rem;
}

.vq-panel-title {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--pearl-mint);
  margin: 0 0 0.5rem;
}

.vq-equation {
  min-height: 180px;
}

.vq-policy-sliders .slider-label {
  margin-bottom: 0.55rem;
}

.vq-rollout-log {
  margin-top: 1rem;
}

html[data-theme="light"] .vq-grid-wrap {
  background: rgba(120, 86, 54, 0.06);
  border-color: rgba(120, 86, 54, 0.14);
}

html[data-theme="light"] .vq-cell {
  background: rgba(120, 86, 54, 0.07);
  border-color: rgba(120, 86, 54, 0.16);
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

html[data-theme="light"] .vq-tab {
  color: var(--ink-soft);
}

html[data-theme="light"] .vq-tab.active {
  color: var(--sugar-bright);
}

@media (max-width: 900px) {
  .vq-split {
    grid-template-columns: 1fr;
  }
}

html[data-theme="light"] input[type="range"] {
  background: linear-gradient(90deg, rgba(182, 122, 62, 0.4), rgba(120, 86, 54, 0.18));
  box-shadow: inset 0 0 0 1px rgba(120, 86, 54, 0.12);
}

html[data-theme="light"] input[type="range"]::-webkit-slider-thumb {
  border: 2px solid #fff9f0;
  box-shadow: 0 0 0 6px rgba(182, 122, 62, 0.18);
}

html[data-theme="light"] .value-heat .vcell,
html[data-theme="light"] .dp-cell {
  background: rgba(120, 86, 54, 0.07);
  border-color: rgba(120, 86, 54, 0.16);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.75);
}

html[data-theme="light"] .bellman-trace,
html[data-theme="light"] .transition-viz {
  background: rgba(255, 254, 250, 0.95);
  border: 1px solid rgba(120, 86, 54, 0.1);
}

/* ============================================================
   Practice notebook — hand-worked 2×3 gridworld
   ============================================================ */

.practice-page .practice-h3 {
  margin: 2rem 0 0.75rem;
  font-family: var(--font-display);
  font-size: 1.2rem;
  letter-spacing: -0.02em;
}

.practice-page .practice-h4 {
  margin: 1.35rem 0 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  color: var(--pearl-mint);
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  max-width: 420px;
  margin: 1.25rem 0 1.5rem;
  padding: 0.55rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.18);
}

.board-cell {
  min-height: 72px;
  border-radius: 10px;
  border: 1px solid rgba(243, 231, 214, 0.12);
  background: rgba(243, 231, 214, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  font-family: var(--font-mono);
  font-size: 1.05rem;
  color: var(--foam);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.board-cell.goal {
  background: rgba(111, 155, 120, 0.32);
  color: var(--pearl-mint);
  font-size: 0.85rem;
}

.board-cell.pit {
  background: rgba(168, 90, 74, 0.32);
  color: #d9a39a;
  font-size: 0.85rem;
}

.board-grid.policy .board-cell {
  font-size: 1.45rem;
  color: var(--sugar-bright);
}

.board-grid.values .board-cell strong {
  font-size: 1.15rem;
  color: var(--sugar-bright);
}

.board-grid.values .cell-label {
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

.practice-table {
  width: 100%;
  max-width: 42rem;
  border-collapse: collapse;
  margin: 1rem 0 1.4rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

.practice-table caption {
  caption-side: top;
  text-align: left;
  margin-bottom: 0.45rem;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--pearl-mint);
}

.practice-table th,
.practice-table td {
  border: 1px solid var(--line);
  padding: 0.55rem 0.75rem;
  text-align: left;
}

.practice-table th {
  background: rgba(201, 137, 74, 0.12);
  color: var(--foam);
  font-weight: 500;
}

.practice-table td {
  color: var(--ink-soft);
  background: rgba(0, 0, 0, 0.12);
}

.boxed-ans {
  display: inline-block;
  margin: 0.35rem 0 1.1rem;
  padding: 0.55rem 0.95rem;
  border-radius: 10px;
  border: 1.5px solid var(--sugar);
  background: rgba(201, 137, 74, 0.12);
  font-family: var(--font-mono);
  font-size: 1rem;
  color: var(--sugar-bright);
  box-shadow: 0 0 0 4px rgba(201, 137, 74, 0.08);
}

.path-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin: 1rem 0 1.25rem;
}

.path-node {
  min-width: 2.4rem;
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(243, 231, 214, 0.08);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  text-align: center;
  color: var(--foam);
}

.path-node.goal {
  background: rgba(111, 155, 120, 0.3);
  border-color: rgba(111, 155, 120, 0.5);
  color: var(--pearl-mint);
}

.path-arrow {
  color: var(--ink-mute);
  font-family: var(--font-mono);
}

.flow-steps {
  display: grid;
  gap: 0.35rem;
  max-width: 28rem;
  margin: 1.25rem 0 1.5rem;
}

.flow-step {
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.18);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.flow-step.highlight {
  border-color: var(--sugar);
  background: rgba(201, 137, 74, 0.16);
  color: var(--sugar-bright);
}

.flow-arrow {
  text-align: center;
  color: var(--ink-mute);
  font-family: var(--font-mono);
  line-height: 1;
}

.compare-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  margin: 1.25rem 0 1.5rem;
}

.compare-card {
  padding: 1.1rem 1.15rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--glass);
}

.compare-card h4 {
  margin: 0 0 0.5rem;
  font-family: var(--font-display);
  font-size: 1.05rem;
}

.compare-card p {
  margin: 0 0 0.65rem;
  color: var(--ink-soft);
  font-size: 0.98rem;
}

.compare-card .mono-line {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--pearl-mint);
  letter-spacing: 0.02em;
}

.wave-diagram {
  margin: 1.5rem 0;
  padding: 1rem 1.1rem;
  border-radius: 14px;
  border: 1px dashed rgba(201, 137, 74, 0.4);
  background: rgba(0, 0, 0, 0.16);
  max-width: 28rem;
}

.wave-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin-bottom: 5px;
}

.wave-cell {
  text-align: center;
  padding: 0.55rem 0.35rem;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  border: 1px solid var(--line);
  color: var(--ink-mute);
}

.wave-cell.dim {
  background: rgba(243, 231, 214, 0.05);
}

.wave-cell.hot {
  background: rgba(201, 137, 74, 0.28);
  border-color: var(--sugar);
  color: var(--sugar-bright);
}

.wave-cell.goal {
  background: rgba(111, 155, 120, 0.3);
  color: var(--pearl-mint);
}

.wave-cell.pit {
  background: rgba(168, 90, 74, 0.28);
  color: #d9a39a;
}

.wave-cap {
  margin: 0.35rem 0 1rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  color: var(--ink-mute);
}

.wave-cap:last-child {
  margin-bottom: 0;
}

html[data-theme="light"] .board-grid,
html[data-theme="light"] .wave-diagram,
html[data-theme="light"] .flow-step {
  background: rgba(120, 86, 54, 0.05);
}

html[data-theme="light"] .board-cell,
html[data-theme="light"] .path-node {
  background: rgba(120, 86, 54, 0.07);
  border-color: rgba(120, 86, 54, 0.16);
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

html[data-theme="light"] .practice-table td {
  background: rgba(255, 252, 247, 0.9);
  color: var(--ink-soft);
}

html[data-theme="light"] .compare-card {
  background: var(--panel-bg);
}

@media (max-width: 700px) {
  .compare-pair {
    grid-template-columns: 1fr;
  }
}

.study-figure {
  margin: 1.25rem 0 1.5rem;
  max-width: 36rem;
}
.study-figure img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
  background: var(--eq-bg);
}
.study-figure figcaption {
  margin-top: 0.55rem;
  font-size: 0.82rem;
  color: var(--ink-mute);
  line-height: 1.4;
}
