/* Colour tokens: copied from web/index.html by bun run manuals. */
:root {
    color-scheme: dark;
    --bg: #16191e; --fg: #eef0f3; --muted: #a6acb5; --line: rgb(255 255 255 / 0.09); --hover: rgb(255 255 255 / 0.04);
    --side: #1f2329; --side-fg: #cdd1d7; --side-hover: rgb(255 255 255 / 0.06); --side-active: rgb(79 156 249 / 0.22); --side-active-fg: #eef0f3;
    --side-strong: #eef0f3; --side-muted: #a6acb5; --side-accent: #4f9cf9; --side-line: rgb(255 255 255 / 0.08); --side-fill: rgb(255 255 255 / 0.06); --side-green: #5be3a2;
    --mark-a: #eef0f3; --mark-b: #4f9cf9; --mark-c: #ffe492;
    --accent: #4f9cf9; --paper: #ffffff; --ink: #212529; --accent-fill: #1f64c4; --fail: #ff7a70; --badge: #ffe492; --card: #262a31; --shadow: rgb(0 0 0 / 0.55);
    --caution: #f2b630; --on-caution: #1f2329; --notice: rgb(31 35 41 / 0.96);
    --bar: rgb(22 25 30 / 0.85); --fill: rgb(255 255 255 / 0.06); --fill2: rgb(255 255 255 / 0.11); --code: rgb(255 255 255 / 0.06);
    --green: #3dd68c; --green-soft: rgb(61 214 140 / 0.16); --green-text: #5be3a2; --mention: rgb(255 228 146 / 0.10);
    --mention-chip: rgb(79 156 249 / 0.22); --caution-soft: rgb(255 228 146 / 0.22); --danger-fill: #b3261e; --edge: rgb(255 255 255 / 0.10); --tile: #101216; --seg-on: rgb(255 255 255 / 0.14);
    --p0: #fea09f; --p1: #67d6b2; --p2: #dfa5ec; --p3: #c2c469; --p4: #98bffe; --p5: #f9a779; --p6: #4dd4db; --p7: #f69fc8; --p8: #96d089; --p9: #bcb2fe; --p10: #e5b562; --p11: #65cbf9;
    --pf0: #a74449; --pf1: #047b60; --pf2: #894d97; --pf3: #6d6e04; --pf4: #3967b3; --pf5: #a24e10; --pf6: #02787d; --pf7: #9e4573; --pf8: #3b7a2c; --pf9: #6959ae; --pf10: #896105; --pf11: #067398;
  }
  :root[data-theme="light"] {
    color-scheme: light;
    --bg: #ffffff; --fg: #212529; --muted: #5e6875; --line: rgb(4 56 115 / 0.12); --hover: rgb(4 56 115 / 0.04);
    --side: #043873; --side-fg: #dce9fb; --side-hover: rgb(255 255 255 / 0.10); --side-active: #ffffff; --side-active-fg: #043873;
    --side-strong: #ffffff; --side-muted: #a7cefc; --side-accent: #ffe492; --side-line: rgb(255 255 255 / 0.14); --side-fill: rgb(255 255 255 / 0.10); --side-green: #5be3a2;
    --mark-a: #043873; --mark-b: #4f9cf9; --mark-c: #f2b630;
    --accent: #1f64c4; --paper: #ffffff; --ink: #212529; --accent-fill: #043873; --fail: #c4281c; --badge: #ffe492; --card: #ffffff; --shadow: rgb(4 56 115 / 0.16);
    --caution: #f2b630; --on-caution: #043873; --notice: rgb(4 56 115 / 0.96);
    --bar: rgb(255 255 255 / 0.85); --fill: rgb(4 56 115 / 0.05); --fill2: rgb(4 56 115 / 0.09); --code: rgb(4 56 115 / 0.05);
    --green: #1f8a52; --green-soft: rgb(31 138 82 / 0.12); --green-text: #176e41; --mention: rgb(245 197 66 / 0.16);
    --mention-chip: rgb(167 206 252 / 0.55); --caution-soft: rgb(255 228 146 / 0.85); --danger-fill: #b3261e; --edge: rgb(4 56 115 / 0.10); --tile: #e8f1fe; --seg-on: #ffffff;
    --p0: #a43a41; --p1: #04755b; --p2: #854494; --p3: #676803; --p4: #2f60b2; --p5: #9c4700; --p6: #057176; --p7: #9b3b6e; --p8: #2f751d; --p9: #6451ac; --p10: #815b04; --p11: #066d90;
    --pf0: #91343a; --pf1: #006850; --pf2: #763d83; --pf3: #5c5c03; --pf4: #2b569d; --pf5: #8b3f01; --pf6: #056569; --pf7: #893562; --pf8: #2b681c; --pf9: #594898; --pf10: #735101; --pf11: #026181;
  }
