/* Layout idea: one calm reading column (about 65 characters), with figures
   allowed to run a little wider than the text, like plates in a printed book. */
:root {
  --paper: #f4f6f3;
  --panel: #fbfcfa;
  --ink: #1b2530;
  --muted: #586470;
  --rule: #d3d9d5;
  --accent: #0d6b5e;
  --accent-soft: #dcebe6;
  --warn: #9a4a12;

  /* one colour per letter, everywhere in the book */
  --letter-0: #1f68b3; /* a, 0 */
  --letter-1: #bb3327; /* b, 1: control letters are warm */
  --letter-2: #6b4bb5; /* c */
  --letter-3: #a8610a; /* d, push */
  --token: #1b2530;    /* an occupied state always looks like this */
  --token-ink: #f4f6f3;
  --setup: #a86a00;      /* setup move: amber, with the wind-up arrow */
  --setup-soft: #f6ead0;
  --payoff: #23803a;     /* payoff move: green, with the spark */
  --payoff-soft: #dcefdf;

  --font-body: "Literata", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --font-ui: "Instrument Sans", "Avenir Next", "Segoe UI", system-ui, sans-serif;

  --measure: 34rem;
  --wide: 44rem;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #12181e;
    --panel: #19212a;
    --ink: #e3e8ea;
    --muted: #98a4ad;
    --rule: #2c3741;
    --accent: #62c7b1;
    --accent-soft: #1b3531;
    --warn: #f0a868;
    --letter-0: #74b4f2;
    --letter-1: #f5846f;
    --letter-2: #b49cf5;
    --letter-3: #e6a94a;
    --token: #e3e8ea;
    --token-ink: #12181e;
    --setup: #e9b44c; --setup-soft: #3a2f16; --payoff: #6fd08a; --payoff-soft: #173322;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #12181e;
  --panel: #19212a;
  --ink: #e3e8ea;
  --muted: #98a4ad;
  --rule: #2c3741;
  --accent: #62c7b1;
  --accent-soft: #1b3531;
  --warn: #f0a868;
  --letter-0: #74b4f2;
  --letter-1: #f5846f;
  --letter-2: #b49cf5;
  --letter-3: #e6a94a;
  --token: #e3e8ea;
  --token-ink: #12181e;
  --setup: #e9b44c; --setup-soft: #3a2f16; --payoff: #6fd08a; --payoff-soft: #173322;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.125rem;
  line-height: 1.65;
  font-optical-sizing: auto;
}
@media (max-width: 480px) { body { font-size: 1.0625rem; } }

a { color: var(--accent); text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
button, input, select { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- top bar */
.bar {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap;
  max-width: calc(var(--wide) + 2.5rem);
  margin: 0 auto; padding: 1rem 1.25rem 0.75rem;
  font-family: var(--font-ui); font-size: 0.875rem;
  border-bottom: 1px solid var(--rule);
}
.bar a { color: var(--muted); text-decoration: none; }
.bar a:hover { color: var(--ink); }
.bar-title { font-weight: 600; letter-spacing: 0.01em; color: var(--ink) !important; }
.bar-where { color: var(--muted); }

main { max-width: calc(var(--wide) + 2.5rem); margin: 0 auto; padding: 0 1.25rem 5rem; }
main > *, .chapter > *, .section > * { max-width: var(--measure); margin-left: auto; margin-right: auto; }
.chapter > .section { max-width: none; }

/* ------------------------------------------------------------------- home */
.home-head { padding: 3rem 0 1rem; }
.home-kicker { font-family: var(--font-ui); font-size: 0.8125rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); margin: 0 0 0.75rem; }
.home-head h1 { font-size: clamp(2.1rem, 7vw, 3.1rem); line-height: 1.08; font-weight: 500; margin: 0 0 1rem; text-wrap: balance; letter-spacing: -0.01em; }
.home-head h1 em { font-weight: 400; }
.home-lede { font-size: 1.2rem; line-height: 1.55; color: var(--muted); margin: 0; }
.home-byline { font-family: var(--font-ui); font-size: 0.875rem; color: var(--muted); margin-top: 1.25rem; }

.contents { list-style: none; padding: 0; margin: 1rem auto 0; display: flex; flex-direction: column; }
.contents li { border-top: 1px solid var(--rule); }
.contents li:last-child { border-bottom: 1px solid var(--rule); }
.contents a, .contents .stub {
  display: grid; grid-template-columns: 2.5rem 1fr; column-gap: 0.5rem; padding: 0.9rem 0;
  text-decoration: none; color: inherit;
}
.contents .num { font-family: var(--font-ui); font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 600; padding-top: 0.12em; }
.contents .t { font-size: 1.2rem; font-weight: 500; line-height: 1.3; }
.contents .d { grid-column: 2; color: var(--muted); font-size: 0.975rem; line-height: 1.5; margin-top: 0.15rem; }
.contents a:hover .t { text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 0.2em; }
.contents .stub .num, .contents .stub .t { color: var(--muted); }
.contents .tag { font-family: var(--font-ui); font-size: 0.72rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); border: 1px solid var(--rule); border-radius: 999px; padding: 0.05rem 0.5rem; margin-left: 0.5rem; white-space: nowrap; vertical-align: 0.15em; }
h2.contents-h { font-family: var(--font-ui); font-size: 0.8125rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin-top: 3rem; margin-bottom: 0; }

/* ---------------------------------------------------------------- chapter */
.chapter-head { padding: 3rem 0 0.5rem; }
.chapter-num { font-family: var(--font-ui); font-size: 0.8125rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); margin: 0 0 0.6rem; }
.chapter-head h1 { font-size: clamp(2rem, 6.5vw, 2.8rem); line-height: 1.1; font-weight: 500; margin: 0 0 0.9rem; text-wrap: balance; letter-spacing: -0.01em; }
.chapter-lede { font-size: 1.2rem; line-height: 1.55; color: var(--muted); margin: 0; }

.chapter h2 { font-size: 1.55rem; line-height: 1.2; font-weight: 600; margin-top: 3.2rem; margin-bottom: 0.8rem; text-wrap: balance; }
.chapter h2 .sec { font-family: var(--font-ui); font-size: 0.9rem; font-weight: 600; color: var(--accent); display: block; margin-bottom: 0.3rem; font-variant-numeric: tabular-nums; letter-spacing: 0.04em; }
.chapter h3 { font-size: 1.15rem; margin-top: 2rem; margin-bottom: 0.5rem; }
.chapter p { margin-top: 0; margin-bottom: 1.05rem; hanging-punctuation: first; }
.chapter ul, .chapter ol { padding-left: 1.4rem; margin-top: 0; margin-bottom: 1.05rem; }
.chapter li { margin-bottom: 0.35rem; }
.chapter strong.term { font-weight: 700; color: var(--accent); }
.chapter .display { overflow-x: auto; overflow-y: hidden; padding: 0.2rem 0; }

/* words over an alphabet, coloured letter by letter */
.w { font-family: var(--font-ui); font-weight: 600; letter-spacing: 0.04em; white-space: nowrap; }
.am-l0 { color: var(--letter-0); }
.am-l1 { color: var(--letter-1); }
.am-l2 { color: var(--letter-2); }
.am-l3 { color: var(--letter-3); }
.katex .am-l0, .katex .am-l1, .katex .am-l2, .katex .am-l3 { font-weight: 600; }

