/* ==========================================================================
   Dots & Lines — Networks & Graphs
   Visual identity: a transit-map on pale map paper.
   Fixed colour meanings (used everywhere in the book):
     blue      = an ordinary node at rest (in contagion: susceptible)
     vermilion = something flowing: infection, rumour, search frontier, walker
     teal      = a connection found: path, tree, giant cluster, reached
     amber     = importance: degree, hubs, centrality, PageRank
     slate     = finished or removed: recovered, cut, deleted
     violet    = protected: immunised
   ========================================================================== */

:root {
  --paper: #f3f5f4;
  --paper-dot: #dfe5e2;
  --card: #ffffff;
  --card-soft: #f8faf9;
  --canvas: #fbfcfb;
  --line: #d8dfdc;
  --line-strong: #bcc6c2;

  --ink: #1b2433;
  --ink-soft: #3b4657;
  --muted: #5f6b7b;
  --dim: #8a95a3;

  /* fixed meanings (fills) */
  --node: #3563c9;
  --flow: #e4572e;
  --link: #10988b;
  --hub: #eba10f;
  --done: #a3adba;
  --shield: #7c4dd8;

  /* darker text-safe variants */
  --node-t: #2a52ab;
  --flow-t: #c4401c;
  --link-t: #0b7a70;
  --hub-t: #9a6500;
  --done-t: #616c7b;
  --shield-t: #6337bd;

  --font-display: 'Sora', 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  --font-body: 'Source Serif 4', 'Source Serif Pro', Georgia, 'Times New Roman', serif;
  --font-mono: 'IBM Plex Mono', Consolas, 'SFMono-Regular', ui-monospace, Menlo, monospace;

  --sidebar-w: 288px;
  --content-max: 800px;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(27, 36, 51, 0.05), 0 8px 26px rgba(27, 36, 51, 0.07);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.68;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--paper);
  background-image: radial-gradient(var(--paper-dot) 1px, transparent 1.2px);
  background-size: 22px 22px;
}

a { color: var(--link-t); text-decoration: underline; text-decoration-color: rgba(16, 152, 139, 0.35); text-underline-offset: 2px; }
a:hover { color: var(--flow-t); text-decoration-color: currentColor; }

:focus-visible { outline: 3px solid rgba(16, 152, 139, 0.55); outline-offset: 2px; border-radius: 4px; }

/* ---------- Reading progress ---------- */
.reading-progress {
  position: fixed; top: 0; left: 0; height: 4px; width: 0%;
  background: linear-gradient(90deg, var(--link), var(--node) 45%, var(--hub) 75%, var(--flow));
  z-index: 1000;
}

/* ---------- Mobile top bar ---------- */
.mobile-topbar {
  display: none; position: sticky; top: 0; z-index: 90;
  background: rgba(243, 245, 244, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 0.6rem 1rem;
  align-items: center; justify-content: space-between; gap: 0.75rem;
  font-family: var(--font-display);
}
.mobile-menu-btn {
  font-family: var(--font-display); font-size: 0.85rem; font-weight: 600;
  background: var(--card); color: var(--ink); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); padding: 0.4rem 0.75rem; cursor: pointer;
}
.mobile-brand { font-weight: 700; color: var(--ink); text-decoration: none; font-size: 0.92rem; }

/* ---------- Layout ---------- */
.book-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--line);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  padding: 1.4rem 1rem 2.4rem;
  display: flex; flex-direction: column; gap: 1.1rem;
  font-family: var(--font-display);
  z-index: 95;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--line); border-radius: 99px; }

.sidebar-brand {
  display: flex; align-items: center; gap: 0.7rem; text-decoration: none; color: var(--ink);
  padding: 0.2rem 0.3rem 0.95rem; border-bottom: 1px solid var(--line);
}
.brand-mark { width: 38px; height: 38px; flex-shrink: 0; }
.brand-title { display: block; font-weight: 700; font-size: 1rem; line-height: 1.15; letter-spacing: -0.01em; }
.brand-sub { display: block; font-size: 0.7rem; color: var(--muted); margin-top: 3px; }

