:root {
  --ink: #1d1f23; --muted: #5b6270; --rule: #d5d9e0; --paper: #ffffff;
  --accent: #1f5f8b; --accent-soft: #e9f2f8;
  --why: #2f6b3a; --why-soft: #eaf5ec;
  --tempt: #9a5a0b; --tempt-soft: #fbf1e3;
  --plain: #4b3f8f; --plain-soft: #efedf9;
  --note: #5b6270; --note-soft: #f3f4f6;
  --code-bg: #f4f5f7;
  --serif: "Charter", "Bitstream Charter", "Georgia", "Cambria", serif;
  --sans: "Inter", "Helvetica Neue", "Segoe UI", "Arial", sans-serif;
  --mono: "JetBrains Mono", "DejaVu Sans Mono", "Consolas", monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #e4e6ea; --muted: #a2a9b6; --rule: #3a3f48; --paper: #16181c;
    --accent: #7fb6dd; --accent-soft: #1d2a35;
    --why: #8fcf9a; --why-soft: #1b2a1e;
    --tempt: #e7b066; --tempt-soft: #2d2417;
    --plain: #b7adf0; --plain-soft: #24213a;
    --note: #a2a9b6; --note-soft: #202328; --code-bg: #20232a;
  }
}
:root[data-theme="dark"] {
  --ink: #e4e6ea; --muted: #a2a9b6; --rule: #3a3f48; --paper: #16181c;
  --accent: #7fb6dd; --accent-soft: #1d2a35;
  --why: #8fcf9a; --why-soft: #1b2a1e;
  --tempt: #e7b066; --tempt-soft: #2d2417;
  --plain: #b7adf0; --plain-soft: #24213a;
  --note: #a2a9b6; --note-soft: #202328; --code-bg: #20232a;
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  margin: 0 auto; max-width: 46rem; padding: 0 16px 4rem;
  font-family: var(--serif); font-size: 17px; line-height: 1.6;
  color: var(--ink); background: var(--paper);
  hyphens: auto; -webkit-hyphens: auto;
}
h1, h2, h3, h4, .chapno, .toc, figcaption, caption, th, .part-title,
aside::before, .backrefs { font-family: var(--sans); }
h1 { font-size: 2rem; line-height: 1.2; margin: 0.2em 0 0.8em; }
h2 { font-size: 1.35rem; margin: 2em 0 0.6em; line-height: 1.3; }
h3 { font-size: 1.1rem; margin: 1.6em 0 0.4em; }
h4 { font-size: 1rem; margin: 1.2em 0 0.3em; }
.secno { color: var(--muted); font-weight: 600; margin-right: 0.35em; }
p { margin: 0 0 0.9em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a.term {
  color: inherit; text-decoration: underline dotted var(--accent);
  text-underline-offset: 3px; text-decoration-thickness: 1.5px;
}
a.term:hover { background: var(--accent-soft); }
.term.missing { outline: 1px dashed red; }
.xref.broken, .xman.broken { color: red; }
code, kbd, pre { font-family: var(--mono); font-size: 0.86em; }
code { background: var(--code-bg); padding: 0.05em 0.3em; border-radius: 3px; }
pre {
  background: var(--code-bg); padding: 0.8em 1em; border-radius: 4px;
  overflow-x: auto; line-height: 1.4; white-space: pre-wrap;
}
.chain { font-family: var(--mono); font-size: 0.88em; white-space: nowrap; }
ul, ol { padding-left: 1.4em; margin: 0 0 0.9em; }
li { margin: 0.2em 0; }

/* title page + contents */
.titlepage { min-height: 80vh; display: flex; flex-direction: column;
  justify-content: center; }
.tp-mark { font-family: var(--sans); font-weight: 800; letter-spacing: 0.08em;
  color: var(--accent); font-size: 1.1rem; text-transform: uppercase; }
.tp-title { font-size: 3rem; margin: 0.1em 0 0.3em; }
.tp-sub { font-size: 1.2rem; color: var(--muted); max-width: 32rem; }
.tp-author { font-family: var(--sans); font-size: 1rem; margin-top: 1.4rem; }
.toc ol { list-style: none; padding-left: 0; }
.toc .toc-part { font-weight: 700; margin-top: 1.1em; text-transform: uppercase;
  font-size: 0.85rem; letter-spacing: 0.04em; }
.toc .toc-chap { font-weight: 600; margin-top: 0.35em; }
.toc .toc-sec { padding-left: 1.6em; font-weight: 400; font-size: 0.9rem; }
.toc .toc-sec li { margin: 0.05em 0; }
.toc a { color: var(--ink); }

/* chapters */
.part { padding: 4rem 0 2rem; }
.part-title { font-size: 2.4rem; color: var(--accent); }
.chapter { padding-top: 3rem; }
.chapter-head { border-bottom: 2px solid var(--accent); margin-bottom: 1.4em; }
.chapno { display: block; color: var(--accent); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.85rem; }
.stub { color: var(--muted); font-style: italic; border: 1px dashed var(--rule);
  padding: 1em; }

/* callouts */
aside {
  margin: 1.2em 0; padding: 0.8em 1em 0.2em; border-left: 4px solid;
  border-radius: 0 4px 4px 0; break-inside: avoid;
}
aside::before { display: block; font-weight: 700; font-size: 0.8rem;
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.3em; }
aside.plain { border-color: var(--plain); background: var(--plain-soft); }
aside.plain::before { content: "In plain words"; color: var(--plain); }
aside.why { border-color: var(--why); background: var(--why-soft); }
aside.why::before { content: "Why it's done this way"; color: var(--why); }
aside.tempting { border-color: var(--tempt); background: var(--tempt-soft); }
aside.tempting::before { content: "The tempting alternative"; color: var(--tempt); }
aside.note { border-color: var(--note); background: var(--note-soft); }
aside.note::before { content: "Note"; color: var(--note); }
aside.operator { border-color: var(--accent); background: var(--accent-soft); }
aside.operator::before { content: "At the radio"; color: var(--accent); }

/* figures + tables */
figure { margin: 1.4em 0; break-inside: avoid; text-align: center; }
figure svg, figure img { max-width: 100%; height: auto; }
figure img { border: 1px solid var(--rule); }
figcaption, caption { font-size: 0.85rem; color: var(--muted); text-align: left;
  margin-top: 0.5em; line-height: 1.45; }
.figno { font-weight: 700; color: var(--ink); }
figure svg text { font-family: var(--sans); fill: var(--ink); }
figure svg .muted { fill: var(--muted); }
table { border-collapse: collapse; width: 100%; margin: 1.2em 0;
  font-size: 0.9rem; break-inside: avoid; }
caption { caption-side: top; margin: 0 0 0.4em; }
th, td { border-bottom: 1px solid var(--rule); padding: 0.35em 0.5em;
  text-align: left; vertical-align: top; }
th { font-size: 0.82rem; border-bottom: 2px solid var(--ink); }
.table-wrap { overflow-x: auto; }

/* glossary */
dl.glossary dt { font-family: var(--sans); font-weight: 700; margin-top: 0.9em; }
dl.glossary dd { margin: 0.15em 0 0 1.2em; }
.backrefs { display: block; font-size: 0.78rem; color: var(--muted); margin-top: 0.2em; }

@media (max-width: 600px) {
  body { font-size: 16px; }
  .tp-title { font-size: 2.2rem; }
  h1 { font-size: 1.6rem; }
}

/* ------------------------------------------------------------ print ---- */
@page { size: letter; margin: 0.85in 0.8in 0.9in;
  @bottom-center { content: counter(page); font-family: sans-serif;
    font-size: 9pt; color: #666; } }
@page :first { @bottom-center { content: none; } }
@media print {
  :root { --paper: #fff; --ink: #000; }
  html, body { background: #fff; }
  body { max-width: none; padding: 0; font-size: 10.5pt; line-height: 1.45; }
  .titlepage { min-height: 9in; break-after: page; }
  .toc { break-after: page; }
  .toc .toc-sec { display: none; }
  .part { break-before: page; padding-top: 3in; }
  .part + .chapter { break-before: page; }
  .chapter { break-before: page; padding-top: 0; }
  h1, h2, h3, h4 { break-after: avoid; }
  p, li { orphans: 3; widows: 3; }
  a { color: inherit; }
  a.term { text-decoration: none; border-bottom: 0.5pt dotted #999; }
  aside { background: none !important; }
  pre { white-space: pre-wrap; }
}

/* Quickstart: the pointer to the full manual at the foot of a page. */
p.more { margin-top: 1.4em; font-size: 0.88em; color: var(--muted);
         border-top: 1px solid var(--rule, #ccc); padding-top: 0.5em; }

/* Headline figures: a few large numbers, each with a short label under it. */
table.headline td { width: 33%; text-align: center; vertical-align: top;
  padding: 0.9em 0.6em; line-height: 1.35; }
table.headline td strong { display: block; font-size: 1.7em; line-height: 1.2; }
