/* CyberNugget: a field-manual binder. Index of modules on the left, the open lesson on the right,
   set in a reading serif with condensed labels and monospace for IDs and diagrams. */
:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --sunken: #e3e8ee;
  --ink: #17202b;
  --muted: #5a6677;
  --line: #d3dae3;
  --accent: #2b52b3;
  --accent-soft: #e2e9fa;
  --on-accent: #ffffff;
  --good: #1d7a4f; --good-soft: #def2e7;
  --warn: #9a6400; --warn-soft: #f8ecd2;
  --bad: #b3362b;  --bad-soft: #f8e0dd;
  --code-bg: #f5f7fa;
  --f-display: "IBM Plex Sans Condensed", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  --f-body: "Source Serif 4", Georgia, "Times New Roman", serif;
  --f-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --nav-w: 300px;
  --scale: 1;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b; --surface: #161d26; --sunken: #1c2531; --ink: #e3e8ee; --muted: #94a1b2;
    --line: #2a3442; --accent: #86a6ff; --accent-soft: #1f2b47; --on-accent: #0f141b;
    --good: #5fcf96; --good-soft: #15302a; --warn: #e4b45a; --warn-soft: #33290f;
    --bad: #f08a80; --bad-soft: #3a1d1c; --code-bg: #121820;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141b; --surface: #161d26; --sunken: #1c2531; --ink: #e3e8ee; --muted: #94a1b2;
  --line: #2a3442; --accent: #86a6ff; --accent-soft: #1f2b47; --on-accent: #0f141b;
  --good: #5fcf96; --good-soft: #15302a; --warn: #e4b45a; --warn-soft: #33290f;
  --bad: #f08a80; --bad-soft: #3a1d1c; --code-bg: #121820;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 17px; line-height: 1.6; -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); }
button { font: inherit; color: inherit; }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.app {
  display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr);
  min-height: 100vh; min-height: 100dvh;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* ---------- Index (nav) ---------- */
nav.index {
  position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto; overscroll-behavior: contain;
  border-right: 1px solid var(--line);
  padding-block: 20px 40px; padding-right: 16px;
  font-family: var(--f-display);
}
.brand { display: flex; flex-direction: column; gap: 6px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.brand a { text-decoration: none; color: var(--ink); }
.brand-name { display: flex; align-items: center; gap: 10px; font-size: 24px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.1; }
.brand-name img { border-radius: 7px; }
.tlp { align-self: flex-start; font-family: var(--f-mono); font-size: 11px; letter-spacing: 0.06em;
  padding: 2px 7px; border: 1px solid var(--line); border-radius: 3px; color: var(--muted); background: var(--surface); }
.tlp b { color: var(--ink); }
.meter { display: flex; flex-direction: column; gap: 6px; padding-block: 14px; border-bottom: 1px solid var(--line); }
.meter-row { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.meter-row strong { color: var(--ink); font-weight: 600; }
.bar { height: 6px; background: var(--sunken); border-radius: 3px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; min-width: 3px; }
.search { margin-block: 14px 6px; }
.search input { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); color: var(--ink); font-family: var(--f-display); font-size: 16px; }
.mod { margin-top: 14px; }
.mod-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
  padding: 4px 6px; }
.mod-head span:last-child { font-family: var(--f-mono); letter-spacing: 0; font-weight: 400; }
.mod ul { list-style: none; margin: 0; padding: 0; }
.item { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; align-items: center; gap: 6px;
  padding: 6px 6px; min-height: 36px; border-radius: 6px; text-decoration: none; color: var(--ink); font-size: 15px; line-height: 1.3; }
