/* ============================================================
   Lecture notes — shared stylesheet for the RL and Reward Model
   series: plain serif reading page, sidebar, interactive labs
   ============================================================ */

:root {
  --roast: #ffffff;
  --roast-2: #fafafa;
  --bark: #e6e6e6;
  --foam: #111111;
  --foam-dim: #444444;
  --milk: #111111;
  --sugar: #224b8d;
  --sugar-bright: #224b8d;
  --control-bg: #222222;
  --accent-secondary: #527bbd;
  --pit: #a8453c;
  --goal: #3f7a4a;
  --ink: #111111;
  --ink-soft: #1f1f1f;
  --ink-mute: #666666;
  --line: #d6d6d6;
  --glass: #fafafa;
  --topbar-bg: #ffffff;
  --panel-bg: #f7f7f7;
  --eq-bg: #ffffff;
  --btn-primary-fg: #ffffff;
  --radius: 3px;
  --font-display: Georgia, "Times New Roman", Times, serif;
  --font-body: Georgia, "Times New Roman", Times, serif;
  --font-mono: Menlo, Monaco, Consolas, monospace;
  --ease: ease;
}

*,
*::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: var(--roast);
  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);
}

a {
  text-underline-offset: 0.18em;
}

:focus-visible {
  outline: 3px solid var(--sugar-bright);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 100;
  padding: 0.55rem 0.8rem;
  color: #ffffff;
  background: #172033;
  border-radius: 6px;
  font: 600 0.78rem/1 var(--font-mono);
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: translateY(0);
}

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

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

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

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"] .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, #172033 10%, #2458b8 55%, #2458b8 120%);
  -webkit-background-clip: text;
  background-clip: text;
}


html[data-theme="light"] select {
  background: #ffffff !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(--accent-secondary);
  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(--accent-secondary);
  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: var(--panel-bg);
  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(--accent-secondary) 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;
}

.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: var(--panel-bg);
  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(37, 99, 235, 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: var(--panel-bg);
  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(37, 99, 235, 0.55);
}

.tuple-card.active {
  background: linear-gradient(160deg, rgba(37, 99, 235, 0.22), var(--panel-bg));
  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(--accent-secondary);
}