/* The manual kit (docs/MANUALS.md). Layout only: the colour tokens come first in the built kit.css, copied from
   web/index.html by `npm run manuals`, so the manuals and the app always share one palette. No literal colour here
   except white on a coloured fill, as in the app, and the white paper behind a figure or a diagram (they are drawn
   for a white page). */

@font-face { font-family: "Inter"; src: url("/fonts/inter.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }

/* Titles: navy on white in light; on the dark grey page navy is too weak (3:1), so they take --fg there, as the app's do. */
:root { --title: var(--fg); }
:root[data-theme="light"] { --title: var(--accent-fill); }

*, *::before, *::after { box-sizing: border-box; }
/* `hidden` must win over a rule that sets display (`.card` is flex): the library's group chips hide cards with it. */
[hidden] { display: none !important; }
html { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
body { margin: 0; font-family: Inter, system-ui, sans-serif; background: var(--bg); color: var(--fg); line-height: 1.6; font-size: 16px; }
a { color: var(--accent); }
a:hover { color: var(--title); }
:focus-visible { outline: 2px solid var(--side-accent); outline-offset: 2px; }
button { font: inherit; cursor: pointer; }
img { max-width: 100%; height: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- top bar */
/* On --side (navy in light), as the app's sidebar: its own text and mark tokens. */
.top, .hero, body:has(main.gate) { --mark-a: var(--side-strong); --mark-c: var(--badge); }
.top { background: var(--side); color: var(--side-strong); display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 10px 20px; position: sticky; top: 0; z-index: 10; }
.top .brand { display: flex; align-items: center; gap: 10px; color: var(--side-strong); text-decoration: none; font-weight: 800; font-size: 17px; }
.top .brand .a { fill: var(--mark-a); } .top .brand .b { fill: var(--mark-b); } .top .brand .c { fill: var(--mark-c); }
.top form { flex: 1 1 260px; max-width: 560px; display: flex; align-items: center; gap: 8px; height: 40px; border-radius: 10px; background: var(--side-fill); border: 1px solid var(--side-line); padding: 0 12px; color: var(--side-muted); }
.top input[type="search"] { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--side-strong); font: inherit; font-size: 14px; outline: none; }
.top input[type="search"]::placeholder { color: var(--side-muted); }
.top kbd { font: inherit; font-size: 12px; border: 1px solid var(--side-line); border-radius: 6px; padding: 0 6px; }
.top .grow { flex: 1 1 0; }
.top .menu { display: none; width: 40px; height: 40px; border: 0; border-radius: 10px; background: var(--side-fill); color: var(--side-strong); }
.top .app { color: var(--badge); font-weight: 600; font-size: 14px; text-decoration: none; }
.theme { display: flex; background: var(--side-fill); border-radius: 10px; padding: 3px; gap: 2px; }
.theme button { border: 0; border-radius: 8px; padding: 5px 11px; font-size: 13px; font-weight: 600; background: transparent; color: var(--side-fg); }
.theme button[aria-pressed="true"] { background: var(--side-active); color: var(--side-active-fg); }

/* ---- three columns: chapters, the page, on this page */
.layout { display: flex; flex-wrap: wrap; max-width: 1440px; margin: 0 auto; align-items: flex-start; }
.chapters { flex: 1 1 260px; max-width: 300px; padding: 22px 14px 40px 20px; border-right: 1px solid var(--line); position: sticky; top: 60px; max-height: calc(100vh - 60px); overflow: auto; }
.chapters .book { display: flex; align-items: center; gap: 10px; margin: 4px 0 14px; text-decoration: none; color: var(--fg); }
.chapters .book b { color: var(--title); display: block; line-height: 1.3; }
.chapters .book small { color: var(--muted); font-size: 12px; }
.tile { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; font-size: 12px; flex: none; background: var(--badge); color: var(--on-caution); }
.chapters details { margin: 2px 0; }
.chapters summary { list-style: none; padding: 7px 10px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--fg); display: flex; gap: 8px; align-items: center; }
.chapters summary::-webkit-details-marker { display: none; }
.chapters summary::before { content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform .15s; flex: none; }
.chapters details[open] > summary::before { transform: rotate(45deg); }
.chapters summary:hover, .chapters a.page:hover { background: var(--hover); }
.chapters a.page { display: block; padding: 6px 10px 6px 26px; border-radius: 6px; font-size: 13px; color: var(--muted); text-decoration: none; }
.chapters a.page[aria-current="page"] { background: var(--tile); color: var(--title); font-weight: 700; }
.chapters .pdfs { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.chapters .pdfs a { display: flex; gap: 8px; align-items: center; font-size: 13px; padding: 5px 10px; text-decoration: none; }

main.page { flex: 999 1 560px; min-width: 0; padding: 26px 40px 64px; }
.article { max-width: 780px; margin: 0 auto; }
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.crumbs a { text-decoration: none; }
.article h1 { font-size: 32px; line-height: 1.2; margin: 0 0 16px; color: var(--title); }
.article h2 { font-size: 23px; line-height: 1.25; margin: 36px 0 12px; color: var(--title); }
.article h3 { font-size: 18px; margin: 26px 0 10px; color: var(--title); }
.article h4, .article h5 { font-size: 16px; margin: 20px 0 8px; }
.article :is(h1, h2, h3, h4) { scroll-margin-top: 76px; position: relative; }
.article .anchor { margin-left: 8px; border: 0; background: transparent; color: var(--muted); font-size: 14px; opacity: 0; vertical-align: middle; padding: 2px 6px; border-radius: 6px; }
.article :is(h2, h3, h4):hover .anchor, .article .anchor:focus-visible { opacity: 1; }
.article p, .article li { font-size: 16px; }
.article code { font-family: ui-monospace, Consolas, monospace; font-size: 14px; background: var(--fill); padding: 1px 5px; border-radius: 4px; }
.article pre { overflow-x: auto; background: var(--fill); border-radius: 12px; padding: 14px 16px; font-size: 13px; line-height: 1.45; }
.article pre code { background: transparent; padding: 0; }
.article blockquote { margin: 16px 0; padding: 4px 16px; border-left: 3px solid var(--line); color: var(--muted); }
.article hr { border: 0; border-top: 1px solid var(--line); margin: 28px 0; }
.article .dead-link { color: var(--muted); text-decoration: underline dotted; }
.article .dead-image { display: inline-block; color: var(--muted); border: 1px dashed var(--line); border-radius: 8px; padding: 6px 10px; font-size: 13px; }
.article math[display="block"] { display: block; overflow-x: auto; margin: 14px 0; }

/* alerts: from > [!NOTE], [!TIP], [!IMPORTANT], [!WARNING], [!CAUTION] */
.alert { border-radius: 12px; margin: 18px 0; overflow: hidden; border: 2px solid transparent; }
.alert > :not(.alert-label) { margin-left: 16px; margin-right: 16px; }
.alert > :last-child { margin-bottom: 14px; }
.alert-label { margin: 0 0 10px; padding: 8px 16px; font-size: 12px; font-weight: 800; letter-spacing: .08em; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.alert-warning { border-color: var(--danger-fill); background: color-mix(in srgb, var(--danger-fill) 7%, var(--bg)); }
.alert-warning .alert-label { background: var(--danger-fill); color: #ffffff; }
.alert-caution { border-color: var(--caution); background: var(--caution-soft); }
.alert-caution .alert-label { background: var(--caution); color: var(--on-caution); }
.alert-note, .alert-tip, .alert-important { background: var(--tile); }
.alert-note .alert-label, .alert-tip .alert-label, .alert-important .alert-label { color: var(--accent); padding-bottom: 0; }
.alert :is(h2, h3, h4) { margin-top: 4px; font-size: 16px; }
/* memory items: bold lines inside a WARNING */
.alert-warning p > strong + br { display: none; }
.alert-warning p > strong { display: block; font-size: 17px; letter-spacing: .02em; padding: 6px 0; border-bottom: 1px solid var(--line); }
.memory .act { display: inline; }
.memory.hidden .act { display: none; }
.memory .reveal { display: none; margin-left: 10px; border: 1px dashed currentColor; background: transparent; color: inherit; border-radius: 8px; padding: 2px 10px; font-size: 13px; font-weight: 700; }
.memory.hidden .reveal { display: inline-block; }
.drill { margin-left: auto; border: 1px solid #ffffff; background: transparent; color: #ffffff; border-radius: 999px; padding: 3px 12px; font-size: 12px; font-weight: 700; }
.drill[aria-pressed="true"] { background: #ffffff; color: var(--danger-fill); }

/* checklists: from - [ ] */
.article ul:has(> li > input.task, > li > p:first-child > input.task) { list-style: none; padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--card); overflow: hidden; }
.article li:has(> input.task, > p:first-child > input.task) { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-bottom: 1px solid var(--line); min-height: 44px; }
.article li:has(> input.task, > p:first-child > input.task):last-child { border-bottom: 0; }
.article input.task { width: 20px; height: 20px; margin: 3px 0 0; accent-color: var(--green); flex: none; cursor: pointer; }
.article li:has(> input.task:checked, > p:first-child > input.task:checked) { color: var(--muted); text-decoration: line-through; }
.checkbar { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); margin: 6px 0 18px; flex-wrap: wrap; }
.checkbar .bar { width: 120px; height: 6px; border-radius: 3px; background: var(--fill); overflow: hidden; }
.checkbar .bar span { display: block; height: 100%; background: var(--green); width: 0; }
.checkbar button { border: 0; background: transparent; color: var(--accent); font-weight: 600; font-size: 13px; }

/* tables, figures, diagrams */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; margin: 16px 0; }
.article table { border-collapse: collapse; width: 100%; font-size: 14px; }
.article th { text-align: left; background: var(--fill); color: var(--title); padding: 9px 12px; }
.article td { padding: 9px 12px; border-top: 1px solid var(--line); vertical-align: top; }
.article .align-center { text-align: center; } .article .align-right { text-align: right; }
.article p > img, .article figure img { border-radius: 8px; border: 1px solid var(--line); background: #ffffff; cursor: zoom-in; }
.article figure.diagram { margin: 18px 0; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: #ffffff; text-align: center; }
.article figure.diagram img { border: 0; cursor: zoom-in; }
dialog.zoom { border: 0; border-radius: 12px; padding: 0; max-width: 96vw; max-height: 94vh; background: #ffffff; }
dialog.zoom::backdrop { background: color-mix(in srgb, var(--side) 80%, transparent); }
dialog.zoom img { display: block; max-width: 96vw; max-height: 88vh; }
dialog.zoom form { display: flex; justify-content: flex-end; padding: 8px; }
dialog.zoom button { border: 0; border-radius: 8px; padding: 6px 14px; background: var(--accent-fill); color: #ffffff; font-weight: 700; }

.pager { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-top: 40px; }
.pager a { border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; text-decoration: none; background: var(--card); display: flex; flex-direction: column; }
.pager small { color: var(--muted); }
.pager b { color: var(--title); }
.pager .next { text-align: right; }

.toc { flex: 1 1 220px; max-width: 260px; padding: 26px 20px; position: sticky; top: 60px; max-height: calc(100vh - 60px); overflow: auto; }
.toc h2 { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }
.toc a { display: block; border-left: 2px solid var(--line); padding: 4px 10px; font-size: 13px; color: var(--muted); text-decoration: none; }
.toc a.l3 { padding-left: 22px; }
.toc a.here { border-left-color: var(--accent); color: var(--title); font-weight: 700; }

/* ---- library and search */
.hero { background: var(--side); color: var(--side-strong); padding: 36px 24px 72px; }
.hero > div { max-width: 880px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.hero h1 { margin: 0; font-size: 38px; line-height: 1.15; }
.hero h1 span { color: var(--badge); }
.hero p { margin: 0; color: var(--side-muted); font-size: 17px; }
.hero form { display: flex; flex-wrap: wrap; gap: 10px; }
.hero label.box { flex: 1 1 300px; display: flex; align-items: center; gap: 10px; background: var(--card); color: var(--muted); border-radius: 12px; padding: 0 16px; height: 54px; }
.hero input { flex: 1; min-width: 0; border: 0; background: transparent; font: inherit; font-size: 17px; color: var(--fg); outline: none; }
.hero button[type="submit"] { height: 54px; padding: 0 26px; border: 0; border-radius: 12px; background: var(--badge); color: var(--on-caution); font-weight: 800; font-size: 16px; }
.shelf { max-width: 1200px; margin: -40px auto 0; padding: 0 24px 64px; display: flex; flex-direction: column; gap: 24px; }
.filters { background: var(--card); border-radius: 16px; box-shadow: 0 6px 24px var(--shadow); padding: 16px 18px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--title); border-radius: 999px; padding: 7px 15px; font-size: 14px; font-weight: 600; }
.chip[aria-pressed="true"] { background: var(--accent-fill); color: #ffffff; border-color: var(--accent-fill); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 18px; }
.card { display: flex; flex-direction: column; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 20px; text-decoration: none; color: var(--fg); transition: box-shadow .15s; }
.card:hover { box-shadow: 0 10px 28px var(--shadow); }
.card .group { font-size: 12px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .05em; }
.card b { font-size: 17px; color: var(--title); line-height: 1.3; }
.card p { margin: 0; font-size: 14px; color: var(--muted); }
.card .tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }
.tag { font-size: 12px; font-weight: 600; color: var(--title); background: var(--tile); border-radius: 6px; padding: 3px 8px; }
.results { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.results a { display: flex; flex-direction: column; gap: 4px; border: 1px solid var(--line); border-radius: 14px; padding: 14px 18px; text-decoration: none; color: var(--fg); background: var(--card); }
.results a:hover, .results a:focus-visible { border-color: var(--accent); }
.results small { color: var(--muted); }
.results b { color: var(--title); font-size: 17px; }
.results mark { background: var(--badge); color: var(--on-caution); border-radius: 3px; padding: 0 2px; }
.empty { border: 1px dashed var(--line); border-radius: 14px; padding: 28px; text-align: center; color: var(--muted); }

/* ---- the gate */
main.gate { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; gap: 14px; max-width: 560px; margin: 0 auto; padding: 32px 24px; }
body:has(main.gate) { background: var(--side); color: var(--side-strong); }
main.gate p { color: var(--side-muted); }
main.gate a { align-self: flex-start; background: var(--badge); color: var(--on-caution); border-radius: 12px; padding: 12px 20px; font-weight: 800; text-decoration: none; }

/* ---- phone */
@media (max-width: 900px) {
  .toc { display: none; }
}
@media (max-width: 720px) {
  .top .menu { display: grid; place-items: center; }
  .top form { order: 5; flex-basis: 100%; max-width: none; }
  .chapters { position: fixed; inset: 0 auto 0 0; width: min(320px, 88vw); max-width: none; max-height: none; top: 0; background: var(--bg); z-index: 20; transform: translateX(-105%); }
  body.nav-anim .chapters { transition: transform .2s; box-shadow: 0 0 40px var(--shadow); }
  body.nav-open .chapters { transform: none; }
  main.page { padding: 18px 16px 48px; }
  .article h1 { font-size: 26px; }
  .hero h1 { font-size: 28px; }
}
@media print {
  .top, .chapters, .toc, .pager, .anchor, .checkbar, .drill { display: none !important; }
  main.page { padding: 0; }
}

/* ---- search results page and the PDF reader */
.results-page { margin-top: 24px; }
.results-page h1 { color: var(--title); font-size: 24px; margin: 0; }
main.pdf-reader { display: flex; flex-direction: column; min-height: calc(100vh - 60px); background: var(--tile); }
.pdf-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 20px; background: var(--card); border-bottom: 1px solid var(--line); }
.pdf-tools b { margin-right: auto; color: var(--title); overflow-wrap: anywhere; }
.pdf-tools button, .pdf-tools a { min-width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--title); font-weight: 700; padding: 0 10px; display: inline-grid; place-items: center; text-decoration: none; }
.pdf-tools input { width: 56px; height: 36px; border: 1px solid var(--line); border-radius: 8px; text-align: center; font: inherit; background: var(--bg); color: var(--fg); }
#pdf-status { margin: 12px 20px 0; color: var(--muted); }
#pdf-status:empty { display: none; }
.pdf-stage { flex: 1; overflow: auto; padding: 20px; display: flex; justify-content: center; align-items: flex-start; }
.pdf-stage canvas { background: #ffffff; box-shadow: 0 8px 30px var(--shadow); border-radius: 4px; max-width: none; }