.item:hover { background: var(--sunken); }
.item.current { background: var(--accent-soft); }
.item .id { font-family: var(--f-mono); font-size: 12px; color: var(--muted); }
.item.seen .id { color: var(--accent); font-weight: 600; }
.item.done .id { color: var(--good); font-weight: 600; }
.chip { font-family: var(--f-mono); font-size: 11px; padding: 1px 6px; border-radius: 10px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.next { background: var(--accent); color: var(--on-accent); }
.chip.plain { background: var(--sunken); color: var(--muted); }
.subs { list-style: none; margin: 2px 0 6px 46px; padding: 0 0 0 8px; border-left: 1px solid var(--line); display: flex; flex-direction: column; gap: 1px; }
.sub { display: flex; flex-direction: column; padding: 4px 8px; border-radius: 6px; text-decoration: none; color: var(--ink); font-size: 14px; line-height: 1.25; }
.sub:hover { background: var(--sunken); }
.sub.current { background: var(--accent-soft); }
.sub .k { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); font-weight: 600; }
.nav-foot { margin-top: 24px; font-size: 12px; color: var(--muted); font-family: var(--f-mono); line-height: 1.5; }

/* ---------- Main ---------- */
main { min-width: 0; padding-block: 28px 96px; padding-left: clamp(16px, 4vw, 56px); font-size: calc(17px * var(--scale)); }
.wrap { max-width: 760px; }
.loading { color: var(--muted); font-family: var(--f-display); }
.eyebrow { font-family: var(--f-display); font-size: 13px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
h1, h2, h3 { font-family: var(--f-display); text-wrap: balance; line-height: 1.2; letter-spacing: -0.005em; }
.page-title { font-size: clamp(32px, 5vw, 46px); font-weight: 700; margin: 6px 0 10px; }
.lede { font-size: 1.12em; color: var(--muted); max-width: 62ch; margin: 0; }

/* Topbar (desktop: just the settings button, top-right) */
.topbar { position: relative; display: flex; justify-content: flex-end; margin: -12px 0 8px; font-family: var(--f-display); }
.topbar #menu, .topbar-brand, .readbar { display: none; }
.settings-btn, .icon-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; cursor: pointer;
  min-width: 40px; min-height: 40px; padding: 4px 10px; font-family: var(--f-display); font-weight: 700; }
.settings-btn:hover, .icon-btn:hover { border-color: var(--accent); color: var(--accent); }

.metaline { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; font-family: var(--f-display); font-size: 14px; color: var(--muted); margin-top: 4px; }