/* ---------- 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, var(--panel-bg), var(--panel-bg));
  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(37, 99, 235, 0.35), rgba(148, 163, 184, 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(37, 99, 235, 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(37, 99, 235, 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: var(--panel-bg);
  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: var(--panel-bg);
  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(148, 163, 184, 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(--accent-secondary);
}

/* ---------- 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(--accent-secondary);
  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: var(--panel-bg);
  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(37, 99, 235, 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: var(--panel-bg);
}

.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, var(--panel-bg), var(--panel-bg));
}

.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(148, 163, 184, 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(148, 163, 184, 0.09);
  border: 1px solid rgba(148, 163, 184, 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 var(--panel-bg);
  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(37, 99, 235, 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: var(--panel-bg);
  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(--accent-secondary);
}

.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: var(--panel-bg);
}

.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(--accent-secondary);
}

.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(148, 163, 184, 0.08);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--sugar), var(--accent-secondary));
  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;
  }

}

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

}

/* 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;
}

.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(--accent-secondary);
  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: var(--panel-bg);
  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(37, 99, 235, 0.1);
  border-left: 3px solid var(--sugar);
}

.thm-box {
  background: var(--panel-bg);
  border-color: rgba(37, 99, 235, 0.4);
}

.remark-box {
  background: var(--panel-bg);
}

.analysis-box {
  background: linear-gradient(160deg, rgba(168, 90, 74, 0.1), var(--panel-bg));
}

.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(--accent-secondary);
}

.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: var(--panel-bg);
  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(37, 99, 235, 0.45);
  background: var(--panel-bg);
  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(--accent-secondary);
}

.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: var(--panel-bg);
}

.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(148, 163, 184, 0.12);
  background: rgba(148, 163, 184, 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: var(--panel-bg);
  border-radius: 10px;
  padding: 0.75rem;
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
}

/* ============================================================
   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(148, 163, 184, 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(148, 163, 184, 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(37, 99, 235, 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(37, 99, 235, 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: var(--panel-bg);
  max-width: 380px;
}

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

.vq-cell {
  aspect-ratio: 1;
  min-height: 64px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.12);
  background: rgba(148, 163, 184, 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(--accent-secondary);
}

.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(37, 99, 235, 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(--accent-secondary);
  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(71, 85, 105, 0.06);
  border-color: rgba(71, 85, 105, 0.14);
}

html[data-theme="light"] .vq-cell {
  background: rgba(71, 85, 105, 0.07);
  border-color: rgba(71, 85, 105, 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(37, 99, 235, 0.4), rgba(71, 85, 105, 0.18));
  box-shadow: inset 0 0 0 1px rgba(71, 85, 105, 0.12);
}

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

html[data-theme="light"] .value-heat .vcell,
html[data-theme="light"] .dp-cell {
  background: rgba(71, 85, 105, 0.07);
  border-color: rgba(71, 85, 105, 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(71, 85, 105, 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(--accent-secondary);
}

.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: var(--panel-bg);
}

.board-cell {
  min-height: 72px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.12);
  background: rgba(148, 163, 184, 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(--accent-secondary);
  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(--accent-secondary);
}

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

.practice-table th {
  background: rgba(37, 99, 235, 0.12);
  color: var(--foam);
  font-weight: 500;
}

.practice-table td {
  color: var(--ink-soft);
  background: var(--panel-bg);
}

.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(37, 99, 235, 0.12);
  font-family: var(--font-mono);
  font-size: 1rem;
  color: var(--sugar-bright);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 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(148, 163, 184, 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(--accent-secondary);
}

.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: var(--panel-bg);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.flow-step.highlight {
  border-color: var(--sugar);
  background: rgba(37, 99, 235, 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(--accent-secondary);
  letter-spacing: 0.02em;
}

.wave-diagram {
  margin: 1.5rem 0;
  padding: 1rem 1.1rem;
  border-radius: 14px;
  border: 1px dashed rgba(37, 99, 235, 0.4);
  background: var(--panel-bg);
  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(148, 163, 184, 0.05);
}

.wave-cell.hot {
  background: rgba(37, 99, 235, 0.28);
  border-color: var(--sugar);
  color: var(--sugar-bright);
}

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

.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(71, 85, 105, 0.05);
}

html[data-theme="light"] .board-cell,
html[data-theme="light"] .path-node {
  background: rgba(71, 85, 105, 0.07);
  border-color: rgba(71, 85, 105, 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;
}

/* ============================================================
   Plain notes layer — jemdoc-style sidebar and serif reading page
   ============================================================ */

html {
  scroll-behavior: auto;
}

body {
  font-size: 1.0625rem;
  line-height: 1.55;
  transition: none;
}

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

a:hover {
  text-decoration: underline;
  text-decoration-style: dotted;
}

.layout-book {
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 0;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
}

/* sidebar */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 1rem 0.75rem 2rem 0.9rem;
  background: #f6f6f6;
  border-right: 1px solid #dddddd;
  font-size: 0.95rem;
  line-height: 1.35;
}

.menu-category {
  margin: 1.1rem 0 0.35rem;
  padding-bottom: 0.1rem;
  border-bottom: 1px solid #888888;
  font-weight: bold;
  color: #000000;
}

.menu-category:first-child {
  margin-top: 0;
}

.menu-item a,
.menu-item.locked {
  display: block;
  padding: 0.14rem 0 0.14rem 0.5rem;
  color: #527bbd;
}

.menu-item a.current {
  color: #022b6d;
  text-decoration: underline;
  text-decoration-color: #888888;
  text-underline-offset: 0.2em;
}

.menu-item.locked {
  color: #999999;
  font-style: italic;
}

.sidebar .toc {
  list-style: none;
  margin: 0.15rem 0 0.45rem 0.85rem;
  padding: 0;
  font-size: 0.82rem;
}

.sidebar .toc a {
  display: block;
  padding: 0.1rem 0 0.1rem 0.5rem;
  border-left: 2px solid #dddddd;
  color: #555555;
}

.sidebar .toc a.active {
  border-left-color: #527bbd;
  color: #000000;
}

/* page */
.study-main,
.study-section.lab-wide {
  max-width: none;
}

.study-main {
  padding: 1.25rem clamp(1rem, 3vw, 3rem) 3rem;
}

.chapter-kicker {
  margin: 0 0 0.3rem;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-style: italic;
  letter-spacing: 0;
  text-transform: none;
  color: #555555;
}

