:root {
  --paper: #fbfaf6; --panel: #f1efe8; --ink: #1f1d1a; --muted: #6e6a62; --rule: rgba(31, 29, 26, 0.12);
  /* one color per rule, used everywhere */
  --random: #8c8a85; --least: #d9541e; --two: #12876f; --fresh: #3d6bd6; --stagger: #8a4fb8; --tied: #c2185b; --home: #8d6e63; --bounded: #3f51b5; --rr: #546e7a; --retry: #0277bd;
  --idle: #e8a317; --report: #b07a10;
  /* request moods: calm -> fed up */
  --mood-0: #7fd1b0; --mood-1: #f2d16b; --mood-2: #f39a55; --mood-3: #e5533d;
  --body-font: "Source Serif 4", Georgia, serif; --ui-font: "Inter", system-ui, -apple-system, sans-serif;
  --text: 680px; --wide: 900px;
  color-scheme: light; background: var(--paper);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #161513; --panel: #23211e; --ink: #ece8df; --muted: #9d978c; --rule: rgba(236, 232, 223, 0.13);
    --random: #a3a09a; --least: #f2774a; --two: #2fc29f; --fresh: #6f93f0; --report: #e0aa3e; --stagger: #b183dc; --tied: #f06292; --home: #bcaaa4; --bounded: #9fa8da; --rr: #90a4ae; --retry: #4fc3f7;
  }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --paper: #161513; --panel: #23211e; --ink: #ece8df; --muted: #9d978c; --rule: rgba(236, 232, 223, 0.13);
    --random: #a3a09a; --least: #f2774a; --two: #2fc29f; --fresh: #6f93f0; --report: #e0aa3e; --stagger: #b183dc; --tied: #f06292; --home: #bcaaa4; --bounded: #9fa8da; --rr: #90a4ae; --retry: #4fc3f7;
  }
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 19px/1.62 var(--body-font); }
main { padding: 0 16px 120px; }
header, section > h2, section > h3, section > p, section > ul, section > details, footer, .draft-note { max-width: var(--text); margin-left: auto; margin-right: auto; }
.draft-note { font: 12.5px var(--ui-font); color: var(--muted); padding-top: 16px; }

header { padding: 72px 0 12px; }
h1 { font-size: clamp(40px, 8vw, 68px); line-height: 1.02; letter-spacing: -0.02em; margin: 0 0 16px; }
.dek { font-size: 22px; line-height: 1.45; color: var(--muted); margin: 0; }

section { padding-top: 56px; }
h2 { font-size: 30px; line-height: 1.15; letter-spacing: -0.01em; margin: 0 0 18px; }
h2 .num { display: block; font: 600 13px/1 var(--ui-font); letter-spacing: 0.12em; color: var(--muted); margin-bottom: 10px; }
h3 { font: 600 18px/1.3 var(--ui-font); margin: 36px auto 10px; }
p { margin: 0 0 1.05em; }
strong { font-weight: 650; }
a { color: var(--two); text-underline-offset: 2px; }
a.cite { color: var(--muted); text-decoration: none; font-size: 0.9em; }
a.cite:hover { color: var(--two); text-decoration: underline; }
.c-random { color: var(--random); font-weight: 650; } .c-least { color: var(--least); font-weight: 650; }
.c-two { color: var(--two); font-weight: 650; } .c-fresh { color: var(--fresh); font-weight: 650; } .c-report { color: var(--report); font-weight: 650; }
.key { display: inline-block; vertical-align: -2px; }
blockquote { max-width: var(--text); margin: 1.4em auto 1.6em; border-left: 3px solid var(--two); padding: 4px 0 4px 20px; font-size: 1.08em; font-style: italic; color: var(--ink); }
blockquote .cite { font-style: normal; }

