/* figure font: a subset of Inter (SIL OFL 1.1, see fonts/OFL.txt), self-hosted so figure layout is identical everywhere */
@font-face { font-family: "InterFig"; src: url("fonts/inter-fig-400.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "InterFig"; src: url("fonts/inter-fig-600.woff2") format("woff2"); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: "InterFig"; src: url("fonts/inter-fig-700.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }
/* CS224W study guides — shared theme.
   Palette and typography follow dooon.ir (green / navy / gold on a pale sage background,
   serif headings, pill buttons, 16px cards). Dark mode mirrors the same tokens. */

:root {
  --bg: #f5f8f3; --surface: #ffffff; --panel: #eef3ea; --text: #16201a; --ink: #16201a; --muted: #5a665d;
  --line: #dce5d8; --green: #59b24c; --green-ink: #2e7a23; --green-soft: #e7f3e3;
  --navy: #1d3557; --navy-soft: #e6ecf4; --gold: #b7862c; --gold-soft: #f6eedb;
  --red: #c0453a; --red-soft: #f8e5e2;
  --hero-from: #eaf5e6; --hero-to: #f5f8f3;
  --accent: var(--green-ink); --accent-2: var(--gold); --good: var(--green-ink); --bad: var(--red);
  --key-bg: var(--green-soft); --flash: #fff1c2; --tip-bg: #16201a; --tip-ink: #f5f8f3;
  --ctx-bg: var(--gold-soft); --res-bg: var(--navy-soft);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --figsans: "InterFig", "Inter", "Inter Variable", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --shadow: 0 6px 24px rgba(20, 50, 20, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1411; --surface: #161e19; --panel: #1b2420; --text: #e5ece6; --ink: #e5ece6; --muted: #9aa89d;
    --line: #27322b; --green: #6cc35e; --green-ink: #86d679; --green-soft: #1a2b1c;
    --navy: #a9c3e6; --navy-soft: #1b2635; --gold: #d9ae5e; --gold-soft: #2b2619;
    --red: #ff8a7a; --red-soft: #3a211e;
    --hero-from: #13221a; --hero-to: #0f1411; --flash: #4a3f1a; --tip-bg: #e5ece6; --tip-ink: #0f1411;
    --shadow: 0 6px 24px rgba(0, 0, 0, .35);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1411; --surface: #161e19; --panel: #1b2420; --text: #e5ece6; --ink: #e5ece6; --muted: #9aa89d;
  --line: #27322b; --green: #6cc35e; --green-ink: #86d679; --green-soft: #1a2b1c;
  --navy: #a9c3e6; --navy-soft: #1b2635; --gold: #d9ae5e; --gold-soft: #2b2619;
  --red: #ff8a7a; --red-soft: #3a211e;
  --hero-from: #13221a; --hero-to: #0f1411; --flash: #4a3f1a; --tip-bg: #e5ece6; --tip-ink: #0f1411;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 70px; }
body { margin: 0; background: var(--bg); color: var(--text); font: 17px/1.7 var(--sans); -webkit-font-smoothing: antialiased; overflow-x: hidden; }
main { max-width: 960px; margin: 0 auto; padding: 0 16px 72px; }
a { color: var(--green-ink); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 500; line-height: 1.2; }
h1 { font-size: clamp(32px, 5.5vw, 48px); margin: 6px 0 12px; }
h3 { font-size: 1.3rem; margin: 28px 0 8px; }
h4 { font-size: 1rem; margin: 18px 0 4px; color: var(--green-ink); }
p { margin: 10px 0; }
code { background: var(--panel); padding: 1px 6px; border-radius: 6px; font-family: var(--mono); font-size: .86em; }
pre { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; overflow-x: auto; font-size: .84rem; line-height: 1.5; }
pre code { background: none; padding: 0; }
[lang="fa"] { font-family: Vazirmatn, Tahoma, sans-serif; direction: rtl; unicode-bidi: isolate; font-size: 1.02em; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar .inner { max-width: 960px; margin: 0 auto; padding: 0 16px; height: 56px; display: flex; gap: 8px; align-items: center; }
.topbar .home { display: flex; align-items: center; gap: 9px; font-family: var(--serif); font-size: 18px; color: var(--text); white-space: nowrap; }
.topbar .home i { width: 10px; height: 10px; border-radius: 50%; background: var(--green); display: inline-block; box-shadow: 0 0 0 4px var(--green-soft); }
.topbar .home:hover { text-decoration: none; }
.topbar nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; mask-image: linear-gradient(90deg, #000 92%, transparent); }
.topbar nav::-webkit-scrollbar { display: none; }
.topbar nav a, .topbar button { font: 600 .78rem var(--sans); color: var(--muted); white-space: nowrap; padding: 6px 10px; border-radius: 999px; border: 0; background: none; cursor: pointer; }
.topbar nav a:hover, .topbar button:hover { background: var(--green-soft); color: var(--green-ink); text-decoration: none; }
.topbar nav a.active { background: var(--green-soft); color: var(--green-ink); }
.topbar button { border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.score { font: 700 .75rem var(--sans); color: var(--green-ink); white-space: nowrap; }
.progress { position: absolute; left: 0; bottom: -1px; height: 2px; background: var(--green); width: 0; }

/* ---------- hero ---------- */
.hero { background: radial-gradient(1100px 420px at 85% -10%, var(--hero-from), var(--hero-to)); position: relative; overflow: hidden; border-bottom: 1px solid var(--line); }
.hero .net { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; opacity: .55; }
.hero .inner { position: relative; max-width: 960px; margin: 0 auto; padding: 28px 16px 26px; }
.eyebrow { color: var(--green-ink); font-size: 13px; letter-spacing: .14em; text-transform: uppercase; font-weight: 700; margin: 0 0 10px; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.eyebrow a { font-weight: 600; letter-spacing: 0; text-transform: none; font-size: 13px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 2px 10px; }
.eyebrow a:hover { border-color: var(--green); text-decoration: none; }
.hook { font-size: 19px; color: var(--muted); max-width: 720px; margin: 0 0 18px; }
.kicker { color: var(--muted); font-size: .85rem; margin: 0; }
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin: 14px 0 0; }
@media (max-width: 900px) { .stats { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 560px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; display: flex; gap: 12px; align-items: center; box-shadow: var(--shadow); }
.stat .ico { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--green-soft); color: var(--green-ink); flex: 0 0 auto; font: 700 15px var(--serif); }
.stat .ico.navy { background: var(--navy-soft); color: var(--navy); }
.stat .ico.gold { background: var(--gold-soft); color: var(--gold); }
.stat b { display: block; font-size: 16px; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 12.5px; line-height: 1.35; display: block; }

/* ---------- roadmap ---------- */
.roadmap { display: grid; grid-template-columns: repeat(21, 1fr); gap: 3px; margin: 18px 0 6px; }
.roadmap a { display: block; text-decoration: none; text-align: center; padding: 4px 0; border-radius: 7px;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted); font: 600 .7rem var(--sans); position: relative; }
.roadmap a span { display: none; }
.roadmap a.cur { background: var(--green); border-color: var(--green); color: #fff; }
.roadmap a.seen::after { content: ""; position: absolute; left: 25%; right: 25%; bottom: 2px; height: 2px; border-radius: 2px; background: var(--green); }
.roadmap a.cur.seen::after { background: #fff; }
.roadmap a:hover { border-color: var(--green); text-decoration: none; }
.roadmap a:hover span { display: block; position: absolute; top: 120%; left: 50%; transform: translateX(-50%); z-index: 5;
  background: var(--tip-bg); color: var(--tip-ink); padding: 4px 8px; border-radius: 6px; white-space: nowrap; font-weight: 400; }
@media (max-width: 700px) { .roadmap { grid-template-columns: repeat(11, 1fr); } }

/* ---------- sections ---------- */
section { padding: 0; }
section > details > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 12px;
  margin: 44px 0 14px; user-select: none; }
section > details > summary::-webkit-details-marker { display: none; }
section > details > summary::before { content: attr(data-num); font: 700 12px var(--sans); color: var(--green-ink); background: var(--green-soft); border-radius: 8px; padding: 3px 9px; min-width: 2.2em; text-align: center; transition: transform .15s; }
section > details:not([open]) > summary::before { opacity: .6; }
section > details > summary::after { content: ""; flex: 1; height: 1px; background: var(--line); order: 2; }
section h2 { font-family: var(--serif); font-weight: 500; font-size: 1.55rem; margin: 0; color: var(--text); order: 1; }
section > details > summary:hover h2 { color: var(--green-ink); }
label.done { order: 3; font-size: .78rem; color: var(--muted); display: flex; align-items: center; gap: 5px; cursor: pointer; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 2px 10px; white-space: nowrap; }
label.done input { accent-color: var(--green); margin: 0; }
label.done:has(input:checked) { color: var(--green-ink); border-color: var(--green); font-weight: 600; background: var(--green-soft); }
.scope { font-size: .92rem; color: var(--muted); font-style: italic; }
.note { font-size: .92rem; color: var(--muted); }

/* ---------- figures & diagrams ---------- */
figure { margin: 0; }
figure.diagram { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin: 14px 0; box-shadow: var(--shadow); }
figure.diagram svg { display: block; width: 100%; height: auto; }
figure.diagram svg text { font-family: var(--sans); fill: var(--ink); }
figure.diagram svg .step { transition: opacity .15s; cursor: pointer; }
figure.diagram.focusing svg .step { opacity: .22; }
figure.diagram.focusing svg .step.on { opacity: 1; }
figure.diagram figcaption { font-size: .85rem; color: var(--muted); margin-top: 6px; }
ol.read { padding-left: 1.4em; }
ol.read li { margin: 6px 0; padding: 2px 6px; border-radius: 6px; cursor: default; transition: background .15s; }
ol.read li.on { background: var(--green-soft); }
/* lightbox */
.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(8,12,10,.9); display: flex; align-items: center; justify-content: center; flex-direction: column; padding: 20px; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: min(1100px, 92vw); max-height: 82vh; width: auto; height: auto; border-radius: 10px; background: #fff; }
.lightbox .lb-cap { color: #e8ede6; font-size: .92rem; margin: 12px 0 0; text-align: center; max-width: 900px; }
.lightbox .lb-cap a { color: #a9d79f; }
.lightbox button { position: absolute; background: rgba(255,255,255,.14); color: #fff; border: 0; font-size: 2rem; line-height: 1; width: 46px; height: 46px; border-radius: 50%; cursor: pointer; display: grid; place-items: center; }
.lightbox button:hover { background: rgba(255,255,255,.28); }
.lb-x { top: 16px; right: 16px; } .lb-prev { left: 12px; top: 50%; transform: translateY(-50%); } .lb-next { right: 12px; top: 50%; transform: translateY(-50%); }
@media print { .lightbox { display: none !important; } }

/* redrawn slide figures */
figure.rfig { margin: 14px 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px 10px; box-shadow: var(--shadow); }
figure.rfig .fbody svg { display: block; width: 100%; height: auto; max-height: 420px; margin: 0 auto; }
figure.rfig .fbody svg text { font-family: var(--figsans); }
figure.rfig figcaption { font-size: .86rem; color: var(--muted); margin-top: 8px; display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
figure.rfig figcaption span { flex: 1; }
figure.rfig figcaption b { color: var(--text); }
figure.rfig.half { max-width: 440px; }
figure.rfig.narrow { max-width: 340px; }
.figrow { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin: 14px 0; }
.figrow figure.rfig { margin: 0; max-width: none; }
.fsteps { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 2px; }
.fsteps button { font: 600 .74rem var(--sans); border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 3px 10px; cursor: pointer; }
.fsteps button.on { background: var(--green); border-color: var(--green); color: #fff; }
.fsteps button:hover { border-color: var(--green); }
figure.rfig .legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .8rem; color: var(--muted); margin-top: 6px; }
figure.rfig .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: -1px; }
/* review box at the end of each walkthrough block */
.review { margin: 16px 0 4px; border: 1px solid var(--line); border-left: 4px solid var(--navy); background: var(--navy-soft); border-radius: 12px; padding: 10px 16px 10px; }
.review > b { display: block; font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; color: var(--navy); margin-bottom: 4px; }
.review ul { margin: 0 0 6px; padding-left: 18px; }
.review li { margin: 2px 0; font-size: .95rem; }
.review details { margin-top: 6px; font-size: .93rem; }
.review summary { cursor: pointer; font-weight: 600; color: var(--navy); }
.review details p { margin: 6px 0 0; }
@media (max-width: 700px) { .figrow { grid-template-columns: 1fr; } }

figure.nfig { margin: 14px 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px; max-width: 560px; }
figure.nfig img { display: block; width: 100%; border-radius: 8px; background: #fff; cursor: zoom-in; }
figure.nfig figcaption { font-size: .85rem; color: var(--muted); margin-top: 6px; display: flex; justify-content: space-between; gap: 10px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 700px) { .split { grid-template-columns: 1fr; } }
a.pdfp { font-size: .8rem; white-space: nowrap; text-decoration: none; color: var(--green-ink); border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; background: var(--surface); }
a.pdfp:hover { border-color: var(--green); text-decoration: none; }

/* ---------- boxes ---------- */
.formula { text-align: center; margin: 14px 0 4px; overflow-x: auto; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.key { background: var(--green-soft); border-left: 4px solid var(--green); padding: 14px 18px; border-radius: 10px; font-size: 1.08rem; font-weight: 600; font-family: var(--serif); }
.example { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px 18px; }
.example ol { margin: 6px 0 0; padding-left: 1.3em; }
.box { border-radius: 14px; padding: 12px 18px; margin: 16px 0; border: 1px solid var(--line); background: var(--surface); }
.box > b:first-child, .box > strong:first-child { display: block; font-size: .76rem; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 4px; }
.box.ctx { background: var(--gold-soft); border-color: transparent; }
.box.ctx > b:first-child { color: var(--gold); }
.box.res { background: var(--navy-soft); border-color: transparent; }
.box.res > b:first-child { color: var(--navy); }
.box.warn { background: var(--red-soft); border-color: transparent; }
.box.warn > b:first-child { color: var(--red); }
.box.notes { border-left: 4px solid var(--green); background: var(--green-soft); border-color: transparent; border-left-color: var(--green); }
.box.notes > b:first-child { display: block; margin-bottom: 4px; color: var(--green-ink); }
.box.tip { background: var(--green-soft); border-color: transparent; border-left: 4px solid var(--green); }
.box.tip > b:first-child { color: var(--green-ink); }
details.think { background: var(--surface); border: 1px dashed var(--green); border-radius: 14px; padding: 10px 16px; margin: 14px 0; }
details.think > summary { cursor: pointer; font-weight: 600; list-style: none; }
details.think > summary::-webkit-details-marker { display: none; }
details.think > summary::before { content: "Think first · "; color: var(--green-ink); font-size: .76rem; text-transform: uppercase; letter-spacing: .08em; }
details.think > summary::after { content: "  (click to reveal)"; color: var(--muted); font-weight: 400; font-size: .82rem; }
details.think[open] > summary::after { content: ""; }
details.think > div { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 8px; }

/* ---------- glossary ---------- */
a.term { color: inherit; text-decoration: none; border-bottom: 2px dotted var(--gold); cursor: help; }
a.term:hover, a.term:focus { background: color-mix(in srgb, var(--gold) 16%, transparent); outline: none; }
.tip { position: fixed; z-index: 30; max-width: 300px; background: var(--tip-bg); color: var(--tip-ink);
  padding: 10px 12px; border-radius: 10px; font-size: .88rem; line-height: 1.45; pointer-events: none;
  opacity: 0; transform: translateY(4px); transition: opacity .12s, transform .12s; box-shadow: 0 6px 24px rgba(0,0,0,.18); }
.tip.show { opacity: 1; transform: none; }
.tip b { display: block; margin-bottom: 2px; }
.tip .fa { display: block; margin-top: 4px; opacity: .85; }
.tip .hint { display: block; margin-top: 6px; font-size: .75rem; opacity: .6; }
.backbtn { position: fixed; right: 16px; bottom: 16px; z-index: 25; display: none; font: 600 .85rem var(--sans);
  background: var(--green); color: #fff; border: 0; border-radius: 999px; padding: 10px 16px; cursor: pointer; box-shadow: 0 4px 16px rgba(0,0,0,.2); }
.backbtn.show { display: block; }

table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: left; vertical-align: top; padding: 9px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 700; font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; }
.tablewrap { overflow-x: auto; }
table.gloss td:first-child { font-weight: 600; white-space: nowrap; }
table.gloss tr { transition: background .6s; }
table.gloss tr.flash { background: var(--flash); transition: none; }
.pos { font-weight: 400; color: var(--muted); font-size: .8rem; margin-left: 4px; }
.ctx { font-style: italic; color: var(--muted); }
@media (max-width: 600px) {
  table.gloss thead { display: none; }
  table.gloss tr { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); }
  table.gloss td { display: block; border: 0; padding: 2px 0; }
  table.gloss td:first-child { white-space: normal; }
}

/* ---------- readings / homework ---------- */
.reading { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--green); border-radius: 12px; padding: 12px 16px; margin: 12px 0; }
.reading h4 { margin: 0 0 2px; color: var(--text); font-size: 1.02rem; font-family: var(--sans); }
.reading .meta { font-size: .82rem; color: var(--muted); margin-bottom: 6px; }
.badge { display: inline-block; font: 700 .68rem var(--sans); padding: 2px 8px; border-radius: 6px; margin-right: 4px; vertical-align: 2px; }
.badge.must { background: var(--navy); color: #fff; }
.badge.good { background: var(--green); color: #fff; }
.badge.opt { background: var(--panel); color: var(--muted); border: 1px solid var(--line); }
.reading ul { margin: 4px 0; padding-left: 1.2em; }
.hw { border-left: 4px solid var(--gold); background: var(--surface); border: 1px solid var(--line); border-left-color: var(--gold); border-radius: 12px; padding: 12px 16px; margin: 12px 0; }
.hw h4 { margin: 0 0 4px; color: var(--text); font-family: var(--sans); }
.hw .meta { font-size: .82rem; color: var(--muted); }

/* ---------- quiz & flashcards ---------- */
.quiz { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; margin: 12px 0; }
.quiz .qq { font-weight: 600; margin: 0 0 6px; }
.quiz ol { list-style: upper-alpha; padding-left: 1.6em; margin: 0; }
.quiz li { padding: 4px 8px; margin: 3px 0; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.quiz li:hover { background: var(--panel); }
.quiz li.right { background: var(--green-soft); border-color: var(--green); }
.quiz li.wrong { background: var(--red-soft); border-color: var(--red); }
.quiz .why { display: none; font-size: .92rem; color: var(--muted); margin: 8px 0 0; border-top: 1px solid var(--line); padding-top: 6px; }
.quiz.answered .why { display: block; }
.qscore { font-weight: 700; color: var(--green-ink); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; margin: 12px 0; }
.card { perspective: 800px; cursor: pointer; min-height: 120px; }
.card > div { position: relative; width: 100%; height: 100%; min-height: 120px; transition: transform .45s; transform-style: preserve-3d; }
.card.flip > div { transform: rotateY(180deg); }
.card .f, .card .b { position: absolute; inset: 0; backface-visibility: hidden; border-radius: 14px; padding: 12px 14px;
  display: flex; align-items: center; justify-content: center; text-align: center; font-size: .92rem; overflow: auto; border: 1px solid var(--line); }
.card .f { background: var(--green-soft); font-weight: 600; border-color: transparent; }
.card .b { background: var(--surface); transform: rotateY(180deg); }

/* ---------- history timeline ---------- */
section#history ul.tl, ul.tl { list-style: none; margin: 8px 0 16px; padding: 0 0 0 28px; position: relative; }
ul.tl::before { content: ""; position: absolute; top: 8px; bottom: 8px; left: 8px; width: 2px; background: linear-gradient(var(--green), var(--line)); }
ul.tl li { position: relative; padding: 0 0 16px; margin: 0; }
ul.tl li::before { content: ""; position: absolute; left: -26px; top: 8px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 3px solid var(--green); }
ul.tl li b { font-family: var(--serif); font-weight: 600; font-size: 1.02rem; }
ul.deeper li { margin: 6px 0; }

/* ---------- walkthrough ---------- */
.wblock { margin: 22px 0 30px; padding-top: 10px; border-top: 1px dashed var(--line); }
.wblock h3 { margin: 8px 0 6px; font-size: 1.15rem; display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; }
.wblock h3 .wp { font: 600 .74rem var(--sans); color: var(--green-ink); border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 1px 9px; white-space: nowrap; }
.wblock h3 .wp:hover { border-color: var(--green); text-decoration: none; }
.wtext { margin-top: 8px; }
.wskip { font-style: italic; }
.wtoc { columns: 2; column-gap: 24px; font-size: .9rem; margin: 6px 0 14px; padding-left: 1.3em; }
.wtoc li { break-inside: avoid; margin: 2px 0; }
@media (max-width: 600px) { .wtoc { columns: 1; } }

/* ---------- lab / frontier / sna ---------- */
.widget { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; margin: 16px 0; box-shadow: var(--shadow); overflow: hidden; }
.widget .wtitle { font: 700 .76rem var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--green-ink); margin: 0 0 6px; display: flex; align-items: center; gap: 8px; }
.widget .wtitle::before { content: "▶"; font-size: .6rem; }
.widget .wcap { font-size: .88rem; color: var(--muted); margin: 8px 0 0; }
.widget .ctrls { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin: 6px 0 8px; font-size: .86rem; }
.widget .ctrls label { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.widget .ctrls input[type=range] { width: 130px; accent-color: var(--green); }
.widget .ctrls select { font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 8px; padding: 3px 6px; }
.widget .ctrls button, .btn { font: 600 .84rem var(--sans); border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 999px; padding: 5px 13px; cursor: pointer; }
.widget .ctrls button:hover, .btn:hover { border-color: var(--green); text-decoration: none; }
.widget .ctrls button.primary, .btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.widget svg { display: block; width: 100%; height: auto; }
.widget svg text { font-family: var(--sans); fill: var(--text); }
.widget .out { font-family: var(--mono); font-size: .84rem; background: var(--panel); border-radius: 8px; padding: 6px 10px; margin-top: 8px; white-space: pre-wrap; }
.widget .val { font-family: var(--mono); color: var(--text); min-width: 2.5em; display: inline-block; }
.widget .two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
@media (max-width: 640px) { .widget .two { grid-template-columns: 1fr; } }
.widget .legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .8rem; color: var(--muted); margin-top: 4px; }
.widget .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.widget table { font-size: .86rem; }
.widget td.ok { color: var(--green-ink); font-weight: 700; } .widget td.no { color: var(--red); font-weight: 700; }

.tips { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin: 12px 0; }
.tipcard { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; font-size: .93rem; }
.tipcard b { display: block; margin-bottom: 3px; font-family: var(--serif); font-size: 1.02rem; }
.tipcard code { font-size: .82em; }
.nbline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0 4px; font-size: .9rem; }
.tag { background: var(--green-soft); color: var(--green-ink); border-radius: 999px; padding: 3px 11px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.tag.n { background: var(--navy-soft); color: var(--navy); }
.tag.g { background: var(--gold-soft); color: var(--gold); }

.front { display: grid; gap: 10px; margin: 12px 0; }
.fitem { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--navy); border-radius: 12px; padding: 10px 14px; font-size: .95rem; }
.fitem b { font-family: var(--serif); font-size: 1.03rem; }
.fitem .vb { font: 700 .68rem var(--sans); color: #fff; background: var(--navy); border-radius: 6px; padding: 2px 7px; margin-right: 6px; vertical-align: 2px; white-space: nowrap; }
.fitem .fsrc { display: block; margin-top: 6px; font: 500 .74rem var(--sans); color: var(--muted); }
.fitem .fsrc a { color: var(--muted); text-decoration: underline dotted; }
.fitem .vb.g { background: var(--green); } .fitem .vb.w { background: var(--gold); }
html[data-theme="dark"] .fitem .vb, html[data-theme="dark"] .badge.must { color: #0f1411; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .fitem .vb, :root:not([data-theme="light"]) .badge.must { color: #0f1411; } }
.fq { background: var(--navy-soft); border-radius: 12px; padding: 10px 14px; margin: 10px 0; font-family: var(--serif); font-size: 1.05rem; }
.fq b { font-family: var(--sans); font-size: .74rem; letter-spacing: .08em; text-transform: uppercase; color: var(--navy); display: block; margin-bottom: 2px; }

table.bridge td:first-child { font-weight: 600; width: 22%; }
table.bridge td:nth-child(2) { width: 30%; }
table.bridge td { font-size: .9rem; }

/* ---------- pager / footer ---------- */
.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 56px; padding: 18px 0 0; border-top: 1px solid var(--line); font-weight: 600; }
.pager a { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 16px; }
.pager a:hover { border-color: var(--green); text-decoration: none; }
.pager a.next { background: var(--green); border-color: var(--green); color: #fff; }
.fine { font-size: .8rem; color: var(--muted); margin: 22px 0 0; }
@media print { .topbar, .backbtn, .tip, .roadmap, .widget .ctrls { display: none !important; } }

/* code-bearing tip cards take the full row */
.tipcard:has(pre) { grid-column: 1 / -1; }
.tipcard pre { margin: 8px 0; }
code { overflow-wrap: anywhere; }

/* --- per-page review section --- */
.rv { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.rv-col { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px 12px; }
.rv-col h3, .rv-check h3 { margin: 4px 0 8px; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--navy); }
.rv-col ul, .rv-col ol { margin: 0; padding-left: 20px; }
.rv-col li { margin: 4px 0; font-size: .95rem; }
.rv-thread, .rv-next { margin: 14px 0 0; padding: 10px 16px; border-radius: 12px; border-left: 4px solid var(--green); background: var(--green-soft); }
.rv-next { border-left-color: var(--gold); background: var(--gold-soft); }
.rv-check { margin-top: 14px; border: 1px solid var(--line); border-left: 4px solid var(--navy); background: var(--navy-soft); border-radius: 12px; padding: 10px 16px 12px; }
.rv-check details { margin: 4px 0; font-size: .95rem; }
.rv-check summary { cursor: pointer; font-weight: 600; color: var(--navy); }
.rv-check details p { margin: 6px 0 4px 18px; }
@media (max-width: 760px) { .rv { grid-template-columns: 1fr; } }

/* predict-then-reveal "Check yourself" (answer hidden until asked) */
details.cy { margin: 12px 0; padding: 8px 12px; border: 1px dashed var(--line); border-radius: 10px; background: var(--panel); }
details.cy > summary { cursor: pointer; list-style: none; }
details.cy > summary::-webkit-details-marker { display: none; }
details.cy .cy-hint { font: 600 .72rem var(--sans); color: var(--green); margin-left: 6px; white-space: nowrap; }
details.cy[open] .cy-hint { display: none; }
details.cy > p { margin: 8px 0 0; padding-top: 8px; border-top: 1px solid var(--line); }
/* the slide-by-slide walkthrough is a reference: collapsed by default */
h2 .refnote { font: 600 .72rem var(--sans); color: var(--muted); margin-left: 8px; letter-spacing: .02em; vertical-align: 3px; white-space: nowrap; }
details.ref:not([open]) { opacity: .92; }
/* proof workshop */
.pw { border-left: 4px solid var(--gold); background: var(--surface); border-radius: 12px; padding: 12px 16px; margin: 12px 0; }
.pw .pw-q { font-family: var(--serif); font-size: 1.04rem; }
.pw details { margin: 8px 0; }
.pw details > summary { cursor: pointer; font: 600 .82rem var(--sans); color: var(--navy); }
.pw details > div { margin-top: 6px; padding-left: 10px; border-left: 2px solid var(--line); }
@media (max-width: 640px) { h2 .refnote { display: block; margin: 4px 0 0; white-space: normal; } }

.cy-from { margin: -6px 0 10px 12px; font: 500 .74rem var(--sans); color: var(--muted); }
.cy-from a { color: var(--muted); }

/* narrow screens: wide tables and long formulas scroll inside their box instead of widening the page */
.tablewrap { max-width: 100%; }
main section, main section > details, main .wblock, main .wtext { min-width: 0; max-width: 100%; }
main section > details { overflow-x: auto; }
.katex-display { overflow-x: auto; overflow-y: hidden; max-width: 100%; padding: 2px 0; }

/* "Sharper lens" sections: precise statements, second viewpoints and limits the slides round off */
.lens { display: grid; gap: 12px; margin: 12px 0; }
.lens-i { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--navy); border-radius: 12px; padding: 12px 16px; }
.lens-i.g { border-left-color: var(--green); } .lens-i.o { border-left-color: var(--gold); }
.lens-i h3 { margin: 6px 0 4px; font-size: 1.02rem; }
.lens-i p { margin: 6px 0; }
.lens-i details { margin: 6px 0 2px; }
.lens-i details > summary { cursor: pointer; font: 600 .82rem var(--sans); color: var(--navy); }
.lens-i details > div { margin-top: 6px; padding-left: 10px; border-left: 2px solid var(--line); }

/* opening review of earlier sessions (#before, written by scripts/guide_recap.py) */
#before .rv-col { margin-top: 12px; }
.rc { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; margin: 10px 0 4px; }
.rc-card { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--green); border-radius: 12px; padding: 10px 16px 12px; }
.rc-card .rc-h { margin: 2px 0 6px; font: 700 .8rem var(--sans); text-transform: uppercase; letter-spacing: .06em; color: var(--navy); }
.rc-card .rc-h a { color: inherit; }
.rc-card .rc-idea { margin: 0 0 4px; font-family: var(--serif); }
.rc-card .formula { margin: 8px 0 2px; font-size: .92em; }
.rc-card .note { margin: 6px 0 0; }
.rc-from { font: 500 .74rem var(--sans); color: var(--muted); margin-left: 6px; white-space: nowrap; }
#before h3 { margin: 18px 0 4px; }

/* phone width: grid items may shrink below their content, and KaTeX's hidden MathML stays inside its scroller */
.lens-i, .rv-col, .split > *, .figrow > * { min-width: 0; }
.katex { position: relative; }

/* "The mathematics, step by step" (#math): a symbol table, then one card per formula */
table.mx-sym td:first-child { white-space: nowrap; }
table.mx-sym td:last-child { color: var(--muted); font-size: .88rem; }
.mx-card { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--navy); border-radius: 12px; padding: 6px 18px 12px; margin: 16px 0; }
.mx-card h3 { margin: 10px 0 2px; font-size: 1.05rem; display: flex; align-items: baseline; gap: 10px; }
.mx-card .mx-n { flex: none; display: inline-grid; place-items: center; width: 1.6em; height: 1.6em; border-radius: 50%; background: var(--navy); color: #fff; font: 700 .78rem var(--sans); transform: translateY(-1px); }
.mx-card .formula { margin: 8px 0 6px; padding: 6px 10px; background: var(--panel); border-radius: 10px; }
.mx-card p { margin: 8px 0; }
.mx-l { font: 700 .74rem var(--sans); text-transform: uppercase; letter-spacing: .07em; color: var(--navy); margin-right: 4px; }
.mx-num { margin: 10px 0; padding: 8px 14px; border-radius: 10px; background: var(--green-soft); border-left: 4px solid var(--green); }
.mx-num .mx-l { color: var(--green-ink); }
.mx-warn { padding: 8px 14px; border-radius: 10px; background: var(--gold-soft); border-left: 4px solid var(--gold); font-size: .95rem; }
