@import url('fonts.css');

/* ---------- Theme tokens ---------- */
:root {
  --paper: #FBF6EC;
  --paper-2: #F3EBDB;
  --card: #FFFDF8;
  --ink: #1D1B16;
  --ink-2: #3A362E;
  --muted: #6E685C;
  --line: #E3D8C3;
  --accent: #FF5B23;
  --accent-ink: #C2410C;
  --accent-soft: #FFE6DA;
  --blue: #2563EB;
  --teal: #0E9F8E;
  --teal-soft: #DDF3EF;
  --gold: #F2B705;
  --gold-soft: #FFF3C7;
  --good: #1F9D55;
  --good-soft: #E1F4E8;
  --bad: #DC3B3B;
  --bad-soft: #FBE3E1;
  --violet: #6D4AFF;
  --violet-soft: #ECE7FF;
  --code-bg: #1F1C17;
  --code-ink: #F6F1E6;
  --shadow: 0 1px 0 rgba(29, 27, 22, .04), 0 8px 24px -12px rgba(29, 27, 22, .18);
  --radius: 18px;
  --font-body: 'Figtree', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-head: 'Bricolage Grotesque', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #14130F; --paper-2: #1C1A16; --card: #211F1A; --ink: #F4EFE4; --ink-2: #DCD5C6;
    --muted: #A69F90; --line: #37322B; --accent: #FF7A45; --accent-ink: #FF9A70; --accent-soft: #3A2016;
    --blue: #7AA7FF; --teal: #3CCFBC; --teal-soft: #12302C; --gold: #FFCB3D; --gold-soft: #33290B;
    --good: #4CC384; --good-soft: #13301F; --bad: #FF6B6B; --bad-soft: #3A1717; --violet: #A391FF;
    --violet-soft: #241D45; --code-bg: #0E0D0B; --code-ink: #F6F1E6;
    --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 10px 30px -12px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #14130F; --paper-2: #1C1A16; --card: #211F1A; --ink: #F4EFE4; --ink-2: #DCD5C6;
  --muted: #A69F90; --line: #37322B; --accent: #FF7A45; --accent-ink: #FF9A70; --accent-soft: #3A2016;
  --blue: #7AA7FF; --teal: #3CCFBC; --teal-soft: #12302C; --gold: #FFCB3D; --gold-soft: #33290B;
  --good: #4CC384; --good-soft: #13301F; --bad: #FF6B6B; --bad-soft: #3A1717; --violet: #A391FF;
  --violet-soft: #241D45; --code-bg: #0E0D0B; --code-ink: #F6F1E6;
  --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 10px 30px -12px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 80px; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--font-body); font-size: 19px; line-height: 1.7;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