/* figures */
.figure { max-width: var(--wide); margin: 28px auto 34px; background: var(--panel); border-radius: 14px; padding: 14px 16px; }
.figure canvas { display: block; width: 100%; }
.panes { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.pane-title { font: 600 13.5px var(--ui-font); margin: 0 0 4px; }
.figcaption { font: 13.5px/1.5 var(--ui-font); color: var(--muted); margin: 10px 2px 0; }
.figcaption b { color: var(--ink); font-weight: 600; }
.controls { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin: 0 0 10px; font: 13.5px var(--ui-font); }
.controls label { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.controls output { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; min-width: 5.5em; }
.controls .spacer { flex: 1; }
.ctl-name { color: var(--muted); margin-right: 2px; }
.seg { display: inline-flex; background: var(--paper); border: 1px solid var(--rule); border-radius: 9px; padding: 2px; }
.seg button { font: 600 13px var(--ui-font); border: 0; background: transparent; color: var(--muted); padding: 5px 10px; border-radius: 7px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.seg.rules button[data-v="random"][aria-pressed="true"] { background: var(--random); color: #fff; }
.seg.rules button[data-v="least"][aria-pressed="true"] { background: var(--least); color: #fff; }
.seg.rules button[data-v="two"][aria-pressed="true"] { background: var(--two); color: #fff; }
.btn { font: 600 13px var(--ui-font); border: 1px solid var(--rule); background: var(--paper); color: var(--ink); padding: 6px 12px; border-radius: 9px; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
input[type="range"] { accent-color: var(--two); width: 160px; }
.scoreboard { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; margin-top: 10px; }
.stat { background: var(--paper); border-radius: 10px; padding: 8px 12px; }
.stat .label { font: 600 11px/1.2 var(--ui-font); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.stat .value { font: 650 24px/1.25 var(--ui-font); font-variant-numeric: tabular-nums; }
.stat .unit { font: 13px var(--ui-font); color: var(--muted); margin-left: 3px; }
.stat.ref .value { color: var(--muted); font-size: 18px; padding-top: 4px; }
.legend-faces { display: flex; flex-direction: column; gap: 4px; font: 12.5px var(--ui-font); color: var(--muted); margin-top: 8px; }
.legend-faces canvas { width: 16px; height: 16px; vertical-align: -3px; margin-right: 4px; display: inline-block; }
.legend-faces .box { display: inline-block; width: 18px; height: 10px; border-radius: 3px; vertical-align: 0; margin-right: 5px; }

/* charts */
.chart { position: relative; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font: 12.5px var(--ui-font); color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 14px; height: 4px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.chart-tip { position: absolute; pointer-events: none; opacity: 0; transition: opacity .12s; background: var(--paper); border: 1px solid var(--rule); border-radius: 8px; padding: 7px 9px; font: 12px/1.5 var(--ui-font); min-width: 170px; box-shadow: 0 4px 16px rgba(0,0,0,.08); }
.chart-tip i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.tip-x { color: var(--muted); margin-bottom: 2px; } .tip-m { color: var(--muted); }
.stair-text { font: 15px/1.55 var(--ui-font); min-height: 4.6em; margin: 10px 2px 0; font-variant-numeric: tabular-nums; }
.stair-btns { display: flex; gap: 8px; margin-top: 8px; }

details { background: var(--panel); border-radius: 12px; padding: 4px 18px; margin: 1.4em auto; }
details[open] { padding-bottom: 14px; }
summary { cursor: pointer; font: 600 15px var(--ui-font); padding: 10px 0; list-style: none; }
summary::before { content: "＋"; color: var(--two); margin-right: 8px; }
details[open] summary::before { content: "－"; }
details p { font-size: 17.5px; }

footer { padding-top: 64px; font: 14px/1.6 var(--ui-font); color: var(--muted); }
footer ol { padding-left: 20px; } footer li { margin: 4px 0; }
.closing { font-size: 21px; line-height: 1.5; }
@media (max-width: 720px) { .panes { grid-template-columns: 1fr; } body { font-size: 18px; } }

.legend-lead { color: var(--ink); font-weight: 600; }
.legend-faces .legend-lead + span { margin-left: -6px; }
.legend-row { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; }
.ctl-static { color: var(--muted); } .ctl-static b { color: var(--ink); font-weight: 600; }

table.data { border-collapse: collapse; font: 14.5px var(--ui-font); width: 100%; font-variant-numeric: tabular-nums; background: var(--paper); border-radius: 10px; overflow: hidden; }
table.data th, table.data td { padding: 7px 14px; text-align: right; border-bottom: 1px solid var(--rule); }
table.data th { font-weight: 600; } table.data td:first-child, table.data th:first-child { text-align: left; color: var(--muted); }
table.data tr:last-child td { border-bottom: 0; }
.narrow-fig { max-width: 640px; }
.square-panels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.square-panels canvas { width: 100%; }
.panel-cap { font: 13px/1.4 var(--ui-font); color: var(--muted); text-align: center; margin-top: 4px; }
.panel-cap b { color: var(--ink); font-size: 18px; display: block; }

h1 .part { display: block; font-size: 0.5em; color: var(--muted); letter-spacing: -0.01em; margin-top: 10px; }
.next-part { text-align: center; }
.next-part a { font: 600 18px var(--ui-font); text-decoration: none; background: var(--two); color: #fff; padding: 12px 22px; border-radius: 10px; display: inline-block; }
.legend i.dashed { background: repeating-linear-gradient(90deg, currentColor 0 5px, transparent 5px 8px) !important; }

details.deep { max-width: var(--text); }
details.deep .figure { background: var(--paper); margin-left: -8px; margin-right: -8px; }
details.deep blockquote { margin-left: 0; }
.aside-link { font: 15px var(--ui-font); color: var(--muted); margin-top: 18px; }
.c-stagger { color: var(--stagger); font-weight: 650; }
.seg.sync button[data-v="false"][aria-pressed="true"], .seg.info button[data-v="staggered"][aria-pressed="true"] { background: var(--stagger); color: #fff; }
.seg.measure button[data-v="time"][aria-pressed="true"] { background: var(--fresh); color: #fff; }
.c-time { color: var(--fresh); font-weight: 650; }
.seg.stall button[data-v="0.05"][aria-pressed="true"] { background: var(--mood-3); color: #fff; }
.try { font: 14px/1.5 var(--ui-font); margin: 0 2px 10px; color: var(--ink); }
.try .step { display: inline-block; width: 18px; height: 18px; border-radius: 50%; background: var(--ink); color: var(--paper); font-size: 11px; font-weight: 700; text-align: center; line-height: 18px; margin: 0 4px 0 8px; }
.try .step:first-of-type { margin-left: 4px; }
.c-stall { color: var(--mood-3); font-weight: 650; }
.c-tied { color: var(--tied); font-weight: 650; }
.seg.rules button[data-v="tied"][aria-pressed="true"] { background: var(--tied); color: #fff; }
.ringkey { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2.5px solid; vertical-align: -2px; margin-right: 5px; }
.c-home { color: var(--home); font-weight: 650; } .c-bounded { color: var(--bounded); font-weight: 650; }
.seg.rules button[data-v="home"][aria-pressed="true"] { background: var(--home); color: #fff; }
.seg.rules button[data-v="bounded"][aria-pressed="true"] { background: var(--bounded); color: #fff; }
.c-rr { color: var(--rr); font-weight: 650; }
.seg.rules button[data-v="rr"][aria-pressed="true"] { background: var(--rr); color: #fff; }
.fan-out { font: 15px var(--ui-font); color: var(--muted); margin: 6px 2px 10px; }
.fan-out b { font-size: 26px; color: var(--ink); margin-right: 4px; font-variant-numeric: tabular-nums; }
.fan-grid { display: grid; grid-template-columns: repeat(20, 1fr); gap: 4px; max-width: 520px; }
.fan-grid i { aspect-ratio: 1; border-radius: 3px; background: var(--mood-0); transition: background .2s; }
.fan-grid i.slow { background: var(--mood-3); }

/* page chrome: theme toggle and contents */
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
section { scroll-margin-top: 8px; }
body { position: relative; }
.theme-toggle { position: fixed; z-index: 10; top: 14px; right: 18px; width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid var(--rule); border-radius: 50%; background: var(--paper); color: var(--muted); cursor: pointer; transition: color .15s, border-color .15s; }
.theme-toggle:hover { color: var(--ink); border-color: var(--muted); }
/* where the text column reaches the right edge, the toggle would sit on top of the text, so it hides after the top of the page */
@media (max-width: 800px) {
  .theme-toggle { transition: opacity .2s, transform .2s, color .15s, border-color .15s; }
  body.scrolled .theme-toggle { opacity: 0; transform: translateY(-6px); pointer-events: none; }
}
.toc { display: none; }
@media (min-width: 1320px) {
  .toc { display: block; position: fixed; top: 0; left: 0; width: 210px; max-height: 100vh; overflow-y: auto; padding: 40px 18px 40px 30px; font: 13px/1.4 var(--ui-font); }
  .toc a { color: var(--muted); text-decoration: none; transition: color .15s; }
  .toc a:hover { color: var(--ink); }
  .toc ol { list-style: none; margin: 0; padding: 0; }
  .toc-title { display: block; font-weight: 600; color: var(--ink) !important; margin-bottom: 22px; letter-spacing: -0.005em; }
  .toc-parts > li { margin-bottom: 16px; }
  .toc-part { display: block; font-weight: 600; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; }
  .toc-part span { display: block; font-weight: 400; font-size: 13px; letter-spacing: 0; text-transform: none; margin-top: 2px; }
  .toc-parts > li.current > .toc-part { color: var(--ink); }
  .toc-chapters { margin-top: 10px !important; border-left: 1px solid var(--rule); }
  .toc-chapters a { display: flex; gap: 8px; padding: 4px 0 4px 12px; margin-left: -1px; border-left: 2px solid transparent; }
  .toc-chapters b { font-weight: 600; min-width: 0.7em; font-variant-numeric: tabular-nums; opacity: .7; }
  .toc-chapters a.active { color: var(--ink); border-left-color: var(--two); }
}

.c-retry { color: var(--retry); font-weight: 650; } .c-budget { color: var(--two); font-weight: 650; }
.seg.retry button[data-v="now"][aria-pressed="true"] { background: var(--mood-3); color: #fff; }
.seg.retry button[data-v="budget"][aria-pressed="true"] { background: var(--two); color: #fff; }
.btn.hiccup { border-color: var(--mood-3); color: var(--mood-3); }
.btn.hiccup:disabled { opacity: .6; cursor: default; }
.seg button:disabled { opacity: .4; cursor: default; }
.seg.rules button[data-v="one"][aria-pressed="true"] { background: var(--random); color: #fff; }
.seg.rules button[data-v="cuckoo"][aria-pressed="true"] { background: var(--fresh); color: #fff; }
.next-part a + a { margin-left: 10px; }
.next-part a.back { background: transparent; color: var(--ink); border: 1px solid var(--rule); }
.legend i.sq { width: 11px; height: 11px; border-radius: 2px; vertical-align: -1px; }
.legend i.sq { box-shadow: inset 0 0 0 1px var(--rule); }
.legend i.dot { width: 9px; height: 9px; border-radius: 50%; vertical-align: 0; }
/* step-by-step derivations */
.derive-head { font: 600 13.5px var(--ui-font); color: var(--muted); margin: 18px 0 6px; }
.derive { display: grid; grid-template-columns: auto 1fr; gap: 6px 22px; font-size: 17px; line-height: 1.5; font-variant-numeric: tabular-nums; }
.derive .note { font: 12.5px var(--ui-font); color: var(--muted); margin-left: 10px; }
.derive sup sup { font-size: 0.8em; }
@media (max-width: 600px) { .derive { grid-template-columns: 1fr; gap: 2px; } .derive span:nth-child(even):not(:empty) { padding-left: 14px; margin-bottom: 6px; } }
table.data th.grp { text-align: center; border-bottom: 1px solid var(--rule); }
.pane-title-row { display: flex; align-items: center; justify-content: space-between; min-height: 34px; }
.stair-text.step-text { min-height: 0; margin-bottom: 0; }
.stair-text.step-text + .figcaption { margin-top: 4px; }
/* a displayed equation */
.eq { text-align: center; font-size: 18px; margin: 4px auto 18px; color: var(--ink); }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; margin-left: 6px; font-size: 0.95em; }
.frac > span:first-child { border-bottom: 1.5px solid var(--ink); padding: 0 6px 2px; }
.frac > span:last-child { padding: 2px 6px 0; }
.eq sup { font-size: 0.62em; }
/* previous / next part links above the title */
.part-nav { max-width: var(--text); margin: 0 auto; padding-top: 22px; display: flex; justify-content: space-between; font: 600 13.5px var(--ui-font); }
.part-nav a { color: var(--muted); text-decoration: none; }
.part-nav a:hover { color: var(--ink); }
.part-nav a:only-child { margin-right: auto; }
@media (max-width: 800px) { .part-nav { padding-right: 52px; } } /* leave room for the theme button */
.part-nav + header { padding-top: 40px; }
.twice-out { min-height: 0; margin: 6px 0 0; font-size: 14px; }
[data-fig="twice"] canvas { display: block; margin: 0 auto; }
[data-fig="twice"] .pane-title, [data-fig="twice"] .twice-out { text-align: center; }

/* moving between parts: the title stays put, the page cross-fades (browsers that support cross-page view transitions) */
@view-transition { navigation: auto; }
.title-main { view-transition-name: series-title; }
.toc { view-transition-name: contents; }
.theme-toggle { view-transition-name: theme-toggle; }
::view-transition-group(series-title) { animation-duration: 450ms; animation-timing-function: cubic-bezier(.3, .7, .2, 1); }
::view-transition-old(root) { animation: 200ms ease-out both vt-fade-out; }
::view-transition-new(root) { animation: 420ms cubic-bezier(.2, .7, .2, 1) 60ms both vt-fade-in; }
@keyframes vt-fade-out { to { opacity: 0; } }
@keyframes vt-fade-in { from { opacity: 0; transform: translateY(8px); } }

/* part buttons: the arrow nudges toward where it leads */
.next-part a { transition: filter .2s, background-color .2s; }
.next-part a:hover { filter: brightness(0.93); }
.next-part a.back:hover { filter: none; background: var(--panel); }
.next-part .arr { display: inline-block; transition: transform .25s cubic-bezier(.3, .7, .2, 1); }
.next-part a:hover .arr { transform: translateX(4px); }
.next-part a.back:hover .arr { transform: translateX(-4px); }

/* direction of travel between parts: forward drifts up, back drifts down */
@keyframes vt-up-out { to { opacity: 0; transform: translateY(-28px); } }
@keyframes vt-up-in { from { opacity: 0; transform: translateY(28px); } }
@keyframes vt-down-out { to { opacity: 0; transform: translateY(28px); } }
@keyframes vt-down-in { from { opacity: 0; transform: translateY(-28px); } }
html:active-view-transition-type(forward)::view-transition-old(root) { animation: 260ms cubic-bezier(.4, 0, .6, 1) both vt-up-out; }
html:active-view-transition-type(forward)::view-transition-new(root) { animation: 480ms cubic-bezier(.2, .7, .2, 1) 80ms both vt-up-in; }
html:active-view-transition-type(back)::view-transition-old(root) { animation: 260ms cubic-bezier(.4, 0, .6, 1) both vt-down-out; }
html:active-view-transition-type(back)::view-transition-new(root) { animation: 480ms cubic-bezier(.2, .7, .2, 1) 80ms both vt-down-in; }
/* the links at the top of the page stay put during a transition, so the next one is ready to click right away */
.part-nav { view-transition-name: part-nav; }
::view-transition-group(part-nav) { animation: none; }
::view-transition-old(part-nav) { display: none; }
::view-transition-new(part-nav) { animation: none; }
::view-transition { pointer-events: none; background: var(--paper); } /* behind both pages mid-transition: the theme's paper, never the browser's white */ /* clicks reach the new page while it animates in */
/* inline links: a soft tint of the link's own color on hover (citations and buttons keep their own styles) */
main :is(p, li) > a:not(.cite):not(.next-part a):not([href^="#src"]) { border-radius: 3px; padding: 0 2px; margin: 0 -2px; transition: background-color .15s, text-decoration-color .15s; }
main :is(p, li) > a:not(.cite):not(.next-part a):not([href^="#src"]):hover { background: color-mix(in srgb, var(--two) 15%, transparent); text-decoration-thickness: 2px; }
/* arriving after the curtain of servers: the page starts covered by the same wall of bars (drawn before anything else) */
html.curtain-in body::after { content: ""; position: fixed; inset: 0; z-index: 100; background: repeating-linear-gradient(to right, var(--two) 0 4.5px, var(--paper) 4.5px 6px); }
html.cuckoo-in body::after { content: ""; position: fixed; inset: 0; z-index: 100; background:
  linear-gradient(to right, var(--paper) 2px, transparent 2px 20px, var(--paper) 20px) 0 0 / 22px 22px,
  linear-gradient(to bottom, var(--paper) 2px, transparent 2px 20px, var(--paper) 20px) 0 0 / 22px 22px, var(--fresh); }