/* ----------------------------------------------------------------- figure */
.fig { max-width: var(--wide) !important; margin-top: 1.8rem; margin-bottom: 1.8rem; padding: 0; }
.fig figcaption { font-family: var(--font-ui); font-size: 0.875rem; line-height: 1.5; color: var(--muted); max-width: var(--measure); margin: 0.7rem auto 0; }
.fig figcaption b { color: var(--ink); font-weight: 600; }
.fig-svg { display: block; margin: 0 auto; max-width: 100%; height: auto; }
.fig-svg text { font-family: var(--font-ui); fill: var(--ink); }

/* ----------------------------------------------------------------- boxes */
.defn, .tryit, .background, .pause, .claim {
  border-radius: 6px; padding: 1rem 1.15rem; margin-top: 1.5rem; margin-bottom: 1.5rem;
}
.defn > :last-child, .tryit > :last-child, .background > :last-child, .claim > :last-child, .answer > :last-child, .pause > :last-child { margin-bottom: 0; }
.box-label { display: block; font-family: var(--font-ui); font-size: 0.78rem; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; margin-bottom: 0.35rem; }

.defn { border-left: 3px solid var(--accent); background: var(--panel); border-radius: 0 6px 6px 0; }
.defn .box-label { color: var(--accent); }
.claim { border: 1px solid var(--ink); background: var(--panel); }
.claim .box-label { color: var(--ink); }

.tryit { background: var(--accent-soft); }
.tryit .box-label { color: var(--accent); }

.pause { border: 1px dashed var(--muted); padding: 0; }
.pause > summary { cursor: pointer; padding: 0.85rem 1.15rem; list-style: none; font-style: italic; }
.pause > summary::-webkit-details-marker { display: none; }
.pause > summary::before { content: "Pause and guess"; display: block; font-style: normal; font-family: var(--font-ui); font-size: 0.78rem; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); margin-bottom: 0.25rem; }
.pause > summary::after { content: "Show what happens"; display: inline-block; margin-top: 0.5rem; font-style: normal; font-family: var(--font-ui); font-size: 0.85rem; font-weight: 600; color: var(--accent); text-decoration: underline; text-underline-offset: 0.2em; }
.pause[open] > summary::after { content: "Hide"; }
.pause > .pause-body { padding: 0 1.15rem 1rem; }
.pause > .pause-body > :last-child { margin-bottom: 0; }

/* background box: standard material summarised, with links out */
.background { border: 1px solid var(--rule); background: var(--panel); font-size: 1rem; line-height: 1.6; }
.background .box-label { color: var(--muted); }
.background h3 { margin: 0 0 0.6rem; font-size: 1.15rem; }
.background h4 { font-family: var(--font-ui); font-size: 0.8rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); margin: 0.9rem 0 0.25rem; }
.background p, .background ul { margin-bottom: 0.6rem; }
.background .later { font-family: var(--font-ui); font-size: 0.8rem; color: var(--muted); border-top: 1px solid var(--rule); padding-top: 0.6rem; margin-top: 0.9rem; }

/* transition tables */
.table-wrap { overflow-x: auto; }
.ttable { border-collapse: collapse; font-family: var(--font-ui); font-size: 0.95rem; font-variant-numeric: tabular-nums; margin: 0 auto; }
.ttable th, .ttable td { padding: 0.35rem 1rem; text-align: center; border-bottom: 1px solid var(--rule); }
.ttable thead th { border-bottom: 1.5px solid var(--ink); font-weight: 600; }
.ttable tbody th { font-weight: 600; border-right: 1px solid var(--rule); }
.ttable caption { caption-side: bottom; font-size: 0.85rem; color: var(--muted); padding-top: 0.5rem; }

/* exercises */
.exercises ol { list-style: none; padding: 0; counter-reset: ex; }
.exercises ol > li { counter-increment: ex; position: relative; padding-left: 2rem; margin-bottom: 1.6rem; }
.exercises ol > li::before { content: counter(ex); position: absolute; left: 0; top: 0.05em; font-family: var(--font-ui); font-weight: 600; font-size: 0.95rem; color: var(--accent); font-variant-numeric: tabular-nums; }
.answer { border-top: 1px solid var(--rule); margin-top: 0.4rem; }
.answer > summary { cursor: pointer; font-family: var(--font-ui); font-size: 0.875rem; font-weight: 600; color: var(--accent); padding: 0.45rem 0; }
.answer[open] { padding-bottom: 0.4rem; }
.answer .fig { margin-top: 1rem; margin-bottom: 0.5rem; }

.chapter-nav { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-top: 4rem !important; padding-top: 1.2rem; border-top: 1px solid var(--rule); font-family: var(--font-ui); font-size: 0.95rem; }
.chapter-nav a { text-decoration: none; font-weight: 600; }
.chapter-nav span { color: var(--muted); }
.loading, .load-error { padding: 4rem 0; color: var(--muted); font-family: var(--font-ui); }

/* ------------------------------------------------------ automaton widget */
.am { border: 1px solid var(--rule); border-radius: 8px; background: var(--panel); padding: 0.9rem 1rem 1rem; font-family: var(--font-ui); font-size: 0.925rem; line-height: 1.45; }
.am-head { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.4rem; }
.am-title { font-weight: 600; }
.am-pick select { border: 1px solid var(--rule); border-radius: 5px; background: var(--paper); padding: 0.15rem 0.3rem; }
.am-body { display: flex; flex-wrap: wrap; gap: 0.75rem 1.5rem; align-items: center; }
.am-stage { flex: 1 1 15rem; min-width: 0; display: flex; justify-content: center; }
.am-stage svg { width: 100%; height: auto; display: block; overflow: visible; }
.am-side { flex: 1 1 15rem; min-width: 0; display: flex; flex-direction: column; gap: 0.7rem; }