.course-progress-box { background: var(--card-soft); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.65rem 0.8rem; }
.course-progress-label { display: flex; justify-content: space-between; font-size: 0.74rem; color: var(--muted); margin-bottom: 0.4rem; }
.course-progress-track { height: 6px; background: #e7ecea; border-radius: 99px; overflow: hidden; }
.course-progress-fill { height: 100%; background: linear-gradient(90deg, var(--link), var(--node)); border-radius: 99px; transition: width 0.3s ease; }

.toc-part-title {
  font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.11em; font-weight: 700;
  color: var(--dim); margin: 0.8rem 0 0.3rem 0.4rem;
}
.toc-list { list-style: none; margin: 0; padding: 0; position: relative; }
.toc-list::before {
  content: ''; position: absolute; left: 1.05rem; top: 0.9rem; bottom: 0.9rem; width: 3px;
  background: #e3e9e6; border-radius: 3px;
}
.toc-link {
  position: relative; display: flex; align-items: center; gap: 0.6rem;
  padding: 0.38rem 0.5rem; border-radius: var(--radius-sm);
  color: var(--ink-soft); font-size: 0.84rem; line-height: 1.3; text-decoration: none;
}
.toc-link:hover { background: #eef3f1; color: var(--ink); }
.toc-stop {
  position: relative; z-index: 1; width: 1.3rem; height: 1.3rem; flex-shrink: 0; border-radius: 50%;
  display: grid; place-items: center; font-family: var(--font-mono); font-size: 0.62rem; font-weight: 600;
  background: var(--card); border: 2px solid var(--line-strong); color: var(--muted);
}
.toc-link.active { background: rgba(16, 152, 139, 0.1); color: var(--link-t); font-weight: 600; }
.toc-link.active .toc-stop { border-color: var(--link); color: var(--link-t); }
.toc-link.completed .toc-stop { background: var(--link); border-color: var(--link); color: #fff; }
.toc-check { margin-left: auto; font-size: 0.72rem; color: var(--link-t); opacity: 0; }
.toc-link.completed .toc-check { opacity: 1; }

/* ---------- Content ---------- */
.chapter-content {
  flex: 1; min-width: 0;
  padding: 2.6rem clamp(1rem, 4vw, 3.4rem) 5rem;
  max-width: calc(var(--content-max) + 6.8rem);
  margin: 0 auto;
}

.chapter-header { margin-bottom: 2.2rem; padding-bottom: 1.6rem; border-bottom: 1px solid var(--line); }
.transit-stripe { display: flex; align-items: center; gap: 0; margin-bottom: 1rem; height: 14px; }
.transit-stripe span { height: 5px; flex: 1; }
.transit-stripe span:nth-of-type(1) { background: var(--node); border-radius: 3px 0 0 3px; }
.transit-stripe span:nth-of-type(2) { background: var(--link); }
.transit-stripe span:nth-of-type(3) { background: var(--hub); }
.transit-stripe span:nth-of-type(4) { background: var(--flow); border-radius: 0 3px 3px 0; }
.transit-stripe i {
  width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--ink); flex-shrink: 0; margin: 0 -2px; position: relative; z-index: 1;
}

.chapter-eyebrow {
  font-family: var(--font-display); font-size: 0.74rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.13em; color: var(--link-t); margin-bottom: 0.55rem;
}
.chapter-header h1 {
  font-family: var(--font-display); font-weight: 700; letter-spacing: -0.025em;
  font-size: clamp(2rem, 4.6vw, 2.95rem); line-height: 1.1; margin: 0 0 0.8rem; color: var(--ink);
}
.chapter-subtitle { font-size: 1.15rem; color: var(--ink-soft); margin: 0; max-width: 64ch; line-height: 1.6; }

.chapter-content h2 {
  font-family: var(--font-display); font-weight: 700; letter-spacing: -0.015em;
  font-size: 1.5rem; line-height: 1.25; color: var(--ink); margin: 2.7rem 0 0.85rem;
}
.chapter-content h3 { font-family: var(--font-display); font-size: 1.08rem; color: var(--ink); margin: 1.8rem 0 0.5rem; }
.chapter-content p { margin: 0 0 1.1rem; max-width: 68ch; }
.chapter-content ul, .chapter-content ol { margin: 0 0 1.2rem; padding-left: 1.35rem; max-width: 66ch; }
.chapter-content li { margin-bottom: 0.4rem; }
strong { font-weight: 600; color: var(--ink); }

/* colour words (text-safe) */
.c-node { color: var(--node-t); font-weight: 600; }
.c-flow { color: var(--flow-t); font-weight: 600; }
.c-link { color: var(--link-t); font-weight: 600; }
.c-hub { color: var(--hub-t); font-weight: 600; }
.c-done { color: var(--done-t); font-weight: 600; }
.c-shield { color: var(--shield-t); font-weight: 600; }

/* ---------- Formula ---------- */
.formula {
  margin: 1.4rem 0; padding: 1rem 1.2rem; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius-sm); max-width: 68ch; text-align: center;
}
.formula .eq { font-family: var(--font-mono); font-size: 1.08rem; color: var(--ink); letter-spacing: 0.01em; }
.formula .aloud { display: block; margin-top: 0.45rem; font-size: 0.93rem; color: var(--muted); font-style: italic; }

/* ---------- Callouts ---------- */
.callout {
  margin: 1.6rem 0; padding: 1rem 1.2rem 1rem 1.25rem; max-width: 68ch;
  background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--link);
  border-radius: var(--radius-sm); box-shadow: 0 1px 2px rgba(27, 36, 51, 0.04);
}
.callout-title {
  font-family: var(--font-display); font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.11em; color: var(--link-t); margin-bottom: 0.3rem;
}
.callout p { margin: 0; }
.callout p + p { margin-top: 0.6rem; }
.callout.principle { border-left-color: var(--link); background: linear-gradient(90deg, rgba(16, 152, 139, 0.07), #fff 45%); }
.callout.principle p { font-size: 1.06rem; }
.callout.closer { border-left-color: var(--hub); }
.callout.closer .callout-title { color: var(--hub-t); }
.callout.careful { border-left-color: var(--flow); }
.callout.careful .callout-title { color: var(--flow-t); }
.callout.history { border-left-color: var(--node); }
.callout.history .callout-title { color: var(--node-t); }

/* ---------- Interactive figure ---------- */
.interactive {
  margin: 2rem 0 2.2rem; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.fig-head {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.35rem 0.8rem;
  padding: 0.8rem 1.1rem 0.7rem; border-bottom: 1px solid var(--line); background: var(--card-soft);
  font-family: var(--font-display);
}
.fig-badge {
  font-size: 0.66rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: #fff; background: var(--ink); border-radius: 99px; padding: 0.18rem 0.6rem; white-space: nowrap;
}
.fig-title { margin: 0 !important; font-size: 1rem !important; font-weight: 700; color: var(--ink); }
.fig-hint { flex-basis: 100%; margin: 0 !important; font-size: 0.8rem !important; color: var(--muted); font-family: var(--font-display); }

.canvas-wrap { position: relative; background: var(--canvas); line-height: 0; border-bottom: 1px solid var(--line); }
.canvas-wrap canvas { display: block; width: 100%; height: 400px; user-select: none; -webkit-user-select: none; touch-action: pan-y; }
.canvas-wrap canvas.edit { touch-action: none; }
.canvas-wrap.short canvas { height: 300px; }
.canvas-wrap.tall canvas { height: 470px; }
.canvas-wrap.xtall canvas { height: 540px; }

.lab-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); border-bottom: 1px solid var(--line); }
.lab-grid .canvas-wrap { border-bottom: none; }
.lab-grid .canvas-wrap + .canvas-wrap { border-left: 1px solid var(--line); }

.controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.7rem 1.1rem;
  padding: 0.8rem 1.1rem; font-family: var(--font-display); font-size: 0.82rem; color: var(--ink-soft);
}
.controls + .controls { padding-top: 0; }
.ctl { display: inline-flex; align-items: center; gap: 0.5rem; }
.ctl label { white-space: nowrap; font-weight: 600; }
.ctl output, .ctl .val { font-family: var(--font-mono); font-size: 0.8rem; color: var(--ink); min-width: 3.2em; }
.ctl-sep { width: 1px; align-self: stretch; background: var(--line); }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; }
.seg .btn { border: none; border-radius: 0; border-right: 1px solid var(--line-strong); }
.seg .btn:last-child { border-right: none; }
.seg-label { font-weight: 600; margin-right: 0.2rem; }