.study-title {
  margin: 0 0 1.5rem;
  padding-bottom: 0.3rem;
  border-bottom: 3px double #888888;
  font-weight: bold;
  font-size: 1.75rem;
  letter-spacing: 0;
  line-height: 1.2;
  color: #527bbd;
}

.study-title em {
  font-style: normal;
  background: none;
  color: inherit;
}

.abstract {
  margin: 0 0 1.5rem;
  padding: 0;
  border: none;
  background: none;
  font-size: 1rem;
  font-style: italic;
  color: var(--ink-soft);
}

.abstract strong {
  font-style: normal;
}

.study-section {
  padding: 0;
  margin-top: 2rem;
  border-top: none;
}

.study-section > h2 {
  margin: 0 0 0.75rem;
  padding-bottom: 0.2rem;
  border-bottom: 1px solid #aaaaaa;
  font-size: 1.3rem;
  letter-spacing: 0;
  color: #527bbd;
}

.study-section > h3,
.practice-page .practice-h3 {
  margin: 1.5rem 0 0.5rem;
  font-size: 1.1rem;
  letter-spacing: 0;
  color: #000000;
}

.study-section > h4,
.practice-page .practice-h4 {
  margin: 1.2rem 0 0.4rem;
  font-family: var(--font-body);
  font-size: 1rem;
  font-style: italic;
  letter-spacing: 0;
  text-transform: none;
  color: #000000;
}

.prose-study,
.prose-study strong,
.prose-study p.lead {
  color: var(--ink-soft);
}

.prose-study p,
.prose-study ul,
.prose-study ol {
  max-width: none;
  margin-bottom: 0.85rem;
}

.prose-study p.lead {
  font-size: inherit;
}

.prose-study strong {
  font-weight: bold;
}

/* boxed blocks: one quiet style, a rule on the left */
.note-box,
.def-box,
.thm-box,
.remark-box,
.analysis-box,
.see-also {
  max-width: none;
  margin: 1rem 0 1.2rem;
  padding: 0.6rem 0.9rem;
  border: none;
  border-left: 3px solid #cccccc;
  border-radius: 0;
  background: #f8f8f8;
}

.def-box,
.thm-box {
  border-left-color: #527bbd;
}

.box-label,
.see-also h4,
.lesson-tag,
.lab-head span {
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: bold;
  letter-spacing: 0;
  text-transform: none;
  color: #000000;
}

.box-label {
  margin-bottom: 0.25rem;
}

.def-box .box-label,
.thm-box .box-label,
.note-box p,
.def-box p,
.thm-box p,
.remark-box p,
.analysis-box p,
.see-also ul {
  color: var(--ink-soft);
}

.eq-block,
html[data-theme="light"] .eq-block {
  max-width: none;
  margin: 0.9rem 0 1rem;
  padding: 0.25rem 2.5rem 0.25rem 0;
  border: none;
  border-radius: 0;
  background: none;
  box-shadow: none;
}

.eq-block .eq-tag {
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  font-family: var(--font-body);
  font-size: 0.9rem;
}

/* interactive labs */
.lab,
html[data-theme="light"] .lab {
  margin: 1.5rem 0 1rem;
  padding: 0.9rem 1rem 1rem;
  border: 1px solid #cccccc;
  border-radius: 0;
  background: #fbfbfb;
  box-shadow: none;
}

.lab-head h3 {
  font-size: 1.05rem;
}

.lab > .lab-intro {
  max-width: none;
  color: var(--ink-mute);
}

.practice-table {
  max-width: none;
}

.btn {
  padding: 0.35rem 0.75rem;
  border: 1px solid #aaaaaa;
  border-radius: 2px;
  background: #ffffff;
  color: #111111;
  font-family: var(--font-body);
  font-size: 0.88rem;
  letter-spacing: 0;
  text-transform: none;
}

.btn.small {
  padding: 0.25rem 0.6rem;
  font-size: 0.82rem;
}

.btn:hover {
  transform: none;
  border-color: #527bbd;
}

.btn.primary,
html[data-theme="light"] .btn.primary {
  background: #333333;
  border-color: #333333;
  color: #ffffff;
}

.btn.primary:hover,
html[data-theme="light"] .btn.primary:hover {
  background: #527bbd;
  border-color: #527bbd;
  color: #ffffff;
}

.btn.ghost {
  background: #ffffff;
  color: #111111;
  border-color: #aaaaaa;
}

.control-label,
.slider-label,
.gamma-row,
.caption {
  font-family: var(--font-body);
  font-size: 0.88rem;
  letter-spacing: 0;
  text-transform: none;
}