img, video, canvas { max-width: 100%; display: block; }
a { color: var(--accent-ink); text-decoration-thickness: 2px; text-underline-offset: 3px; }
a:hover { color: var(--accent); }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; border-radius: 6px; }
h1, h2, h3, h4 { font-family: var(--font-head); line-height: 1.12; letter-spacing: -0.02em; color: var(--ink); }
h2 { font-size: 2.05rem; font-weight: 800; margin: 3.2rem 0 1rem; }
h3 { font-size: 1.4rem; font-weight: 750; margin: 2.2rem 0 .6rem; }
h4 { font-size: 1.1rem; font-weight: 750; margin: 1.6rem 0 .4rem; }
p { margin: 0 0 1.05rem; }
strong, b { font-weight: 750; }
ul, ol { padding-left: 1.3rem; margin: 0 0 1.1rem; }
li { margin: .3rem 0; }
mark {
  background: linear-gradient(100deg, transparent 2%, var(--gold-soft) 4%, var(--gold-soft) 96%, transparent 98%);
  color: inherit; padding: 0 .2em; border-radius: .2em;
  box-decoration-break: clone; -webkit-box-decoration-break: clone;
  box-shadow: inset 0 -0.45em 0 color-mix(in srgb, var(--gold) 45%, transparent);
}
code { font-family: var(--font-mono); font-size: .86em; background: var(--paper-2); border: 1px solid var(--line); padding: .08em .35em; border-radius: 6px; overflow-wrap: anywhere; word-break: break-word; }
.recap code, .prompt code { background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .22); color: inherit; }
hr { border: 0; height: 1px; background: var(--line); margin: 3rem 0; }
table { width: 100%; border-collapse: collapse; margin: 1.2rem 0 1.6rem; font-size: .92em; }
th, td { text-align: left; padding: .65rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-family: var(--font-head); font-weight: 750; background: var(--paper-2); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 1.2rem 0 1.6rem; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.table-wrap table { margin: 0; }

/* ---------- Top bar and progress ---------- */
.progress { position: fixed; inset: 0 0 auto 0; height: 4px; z-index: 50; background: transparent; }
.progress span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--gold)); transition: width .1s linear; }
.topbar {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: .75rem;
  padding: .7rem 1rem; background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .55rem; font-family: var(--font-head); font-weight: 800; font-size: 1.05rem; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.brand svg { width: 28px; height: 28px; flex: none; }
.topbar .spacer { flex: 1; }
.icon-btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 12px; height: 40px; min-width: 40px; padding: 0 .7rem; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: 600 .9rem var(--font-body); cursor: pointer; text-decoration: none;
}
.icon-btn:hover { border-color: var(--muted); }
.icon-btn svg { width: 20px; height: 20px; }
.menu-btn { display: none; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: 100vh; }
body.public .layout { grid-template-columns: minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 61px; height: calc(100vh - 61px); overflow-y: auto; padding: 1.4rem 1rem 3rem 1.2rem;
  border-right: 1px solid var(--line); font-size: .92rem; line-height: 1.4;
}
.toc-part { margin: 1.3rem 0 .45rem; font-family: var(--font-head); font-weight: 800; font-size: .74rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.toc-part:first-child { margin-top: 0; }
.toc a {
  display: flex; gap: .55rem; align-items: baseline; padding: .42rem .6rem; margin: 1px 0; border-radius: 10px;
  color: var(--ink-2); text-decoration: none;
}
.toc a:hover { background: var(--paper-2); color: var(--ink); }
.toc a.active { background: var(--accent-soft); color: var(--ink); font-weight: 700; }
.toc .n { font-family: var(--font-head); font-weight: 800; color: var(--muted); min-width: 1.4rem; font-size: .85em; }
.toc a.done .n { color: var(--good); }
.toc a.done .n::before { content: "\2713"; }
.toc a.done .n span { display: none; }
main { min-width: 0; padding: 0 1.25rem 6rem; }
.article { max-width: 44rem; margin: 0 auto; }

/* ---------- Chapter header ---------- */
.chapter-head { padding: 3.6rem 0 1.6rem; border-bottom: 1px solid var(--line); margin-bottom: 2.4rem; }
.kicker { display: inline-flex; align-items: center; gap: .5rem; font-family: var(--font-head); font-weight: 800; font-size: .8rem; letter-spacing: .12em; text-transform: uppercase; color: var(--accent-ink); }
.kicker .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.chapter-head h1 { font-size: clamp(2.5rem, 7vw, 4.1rem); font-weight: 800; margin: .7rem 0 .9rem; letter-spacing: -0.035em; }
.chapter-head h1 .num { display: inline-block; color: var(--accent); margin-right: .25em; }
.chapter-head .summary { font-size: 1.2rem; color: var(--ink-2); margin: 0 0 1rem; }
.chapter-head .meta { display: flex; flex-wrap: wrap; gap: .5rem; font-size: .85rem; color: var(--muted); }
.chapter-head .meta span { background: var(--paper-2); border: 1px solid var(--line); border-radius: 999px; padding: .2rem .7rem; }
.chapter-head .meta .lvl { font-weight: 700; color: var(--ink); border-color: transparent; background: var(--teal-soft); }
.chapter-head .meta .lvl[data-lvl="beginner"] { background: var(--good-soft); }
.chapter-head .meta .lvl[data-lvl="intermediate"] { background: var(--gold-soft); }
.chapter-head .meta .lvl[data-lvl="advanced"] { background: var(--accent-soft); }

/* ---------- Text components ---------- */
.lede { font-size: 1.36em; line-height: 1.5; font-weight: 600; color: var(--ink); margin-bottom: 1.6rem; letter-spacing: -0.005em; }
.big { font-size: 1.25em; font-weight: 700; }
.small { font-size: .85em; color: var(--muted); }
.center { text-align: center; }

.story, .analogy, .brain, .tryit, .caught, .honest, .recap, .next, .ba, .quiz, .prompt, figure, .steps, .stats {
  margin: 2rem 0;
}
.story { background: var(--paper-2); border-radius: var(--radius); padding: 1.4rem 1.5rem .5rem; position: relative; }
.story::before { content: "Story time"; display: inline-block; font: 800 .72rem var(--font-head); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-bottom: .5rem; }
.story p { font-size: 1.04em; }

.analogy, .brain, .honest, .tryit, .caught {
  border-radius: var(--radius); padding: 1.25rem 1.4rem .4rem 1.4rem; border: 1px solid var(--line); background: var(--card); box-shadow: var(--shadow); position: relative;
}
.analogy > b, .brain > b, .honest > b, .tryit > b, .caught > b, .recap > b {
  display: flex; align-items: center; gap: .55rem; font-family: var(--font-head); font-weight: 800; font-size: 1.02rem; margin-bottom: .45rem; letter-spacing: -0.01em;
}
.analogy > b::before, .brain > b::before, .honest > b::before, .tryit > b::before {
  content: ""; width: 30px; height: 30px; border-radius: 9px; flex: none; background: currentColor;
  -webkit-mask: var(--icon) center / 18px 18px no-repeat, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask: var(--icon) center / 18px 18px no-repeat exclude, linear-gradient(#000 0 0);
}
.analogy { background: var(--teal-soft); border-color: transparent; }
.analogy > b { color: var(--teal); --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 18h6M10 22h4M12 2a7 7 0 0 0-4 12.7c.6.5 1 1.2 1 2V17h6v-.3c0-.8.4-1.5 1-2A7 7 0 0 0 12 2z'/%3E%3C/svg%3E"); }
.brain { background: var(--violet-soft); border-color: transparent; }
.deeper { border-radius: var(--radius); padding: 1.25rem 1.4rem .4rem 1.4rem; background: var(--card); border: 2px solid var(--ink); position: relative; margin: 2rem 0; }
.deeper > b { display: flex; align-items: center; gap: .55rem; font-family: var(--font-head); font-weight: 800; font-size: 1.02rem; margin-bottom: .45rem; color: var(--ink); }
.deeper > b::after { content: "ADVANCED"; font: 800 .62rem var(--font-head); letter-spacing: .12em; color: var(--paper); background: var(--ink); padding: .18rem .45rem; border-radius: 5px; }
.ai { border-radius: var(--radius); padding: 1.25rem 1.4rem .4rem 1.4rem; background: color-mix(in srgb, var(--blue) 10%, var(--card)); border: 1px solid color-mix(in srgb, var(--blue) 30%, transparent); position: relative; margin: 2rem 0; }
.ai > b { display: flex; align-items: center; gap: .55rem; font-family: var(--font-head); font-weight: 800; font-size: 1.02rem; margin-bottom: .45rem; color: var(--blue); }
.ai > b::before { content: ""; width: 30px; height: 30px; border-radius: 9px; flex: none; background: currentColor; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='6' y='6' width='12' height='12' rx='2'/%3E%3Cpath d='M9 2v4M15 2v4M9 18v4M15 18v4M2 9h4M2 15h4M18 9h4M18 15h4'/%3E%3C/svg%3E") center / 18px 18px no-repeat, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='6' y='6' width='12' height='12' rx='2'/%3E%3Cpath d='M9 2v4M15 2v4M9 18v4M15 18v4M2 9h4M2 15h4M18 9h4M18 15h4'/%3E%3C/svg%3E") center / 18px 18px no-repeat exclude, linear-gradient(#000 0 0); }
.brain > b { color: var(--violet); --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 5a3 3 0 0 0-5.9-.6A3 3 0 0 0 4 9.5a3 3 0 0 0 .5 5.4A3 3 0 0 0 8 19a3 3 0 0 0 4 1V5zM12 5a3 3 0 0 1 5.9-.6A3 3 0 0 1 20 9.5a3 3 0 0 1-.5 5.4A3 3 0 0 1 16 19a3 3 0 0 1-4 1'/%3E%3C/svg%3E"); }
.honest > b { color: var(--muted); --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 8v5M12 16.5v.5'/%3E%3C/svg%3E"); }
.tryit { border: 2px dashed var(--accent); background: transparent; box-shadow: none; }
.tryit > b { color: var(--accent-ink); --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h14M13 5l7 7-7 7'/%3E%3C/svg%3E"); }
.caught { background: var(--gold-soft); border-color: transparent; padding-top: 1.5rem; }
.caught > b { font-size: 1.15rem; }
.caught::after {
  content: "CAUGHT YOU"; position: absolute; top: -12px; right: 16px; transform: rotate(4deg);
  font: 800 .72rem var(--font-head); letter-spacing: .14em; color: #fff; background: var(--accent); padding: .3rem .6rem; border-radius: 6px; box-shadow: var(--shadow);
}
.caught > b { display: none; }

blockquote.said { margin: 2.2rem 0; padding: 0 0 0 0; border: 0; }
blockquote.said p { font-family: var(--font-head); font-weight: 700; font-size: 1.5rem; line-height: 1.3; letter-spacing: -0.015em; margin: 0 0 .5rem; }
blockquote.said p::before { content: "\201C"; color: var(--accent); margin-right: .05em; }
blockquote.said p::after { content: "\201D"; color: var(--accent); margin-left: .05em; }
blockquote.said cite { font-style: normal; font-size: .88rem; color: var(--muted); }
blockquote.said cite::before { content: ""; display: inline-block; width: 22px; height: 2px; background: var(--accent); vertical-align: middle; margin-right: .5rem; }

/* ---------- Before / After ---------- */
.ba { display: grid; gap: .8rem; }
.ba-before, .ba-after { border-radius: 16px; padding: 1rem 1.15rem .2rem; position: relative; }
.ba-before { background: var(--bad-soft); }
.ba-after { background: var(--good-soft); }
.ba-label { display: inline-block; font: 800 .7rem var(--font-head); letter-spacing: .12em; text-transform: uppercase; padding: .2rem .55rem; border-radius: 6px; margin-bottom: .5rem; color: #fff; }
.ba-before .ba-label { background: var(--bad); }
.ba-after .ba-label { background: var(--good); }
.ba-before p { color: var(--ink-2); }
.ba-why { margin: .2rem .2rem 0; font-size: .96em; }
.ba-why b { color: var(--good); }
.ba[data-guess] .ba-after, .ba[data-guess] .ba-why { display: none; }
.ba[data-guess].revealed .ba-after, .ba[data-guess].revealed .ba-why { display: block; animation: pop .35s ease; }
.reveal-btn {
  appearance: none; border: 2px solid var(--ink); background: var(--card); color: var(--ink); border-radius: 12px;
  font: 700 .95rem var(--font-body); padding: .65rem 1rem; cursor: pointer; justify-self: start;
}
.reveal-btn:hover { background: var(--ink); color: var(--paper); }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Prompt boxes ---------- */
.prompt { background: var(--code-bg); color: var(--code-ink); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.prompt-head { display: flex; align-items: center; gap: .6rem; padding: .7rem .8rem .7rem 1.1rem; border-bottom: 1px solid rgba(255, 255, 255, .09); }
.prompt-head .tag { font: 800 .66rem var(--font-head); letter-spacing: .12em; text-transform: uppercase; color: var(--code-bg); background: var(--gold); padding: .18rem .45rem; border-radius: 5px; }
.prompt-head .title { font-family: var(--font-head); font-weight: 700; font-size: .98rem; flex: 1; min-width: 0; }
.copy-btn { appearance: none; border: 1px solid rgba(255, 255, 255, .2); background: rgba(255, 255, 255, .06); color: var(--code-ink); border-radius: 10px; font: 700 .82rem var(--font-body); padding: .42rem .75rem; cursor: pointer; flex: none; }
.copy-btn:hover { background: rgba(255, 255, 255, .14); }
.copy-btn.ok { background: var(--good); border-color: var(--good); color: #fff; }
.prompt pre { margin: 0; padding: 1rem 1.15rem 1.15rem; font-family: var(--font-mono); font-size: .8rem; line-height: 1.65; white-space: pre-wrap; word-break: break-word; max-height: 30rem; overflow: auto; }
.prompt .fill { color: #1F1C17; background: #FFCB3D; border-radius: 4px; padding: 0 .2em; font-weight: 700; }

/* ---------- Figures ---------- */
figure { margin-left: 0; margin-right: 0; }
figure.shot img, figure.clip video { width: 100%; border-radius: 16px; border: 1px solid var(--line); background: var(--paper-2); }
figure.clip { position: relative; max-width: 360px; margin-left: auto; margin-right: auto; }
figure.clip.wide { max-width: none; }
figure.clip .sound-btn {
  position: absolute; right: 10px; top: 10px; z-index: 2; appearance: none; border: 0; border-radius: 999px; padding: .45rem .75rem;
  background: rgba(0, 0, 0, .62); color: #fff; font: 700 .78rem var(--font-body); cursor: pointer; display: inline-flex; align-items: center; gap: .35rem;
}
figure.anim { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem; box-shadow: var(--shadow); }
figure.anim canvas { width: 100%; border-radius: 12px; }
figure.anim .anim-fallback { padding: 2rem 1rem; text-align: center; color: var(--muted); font-size: .9rem; }
figure.anim.live { padding: 0; overflow: hidden; }
figure.anim.live { max-width: 420px; margin-left: auto; margin-right: auto; }
figure.anim.live iframe { width: 100%; border: 0; display: block; background: #121016; border-radius: var(--radius) var(--radius) 0 0; }
figure.anim.live figcaption { padding: .2rem 1rem .9rem; }
figcaption { font-size: .86rem; color: var(--muted); margin-top: .6rem; padding: 0 .3rem; line-height: 1.5; }
figure.shot.narrow { max-width: 420px; margin-left: auto; margin-right: auto; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; margin: 2rem 0; }
.compare figure { margin: 0; }
@media (max-width: 640px) { .compare { grid-template-columns: 1fr; } }
.gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; margin: 2rem 0; }
.gallery figure { margin: 0; }

/* ---------- Steps ---------- */
ol.steps { list-style: none; padding: 0; counter-reset: step; }
ol.steps > li { counter-increment: step; position: relative; padding: .1rem 0 .6rem 3.4rem; margin: 0 0 1rem; }
ol.steps > li::before {
  content: counter(step); position: absolute; left: 0; top: 0; width: 2.3rem; height: 2.3rem; border-radius: 50%;
  display: grid; place-items: center; background: var(--ink); color: var(--paper); font: 800 1.05rem var(--font-head);
}
ol.steps > li > b { display: block; font-family: var(--font-head); font-size: 1.12rem; margin-bottom: .2rem; }
ol.steps > li > p { margin-bottom: .4rem; }

/* ---------- Quiz ---------- */
.quiz { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.3rem 1rem; box-shadow: var(--shadow); }
.quiz::before { content: "Quick check"; display: block; font: 800 .72rem var(--font-head); letter-spacing: .12em; text-transform: uppercase; color: var(--blue); margin-bottom: .4rem; }
.quiz .q { font-family: var(--font-head); font-weight: 750; font-size: 1.15rem; line-height: 1.35; }
.quiz .opt {
  display: block; width: 100%; text-align: left; appearance: none; border: 2px solid var(--line); background: var(--paper); color: var(--ink);
  border-radius: 14px; padding: .8rem 1rem; margin: .55rem 0; font: 500 1rem/1.5 var(--font-body); cursor: pointer; transition: border-color .15s, background .15s;
}
.quiz .opt:hover { border-color: var(--muted); }
.quiz .opt.right { border-color: var(--good); background: var(--good-soft); }
.quiz .opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.quiz .explain { display: none; margin-top: .8rem; padding-top: .8rem; border-top: 1px dashed var(--line); }
.quiz.answered .explain { display: block; animation: pop .35s ease; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.stat b { display: block; font-family: var(--font-head); font-weight: 800; font-size: 2rem; line-height: 1.05; letter-spacing: -0.03em; color: var(--accent); }
.stat span { display: block; font-size: .86rem; color: var(--muted); margin-top: .3rem; line-height: 1.35; }

/* ---------- Recap / Next ---------- */
.recap { background: var(--ink); color: var(--paper); border-radius: var(--radius); padding: 1.4rem 1.5rem .6rem; }
.recap > b { color: var(--paper); font-size: 1.2rem; }
.recap ul { list-style: none; padding: 0; }
.recap li { position: relative; padding-left: 1.9rem; margin: .55rem 0; }
.recap li::before { content: "\2713"; position: absolute; left: 0; top: .05rem; width: 1.3rem; height: 1.3rem; border-radius: 50%; background: var(--accent); color: #fff; font-size: .75rem; display: grid; place-items: center; font-weight: 800; }
.next { border-top: 1px solid var(--line); padding-top: 2rem; }
.next p { font-family: var(--font-head); font-weight: 700; font-size: 1.35rem; line-height: 1.35; letter-spacing: -0.015em; }
.next-link {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; text-decoration: none; color: var(--paper); background: var(--accent);
  border-radius: var(--radius); padding: 1.1rem 1.3rem; margin-top: 1rem; box-shadow: var(--shadow); transition: transform .15s;
}
.next-link:hover { color: var(--paper); transform: translateY(-2px); }
.next-link small { display: block; font: 800 .72rem var(--font-head); letter-spacing: .12em; text-transform: uppercase; opacity: .85; }
.next-link strong { display: block; font-family: var(--font-head); font-size: 1.3rem; }
.next-link svg { width: 28px; height: 28px; flex: none; }
.done-row { display: flex; justify-content: center; margin: 2.5rem 0 1rem; }
.done-btn { appearance: none; border: 2px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: .7rem 1.2rem; font: 700 .95rem var(--font-body); cursor: pointer; display: inline-flex; gap: .5rem; align-items: center; }
.done-btn.on { border-color: var(--good); background: var(--good-soft); }
.pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 2rem; font-size: .92rem; }
.pager a { text-decoration: none; color: var(--muted); }
.pager a:hover { color: var(--ink); }

/* ---------- Glossary terms ---------- */
.term { border-bottom: 2px dotted var(--teal); cursor: help; }
.term-pop {
  position: absolute; z-index: 60; max-width: 300px; background: var(--ink); color: var(--paper); border-radius: 14px; padding: .8rem .95rem;
  font-size: .9rem; line-height: 1.5; box-shadow: 0 12px 34px -10px rgba(0, 0, 0, .5);
}
.term-pop b { display: block; font-family: var(--font-head); color: var(--gold); margin-bottom: .15rem; }

/* ---------- Vault and resource lists ---------- */
.vault-tools { position: sticky; top: 61px; z-index: 5; background: var(--paper); padding: .8rem 0; border-bottom: 1px solid var(--line); margin-bottom: 1.5rem; }
.vault-search { width: 100%; font: 500 1.05rem var(--font-body); padding: .85rem 1rem; border-radius: 14px; border: 2px solid var(--line); background: var(--card); color: var(--ink); }
.vault-search:focus { border-color: var(--accent); outline: none; }
.chips { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .7rem; }
.chip { appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink-2); border-radius: 999px; padding: .35rem .8rem; font: 600 .85rem var(--font-body); cursor: pointer; }
.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.vault-count { font-size: .85rem; color: var(--muted); margin-top: .6rem; }
@media (max-width: 640px) {
  .vault-tools { top: 61px; padding: .6rem 0 .5rem; }
  .vault-tools .chips { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: .2rem; margin-top: .5rem; }
  .vault-tools .chips::-webkit-scrollbar { display: none; }
  .vault-tools .chip { flex: none; }
  .vault-count { margin-top: .3rem; }
}
.vault-cat { margin-top: 2.6rem; }
.prompt .when { padding: .8rem 1.15rem 0; font-family: var(--font-body); font-size: .86rem; color: #CFC6B3; margin: 0; }
.prompt .tip { padding: 0 1.15rem 1rem; font-family: var(--font-body); font-size: .84rem; color: #CFC6B3; margin: 0; }
.prompt .tip b { color: var(--gold); }

dl.glossary { margin: 1rem 0 2rem; }
dl.glossary > div { padding: .9rem 0; border-bottom: 1px solid var(--line); }
dl.glossary dt { font-family: var(--font-head); font-weight: 800; font-size: 1.12rem; }
dl.glossary dd { margin: .2rem 0 0; color: var(--ink-2); }
pre.kit-tree { font-family: var(--font-mono); font-size: .8rem; line-height: 1.6; background: var(--paper-2); border: 1px solid var(--line); border-radius: 14px; padding: 1rem 1.1rem; overflow-x: auto; }
ul.resource-list { list-style: none; padding: 0; }
ul.resource-list li { padding: .8rem 0; border-bottom: 1px solid var(--line); margin: 0; }
ul.resource-list li b { font-family: var(--font-head); }
.vault-btn span { font-size: .85rem; }
@media (max-width: 420px) { .vault-btn span { display: none; } }

/* ---------- Footer ---------- */
.site-foot { max-width: 44rem; margin: 4rem auto 0; padding-top: 1.5rem; border-top: 1px solid var(--line); font-size: .82rem; color: var(--muted); }

/* ---------- Mobile ---------- */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 45; top: 61px; left: 0; bottom: 0; width: min(88vw, 340px); height: auto; background: var(--paper);
    transform: translateX(-102%); transition: transform .25s ease; box-shadow: 20px 0 40px -20px rgba(0, 0, 0, .35);
  }
  body.menu-open .sidebar { transform: none; }
  .menu-btn { display: inline-flex; }
  .scrim { position: fixed; inset: 61px 0 0 0; background: rgba(0, 0, 0, .35); z-index: 44; display: none; }
  body.menu-open .scrim { display: block; }
}
@media (max-width: 640px) {
  body { font-size: 17.5px; }
  main { padding: 0 16px 5rem; }
  h2 { font-size: 1.7rem; margin-top: 2.6rem; }
  h3 { font-size: 1.25rem; }
  .chapter-head { padding-top: 2.4rem; }
  .chapter-head .summary { font-size: 1.08rem; }
  .lede { font-size: 1.22em; }
  blockquote.said p { font-size: 1.28rem; }
  .story, .analogy, .brain, .honest, .tryit, .caught, .quiz { padding-left: 1.1rem; padding-right: 1.1rem; }
  .prompt pre { font-size: .76rem; }
  .brand .wordmark { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
@media print {
  .topbar, .sidebar, .progress, .done-row, .pager, .copy-btn { display: none !important; }
  .layout { display: block; }
}