.am-node { fill: var(--panel); stroke: var(--ink); stroke-width: 1.5; }
.am-accept { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.am-token { fill: var(--token); }
.am-label { font-family: var(--font-ui); font-size: 14px; font-weight: 600; fill: var(--ink); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.am-label.on { fill: var(--token-ink); }
.am-edge-line { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.am-edge-head { fill: currentColor; stroke: none; }
.am-edge-label { font-family: var(--font-ui); font-size: 13px; font-weight: 700; fill: currentColor; text-anchor: middle; dominant-baseline: central; paint-order: stroke; stroke: var(--panel); stroke-width: 4px; stroke-linejoin: round; }
.am-lmix, .am-start { color: var(--muted); }
.am-pulse { fill: none; stroke: var(--token); stroke-width: 2; opacity: 0; transform-box: fill-box; transform-origin: center; animation: am-pulse 0.6s ease-out; }
@keyframes am-pulse { from { opacity: 0.9; transform: scale(1); } to { opacity: 0; transform: scale(1.7); } }

.am-keys { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.am-key { min-width: 3rem; padding: 0.45rem 0.9rem; border-radius: 7px; border: 2px solid currentColor; background: var(--paper); font-weight: 700; font-size: 1.05rem; cursor: pointer; transition: transform 0.08s ease; }
.am-key:hover:not(:disabled) { background: var(--panel); box-shadow: 0 2px 0 currentColor; transform: translateY(-1px); }
.am-key:active:not(:disabled) { transform: translateY(1px); box-shadow: none; }
.am-key:disabled { opacity: 0.4; cursor: default; }
.am-tools { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.am-tool { padding: 0.3rem 0.75rem; border-radius: 6px; border: 1px solid var(--muted); background: transparent; color: var(--ink); font-size: 0.875rem; font-weight: 500; cursor: pointer; }
.am-tool:hover:not(:disabled) { border-color: var(--ink); background: var(--paper); }
.am-tool:disabled { opacity: 0.4; cursor: default; }
.am-check { font-size: 0.85rem; color: var(--muted); display: inline-flex; align-items: center; gap: 0.3rem; cursor: pointer; }
.am-check input { accent-color: var(--accent); }

.am-status { min-height: 2.9em; padding: 0.5rem 0.7rem; border-radius: 6px; background: var(--paper); border-left: 3px solid var(--rule); }
.am-status.is-done { border-left-color: var(--accent); background: var(--accent-soft); }
.am-status.is-stuck { border-left-color: var(--warn); }
.am-pill { display: inline-block; font-size: 0.78rem; font-weight: 600; padding: 0.05rem 0.55rem; border-radius: 999px; border: 1.5px solid currentColor; margin-left: 0.25rem; white-space: nowrap; }
.am-pill.yes { color: var(--accent); }
.am-pill.no { color: var(--muted); border-style: dashed; }
.am-word { font-weight: 700; letter-spacing: 0.05em; overflow-wrap: anywhere; }

.am-trail { font-size: 0.85rem; color: var(--muted); display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.15rem 0.3rem; font-variant-numeric: tabular-nums; max-height: 7.5em; overflow-y: auto; }
.am-step { white-space: nowrap; color: var(--ink); }
.am-arrow { white-space: nowrap; font-weight: 700; }
.am-arrow-letter { font-size: 0.8rem; margin-right: 0.1rem; }

.am-transport { border-top: 1px solid var(--rule); padding-top: 0.65rem; display: flex; flex-direction: column; gap: 0.45rem; }
.am-transport[hidden] { display: none; }
.am-transport-word { font-weight: 700; font-size: 1.05rem; letter-spacing: 0.12em; overflow-wrap: anywhere; }
.am-transport-word span { opacity: 0.4; border-bottom: 2px solid transparent; padding-bottom: 1px; }
.am-transport-word span.done { opacity: 1; }
.am-transport-word span.now { border-bottom-color: currentColor; }
.am-transport-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.am-transport-count { font-size: 0.82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.am-play { background: var(--ink); color: var(--paper); border-color: var(--ink); font-weight: 600; min-width: 4.6rem; }
.am-play:hover:not(:disabled) { background: var(--ink); opacity: 0.88; }

.am-run { display: flex; flex-direction: column; gap: 0.4rem; border-top: 1px solid var(--rule); padding-top: 0.65rem; }
.am-run-label { font-size: 0.82rem; color: var(--muted); }
.am-run-row { display: flex; gap: 0.5rem; }
.am-run-row input { flex: 1 1 auto; min-width: 0; padding: 0.3rem 0.55rem; border: 1px solid var(--muted); border-radius: 6px; background: var(--paper); letter-spacing: 0.08em; }
.am-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.am-chip { padding: 0.15rem 0.6rem; border-radius: 999px; border: 1px solid var(--rule); background: var(--paper); font-size: 0.85rem; font-weight: 600; letter-spacing: 0.06em; cursor: pointer; }
.am-chip:hover { border-color: var(--ink); }
.am-solve { border-top: 1px solid var(--rule); padding-top: 0.65rem; display: flex; flex-direction: column; gap: 0.5rem; align-items: flex-start; }
.am-solve-out p { margin: 0 0 0.5rem; }
.am-solve-out:empty { display: none; }
.am-msg { color: var(--warn); font-size: 0.85rem; }
.am-msg:empty { display: none; }

@media (prefers-reduced-motion: reduce) {
  .am-pulse { animation: none; }
  .am-key { transition: none; }
}

/* --------------------------------------------------- part-orienting figure */
.pt-belt { fill: var(--paper); stroke: var(--rule); stroke-width: 1.5; }
.pt-belt-marks path { fill: none; stroke: var(--muted); stroke-width: 1.2; stroke-linecap: round; stroke-linejoin: round; opacity: 0.6; }
.pt-note { font-family: var(--font-ui); font-size: 11px; fill: var(--muted); text-anchor: middle; }
.pt-body { fill: var(--panel); stroke: var(--ink); stroke-width: 1.8; }
.pt-peg { fill: var(--token); opacity: 0.38; transition: transform 0.7s cubic-bezier(0.45, 0, 0.25, 1); }
.pt-peg.sure { opacity: 1; }
.pt-peg.flash { animation: pt-flash 0.5s ease-out; }
@keyframes pt-flash { from { fill: var(--letter-1); } to { fill: var(--token); } }
.pt-rail { fill: var(--letter-1); transition: transform 0.7s linear; }
.pt-spin { fill: none; stroke: var(--letter-0); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; opacity: 0; transition: opacity 0.2s; }
.pt-spin.on { opacity: 1; }
.pt-thumbs { display: flex; gap: 0.4rem; }
.pt-thumb { width: 2.6rem; height: 2.6rem; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper); display: block; }
.pt-thumb svg { width: 100%; height: 100%; display: block; }
.pt-thumb.off { opacity: 0.28; border-style: dashed; }
.pt .am-transport-word { letter-spacing: 0.02em; font-size: 0.95rem; }
@media (prefers-reduced-motion: reduce) {
  .pt-peg, .pt-rail, .pt-spin { transition: none; }
  .pt-peg.flash { animation: none; }
}

/* a letter drawn as a function */
.am-map-head { font-family: var(--font-ui); font-size: 12px; font-weight: 600; fill: var(--muted); text-anchor: middle; }
.am-map-head.am-l0, .am-map-head.am-l1, .am-map-head.am-l2, .am-map-head.am-l3 { fill: currentColor; font-size: 14px; }
.am-map .faded { opacity: 0.25; }
.map-row { display: flex; flex-wrap: wrap; gap: 1rem 2rem; justify-content: center; }
.map-row > div { flex: 0 1 280px; min-width: 200px; }

/* spacing refinements */
.pause > summary::after { display: block; width: fit-content; }
.table-wrap { margin-top: 1.4rem; margin-bottom: 1.6rem; }
.map-row > div { flex: 0 1 240px; }
.pause-body .table-wrap, .answer .table-wrap { margin-top: 0.8rem; margin-bottom: 1rem; }

.contents li.part { font-family: var(--font-ui); font-size: 0.8125rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); padding: 1.6rem 0 0.5rem; border-top: 0; }
.contents li.part:first-child { padding-top: 0.6rem; }
.contents li.part + li { border-top: 1px solid var(--rule); }

/* ------------------------------------------------- sections and contents */
.exercises { margin-top: 3rem; padding-top: 0.4rem; border-top: 1px solid var(--rule); }
.exercises h3 { font-family: var(--font-ui); font-size: 0.8125rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); margin: 1rem 0 1rem; }
.chapter.inner > .section > h2:first-child { margin-top: 0.4rem; font-size: clamp(1.7rem, 5.5vw, 2.2rem); font-weight: 500; }
.chapter:not(.inner) > .section > h2:first-child { margin-top: 2.4rem; }
.crumb { font-family: var(--font-ui); font-size: 0.8125rem; letter-spacing: 0.08em; text-transform: uppercase; padding-top: 2.6rem; margin-bottom: 0; }
.crumb a { color: var(--accent); text-decoration: none; }
.crumb a:hover { text-decoration: underline; }
.bar-where a { text-decoration: underline; text-underline-offset: 0.2em; }

.chapter-nav a { display: flex; flex-direction: column; gap: 0.15rem; flex: 1 1 14rem; max-width: 22rem; padding: 0.7rem 0.9rem; border: 1px solid var(--rule); border-radius: 6px; color: var(--ink); line-height: 1.35; }
.chapter-nav a:hover { border-color: var(--accent); }
.chapter-nav a.next { text-align: right; margin-left: auto; }
.chapter-nav .nl { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.04em; color: var(--accent); }

.start { display: inline-block; font-family: var(--font-ui); font-size: 0.95rem; font-weight: 600; text-decoration: none; padding: 0.55rem 1rem; border-radius: 6px; background: var(--ink); color: var(--paper); margin-top: 0.4rem; }
.start:hover { opacity: 0.88; }
.contents a.ch { padding-bottom: 0.5rem; }
.contents .pre { font-family: var(--font-ui); font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); font-weight: 600; display: block; }
.sections { list-style: none; margin: 0 0 0.9rem; padding: 0 0 0 3rem; display: flex; flex-direction: column; }
.contents .sections li { border: 0; }
.contents .sections a { display: flex; align-items: baseline; gap: 0.6rem; padding: 0.28rem 0; font-size: 1rem; line-height: 1.4; }
.sections .sn { font-family: var(--font-ui); font-size: 0.85rem; font-variant-numeric: tabular-nums; color: var(--muted); min-width: 2rem; }
.sections a:hover .st { text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 0.2em; }
.sections .tick { color: var(--accent); font-family: var(--font-ui); font-size: 0.85rem; }
.sections li.here .st { font-weight: 600; }
.contents .here-tag { color: var(--accent); border-color: var(--accent); margin-left: 0; }
@media (max-width: 480px) { .sections { padding-left: 0.5rem; } }

/* part figure: one real part / all possibilities */
.pt-views { display: inline-flex; align-self: flex-start; border: 1px solid var(--muted); border-radius: 7px; overflow: hidden; }
.pt-view { border: 0; background: transparent; color: var(--ink); padding: 0.32rem 0.7rem; font-size: 0.85rem; font-weight: 500; cursor: pointer; }
.pt-view + .pt-view { border-left: 1px solid var(--muted); }
.pt-view[aria-pressed="true"] { background: var(--ink); color: var(--paper); font-weight: 600; }
.pt-view:focus-visible { outline-offset: -3px; }
.pt-cover rect { fill: var(--panel); stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 5 4; }
.pt-cover text { font-family: var(--font-ui); font-size: 44px; font-weight: 600; fill: var(--muted); text-anchor: middle; dominant-baseline: central; }
.pt-realmark { fill: none; stroke: var(--accent); stroke-width: 3; transition: transform 0.7s cubic-bezier(0.45, 0, 0.25, 1); }
@media (prefers-reduced-motion: reduce) { .pt-realmark { transition: none; } }

/* ------------------------------------------- setup moves and payoff moves */
.mv { font-family: var(--font-ui); font-weight: 700; white-space: nowrap; }
.mv-setup { color: var(--setup); }
.mv-pay { color: var(--payoff); }
.am-trail .mv { font-size: 0.8rem; margin-right: 0.1rem; }
.am-tally { flex-basis: 100%; margin-top: 0.25rem; font-size: 0.82rem; color: var(--muted); }
.am-transport-word span.mvs { box-shadow: 0 4px 0 -1px var(--setup); }
.am-transport-word span.mvp { box-shadow: 0 4px 0 -1px var(--payoff); }
.theme { border-radius: 6px; padding: 1rem 1.15rem; margin-top: 1.5rem; margin-bottom: 1.5rem; background: var(--setup-soft); border-left: 3px solid var(--setup); border-radius: 0 6px 6px 0; }
.theme > :last-child { margin-bottom: 0; }
.theme .box-label { color: var(--setup); }
.tile { display: inline-block; font-family: var(--font-ui); font-weight: 700; font-size: 0.85em; padding: 0.02em 0.5em; border-radius: 5px; white-space: nowrap; }
.tile.setup { background: var(--setup-soft); color: var(--setup); border: 1.5px solid var(--setup); }
.tile.payoff { background: var(--payoff-soft); color: var(--payoff); border: 1.5px solid var(--payoff); }
.theme .tile.setup { background: var(--panel); }
.todo { display: none; }

/* --------------------------------------------- editor, pairs, small figures */
.am-extra { border-top: 1px solid var(--rule); margin-top: 0.9rem; padding-top: 0.8rem; display: flex; flex-direction: column; gap: 0.9rem; }
.am-extra-label { font-size: 0.82rem; color: var(--muted); }
.am-edit, .am-pairs, .wu-col { display: flex; flex-direction: column; gap: 0.6rem; }
.am-table-wrap { overflow-x: auto; }
.am-table { border-collapse: collapse; font-variant-numeric: tabular-nums; }
.am-table th, .am-table td { padding: 0.2rem 0.55rem; text-align: center; border-bottom: 1px solid var(--rule); font-weight: 600; }
.am-table tr:first-child th { border-bottom: 1.5px solid var(--ink); }
.am-cell { min-width: 2.6rem; padding: 0.25rem 0.5rem; border-radius: 6px; border: 1.5px solid currentColor; background: var(--paper); font-weight: 700; cursor: pointer; }
.am-cell-fixed { display: inline-block; min-width: 2.6rem; padding: 0.25rem 0.5rem; font-weight: 700; opacity: 0.75; }
.am-cell:hover { background: var(--panel); box-shadow: 0 2px 0 currentColor; }
.am-table input { accent-color: var(--accent); width: 1.1rem; height: 1.1rem; }
.am-readout { font-size: 0.9rem; padding: 0.5rem 0.7rem; border-radius: 6px; background: var(--paper); border-left: 3px solid var(--rule); }
.am-readout:empty { display: none; }
.am-node.pickable, .wu-click { cursor: pointer; }
.am-token { pointer-events: none; }
.am-pairgrid { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.am-pair { display: inline-flex; flex-direction: column; align-items: center; min-width: 3.6rem; padding: 0.3rem 0.5rem; border-radius: 7px; border: 1.5px solid var(--muted); background: var(--paper); color: var(--ink); cursor: pointer; line-height: 1.25; }
.am-pair:hover { border-color: var(--ink); }
.am-pair-name { font-weight: 700; letter-spacing: 0.06em; }
.am-pair-sub { font-size: 0.74rem; color: var(--muted); }
.am-pair.marked { background: var(--payoff-soft); border-color: var(--payoff); }
.am-pair.marked .am-pair-sub { color: var(--payoff); font-weight: 700; }
.am-pair.current { box-shadow: 0 0 0 2px var(--ink); }

.wu-goals { list-style: none; padding: 0; margin: 0; font-size: 0.88rem; color: var(--muted); }
.wu-goals li { margin: 0 0 0.2rem; }
.wu-goals li.done { color: var(--payoff); font-weight: 600; }
.wu-sel { stroke: var(--accent); stroke-width: 3.5; }
.wu-missed { stroke-dasharray: 4 3; stroke: var(--muted); }
.wu-ghost { fill: none; stroke: var(--token); stroke-width: 2; stroke-dasharray: 3 3; opacity: 0.7; }
.wu-strip { display: flex; gap: 0.35rem; min-height: 2.6rem; align-items: center; flex-wrap: wrap; }
.wu-strip-free { padding: 0.3rem 0.6rem; border: 1px dashed var(--muted); border-radius: 6px; }
.wu-hint { color: var(--muted); font-style: italic; }
.wu-tile { width: 2.3rem; height: 2.5rem; border-radius: 6px; border: 2px dashed var(--muted); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1.15rem; }
.wu-tile.full { border-style: solid; border-color: currentColor; background: var(--paper); }
.wu-log { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.wu-tried { cursor: default; }
.wu-tried.yes { border-color: var(--payoff); background: var(--payoff-soft); }
.wu-two { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; justify-content: center; margin-bottom: 0.6rem; }
.wu-mach { flex: 1 1 12rem; min-width: 0; max-width: 20rem; }
.wu-mach svg { width: 100%; height: auto; display: block; margin: 0 auto; overflow: visible; }
.wu-cap { font-size: 0.82rem; color: var(--muted); text-align: center; }
.wu-gridbox { align-self: flex-start; }
.wu-grid { border-collapse: collapse; margin: 0 auto; }
.wu-grid caption { caption-side: bottom; font-size: 0.8rem; color: var(--muted); padding-top: 0.4rem; }
.wu-grid th { padding: 0.2rem 0.5rem; font-weight: 600; color: var(--muted); }
.wu-grid td { width: 3.4rem; height: 3rem; border: 1.5px solid var(--rule); text-align: center; position: relative; }
.wu-grid td.seen { background: var(--paper); border-color: var(--muted); }
.wu-grid td.acc { background: var(--accent-soft); }
.wu-grid td.cur { border: 2.5px solid var(--ink); }
.wu-dot { display: inline-block; width: 1.3rem; height: 1.3rem; border-radius: 50%; background: var(--token); vertical-align: middle; }
.wu-next { position: absolute; right: 3px; bottom: 0; font-size: 0.78rem; font-weight: 700; }
.wu-next + .wu-next { right: auto; left: 3px; }
.wu-ls { margin-bottom: 0.7rem; }
.wu-ls svg { width: 100%; max-width: 34rem; height: auto; display: block; margin: 0 auto; overflow: visible; }
.wu-ls-node { fill: var(--panel); stroke: var(--ink); stroke-width: 1.3; }
.wu-ls-node.seen { fill: var(--accent-soft); }
.wu-ls-node.cur { fill: var(--token); }
.wu-ls-node.dim { stroke: var(--rule); stroke-dasharray: 3 3; }
.wu-ls-label { font-family: var(--font-ui); font-weight: 600; fill: var(--ink); text-anchor: middle; dominant-baseline: central; pointer-events: none; letter-spacing: 0.04em; }
.wu-ls-label.on { fill: var(--token-ink); }
.wu-ls-label.dim { fill: var(--muted); }
.wu-ls-dist { font-family: var(--font-ui); font-size: 9.5px; font-weight: 700; fill: var(--accent); text-anchor: middle; dominant-baseline: central; }
.wu-ls-path { fill: none; stroke: var(--muted); stroke-width: 2.5; stroke-linecap: round; opacity: 0.45; }
.wu-col input[type=range] { width: 100%; accent-color: var(--accent); }
.wu-bounds { display: flex; flex-direction: column; gap: 0.45rem; }
.wu-brow { display: grid; grid-template-columns: 9.5rem 1fr 6.5rem; gap: 0.6rem; align-items: center; }
.wu-bname { font-weight: 600; line-height: 1.2; }
.wu-bname span { display: block; font-weight: 400; font-size: 0.8rem; color: var(--muted); }
.wu-bbar { height: 0.9rem; background: var(--paper); border-radius: 4px; overflow: hidden; }
.wu-bbar span { display: block; height: 100%; border-radius: 4px; }
.wu-b0 { background: var(--payoff); } .wu-b1 { background: var(--letter-0); } .wu-b2 { background: var(--setup); } .wu-b3 { background: var(--letter-1); }
.wu-bval { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; overflow-wrap: anywhere; }
.wu-bnote { margin: 0.4rem 0 0; font-size: 0.85rem; color: var(--muted); }
@media (max-width: 480px) { .wu-brow { grid-template-columns: 6.5rem 1fr 5rem; font-size: 0.85rem; } .wu-grid td { width: 2.7rem; height: 2.6rem; } }

/* contents: the centrepiece */
.contents li.star .num { color: var(--setup); }

/* ------------------------------------------------------------- puzzles */
.pz { --pz-violet: #7a5bc4; --pz-night: #0c1117; }
.pz-head { align-items: baseline; }
.pz-num { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--accent); margin-right: 0.35rem; }
.pz-stars { font-family: var(--font-ui); color: var(--setup); letter-spacing: 0.08em; white-space: nowrap; font-size: 1.05rem; }
.pz-story { font-family: var(--font-ui); font-size: 0.92rem; line-height: 1.5; margin-bottom: 0.8rem; }
.pz-story p { margin: 0 0 0.4rem; }
.pz-rules { margin: 0 0 0.4rem; padding-left: 1.1rem; }
.pz-rules li { margin-bottom: 0.15rem; }
.pz-goal { font-weight: 600; }
.pz-count { font-size: 0.82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.pz .am-status p { margin: 0 0 0.35rem; }
.pz .am-status p:last-child { margin-bottom: 0; }
.pz [hidden] { display: none !important; }
.pz-trail { display: flex; flex-wrap: wrap; gap: 0.3rem; font-family: var(--font-ui); font-size: 0.78rem; }
.pz-trail:empty { display: none; }
.pz-chip { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.05rem 0.2rem 0.05rem 0.45rem; border-radius: 999px; border: 1px solid currentColor; font-weight: 600; white-space: nowrap; }
.pz-chip-n { min-width: 1.15rem; padding: 0 0.25rem; border-radius: 999px; text-align: center; font-variant-numeric: tabular-nums; }
.pz-chip.pay .pz-chip-n { background: var(--payoff-soft); color: var(--payoff); }
.pz-chip.set .pz-chip-n { background: var(--setup-soft); color: var(--setup); }
.pz-hints { font-family: var(--font-ui); font-size: 0.88rem; }
.pz-hints:empty { display: none; }
.pz-hints p { margin: 0 0 0.35rem; padding-left: 0.6rem; border-left: 3px solid var(--setup); }
.pz-note { font-family: var(--font-ui); font-size: 0.85rem; color: var(--muted); margin: 0.5rem 0 0; }

/* a typed word: the word box of the puzzles and of the figures in the chapter on words */
.pz-inputs { align-self: flex-start; }
.pz-type, .am-type { display: flex; flex-direction: column; gap: 0.4rem; min-width: 0; }
.pz-type-label { font-family: var(--font-ui); font-size: 0.85rem; font-weight: 600; }
.pz-legend { display: flex; flex-wrap: wrap; gap: 0.3rem 0.7rem; align-items: baseline; font-family: var(--font-ui); font-size: 0.88rem; }
.pz-legend-label { color: var(--muted); }
.pz-legend-item { font-weight: 600; white-space: nowrap; }
.pz-legend-item kbd { display: inline-block; min-width: 1.5em; padding: 0 0.3em; border: 1.5px solid currentColor; border-radius: 5px; font-family: var(--font-ui); font-size: 0.95em; font-weight: 700; text-align: center; background: var(--paper); }
.pz-word { width: 100%; min-width: 0; box-sizing: border-box; padding: 0.4rem 0.6rem; border: 1.5px solid var(--muted); border-radius: 6px; background: var(--paper); color: var(--ink); font-family: var(--font-ui); font-size: 1.05rem; font-weight: 600; letter-spacing: 0.14em; }
.pz-word.bad { border-color: var(--warn); }
.pz-word:disabled { opacity: 0.5; }
.pz-type-note { margin: 0; font-family: var(--font-ui); font-size: 0.85rem; color: var(--muted); min-height: 1.2em; }
.pz-word.bad + .pz-type-note { color: var(--warn); }
.am-type[hidden], .am-keys[hidden], .am-chips[hidden] { display: none; }
.pz-diagram-host:empty { display: none; }
.pz-diagram-host { margin-top: 0.7rem; }
.pz-diagram-host .am { border-style: dashed; }

.pz svg text { user-select: none; }
.pz-label { font-family: var(--font-ui); font-size: 12px; fill: var(--ink); text-anchor: middle; }
.pz-label.small { font-size: 9.5px; fill: var(--muted); }
.pz-label.strong { font-weight: 700; }
.pz-label.small.strong { fill: var(--ink); }
.pz-label.warm { fill: var(--letter-1); }
.pz-label.star { fill: var(--setup); font-size: 13px; }
.pz-label.onscreen { fill: #8b98a3; font-size: 10px; }
.pz-room { fill: var(--paper); stroke: none; }
.pz-room.round { stroke: var(--ink); stroke-width: 1.8; }
.pz-tray { fill: var(--setup-soft); }
.pz-wall { fill: none; stroke: var(--ink); stroke-width: 4.5; stroke-linecap: round; }
.pz-wall.box { stroke-width: 3; stroke-linejoin: round; }
.pz-wall.thin { stroke: var(--rule); stroke-width: 1.2; stroke-dasharray: 3 3; }
.pz-wall.thinline { stroke: var(--muted); stroke-width: 1.4; }
.pz-cup { fill: var(--panel); fill-opacity: 0.25; stroke: var(--ink); stroke-width: 1.8; stroke-linejoin: round; transition: fill-opacity 0.25s; }
.pz-dark .pz-cup { fill-opacity: 1; }
.pz-tile { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.3; }
.pz-tile.mark { fill: var(--setup-soft); stroke: var(--setup); }
.pz-tvbox { fill: var(--muted); }
.pz-screen { fill: #0c1117; }
.pz-chan { fill: var(--paper); stroke: var(--muted); stroke-width: 1.3; }
.pz-chan.mark { stroke: var(--setup); stroke-dasharray: 4 2; }
.pz-track { fill: none; stroke: var(--muted); stroke-width: 7; }
.pz-sleepers { fill: none; stroke: var(--panel); stroke-width: 4; stroke-dasharray: 2 7; }
.pz-station { fill: var(--paper); stroke: var(--muted); stroke-width: 1.3; }
.pz-station.mark { fill: var(--setup-soft); stroke: var(--setup); stroke-width: 2; }
.pz-corridor { fill: none; stroke: var(--rule); stroke-width: 12; }
.pz-chute { fill: none; stroke: var(--letter-1); stroke-width: 5; stroke-dasharray: 2 5; stroke-linecap: round; }
.pz-pond { fill: var(--letter-0); fill-opacity: 0.13; }
.pz-pad { fill: var(--payoff); fill-opacity: 0.4; stroke: var(--payoff); stroke-width: 1.3; }
.pz-pad.mark { fill-opacity: 0.85; }
.pz-snake { fill: none; stroke: var(--letter-1); stroke-width: 3; stroke-linecap: round; }
.pz-spring { fill: var(--setup-soft); stroke: var(--setup); stroke-width: 1.3; stroke-dasharray: 3 2; }
.pz-mat { stroke: var(--ink); stroke-width: 1.2; fill-opacity: 0.55; }
.pz-mat.m0 { fill: var(--letter-1); } .pz-mat.m1 { fill: #e8c53a; } .pz-mat.m2 { fill: var(--payoff); } .pz-mat.m3 { fill: var(--letter-0); }
.pz-tube { fill: none; stroke: currentColor; stroke-width: 7; stroke-linecap: round; opacity: 0.45; }
.pz-tube-head { fill: currentColor; stroke: none; }
.pz-wheel { fill: var(--panel); stroke: currentColor; stroke-width: 3; }
.pz-wheel.spoke { fill: none; stroke-width: 1.2; }
.pz-badge { fill: var(--panel); stroke: var(--muted); stroke-width: 1; }
.pz-belt { fill: var(--paper); stroke: var(--rule); stroke-width: 1.5; }
.pz-belt-mark { fill: none; stroke: var(--muted); stroke-width: 1.2; opacity: 0.5; stroke-linecap: round; stroke-linejoin: round; }
.pz-block { fill: var(--panel); stroke: var(--ink); stroke-width: 1.8; }
.pz-card { fill: var(--paper); stroke: var(--rule); stroke-width: 1.2; }
.pz-turntable { fill: none; stroke: var(--rule); stroke-width: 1.2; stroke-dasharray: 2 4; }
.pz-bulb { fill: none; stroke: var(--muted); stroke-width: 1.4; }
.pz-bulb.on { fill: #f0c330; stroke: var(--ink); }
.pz-frame { fill: var(--payoff); fill-opacity: 0.12; stroke: var(--payoff); stroke-width: 3.5; }

.pz-ink { stroke: var(--ink); stroke-width: 1.4; }
.pz-ink-line { fill: none; stroke: var(--ink); stroke-width: 1.4; stroke-linecap: round; }
.pz-f-ink { fill: var(--ink); } .pz-f-paper { fill: #f4f6f3; } .pz-f-token { fill: var(--token); }
.pz-f-cool { fill: var(--letter-0); } .pz-f-warm { fill: var(--letter-1); } .pz-f-gold { fill: var(--letter-3); }
.pz-f-green { fill: var(--payoff); } .pz-f-violet { fill: var(--letter-2); }
.pz-f-glow { fill: var(--letter-3); fill-opacity: 0.75; }

.pz-tok { transition: transform 0.46s cubic-bezier(0.45, 0, 0.25, 1), opacity 0.2s; opacity: 0.5; }
.pz-tok.sure { opacity: 1; }
.pz-cards .pz-tok, .pz-art-tv .pz-tok { opacity: 0.85; }
.pz-tok.bump .pz-tok-in { animation: pz-bump 0.4s ease-in-out; }
@keyframes pz-bump { 0%, 100% { transform: translate(0, 0); } 30% { transform: translate(-3px, 0); } 65% { transform: translate(3px, 0); } }
.pz-flash { fill: none; stroke: var(--payoff); stroke-width: 3; opacity: 0; transform-box: fill-box; transform-origin: center; animation: pz-flash 0.7s ease-out; }
@keyframes pz-flash { from { opacity: 0.9; transform: scale(0.5); } to { opacity: 0; transform: scale(1.5); } }
.pz-veil { opacity: 0; pointer-events: none; transition: opacity 0.3s; }
.pz-veil rect { fill: #0c1117; }
.pz-veil-q { font-family: var(--font-ui); font-size: 22px; font-weight: 700; fill: #f4f6f3; text-anchor: middle; }
.pz-dark .pz-veil { opacity: 0.6; }
.pz-done .am-stage svg { filter: drop-shadow(0 0 6px var(--payoff-soft)); }
.pt-view.on { background: var(--ink); color: var(--paper); font-weight: 600; }
@media (prefers-reduced-motion: reduce) {
  .pz-tok, .pz-veil, .pz-cup { transition: none; }
  .pz-tok.bump .pz-tok-in, .pz-flash { animation: none; }
}

/* the puzzle room */
.pz-room-list { max-width: var(--wide) !important; font-family: var(--font-ui); }
.pz-room-total { font-size: 0.95rem; color: var(--muted); }
.pz-list { list-style: none; padding: 0; margin: 0; }
.pz-item { border-top: 1px solid var(--rule); padding: 0.55rem 0; }
.pz-item:last-child { border-bottom: 1px solid var(--rule); }
.pz-item-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.9rem; }
.pz-item-info { flex: 1 1 14rem; min-width: 0; display: flex; flex-direction: column; }
.pz-item-title { font-weight: 600; }
.pz-item-meta { font-size: 0.82rem; color: var(--muted); }
.pz-item-slot:not(:empty) { margin-top: 0.7rem; }
.pz-item.open .pz-item-title { color: var(--accent); }
.puzzle-fig { max-width: var(--wide) !important; margin: 1.6rem auto; }
.puzzle-fig + .puzzle-fig { margin-top: 2.2rem; }
.start.alt { background: transparent; color: var(--ink); border: 1.5px solid var(--ink); padding: calc(0.55rem - 1.5px) 1rem; margin-left: 0.4rem; }
@media (max-width: 480px) { .start.alt { margin-left: 0; margin-top: 0.5rem; } }
/* KaTeX keeps a hidden MathML copy of every formula for screen readers. It is absolutely positioned at
 * the place of the formula, and near the right edge of a narrow page it widened the page. Pin it to the
 * left edge instead; it stays hidden and readable by assistive technology. */
.katex .katex-mathml { left: 0; }

/* puzzles: the linked representations (picture, dots and arrows, sets) */
.pz .am-stage { flex-direction: column; align-items: center; gap: 0.55rem; }
.pz .am-stage > svg { max-width: 440px; }
.pz-reps { align-self: center; }
.pz-diag { opacity: 0; transition: opacity 0.45s; pointer-events: none; }
.pz-rep-dots .pz-diag { opacity: 1; }
.pz .am-stage > svg > g:first-child, .pz-over { transition: opacity 0.45s; }
.pz-rep-dots .am-stage > svg > g:first-child, .pz-rep-dots .pz-over { opacity: 0.14; }
.pz-rep-dots .pz-tok { opacity: 1; }
.pz-arrow { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; opacity: 0.85; transition: opacity 0.15s; }
.pz-arrow.head { fill: currentColor; stroke: none; }
.pz[data-hl="0"] .pz-arrow:not(.k0), .pz[data-hl="1"] .pz-arrow:not(.k1), .pz[data-hl="2"] .pz-arrow:not(.k2), .pz[data-hl="3"] .pz-arrow:not(.k3) { opacity: 0.08; }
.pz-node { fill: var(--panel); stroke: var(--ink); stroke-width: 1.5; }
.pz-node-label { font-family: var(--font-ui); font-size: 10px; font-weight: 600; fill: var(--ink); text-anchor: middle; }
.pz-dot { fill: var(--token); stroke: var(--token); stroke-width: 1.5; }
.pz-dot-label { font-family: var(--font-ui); font-size: 10px; font-weight: 700; fill: var(--token-ink); text-anchor: middle; }
.pz-point { fill: none; stroke: var(--setup); stroke-width: 3.5; }
.pz-key { max-width: 440px; margin: 0; }
.pz-sets { width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 0.5rem; border-top: 1px solid var(--rule); padding-top: 0.6rem; }
.pz-strip { display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; font-size: 0.8rem; }
.pz-strip-label { color: var(--muted); margin-right: 0.2rem; }
.pz-strip-dot { padding: 0.05rem 0.5rem; border-radius: 999px; border: 1.5px dashed var(--rule); color: var(--muted); cursor: default; }
.pz-strip-dot.on { border: 1.5px solid var(--token); background: var(--token); color: var(--token-ink); font-weight: 600; }
.pz-setmode { align-self: flex-start; }
.pz-land-svg { width: 100%; height: auto; display: block; }
.pz-land-size { font-family: var(--font-ui); font-size: 9px; fill: var(--muted); }
.pz-land-edge { fill: none; stroke: currentColor; stroke-width: 0.9; opacity: 0.3; }
.pz-land-edge.been { stroke-width: 2.4; opacity: 0.95; }
.pz-land-node { fill: var(--panel); stroke: var(--muted); stroke-width: 1.2; }
.pz-land-node.goal { stroke: var(--payoff); stroke-width: 2.2; }
.pz-land-node.been { fill: var(--muted); }
.pz-land-node.here { fill: var(--token); stroke: var(--setup); stroke-width: 3; }
.pz-pairs { overflow-x: auto; }
.pz-pair-table { border-collapse: collapse; font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.pz-pair-table th { font-weight: 600; padding: 0.15rem 0.4rem; color: var(--muted); }
.pz-pair-table td { min-width: 2rem; height: 1.8rem; text-align: center; border: 1px solid var(--rule); color: var(--muted); }
.pz-pair-table td.none { border: 0; }
.pz-pair-table td.in { background: var(--token); color: var(--token-ink); font-weight: 700; }
.pz-pair-table td.stuck { color: var(--warn); font-weight: 700; }
.pz-pair-table td.in.stuck { background: var(--warn); color: var(--paper); }
@media (prefers-reduced-motion: reduce) { .pz-diag, .pz .am-stage > svg > g:first-child, .pz-over { transition: none; } }
/* a long inline formula inside an answer scrolls sideways within its paragraph on a narrow screen */
.pause-body p, .answer p, .exercises li > p { overflow-x: auto; overflow-y: hidden; padding-bottom: 0.1rem; }

/* ------------------------------------- panel: Show Me The Math
 * A folded <details class="maths"> at the end of a section. It maps the plain words of the
 * section to their names in the literature. Notation and names of people are allowed here only.
 * book.js opens and closes the panels and remembers the reader's choice. */
.maths {
  border: 1px solid var(--rule); border-left: 3px solid var(--muted); border-radius: 0 6px 6px 0;
  background: var(--panel); margin-top: 2.6rem; margin-bottom: 1.5rem;
  font-family: var(--font-ui); font-size: 0.9rem; line-height: 1.5;
}
.maths > summary { cursor: pointer; list-style: none; padding: 0.75rem 1rem; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.1rem 0.75rem; }
.maths > summary::-webkit-details-marker { display: none; }
.maths > summary .box-label { display: inline; margin: 0; color: var(--ink); font-size: 0.92rem; letter-spacing: 0.01em; text-transform: none; }
.maths > summary .maths-sub { color: var(--muted); font-size: 0.85rem; }
.maths > summary::after { content: "Open"; margin-left: auto; font-size: 0.85rem; font-weight: 600; color: var(--accent); text-decoration: underline; text-underline-offset: 0.2em; }
.maths[open] > summary::after { content: "Close"; }
.maths[open] > summary { border-bottom: 1px solid var(--rule); }
.maths-body { padding: 0.4rem 1rem 0.9rem; overflow-x: auto; }
.maths .katex { font-size: 1.08em; }
.gloss { width: 100%; border-collapse: collapse; table-layout: fixed; }
.gloss th { text-align: left; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); padding: 0.45rem 0.8rem 0.35rem 0; border-bottom: 1.5px solid var(--ink); }
.gloss th:first-child, .gloss td:first-child { width: 33%; }
.gloss td { vertical-align: top; padding: 0.5rem 0.8rem 0.5rem 0; border-bottom: 1px solid var(--rule); overflow-wrap: break-word; }
.gloss td:last-child, .gloss th:last-child { padding-right: 0; }
.gloss td:first-child { font-family: var(--font-body); font-style: italic; font-size: 0.95rem; }
.gloss td b, .maths-facts b { font-weight: 600; }
.maths-facts { margin-top: 0.9rem; }
.chapter .maths-facts p { margin-bottom: 0.55rem; }
.chapter .maths-refs { list-style: none; padding: 0.7rem 0 0; margin: 0.9rem 0 0; border-top: 1px solid var(--rule); font-size: 0.8rem; color: var(--muted); }
.chapter .maths-refs li { margin-bottom: 0.3rem; overflow-wrap: anywhere; }
.maths-refs::before { content: "References"; display: block; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; margin-bottom: 0.35rem; }
@media (max-width: 560px) {
  .gloss, .gloss tbody, .gloss tr, .gloss td { display: block; width: auto !important; }
  .gloss thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .gloss tr { padding: 0.55rem 0; border-bottom: 1px solid var(--rule); }
  .gloss td { padding: 0; border-bottom: 0; }
  .gloss td:first-child { margin-bottom: 0.2rem; }
  .gloss td:first-child::before { content: "In the book"; }
  .gloss td:last-child::before { content: "In the literature"; }
  .gloss td::before { display: block; font-family: var(--font-ui); font-style: normal; font-size: 0.68rem; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); }
  .gloss td:last-child::before { margin-top: 0.3rem; }
}

/* Bonus question: a card in a main chapter that asks the question a side trip answers, with a link to it.
 * It is part of the text on a small screen and stands above the panel, in the same column, on a wide one. */
.bonus {
  border: 1px solid var(--rule); border-left: 3px solid var(--warn); border-radius: 0 6px 6px 0; background: var(--panel);
  padding: 0.85rem 1.1rem 0.9rem; margin-top: 1.5rem; margin-bottom: 1.5rem;
  font-family: var(--font-ui); font-size: 0.95rem; line-height: 1.5;
}
.bonus .box-label { color: var(--warn); }
.chapter .bonus p { margin-bottom: 0.55rem; }
.chapter .bonus .bonus-go { margin-bottom: 0; }
.bonus-go a { font-weight: 600; white-space: nowrap; }
.bonus-where { display: block; color: var(--muted); font-size: 0.82rem; margin-top: 0.1rem; }

/* On a wide screen the panel stands beside its section, in a column to the right of the page.
 * The reading column keeps its width (text and figures are not squeezed); it and the panel are centred together.
 * The <details> becomes a rail as tall as the section; its heading and its body stay in view while the
 * section scrolls (where the browser cannot do that, the panel stays at the top of the section).
 * book.js writes the height of the heading to --maths-head. Bonus questions stand above the panel.
 * Below 1120 px nothing here applies. */
@supports selector(:has(a)) {
  @media (min-width: 1120px) {
    :root { --side-gap: 2.5rem; --side: 24rem; }
    body:has(#view details.maths) .bar,
    body:has(#view details.maths) main { max-width: calc(var(--measure) + 2.5rem + var(--side-gap) + var(--side)); }
    body:has(#view details.maths) main { padding-right: calc(1.25rem + var(--side-gap) + var(--side)); }
    .section:has(> details.maths) { position: relative; }
    .section > details.maths {
      position: absolute; top: 0; bottom: 0; left: calc(100% + var(--side-gap)); width: var(--side); max-width: none;
      margin: 0; border: 0; border-radius: 0; background: none;
      display: flex; flex-direction: column;
    }
    /* book.js marks the section when it has measured the cards: each card gets its place, the panel starts below them */
    .section.side-ready > .bonus { position: absolute; top: var(--bonus-top, 0); left: calc(100% + var(--side-gap)); width: var(--side); max-width: none; margin: 0; }
    .section.side-ready > details.maths { top: var(--side-top, 0); }
    .section > details.maths > summary {
      position: sticky; top: 0.75rem; z-index: 1; flex: none;
      background: var(--panel); border: 1px solid var(--rule); border-left: 3px solid var(--muted); border-radius: 0 6px 6px 0;
    }
    .section > details.maths[open] > summary { border-radius: 0 6px 0 0; }
    .section > details.maths > summary .maths-sub { order: 3; flex-basis: 100%; }
    .section > details.maths::details-content { flex: 1 1 auto; min-height: 0; }
    .section > details.maths > .maths-body {
      position: sticky; top: calc(0.75rem + var(--maths-head, 4.5rem));
      max-height: calc(100vh - 1.5rem - var(--maths-head, 4.5rem)); overflow-y: auto; overscroll-behavior: contain;
      background: var(--panel); border: 1px solid var(--rule); border-top: 0; border-left: 3px solid var(--muted); border-radius: 0 0 6px 0;
    }
    /* the column is narrow: each row of the glossary is a pair, the term above its name */
    .section > details.maths .gloss, .section > details.maths .gloss tbody, .section > details.maths .gloss tr, .section > details.maths .gloss td { display: block; width: auto !important; }
    .section > details.maths .gloss thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
    .section > details.maths .gloss tr { padding: 0.55rem 0; border-bottom: 1px solid var(--rule); }
    .section > details.maths .gloss td { padding: 0; border-bottom: 0; }
    .section > details.maths .gloss td:first-child { margin-bottom: 0.2rem; }
    .section > details.maths .gloss td:first-child::before { content: "In the book"; }
    .section > details.maths .gloss td:last-child::before { content: "In the literature"; margin-top: 0.3rem; }
    .section > details.maths .gloss td::before { display: block; font-family: var(--font-ui); font-style: normal; font-size: 0.68rem; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); }
  }
}

/* the switch in the top bar that opens or closes every panel */
.bar-maths { font-family: var(--font-ui); font-size: 0.8125rem; font-weight: 600; color: var(--muted); background: none; border: 1px solid var(--rule); border-radius: 999px; padding: 0.15rem 0.7rem; cursor: pointer; white-space: nowrap; }
.bar-maths:hover { color: var(--ink); border-color: var(--muted); }
.bar-maths[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.mval, .mquote { font-variant-numeric: tabular-nums; white-space: nowrap; }
