/* The book: warm paper, black 2px borders, one yellow accent. No frameworks, no CDN.
   Screen styling follows the "card" language; print.css flattens it for A4. */
@font-face {
  font-family: "Space Grotesk";
  src: url("../fonts/SpaceGrotesk.ttf") format("truetype");
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #ece9e1;
  --card: #ffffff;
  --panel: #f6f3ea;
  --panel-2: #efece2;
  --ink: #121212;
  --muted: #6b6f76;
  --line: #121212;
  --rule: #121212;
  --rule-soft: #e4dfd2;
  --accent: #ffd84d;
  --accent-ink: #121212;
  --accent-soft: #fff3c4;
  --link: #2b5ce6;
  --ok: #15803d;
  --warn: #b91c1c;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 3px 0 rgba(18, 18, 18, .10), 0 1px 0 rgba(18, 18, 18, .05);
  --display: "Space Grotesk", "DejaVu Sans", system-ui, sans-serif;
  --sans: "Space Grotesk", "DejaVu Sans", system-ui, sans-serif;
  --serif: "STIX Two Text", "Noto Serif", "DejaVu Serif", Georgia, serif;
  --mono: "DejaVu Sans Mono", "Noto Sans Mono", ui-monospace, monospace;
  --content: 54rem;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
img, svg, video, canvas { max-width: 100%; height: auto; }
a, code, .inet-notation { overflow-wrap: anywhere; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 16px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
@media (min-width: 1100px) { body { font-size: 16.5px; } }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: .75rem;
  height: 58px; padding: 0 16px;
  background: var(--paper); border-bottom: 2px solid var(--line);
}
.brand {
  font: 700 14px/1 var(--display); letter-spacing: -.01em;
  color: var(--ink); text-decoration: none; white-space: nowrap;
  padding: 6px 10px; border: 2px solid var(--line); border-radius: 999px; background: var(--card);
}
.brand span { background: var(--accent); border-radius: 4px; padding: 0 4px; }
.tabs { display: flex; gap: 6px; margin-left: .35rem; }
.tabs a {
  font: 700 11.5px/1 var(--display); letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink); text-decoration: none; padding: 9px 14px;
  border: 2px solid transparent; border-radius: 999px;
}
.tabs a:hover { border-color: var(--line); background: var(--card); }
.tabs a.active { background: var(--accent); border-color: var(--line); }
.tools { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.tools input[type="search"] {
  width: 180px; padding: 8px 12px; border: 2px solid var(--line); border-radius: 999px;
  background: var(--card); font: 12px var(--mono); color: var(--ink);
}
.tools input[type="search"]:focus { outline: 3px solid var(--accent); outline-offset: 1px; }
.tools button, .widget-controls button {
  font: 700 11.5px/1 var(--display); letter-spacing: .04em;
  padding: 9px 13px; border: 2px solid var(--line); border-radius: 999px;
  background: var(--card); color: var(--ink); cursor: pointer;
  box-shadow: 0 2px 0 rgba(18, 18, 18, .12);
  transition: background-color .12s, transform .06s;
}
.tools button:hover, .widget-controls button:hover { background: var(--accent); }
.tools button:active, .widget-controls button:active { transform: translateY(1px); box-shadow: none; }
.toc-toggle { display: none; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 8px; top: 8px; background: #fff; padding: 8px; z-index: 100; border-radius: 8px; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 18px; padding: 18px 18px 60px; align-items: start; }
.sidebar {
  position: sticky; top: 76px; max-height: calc(100vh - 94px);
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.sidebar-inner { height: 100%; max-height: calc(100vh - 98px); overflow: auto; padding: 6px 12px 24px 14px; }
.sidebar-head { display: flex; align-items: center; gap: 6px; padding: 12px 12px 6px 14px; }
.sidebar-head input {
  flex: 1 1 auto; min-width: 0; padding: 8px 12px; border: 2px solid var(--line); border-radius: 999px;
  background: var(--card); font: 12px var(--mono); color: var(--ink);
}
.sidebar-head input:focus { outline: 3px solid var(--accent); outline-offset: 1px; }
.toc-close { display: none; }
.backdrop { display: none; }
.toc-list, .toc-files { list-style: none; margin: 0; padding: 0; }
.toc-list li, .toc-files li { margin: 0; }
.toc-list a, .toc-files a, .toc-h a {
  display: block; padding: 5px 10px; color: var(--muted); text-decoration: none;
  font: 500 12.5px/1.35 var(--sans); border-radius: 8px;
}
.toc-list a:hover, .toc-files a:hover, .toc-h a:hover { color: var(--ink); background: var(--panel); }
.toc-list .lvl2 > a { color: var(--ink); font-weight: 700; margin-top: 4px; }
.toc-list .lvl3 > a { padding-left: 22px; }
.toc-list a.current, .toc-files a.current, .toc-h a.current, .toc-list .lvl2 > a.current {
  color: var(--ink); background: var(--accent); font-weight: 700;
}
.toc-h { font: 700 11px/1.3 var(--display); letter-spacing: .08em; text-transform: uppercase; margin: 12px 0 2px; }
.toc-files a { padding-left: 16px; font-family: var(--mono); font-size: 11px; border-radius: 6px; }
/* compendium: parts are collapsible groups of files */
.toc-part { margin-top: 2px; }
.toc-part > details > summary {
  display: flex; align-items: baseline; gap: 6px; padding: 5px 8px 5px 6px; cursor: pointer;
  font: 700 12.5px/1.3 var(--sans); color: var(--ink); border-radius: 8px; list-style: none;
}
.toc-part > details > summary::-webkit-details-marker { display: none; }
.toc-part > details > summary::before {
  content: "▸"; color: var(--muted); font-size: 10px; width: 10px; flex: 0 0 auto;
}
.toc-part > details[open] > summary::before { content: "▾"; }
.toc-part > details > summary:hover { background: var(--panel); }
.toc-part > details > summary a { color: inherit; text-decoration: none; flex: 1 1 auto; }
.toc-part .toc-n {
  font: 11px var(--mono); color: var(--ink); background: var(--accent);
  border-radius: 999px; padding: 1px 7px;
}
.toc-part .toc-files { margin: 2px 0 8px; }
.toc-files .toc-id { display: inline-block; min-width: 34px; color: var(--muted); }
.toc-files a { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toc-part > details > summary.current a { color: var(--accent); }
.hidden { display: none !important; }

.layout > * { min-width: 0; }
.content {
  /* width:100% matters: with auto margins a grid item is sized to fit-content,
     not stretched, which overflowed the track on every screen narrower than 54rem. */
  width: 100%; max-width: var(--content); min-width: 0; margin: 0 auto; padding: 40px 46px 120px;
  overflow-wrap: anywhere;
  background: var(--card); border: 2px solid var(--line); border-radius: 22px;
  box-shadow: var(--shadow);
}
/* ---------- typography ---------- */
.content h1, .content h2, .content h3, .content h4, .content h5 { font-family: var(--display); line-height: 1.15; letter-spacing: -.02em; }
.content h1 {
  font-size: 2.45rem; font-weight: 700; margin: 0 0 1rem; padding-bottom: .6rem;
  border-bottom: 2px solid var(--line);
}
.content h2 {
  font-size: 1.62rem; font-weight: 700; margin: 2.8rem 0 .9rem; padding-top: 1.4rem;
  border-top: 2px solid var(--rule-soft);
}
.content h2:first-of-type { border-top: 0; padding-top: 0; }
.content h2::before {
  content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 10px;
  background: var(--accent); border: 2px solid var(--line); border-radius: 4px;
  vertical-align: .06em;
}
.content h3 { font-size: 1.16rem; font-weight: 700; margin: 1.9rem 0 .5rem; }
.content h4 { font-size: 1rem; font-weight: 700; margin: 1.4rem 0 .35rem; }
.content h5, .content h6 { font: 700 .8rem/1.3 var(--display); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 1.2rem 0 .3rem; }
p { margin: .7rem 0; }
ul, ol { padding-left: 1.35rem; margin: .65rem 0; }
li { margin: .2rem 0; }
li::marker { color: var(--muted); }
a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 3px; }
a:hover { background: var(--accent-soft); }
a.xref {
  color: var(--ink); text-decoration: none; font-variant-numeric: tabular-nums;
  border-bottom: 2px solid var(--accent); padding-bottom: 1px;
}
a.xref:hover { background: var(--accent-soft); }
hr { border: 0; border-top: 2px solid var(--rule-soft); margin: 2rem 0; }
strong { font-weight: 700; }
blockquote {
  margin: 1.1rem 0; padding: .7rem 1rem; border: 2px solid var(--line);
  border-left-width: 8px; border-radius: var(--radius-sm); background: var(--panel);
}
blockquote p { margin: .35rem 0; }
code { font-family: var(--mono); font-size: .86em; background: var(--panel-2); padding: .08em .32em; border-radius: 5px; }
pre { font-family: var(--mono); font-size: 13px; line-height: 1.5; }
@media screen {
  /* indented code blocks (no class) must scroll on screen, or they widen the page.
     In print a scroll container becomes a page-break trap, so this stays screen-only. */
  pre { overflow-x: auto; max-width: 100%; }
}
pre.code, pre.shiki {
  background: var(--panel); border: 1px solid var(--rule-soft); border-radius: var(--radius-sm);
  padding: 14px 16px; overflow: auto; margin: .95rem 0;
}
pre.ascii {
  background: var(--card); border: 1px solid var(--rule-soft); border-radius: var(--radius-sm);
  padding: 14px; overflow: auto; margin: 1rem 0;
  font-size: 12.5px; line-height: 1.25; white-space: pre; tab-size: 2;
}
pre.ascii code { background: none; padding: 0; font-size: inherit; }
.table-wrap { overflow-x: auto; margin: 1.1rem 0; border: 2px solid var(--line); border-radius: var(--radius-sm); }
table { border-collapse: collapse; width: 100%; font: 13.5px/1.5 var(--sans); background: var(--card); }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--rule-soft); vertical-align: top; }
th { font-weight: 700; background: var(--panel); border-bottom: 2px solid var(--line); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fffdf3; }
details.solution {
  margin: .7rem 0; border: 2px solid var(--line); border-radius: var(--radius-sm); background: var(--card);
  overflow: hidden;
}
details.solution > summary {
  cursor: pointer; padding: 9px 12px; font: 700 11.5px/1.2 var(--display); letter-spacing: .06em;
  text-transform: uppercase; color: var(--ink); background: var(--accent); list-style: none;
}
details.solution > summary::-webkit-details-marker { display: none; }
details.solution > summary::before { content: "▸ "; }
details.solution[open] > summary::before { content: "▾ "; }
details.solution[open] > summary { border-bottom: 2px solid var(--line); }
details.solution > *:not(summary) { margin-left: 16px; margin-right: 16px; }

/* ---------- widgets ---------- */
.widget {
  margin: 1.3rem 0 1.7rem; border: 2px solid var(--line); border-radius: var(--radius);
  background: var(--card); box-shadow: var(--shadow); overflow: hidden;
}
.widget-head {
  display: flex; align-items: center; gap: 10px; padding: 9px 14px;
  border-bottom: 2px solid var(--line); background: var(--panel);
}
.widget-kicker { font: 700 10px/1 var(--display); letter-spacing: .12em; color: var(--muted); }
.net-status, .trace-rule { font: 12px var(--mono); color: var(--muted); margin-left: auto; }
.trace-tally { font: 11px var(--mono); color: var(--muted); }
.net-stage { padding: 6px 8px 0; }
.net-stage svg { display: block; width: 100%; height: auto; }
.widget-controls {
  display: flex; gap: 8px; align-items: center; padding: 10px 14px;
  border-top: 1px solid var(--rule-soft); flex-wrap: wrap; background: var(--card);
}
.widget-controls .step { font: 12px var(--mono); color: var(--muted); margin-left: 8px; }
.widget-controls button[disabled] { opacity: .45; cursor: default; box-shadow: none; background: var(--panel-2); }
.widget figcaption { padding: 9px 14px; font: 12px/1.5 var(--sans); color: var(--muted); border-top: 1px solid var(--rule-soft); }
.widget figcaption code { font-size: .95em; }
.widget figcaption .counts { color: var(--ink); }

.trace-terms { list-style: none; margin: 0; padding: 12px 14px; min-height: 120px; }
.trace-terms li { display: none; }
.trace-terms li.on { display: block; }
.trace-terms .term {
  font: 12.5px/1.55 var(--mono); white-space: pre-wrap; word-break: break-word;
  background: var(--panel); border: 1px solid var(--rule-soft); border-radius: 8px; padding: 10px 12px; margin: 0;
}
.trace-terms mark { background: var(--accent); color: inherit; border-radius: 3px; outline: 0; }
.trace-terms .before { opacity: .5; margin-bottom: 6px; }
.trace-terms .tag { font: 700 10px/1 var(--display); letter-spacing: .1em; color: var(--muted); display: block; margin: 10px 0 4px; }

.chart { margin: 1.1rem 0 1.5rem; border: 2px solid var(--line); border-radius: var(--radius); background: var(--card); padding: 12px 14px 6px; box-shadow: var(--shadow); }
.chart svg { width: 100%; height: auto; display: block; }
.chart .grid { stroke: #e7e2d6; stroke-width: 1; stroke-dasharray: 3 4; }
.chart .axis { font: 10px var(--mono); fill: var(--muted); }
.chart .axis-line { stroke: #121212; stroke-width: 1.5; }
.chart .chart-title { font: 700 11px var(--display); fill: var(--ink); letter-spacing: .04em; }
.chart figcaption { font: 11px var(--mono); color: var(--muted); padding: 8px 2px 4px; }

/* ---------- interaction nets (inet.js), drawn in Lafont's style ---------- */
.inet { margin: 1.3rem 0 1.7rem; border: 2px solid var(--line); border-radius: var(--radius); background: var(--card); overflow: hidden; box-shadow: var(--shadow); }
.inet .widget-head { display: flex; gap: .8rem; align-items: baseline; padding: 9px 14px; border-bottom: 2px solid var(--line); background: var(--panel); }
.inet .inet-title { font: 700 13px/1.3 var(--display); color: var(--ink); }
.inet-row, .inet-grid .pane, .inet-stage {
  background-color: #fdfbf5;
  background-image: radial-gradient(circle, #ddd7c8 0.8px, transparent 1px);
  background-size: 16px 16px;
}
.inet-svg { display: block; width: 100%; height: auto; max-height: 400px; margin: 0 auto; overflow: hidden; }
.inet-svg .halo { fill: none; stroke: #fdfbf5; stroke-width: 6; stroke-linecap: butt; }
.inet-svg .wire { fill: none; stroke: #121212; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.inet-svg .band { fill: none; stroke: #ffd84d; stroke-width: 6.5; stroke-linecap: round; }
.inet-svg .band.next { stroke: #f4b400; stroke-width: 7; }
.inet-svg .cell .body { stroke: #121212; stroke-width: 1.5; stroke-linejoin: round; }
.inet-svg .cell.k-g .body { fill: #121212; }
.inet-svg .cell.k-d .body, .inet-svg .cell.k-e .body { fill: #fff; }
.inet-svg .cell text { font: italic 400 11px var(--serif); text-anchor: middle; dominant-baseline: central; fill: #121212; pointer-events: none; }
.inet-svg .cell.k-g text { fill: #fff; }
.inet-svg .cell text .sub { font-size: 7px; font-style: normal; }
.inet-svg .cell text.tag { fill: var(--muted); text-anchor: start; font-size: 9.5px; }
.inet-svg .cell.ghost .body { fill: none; stroke: #c98a1a; stroke-dasharray: 2.5 2.5; }
.inet-svg .cell.ghost text { display: none; }
.inet-svg .free circle { fill: #fff; stroke: #121212; stroke-width: 1.3; }
.inet-svg .free text, .inet-svg .port-name { font: italic 10px var(--serif); fill: #3f464e; text-anchor: middle; }
.inet-svg .port-name { font-size: 8.5px; text-anchor: start; fill: var(--muted); }
.inet-svg .under { font: 8.5px var(--sans); fill: var(--muted); text-anchor: middle; }
.inet-svg .empty { font: italic 10px var(--serif); fill: var(--muted); text-anchor: middle; }
.inet-svg .stage-cap { font: 7.5px var(--mono); fill: var(--muted); }
.inet-row { display: flex; align-items: center; gap: 4px; padding: 12px 14px 8px; }
.inet-row .pane { flex: 1 1 0; min-width: 0; }
.inet-row .arrow { flex: 0 0 auto; font: 700 11px var(--mono); color: var(--ink); text-align: center; line-height: 1.3; }
.inet-row .arrow b { display: block; font-size: 24px; font-weight: 400; }
.inet-grid { display: grid; gap: 0; }
.inet-grid .pane { border-right: 1px solid var(--rule-soft); border-bottom: 1px solid var(--rule-soft); padding: 4px 6px 8px; display: flex; flex-direction: column; }
.inet-grid .pane .inet-svg { flex: 1 1 auto; }
.inet .pane-cap { font: 700 10.5px/1.4 var(--display); letter-spacing: .02em; color: var(--ink); padding: 6px 4px 0; }
.inet .pane-cap::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 6px; background: var(--accent); border: 1.5px solid var(--line); border-radius: 2px; vertical-align: .02em; }
.inet-notation {
  font: 12.5px/1.6 var(--mono); color: var(--ink); padding: 8px 14px 10px;
  border-top: 1px solid var(--rule-soft); background: var(--card); white-space: pre-wrap; overflow-wrap: anywhere;
}
.inet-notation .eq { display: block; }
.inet-notation .eq.next { color: var(--ink); }
.inet-notation .eq.next::after { content: "   ← fires next"; color: var(--muted); font-style: italic; font-size: 11px; }
.inet-notation .term { display: block; color: var(--link); }
.inet-notation .arrow { color: var(--muted); padding: 0 .4em; }
.inet-notation .counts { color: var(--muted); font-size: 11.5px; }
.pane .inet-notation { border: 0; background: none; padding: 2px 4px; font-size: 11.5px; }
.pane .inet-notation .eq.next::after { content: " ←"; }
.inet figcaption { padding: 9px 14px; font: 12px/1.5 var(--sans); color: var(--muted); border-top: 1px solid var(--rule-soft); }
.inet figcaption .key { font-family: var(--mono); color: var(--ink); }

/* the player */
.inet-player .inet-stage { padding: 6px 12px 0; outline: none; }
.inet-player .inet-stage:focus-visible { box-shadow: inset 0 0 0 3px var(--accent); }
.inet-player .rule-now { font: 700 12px var(--mono); color: var(--ink); background: var(--accent); border-radius: 999px; padding: 3px 10px; margin-left: auto; }
.inet-player .inet-notation .eq { transition: background-color .3s; border-radius: 4px; }
.inet-player .inet-notation .eq.next { background: var(--accent-soft); padding: 0 4px; }
.inet-player input[type=range] {
  flex: 1 1 150px; -webkit-appearance: none; appearance: none; height: 10px; border-radius: 999px;
  background: var(--panel-2); border: 2px solid var(--line);
}
.inet-player input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--line); cursor: pointer; margin-top: -1px;
}
.inet-player input[type=range]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%; background: var(--accent);
  border: 2px solid var(--line); cursor: pointer;
}

/* ---------- archive box diagrams (the compendium's own dialect, vectorised) ---------- */
.inet-grid-svg .box { fill: #fff; stroke: #121212; stroke-width: 1.6; }
.inet-grid-svg .box.agent { fill: #121212; }
.inet-grid-svg text { dominant-baseline: central; }
.inet-grid-svg .agent-label { font: 700 11px var(--mono); letter-spacing: .04em; fill: #fff; text-anchor: middle; }
.inet-grid-svg .agent-label .lbl { font-weight: 400; fill: #f2eee2; font-size: 10px; }
.inet-grid-svg .value-label { font: 11px var(--mono); fill: #121212; text-anchor: middle; }
.inet-grid-svg .free-name { font: italic 11px var(--serif); fill: #3f464e; }
.inet-grid-svg .note { font: 10.7px/1 var(--mono); fill: var(--muted); }
.inet-grid-svg .dtext { font: 10px/1 var(--mono); fill: #121212; }
.inet-grid-svg .head { fill: #121212; }
.inet .src { border-top: 1px solid var(--rule-soft); }
.inet .src > summary { cursor: pointer; padding: 7px 14px; font: 11px var(--sans); color: var(--muted); list-style: none; }
.inet .src > summary::-webkit-details-marker { display: none; }
.inet .src > summary::before { content: "▸ "; }
.inet .src[open] > summary::before { content: "▾ "; }
.inet .src > summary:hover { color: var(--ink); background: var(--panel); }
.inet .src pre.ascii { margin: 0; border: 0; border-top: 1px solid var(--rule-soft); border-radius: 0; background: #fbf9f3; font-size: 11px; }

/* ---------- landing ---------- */
.doc-index .landing { max-width: 1020px; margin: 0 auto; padding: 6vh 22px; }
.kicker { display: inline-block; font: 700 11px var(--display); letter-spacing: .12em; color: var(--ink); background: var(--accent); border: 2px solid var(--line); border-radius: 999px; padding: 5px 12px; }
.landing h1 { font: 700 clamp(2rem, 4.4vw, 3.2rem)/1.05 var(--display); letter-spacing: -.03em; margin: 1rem 0 1rem; }
.lead { font-size: 1.06rem; color: #2b2f34; max-width: 40rem; }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 2.6rem 0 2rem; }
@media (max-width: 760px) { .cards { grid-template-columns: 1fr; } }
.card {
  display: block; padding: 24px; background: var(--card); border: 2px solid var(--line);
  border-radius: var(--radius); color: var(--ink); text-decoration: none; box-shadow: var(--shadow);
  transition: transform .12s, box-shadow .12s;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 0 rgba(18, 18, 18, .12); }
.card-kicker { font: 700 10px var(--display); letter-spacing: .12em; color: var(--muted); }
.card h2 { font: 700 1.6rem/1.1 var(--display); margin: .5rem 0 .6rem; }
.card p { font-size: .95rem; color: var(--muted); margin: 0 0 1.1rem; }
.card-go { display: inline-block; font: 700 12px var(--display); color: var(--ink); background: var(--accent); border: 2px solid var(--line); border-radius: 999px; padding: 6px 12px; }
.foot { font-size: .85rem; color: var(--muted); }

/* compendium files: keep the 4.7 MB page scrollable and searchable */
.content .file { scroll-margin-top: 74px; }

/* print-only bits */
.missing-media { font: 11px var(--mono); color: var(--muted); border: 1px dashed var(--rule-soft); border-radius: 6px; padding: 2px 6px; }

/* ---------- the compendium's printed index ---------- */
.toc-index { columns: 2; column-gap: 34px; margin: 8px 0 18px; font-size: 13px; }
.toc-index p { margin: 12px 0 2px; break-after: avoid; }
.toc-index ul { margin: 0 0 6px; padding-left: 18px; break-inside: avoid; }
.toc-index li { margin: 0; line-height: 1.5; }
.toc-index code { font-size: 11px; background: none; padding: 0; }

/* ================= responsive (last, so it overrides the base rules) ================= */
@media (max-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 10px; gap: 10px; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 60; width: min(88vw, 360px); max-height: none;
    border-radius: 0 18px 18px 0; border-left: 0; transform: translateX(-102%);
    transition: transform .2s ease; display: flex; flex-direction: column;
  }
  .sidebar.open { transform: none; }
  .sidebar-inner { max-height: none; flex: 1 1 auto; }
  .sidebar-head { position: sticky; top: 0; background: var(--card); z-index: 1; }
  .toc-close { display: block; }
  .toc-close, .toc-toggle { font: 700 12px/1 var(--display); }
  .backdrop {
    display: block; position: fixed; inset: 0; z-index: 55; background: rgba(18, 18, 18, .35);
  }
  .backdrop[hidden] { display: none; }
  body.toc-open { overflow: hidden; }
  .toc-toggle { display: inline-block; }
  .content { padding: 22px 16px 90px; border-radius: 16px; }
  .content h1 { font-size: clamp(1.7rem, 6.2vw, 2.45rem); }
  .content h2 { font-size: clamp(1.25rem, 4.6vw, 1.62rem); }
  .toc-list a, .toc-files a { padding: 7px 10px; }
  .inet-svg { max-height: 60vh; }
}

/* ---------- phones ---------- */
@media (max-width: 700px) {
  body { font-size: 16px; }
  .topbar {
    height: auto; min-height: 54px; flex-wrap: wrap; gap: 6px 8px;
    padding: 8px 10px; align-items: center;
  }
  .brand { font-size: 11.5px; padding: 5px 9px; order: 1; }
  .brand .long { display: none; }
  .tools { order: 2; margin-left: auto; gap: 6px; }
  .tools button { padding: 8px 11px; font-size: 11px; }
  .tabs {
    order: 3; width: 100%; margin: 0; gap: 6px; overflow-x: auto; scrollbar-width: none;
    -webkit-overflow-scrolling: touch; padding-bottom: 2px;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { flex: 0 0 auto; padding: 8px 12px; font-size: 11px; }
  .layout { padding: 8px; }
  .content { padding: 18px 13px 80px; border-radius: 14px; }
  .content h1 { font-size: clamp(1.5rem, 7.4vw, 2rem); }
  .content h2 { margin: 2rem 0 .7rem; padding-top: 1rem; }
  .content h3 { margin: 1.5rem 0 .45rem; }
  blockquote { padding: .6rem .8rem; border-left-width: 6px; }
  /* a squeezed 3-column table is unreadable: keep natural column widths and scroll instead */
  .table-wrap { border-radius: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap table { width: max-content; min-width: 100%; }
  table { font-size: 12.5px; }
  th, td { padding: 7px 9px; }
  pre.code, pre.shiki, pre.ascii { font-size: 11.5px; padding: 10px 11px; }
  .widget, .inet, .chart { border-radius: 12px; }
  .widget-head { padding: 8px 11px; }
  .widget-controls { padding: 8px 10px; gap: 6px; }
  .widget-controls button { padding: 10px 13px; font-size: 11px; min-height: 40px; }
  .inet .widget-head, .widget .widget-head { flex-wrap: wrap; row-gap: 4px; }
  .widget-kicker { white-space: nowrap; }
  .inet-player .rule-now { flex: 1 1 auto; text-align: right; font-size: 11px; padding: 3px 9px; }
  .toc-close { width: 40px; height: 40px; padding: 0; display: grid; place-items: center; flex: 0 0 auto; }
  .inet-svg .stage-cap, .inet-svg .under { font-size: 10px; }
  .inet-svg .cell text { font-size: 13px; }
  .inet-svg .free text { font-size: 12px; }
  .toc-toggle, .tools button { min-height: 40px; }
  .toc-list a, .toc-files a { padding: 11px 10px; }
  .inet-player input[type=range] { height: 14px; }
  .inet-player input[type=range]::-webkit-slider-thumb { width: 24px; height: 24px; margin-top: -2px; }
  .inet-player input[type=range]::-moz-range-thumb { width: 22px; height: 22px; }
  .inet-player input[type=range] { flex: 1 1 100%; order: 9; }
  .inet-player .step { margin-left: auto; }
  .inet-row { padding: 8px 10px 4px; gap: 0; flex-direction: column; }
  .inet-row .arrow { padding: 2px 0; }
  .inet-grid { grid-template-columns: minmax(0, 1fr) !important; }
  .inet-grid .pane { border-right: 0; }
  .inet-notation { font-size: 11px; padding: 6px 11px 8px; }
  .inet figcaption, .widget figcaption { font-size: 11px; padding: 8px 11px; }
  .trace-terms .term { font-size: 11px; }
  .cards { margin: 1.6rem 0; }
  .card { padding: 18px; }
  .landing h1 { font-size: clamp(1.7rem, 8vw, 2.4rem); }
  .lead { font-size: 1rem; }
  .foot { font-size: .8rem; }
  .toc-index { columns: 1; }
}