.caption {
  font-style: italic;
}

/* closing blocks */
.chapter-end {
  max-width: none;
  padding: 0.75rem 0 0;
  border: none;
  border-top: 1px solid #cccccc;
  border-radius: 0;
  background: none;
}

.chapter-end h3 {
  font-size: 1.05rem;
}

.site-foot {
  width: auto;
  margin: 0 0 2rem 220px;
  padding: 0.4rem clamp(1rem, 3vw, 3rem) 0;
  max-width: none;
  border-top: none;
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: #999999;
}

.site-foot p {
  margin: 0 0 0.2rem;
}

html[data-theme="light"] .abstract {
  background: none;
  box-shadow: none;
}

/* lab internals: square corners, no tinted cards */
.demo-controls,
.math-live,
.calc-panel,
.grid-wrap,
.worked-board,
.bellman-trace,
.transition-viz,
.markov-col,
.loop-stage,
.loop-node,
.tuple-card,
.tuple-panel,
.stat-strip div,
.dl-inline div,
.compare-card,
.math-steps li,
.episode-log ol,
.reward-chip,
.vq-tab,
.vq-grid-wrap,
.practice-table,
.boxed-ans,
.flow-step,
.path-node,
html[data-theme="light"] .demo-controls,
html[data-theme="light"] .math-live,
html[data-theme="light"] .calc-panel,
html[data-theme="light"] .grid-wrap,
html[data-theme="light"] .worked-board,
html[data-theme="light"] .bellman-trace,
html[data-theme="light"] .transition-viz,
html[data-theme="light"] .markov-col,
html[data-theme="light"] .loop-stage,
html[data-theme="light"] .tuple-panel,
html[data-theme="light"] .compare-card,
html[data-theme="light"] .flow-step,
html[data-theme="light"] .path-node,
html[data-theme="light"] .vq-grid-wrap,
html[data-theme="light"] .vq-tab {
  border-radius: 2px;
  box-shadow: none;
}

.dp-cell,
.cell,
.board-cell,
.wave-cell,
.vq-cell,
.value-heat .vcell,
html[data-theme="light"] .dp-cell,
html[data-theme="light"] .board-cell,
html[data-theme="light"] .vq-cell,
html[data-theme="light"] .value-heat .vcell {
  border-radius: 2px;
  box-shadow: none;
}

.dl-inline {
  max-width: none;
}

.dl-inline div {
  background: none;
  border: none;
  border-bottom: 1px solid #e3e3e3;
  padding-left: 0;
  padding-right: 0;
}

.lab h4,
.loop-label,
.tuple-name,
.next-lock,
.practice-table caption,
.episode-log h4,
.g-build h4,
.stat-strip span,
.vq-panel-title {
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: bold;
  letter-spacing: 0;
  text-transform: none;
  color: #000000;
}

.tuple-card.active,
.loop-node.active {
  background: #eef2f9;
  transform: none;
}

.tuple-card:hover {
  transform: none;
}

.study-figure img {
  border-radius: 0;
}

/* prose inside flow charts and boards reads as text, not code */
.flow-step,
.board-cell,
.compare-card .mono-line {
  font-family: var(--font-body);
}

.board-grid,
html[data-theme="light"] .board-grid {
  padding: 0;
  border: none;
  border-radius: 0;
  background: none;
}

.board-cell,
html[data-theme="light"] .board-cell {
  background: #f7f7f7;
  border: 1px solid #dddddd;
}

.sidebar {
  scrollbar-width: thin;
}

.practice-table th,
html[data-theme="light"] .practice-table th {
  background: #f2f2f2;
  font-family: var(--font-body);
}

.practice-table td,
html[data-theme="light"] .practice-table td {
  background: #ffffff;
}

/* wide equations scroll inside their own line instead of widening the page */
.study-main mjx-container[display="true"] {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

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

  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid #dddddd;
  }

  .sidebar .toc {
    display: none;
  }

  .site-foot {
    margin-left: 0;
  }

  .split > *,
  .demo-shell > *,
  .compare-pair > *,
  .stat-strip > * {
    min-width: 0;
  }

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

  .compare-pair {
    grid-template-columns: 1fr;
  }

  .lab {
    padding: 0.75rem 0.6rem;
  }

  .practice-table {
    display: block;
    overflow-x: auto;
  }
}