.btn {
  font-family: var(--font-display); font-size: 0.8rem; font-weight: 600; line-height: 1.2;
  color: var(--ink); background: var(--card); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); padding: 0.45rem 0.8rem; cursor: pointer;
  display: inline-flex; align-items: center; gap: 0.35rem; text-decoration: none;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.btn:hover { background: #eef3f1; border-color: var(--ink-soft); color: var(--ink); }
.btn.on, .btn[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary { background: var(--link); border-color: var(--link); color: #fff; }
.btn.primary:hover { background: var(--link-t); border-color: var(--link-t); color: #fff; }
.btn.warm { background: #fff4ef; border-color: #f0b8a6; color: var(--flow-t); }
.btn.warm:hover { background: #ffe8de; }
.btn.lg { font-size: 0.95rem; padding: 0.7rem 1.25rem; border-radius: 11px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 140px; height: 6px; border-radius: 99px;
  background: #dfe6e3; outline: none; cursor: pointer; margin: 0;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; border: 4px solid var(--ink); cursor: pointer;
}
input[type="range"]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 4px solid var(--ink); cursor: pointer; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px rgba(16, 152, 139, 0.35); }
select, input[type="number"] {
  font-family: var(--font-display); font-size: 0.8rem; padding: 0.4rem 0.5rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: #fff; color: var(--ink);
}
input[type="number"] { width: 5.2em; font-family: var(--font-mono); }
input[type="number"]:disabled { opacity: 0.5; }

.readout {
  margin: 0 1.1rem 0.85rem; padding: 0.6rem 0.8rem; background: var(--card-soft); border: 1px solid var(--line);
  border-radius: var(--radius-sm); font-family: var(--font-mono); font-size: 0.8rem; line-height: 1.55; color: var(--ink);
}
.readout b { font-weight: 600; }
.readout .verdict { display: block; font-family: var(--font-display); font-size: 0.84rem; margin-top: 0.2rem; color: var(--ink-soft); }

.legend { display: flex; flex-wrap: wrap; gap: 0.35rem 1rem; padding: 0.55rem 1.1rem 0; font-family: var(--font-display); font-size: 0.75rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.legend i { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.legend i.sq { border-radius: 2px; height: 4px; width: 16px; }

.fig-caption {
  padding: 0.75rem 1.1rem 0.95rem; border-top: 1px solid var(--line); background: var(--card-soft);
  font-size: 0.93rem; color: var(--ink-soft); line-height: 1.55;
}
.fig-caption::before { content: 'Notice'; font-family: var(--font-display); font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--link-t); margin-right: 0.5rem; }

/* ---------- Colour key (book-wide legend) ---------- */
.colour-key { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.5rem 1rem; margin: 1rem 0 1.5rem; padding: 0.9rem 1.1rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); font-family: var(--font-display); font-size: 0.82rem; }
.colour-key div { display: flex; align-items: center; gap: 0.55rem; }
.colour-key i { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }

/* ---------- Quiz ---------- */
.quiz { margin: 2.2rem 0; padding: 1.2rem 1.25rem 1.1rem; background: var(--card); border: 1px solid var(--line); border-top: 5px solid var(--hub); border-radius: var(--radius); box-shadow: var(--shadow); max-width: 74ch; }
.quiz h3 { margin: 0 0 0.5rem !important; font-family: var(--font-display); font-size: 0.78rem !important; text-transform: uppercase; letter-spacing: 0.11em; color: var(--hub-t) !important; }
.quiz > p { margin-bottom: 0.9rem; }
.quiz-options { display: flex; flex-direction: column; gap: 0.5rem; }
.quiz-opt {
  text-align: left; font-family: var(--font-body); font-size: 0.98rem; line-height: 1.45; color: var(--ink);
  background: var(--card-soft); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem; cursor: pointer;
}
.quiz-opt:hover { border-color: var(--ink-soft); background: #fff; }
.quiz-opt.correct { border-color: var(--link); background: rgba(16, 152, 139, 0.09); }
.quiz-opt.wrong { border-color: var(--flow); background: rgba(228, 87, 46, 0.07); }
.quiz-fb { margin-top: 0.8rem; font-size: 0.96rem; min-height: 1.2em; }
.quiz-fb.ok { color: var(--link-t); }
.quiz-fb.no { color: var(--flow-t); }

/* ---------- Connections & recap ---------- */
.connections { margin: 2.2rem 0 1.4rem; padding: 1rem 1.2rem; background: var(--card); border: 1px dashed var(--line-strong); border-radius: var(--radius); max-width: 74ch; }
.connections h2 { margin: 0 0 0.5rem !important; font-size: 1rem !important; }
.connections ul { margin: 0; }
.connections li { margin-bottom: 0.35rem; }

.recap { margin: 2.4rem 0 1rem; padding: 1.2rem 1.3rem; background: var(--ink); color: #e9eef3; border-radius: var(--radius); max-width: 74ch; }
.recap h2 { color: #fff !important; margin: 0 0 0.6rem !important; font-size: 1.2rem !important; }
.recap ul { margin: 0; padding-left: 1.2rem; }
.recap li { margin-bottom: 0.45rem; }
.recap li::marker { color: var(--hub); }
.recap strong { color: #fff; }

/* ---------- Footer ---------- */
.chapter-footer { margin-top: 3rem; padding-top: 1.8rem; border-top: 1px solid var(--line); font-family: var(--font-display); }
.complete-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.8rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.9rem 1.15rem; margin-bottom: 1.2rem; }
.complete-bar p { margin: 0; font-size: 0.9rem; color: var(--muted); }
.chapter-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.nav-card { display: flex; flex-direction: column; gap: 0.15rem; padding: 0.95rem 1.15rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); }
.nav-card:hover { border-color: var(--link); color: var(--ink); }
.nav-card.next { text-align: right; align-items: flex-end; }
.nav-dir { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--dim); font-weight: 700; }
.nav-title { font-size: 0.98rem; font-weight: 600; }

/* ---------- Home ---------- */
.hero { padding: 1.2rem 0 2.2rem; border-bottom: 1px solid var(--line); margin-bottom: 2rem; }
.hero-grid { display: grid; grid-template-columns: 1.05fr 1fr; gap: 2.2rem; align-items: center; }
.hero h1 { font-family: var(--font-display); font-weight: 700; letter-spacing: -0.03em; font-size: clamp(2.4rem, 5.2vw, 3.5rem); line-height: 1.04; margin: 0.4rem 0 0.9rem; }
.hero-sub { font-family: var(--font-display); font-size: 1.02rem; font-weight: 600; color: var(--link-t); margin: 0 0 0.9rem; }
.hero-lead { font-size: 1.1rem; color: var(--ink-soft); margin: 0 0 1.4rem; line-height: 1.6; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.hero-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.hero-card .canvas-wrap canvas { height: 330px; }

.progress-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 1.4rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; margin: 0 0 2rem; font-family: var(--font-display); }
.progress-banner .pb-text { flex: 1 1 200px; }
.progress-banner strong { display: block; font-size: 0.95rem; }
.progress-banner .pb-count { font-size: 0.84rem; color: var(--muted); }
.progress-banner .pb-track { flex: 2 1 200px; height: 8px; background: #e5ebe8; border-radius: 99px; overflow: hidden; }
.progress-banner .pb-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--link), var(--node)); border-radius: 99px; }

.part-heading { display: flex; align-items: baseline; gap: 0.75rem; margin: 2.2rem 0 0.9rem; font-family: var(--font-display); }
.part-badge { font-family: var(--font-mono); font-size: 0.72rem; font-weight: 600; color: #fff; background: var(--ink); padding: 0.18rem 0.6rem; border-radius: 99px; white-space: nowrap; }
.part-heading h2 { margin: 0 !important; font-size: 1.35rem !important; }
.chapter-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0.9rem; }
.chapter-card { display: flex; flex-direction: column; gap: 0.4rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.15rem 1.05rem; text-decoration: none; color: var(--ink); transition: border-color 0.15s ease, transform 0.15s ease; }
.chapter-card:hover { border-color: var(--link); transform: translateY(-2px); color: var(--ink); }
.chapter-card-top { display: flex; justify-content: space-between; align-items: center; font-family: var(--font-display); }
.chapter-card-num { font-family: var(--font-mono); font-size: 0.74rem; font-weight: 600; color: var(--link-t); }
.chapter-card-status { font-size: 0.72rem; font-weight: 600; color: var(--link-t); }
.chapter-card h3 { margin: 0 !important; font-family: var(--font-display); font-size: 1.02rem !important; line-height: 1.3; }
.chapter-card p { margin: 0 !important; font-size: 0.9rem; color: var(--ink-soft); line-height: 1.45; }
.chapter-card-sims { margin-top: auto; padding-top: 0.35rem; font-family: var(--font-display); font-size: 0.72rem; color: var(--muted); line-height: 1.4; }
.chapter-card-sims b { color: var(--flow-t); font-weight: 600; }

.site-footer { text-align: center; padding: 2rem 1rem 3rem; font-family: var(--font-display); font-size: 0.8rem; color: var(--muted); }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .mobile-topbar { display: flex; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform 0.25s ease; visibility: hidden; }
  .sidebar.open { transform: translateX(0); visibility: visible; box-shadow: 10px 0 30px rgba(27, 36, 51, 0.18); }
  .sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(27, 36, 51, 0.35); z-index: 92; }
  .sidebar-backdrop.open { display: block; }
  .hero-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .lab-grid { grid-template-columns: 1fr; }
  .lab-grid .canvas-wrap + .canvas-wrap { border-left: none; border-top: 1px solid var(--line); }
}
@media (max-width: 600px) {
  html { font-size: 16px; }
  .chapter-content { padding-top: 1.6rem; }
  .canvas-wrap canvas { height: 340px; }
  .canvas-wrap.short canvas { height: 260px; }
  .canvas-wrap.tall canvas { height: 400px; }
  .canvas-wrap.xtall canvas { height: 440px; }
  .lab-grid .canvas-wrap.chart canvas { height: 220px; }
  .chapter-nav { grid-template-columns: 1fr; }
  .controls { padding: 0.75rem 0.85rem; gap: 0.6rem 0.8rem; }
  .readout { margin: 0 0.85rem 0.8rem; }
  input[type="range"] { width: 120px; }
  .ctl { flex-wrap: wrap; }
  .ctl label { white-space: normal; }
  .fig-head, .fig-caption { padding-left: 0.85rem; padding-right: 0.85rem; }
}