/* On-this-page contents and section headers */
.toc { margin: 18px 0 28px; padding: 14px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; max-width: 70ch; font-family: var(--f-display); }
.toc-h { font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.toc ol { margin: 0; padding-left: 1.4em; font-size: 16px; }
.toc li + li { margin-top: 4px; }
.toc a { text-decoration: none; }
.toc li { padding-block: 3px; line-height: 1.35; }
.toc a:hover { text-decoration: underline; }
.toc .k-qa a { color: var(--ink); }
.toc .k-practice a { color: var(--warn); }
.part { scroll-margin-top: 16px; }
.part + .part { margin-top: 64px; }
.part-h { border-top: 3px solid var(--accent); padding-top: 14px; margin-bottom: 6px; }
.part-h.k-qa { border-top-color: var(--muted); }
.part-h.k-practice { border-top-color: var(--warn); }
.part-k { font-family: var(--f-display); font-size: 13px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.part-h.k-qa .part-k { color: var(--muted); }
.part-h.k-practice .part-k { color: var(--warn); }
.prose .part-h h2 { margin: 4px 0 0; padding-top: 0; border-top: 0; font-size: clamp(24px, 3.4vw, 30px); }
.prose .part-h + * { margin-top: 18px; }

/* Practice quiz */
.practice-note { color: var(--muted); font-size: 0.9em; }
.qcard { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin: 16px 0; }
.qcard.is-right { border-color: var(--good); }
.qcard.is-wrong { border-color: var(--bad); }
.qlabel { font-family: var(--f-display); font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.qtext > :first-child { margin-top: 6px; }
.qtext p { font-weight: 600; }
.opts { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.opt { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 10px; align-items: start; text-align: left; cursor: pointer;
  min-height: 48px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
  font-family: var(--f-body); font-size: 0.94em; line-height: 1.4; touch-action: manipulation; }
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt:disabled { cursor: default; color: var(--ink); opacity: 1; }
.opt .ol { font-family: var(--f-mono); font-size: 12px; font-weight: 600; color: var(--muted); padding-top: 3px; }
.opt.right { border-color: var(--good); background: var(--good-soft); }
.opt.right .ol { color: var(--good); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .ol { color: var(--bad); }
.why { margin-top: 12px; padding: 10px 14px; border-radius: 8px; background: var(--sunken); font-size: 0.92em; }
.qscore { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 8px;
  font-family: var(--f-display); font-weight: 600; font-variant-numeric: tabular-nums; }
.copy { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 6px 12px; min-height: 36px; cursor: pointer; font-family: var(--f-display); font-size: 14px; }
.copy:hover { border-color: var(--accent); color: var(--accent); }

/* Rendered lesson markdown */
.prose { max-width: 70ch; }
.prose > :first-child { margin-top: 0; }
.prose h1 { font-size: clamp(30px, 4.5vw, 40px); margin: 8px 0 6px; }
.prose h1 + p { font-family: var(--f-display); color: var(--muted); font-size: 15px; margin-top: 0; }
.prose h2 { font-size: 1.47em; margin: 44px 0 10px; padding-top: 18px; border-top: 1px solid var(--line); }
.prose h3 { font-size: 1.18em; margin: 30px 0 8px; }
.prose p, .prose li { max-width: 68ch; overflow-wrap: break-word; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li + li { margin-top: 4px; }
.prose strong { font-weight: 600; }
.prose code { font-family: var(--f-mono); font-size: 0.82em; background: var(--code-bg); border: 1px solid var(--line); padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere; }
.codebox { position: relative; margin: 16px 0; }
.prose pre { background: var(--code-bg); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin: 0; overflow-x: auto; line-height: 1.45; max-width: 100%; -webkit-overflow-scrolling: touch; font-size: 0.8em; }
.prose pre code { background: none; border: 0; padding: 0; font-size: inherit; white-space: pre; overflow-wrap: normal; }
.prose pre.fitted { padding-top: 34px; }
.zoom-btn { position: absolute; top: 6px; right: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  border-radius: 6px; padding: 2px 8px; min-height: 30px; font-family: var(--f-display); font-size: 12px; font-weight: 600; cursor: pointer; opacity: .92; }
.zoom-btn:hover { color: var(--accent); border-color: var(--accent); }
.prose blockquote { margin: 18px 0; padding: 8px 16px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 6px 6px 0; }
.prose blockquote p { margin: 6px 0; }
.table-scroll { overflow-x: auto; margin: 16px 0; border: 1px solid var(--line); border-radius: 8px; -webkit-overflow-scrolling: touch; }
.prose table { border-collapse: collapse; width: 100%; font-size: 0.88em; line-height: 1.45; }
.prose th, .prose td { text-align: left; vertical-align: top; padding: 8px 12px; border-bottom: 1px solid var(--line); min-width: 7em; }
.prose th { font-family: var(--f-display); font-weight: 600; background: var(--sunken); font-size: 14px; }
.prose tr:last-child td { border-bottom: 0; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 32px 0; }
.prose details { margin: 14px 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.prose details > summary { cursor: pointer; padding: 12px 16px; min-height: 44px; font-family: var(--f-display); font-weight: 600; color: var(--accent); list-style-position: inside; }
.prose details[open] > summary { border-bottom: 1px solid var(--line); }
.prose details > :not(summary) { margin-inline: 16px; }

.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 56px; padding-top: 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.pager a { display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: var(--ink); font-family: var(--f-display);
  padding: 10px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); min-width: 0; max-width: 48%; }
.pager a:hover { border-color: var(--accent); }
.pager a.nextp { text-align: right; margin-left: auto; }
.pager small { color: var(--muted); font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; }
.mark-done { margin-top: 28px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; font-family: var(--f-display); color: var(--muted); font-size: 15px; }

/* Home */
.home-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 24px 0 28px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.stat b { font-family: var(--f-display); font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat span { font-family: var(--f-display); font-size: 13px; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.upnext { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px 22px; display: flex; flex-direction: column; gap: 10px; }
.upnext h2 { margin: 0; font-size: 26px; }
.upnext h2 a { color: var(--ink); text-decoration: none; }
.upnext h2 a:hover { color: var(--accent); }
.upnext p { margin: 0; color: var(--muted); max-width: 64ch; }
.btn { align-self: flex-start; display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; min-height: 44px; border-radius: 8px;
  background: var(--accent); color: var(--on-accent); text-decoration: none; font-family: var(--f-display); font-weight: 600; font-size: 16px; border: 0; cursor: pointer; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.section-h { font-size: 13px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 36px 0 12px; font-family: var(--f-display); }
.how { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.how div { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; font-size: 0.92em; }
.how b { display: block; font-family: var(--f-display); font-size: 16px; margin-bottom: 4px; }
.track { display: flex; flex-direction: column; gap: 8px; }
.track-row { display: grid; grid-template-columns: minmax(0, 240px) minmax(0, 1fr) 44px; gap: 12px; align-items: center; font-family: var(--f-display); font-size: 15px; }
.track-row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-row .name i { font-style: normal; font-family: var(--f-mono); font-size: 12px; color: var(--muted); margin-right: 6px; }
.cells { display: flex; gap: 4px; flex-wrap: wrap; }
.cell { width: 22px; height: 18px; border-radius: 3px; background: var(--sunken); display: block; }
.cell.seen { background: var(--accent-soft); outline: 1px solid var(--accent); outline-offset: -1px; }
.cell.done { background: var(--good); }
.track-row .count { font-family: var(--f-mono); font-size: 12px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.recent { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.recent a { display: grid; grid-template-columns: 44px minmax(0,1fr) auto; gap: 10px; align-items: center; padding: 10px 14px; min-height: 44px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; text-decoration: none; color: var(--ink); font-family: var(--f-display); }
.recent a:hover { border-color: var(--accent); }
.recent .id { font-family: var(--f-mono); font-size: 12px; color: var(--good); font-weight: 600; }
.empty { color: var(--muted); font-style: italic; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-family: var(--f-display); font-size: 13px; color: var(--muted); }
.legend .cell { display: inline-block; vertical-align: -3px; margin-right: 4px; width: 16px; height: 13px; }
.fine { margin-top: 40px; color: var(--muted); font-size: 14px; font-family: var(--f-display); }

/* Settings sheet */
.sheet { position: fixed; z-index: 50; right: 16px; top: 16px; width: min(360px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px 20px; box-shadow: 0 20px 60px rgba(0,0,0,.25); font-family: var(--f-display); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.setting { margin-top: 18px; }
.setting-k { font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.setting-note { margin: 0 0 8px; color: var(--muted); font-size: 14px; line-height: 1.4; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--sunken); border-radius: 10px; }
.seg button { border: 0; background: transparent; min-height: 40px; border-radius: 7px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.wide-btn { width: 100%; min-height: 44px; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; cursor: pointer; font-weight: 600; }
.wide-btn:hover { border-color: var(--accent); color: var(--accent); }
.wide-btn.danger:hover { border-color: var(--bad); color: var(--bad); }

/* Diagram zoom */
.zoom { position: fixed; inset: 0; z-index: 60; background: var(--bg); display: flex; flex-direction: column;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); }
.zoom-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line);
  font-family: var(--f-display); font-size: 13px; color: var(--muted); }
.zoom-body { flex: 1; margin: 0; overflow: auto; padding: 16px; background: var(--code-bg); line-height: 1.45; -webkit-overflow-scrolling: touch; }
.zoom-body code { font-family: var(--f-mono); font-size: 14px; white-space: pre; }

.scrim { position: fixed; inset: 0; background: rgba(10,14,20,.45); z-index: 25; }

@media (max-width: 880px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  nav.index {
    position: fixed; inset: 0 auto 0 0; width: min(330px, 88vw); height: auto; z-index: 30;
    background: var(--bg); transform: translateX(-102%); transition: transform .2s ease;
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
    padding-left: calc(16px + env(safe-area-inset-left, 0px));
    padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 0 40px rgba(0,0,0,.25);
  }
  nav.index.open { transform: none; }
  .item { min-height: 44px; }
  .sub { padding-block: 8px; }
  main { padding-left: 0; padding-top: 0; padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }
  .topbar {
    position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
    margin: 0 -16px 18px; padding: calc(8px + env(safe-area-inset-top, 0px)) 16px 8px;
    background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
  }
  .topbar #menu { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface);
    border-radius: 8px; min-height: 40px; padding: 4px 12px; cursor: pointer; font-weight: 600; }
  .topbar-brand { display: inline-flex; align-items: center; justify-content: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 18px; }
  .topbar-brand img { border-radius: 5px; }
  .readbar { display: block; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; }
  .readbar span { display: block; height: 100%; width: 0; background: var(--accent); }
  .home-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .how { grid-template-columns: minmax(0, 1fr); }
  .track-row { grid-template-columns: minmax(0, 1fr) 40px; }
  .track-row .cells { grid-column: 1 / -1; order: 3; }
  .cell { width: 26px; height: 22px; }
  .pager a { max-width: 100%; flex: 1 1 100%; }
  .pager a.nextp { order: -1; }
  .prose pre { padding: 12px 10px; }
  .qcard { padding: 14px 14px; }
  .toc { padding: 12px 14px; }
  .sheet { left: 0; right: 0; top: auto; bottom: 0; width: 100%; max-height: 85dvh; border-radius: 16px 16px 0 0;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
  body { font-size: 16px; }
  main { font-size: calc(16.5px * var(--scale)); }
}
@media (prefers-reduced-motion: reduce) { nav.index { transition: none; } }
@media print { nav.index, .topbar, .pager, .zoom-btn { display: none !important; } .app { display: block; } }

/* Direction D · Case File: a declassified dossier. Manila paper, typewriter mono, red stamps. */
:root:root:root {
  --bg: #e9dfc8; --surface: #f8f3e6; --sunken: #e0d4b8; --ink: #2a251d; --muted: #6c624f;
  --line: #cdbf9f; --accent: #b3261e; --accent-soft: #f2dccf; --on-accent: #fff6ea;
  --good: #2e6b3f; --good-soft: #dde8d2; --warn: #8a5a00; --warn-soft: #f1e2bf; --bad: #b3261e; --bad-soft: #f2d6cc;
  --code-bg: #f1e9d6;
  --note: #fff6c9; --note-ink: #2a251d; --note-edge: #d9b84a;
  --f-display: "IBM Plex Mono", ui-monospace, monospace;
  --f-body: "IBM Plex Serif", Georgia, serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root:root:root:not([data-theme="light"]) {
  --bg: #1a1712; --surface: #221e17; --sunken: #2b261d; --ink: #e8dfcb; --muted: #a59a83; --line: #3a3326;
  --accent: #e5675c; --accent-soft: #3b1e1a; --on-accent: #1a1712; --good: #8dc59a; --good-soft: #1e2b20;
  --warn: #e0b45c; --warn-soft: #33280f; --bad: #e5675c; --bad-soft: #3b1e1a; --code-bg: #15120e; --note: #2f2a1a; --note-ink: #efe3b8; --note-edge: #8a7330; color-scheme: dark; } }
body { background-image: radial-gradient(rgba(0,0,0,.035) 1px, transparent 1px); background-size: 3px 3px; }
.page-title, .prose h1 { text-transform: uppercase; font-weight: 700; letter-spacing: 0.02em; font-size: clamp(30px, 6vw, 44px); }
.prose h2 { text-transform: uppercase; font-size: 1.1em; letter-spacing: .06em; border-top: 2px solid var(--ink); }
.eyebrow { display: inline-block; color: var(--accent); border: 2px solid var(--accent); padding: 2px 8px; transform: rotate(-2deg); font-weight: 700; }
.section-h, .toc-h, .part-k, .qlabel, .setting-k, .mod-head { color: var(--ink); font-weight: 700; }
.upnext, .stat, .how div, .toc, .qcard, .recent a, .pager a, .sheet { border-radius: 2px; background: var(--surface); box-shadow: 2px 3px 0 rgba(42,37,29,.12); }
.upnext { position: relative; margin-top: 26px; border-top-left-radius: 0; }
.upnext::before { content: "CASE FILE"; position: absolute; top: -24px; left: -1px; padding: 3px 14px; background: var(--surface);
  border: 1px solid var(--line); border-bottom: 0; font-family: var(--f-display); font-size: 11px; letter-spacing: .12em; font-weight: 700; }
.upnext h2 { text-transform: uppercase; }
.btn { border-radius: 2px; text-transform: uppercase; letter-spacing: .08em; font-family: var(--f-display); }
.tlp { background: var(--ink); color: var(--bg); } .tlp b { color: var(--bg); }
.stat b { font-family: var(--f-display); }
.chip { border-radius: 2px; border: 1.5px solid currentColor; background: transparent !important; text-transform: uppercase; font-weight: 700; transform: rotate(-3deg); display: inline-block; }
.chip.next { color: var(--accent); }
.opt { border-radius: 2px; background: var(--surface); }
.opt .ol::before { content: "☐ "; }
.opt.right .ol::before { content: "☑ "; } .opt.wrong .ol::before { content: "☒ "; }
.why { border-radius: 0; background: var(--note); color: var(--note-ink); border-left: 3px solid var(--note-edge); font-family: var(--f-display); font-size: 0.82em; }
.prose code { background: #111; color: #f2ead7; border: 0; }
.prose pre code { background: none; color: inherit; }
.prose pre { border-radius: 0; border: 1px dashed var(--muted); }
.prose strong { background: linear-gradient(transparent 60%, rgba(179,38,30,.18) 60%); }
.cell { border-radius: 0; } .cell.done { background: var(--ink); }

:root[data-theme="dark"] {
  --bg: #1a1712; --surface: #221e17; --sunken: #2b261d; --ink: #e8dfcb; --muted: #a59a83; --line: #3a3326;
  --accent: #e5675c; --accent-soft: #3b1e1a; --on-accent: #1a1712; --good: #8dc59a; --good-soft: #1e2b20;
  --warn: #e0b45c; --warn-soft: #33280f; --bad: #e5675c; --bad-soft: #3b1e1a; --code-bg: #15120e;
  --note: #2f2a1a; --note-ink: #efe3b8; --note-edge: #8a7330; color-scheme: dark;
}
:root[data-theme="dark"]:root:root { --bg: #1a1712; --surface: #221e17; --sunken: #2b261d; --ink: #e8dfcb; --muted: #a59a83; --line: #3a3326; --accent: #e5675c; --accent-soft: #3b1e1a; --on-accent: #1a1712; --good: #8dc59a; --good-soft: #1e2b20; --warn: #e0b45c; --warn-soft: #33280f; --bad: #e5675c; --bad-soft: #3b1e1a; --code-bg: #15120e; --note: #2f2a1a; --note-ink: #efe3b8; --note-edge: #8a7330; color-scheme: dark; }
