/* Viviani's theorem, formalized. Byrne-inspired palette: one colour per side, everywhere. */

@font-face { font-family: "Caslon Display"; src: url("fonts/caslon-display.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Caslon Text"; src: url("fonts/caslon-text.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Caslon Text"; src: url("fonts/caslon-text-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Caslon Text"; src: url("fonts/caslon-text-bold.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Proof Mono"; src: url("fonts/proof-mono.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }

:root {
  --paper: #edefe9;
  --paper-raised: #f6f7f3;
  --ink: #1a2233;
  --ink-soft: #4b5568;
  --ink-faint: #8a92a1;
  --ink-rgb: 26, 34, 51;
  --rule: rgba(var(--ink-rgb), 0.14);
  --tk-k: #6b2f8f; --tk-c: #6f7a6a; --tk-d: #556052;
  --shadow: rgba(26, 34, 51, 0.12);
  color-scheme: light;

  /* Byrne's primaries. Each one belongs to one side of the triangle. */
  --blue: #1d4f9c;    /* side BC */
  --red: #cb3a24;     /* side CA */
  --yellow: #e1a614;  /* side AB */
  --yellow-ink: #8a6100; /* readable ochre for text */

  --serif: "Caslon Text", "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "STIX Two Text", "Cambria Math", serif;
  --display: "Caslon Display", "Caslon Text", "Iowan Old Style", Georgia, serif;
  --mono: "Proof Mono", "JuliaMono", "DejaVu Sans Mono", "Menlo", "Consolas", monospace;

  --measure: 38rem;
  --note: 16.5rem;
  --gap: clamp(2rem, 4vw, 4.5rem);
  --pad: clamp(1.25rem, 5vw, 4rem);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: clamp(17px, 0.45vw + 15px, 19px);
  line-height: 1.62;
  font-kerning: normal;
  font-variant-ligatures: common-ligatures;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(225, 166, 20, 0.35); }

a { color: inherit; text-decoration-color: var(--ink-faint); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { text-decoration-color: var(--ink); }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; border-radius: 2px; }

p { margin: 0 0 1em; hanging-punctuation: first; }
em, i { font-style: italic; }
strong { font-weight: 700; }
sub, sup { line-height: 0; }

.skip { position: absolute; left: -9999px; top: 0; background: var(--ink); color: var(--paper); padding: 0.5rem 1rem; z-index: 10; }
.skip:focus { left: 1rem; top: 1rem; }

/* Colour words */
.c-blue { color: var(--blue); }
.c-red { color: var(--red); }
.c-yellow { color: var(--yellow-ink); }
.sw { display: inline-block; width: 0.9em; height: 0.22em; vertical-align: 0.22em; border-radius: 1px; margin-right: 0.15em; }
.sw-blue { background: var(--blue); } .sw-red { background: var(--red); } .sw-yellow { background: var(--yellow); }

.m { font-style: italic; }                 /* a variable in running text */
.mr { font-style: normal; }                /* upright maths symbols */
.nowrap { white-space: nowrap; }
code, kbd, .mono { font-family: var(--mono); font-size: 0.84em; }
:not(pre) > code { background: rgba(var(--ink-rgb), 0.06); padding: 0.08em 0.3em; border-radius: 3px; }

/* ---------- Top bar ---------- */
.top {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1.5rem;
  max-width: 82rem; margin: 0 auto; padding: 1.4rem var(--pad) 0;
}
.wordmark { font-family: var(--display); font-size: 1.15rem; text-decoration: none; letter-spacing: 0.01em; display: inline-flex; align-items: center; gap: 0.55rem; }
.wordmark svg { width: 1.15rem; height: 1.15rem; transform: translateY(0.12rem); }
.top nav { display: flex; flex-wrap: wrap; gap: 0.35rem 1.4rem; font-size: 0.92rem; }
.top nav a { text-decoration: none; color: var(--ink-soft); }
.top nav a:hover { color: var(--ink); text-decoration: underline; }
@media (max-width: 760px) { .top nav { display: none; } }

/* ---------- Hero ---------- */
.hero {
  max-width: 82rem; margin: 0 auto; padding: clamp(2.5rem, 7vw, 6rem) var(--pad) clamp(3rem, 6vw, 5rem);
  display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: var(--gap); align-items: center;
}
@media (max-width: 960px) { .hero { grid-template-columns: minmax(0, 1fr); } }

.hero h1 {
  font-family: var(--display); font-weight: 400;
  font-size: clamp(3.2rem, 7.4vw, 6.6rem); line-height: 0.92; letter-spacing: -0.015em;
  margin: 0 0 1.6rem;
}
.hero h1 .line { display: block; }
.hero h1 .line:nth-child(2) { padding-left: 0.9em; }
.lede { font-size: 1.22em; line-height: 1.5; max-width: 30rem; margin-bottom: 1.1rem; }
.sublede { color: var(--ink-soft); max-width: 30rem; }
.byline { color: var(--ink-soft); font-style: italic; margin: 1.6rem 0 1.8rem; }

.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.dl { margin: 1rem 0 0; font-size: 0.92rem; color: var(--ink-soft); }
.btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-family: var(--serif); font-size: 0.95rem; line-height: 1;
  padding: 0.78rem 1.15rem; border-radius: 3px; cursor: pointer;
  border: 1px solid var(--ink); background: transparent; color: var(--ink); text-decoration: none;
  transition: background-color 160ms ease, color 160ms ease;
}
.btn:hover { background: var(--ink); color: var(--paper); }
.btn.solid { background: var(--ink); color: var(--paper); }
.btn.solid:hover { background: var(--blue); border-color: var(--blue); }
.btn.quiet { border-color: var(--rule); color: var(--ink-soft); }
.btn.quiet:hover { background: rgba(var(--ink-rgb), 0.06); color: var(--ink); }
.btn svg { width: 1em; height: 1em; }

.figure { margin: 0; }
.figure svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: none; user-select: none; -webkit-user-select: none; }
.figcap { font-size: 0.9rem; color: var(--ink-soft); font-style: italic; margin-top: 0.4rem; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.4rem 1.2rem; align-items: baseline; }
.figcap button { font: inherit; font-style: normal; background: none; border: 0; padding: 0; color: var(--ink); text-decoration: underline; text-decoration-color: var(--ink-faint); text-underline-offset: 0.18em; cursor: pointer; }

.sum {
  font-family: var(--serif); font-size: clamp(1.05rem, 1.4vw, 1.3rem); margin-top: 0.8rem;
  font-variant-numeric: tabular-nums lining-nums; display: flex; flex-wrap: wrap; gap: 0.2rem 0.45rem; align-items: baseline;
}
.sum .num { min-width: 3.1em; display: inline-block; text-align: right; }
.sum .eq { color: var(--ink-faint); }
.sum .total { font-weight: 700; }

/* SVG drawing language */
.vx, .pt-label, .drag-hint, .rod-label { paint-order: stroke; stroke: var(--paper); stroke-width: 5px; stroke-linejoin: round; }
.tri { fill: none; stroke: var(--ink); stroke-width: 2.2; stroke-linejoin: round; }
.tri-fill { fill: rgba(var(--ink-rgb), 0.035); }
.vx { font-family: var(--serif); font-style: italic; font-size: 22px; fill: var(--ink); }
.vx-sm { font-size: 17px; }
.d-blue { stroke: var(--blue); } .d-red { stroke: var(--red); } .d-yellow { stroke: var(--yellow); }
.f-blue { fill: var(--blue); } .f-red { fill: var(--red); } .f-yellow { fill: var(--yellow); }
.dist { stroke-width: 5; stroke-linecap: butt; fill: none; }
.ra { fill: none; stroke-width: 1.4; }
.pt { fill: var(--ink); }
.pt-ring { fill: none; stroke: var(--ink); stroke-width: 1.2; opacity: 0; }
.pt-hit { fill: transparent; cursor: grab; }
.pt-hit:active { cursor: grabbing; }
.pt-label { font-family: var(--serif); font-style: italic; font-size: 21px; fill: var(--ink); pointer-events: none; dominant-baseline: central; text-anchor: middle; }
.rod-frame { fill: none; stroke: var(--ink); stroke-width: 1.2; }
.rod-tick { stroke: var(--ink); stroke-width: 1.2; }
.rod-label { font-family: var(--serif); font-style: italic; font-size: 17px; fill: var(--ink-soft); }
.alt { stroke: var(--ink-faint); stroke-width: 1.1; stroke-dasharray: 3 5; fill: none; }
.guide { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 2 6; opacity: 0.55; fill: none; }
.drag-hint { font-family: var(--serif); font-style: italic; font-size: 15px; fill: var(--ink-soft); }

#hero-fig [data-focus="true"] .pt-ring { opacity: 1; }
.pulse { animation: pulse 2.4s ease-out 3; transform-box: fill-box; transform-origin: center; }
@keyframes pulse { 0% { opacity: 0.7; transform: scale(0.6); } 100% { opacity: 0; transform: scale(2.4); } }

/* ---------- Sections ---------- */
main { counter-reset: none; }
.section {
  max-width: 82rem; margin: 0 auto; padding: clamp(3.5rem, 8vw, 7rem) var(--pad) 0;
}
.row {
  display: grid; grid-template-columns: minmax(0, var(--measure)) minmax(0, var(--note));
  column-gap: var(--gap); justify-content: start;
}
.row > .main { grid-column: 1; min-width: 0; }
.row > .aside { grid-column: 2; min-width: 0; }
.wide { grid-column: 1 / -1; }
@media (max-width: 1040px) {
  .row { grid-template-columns: minmax(0, 1fr); }
  .row > .aside { grid-column: 1; margin: 0.4rem 0 2rem; }
}

.section h2 {
  font-family: var(--display); font-weight: 400; font-size: clamp(2.2rem, 4.2vw, 3.4rem);
  line-height: 1.02; letter-spacing: -0.01em; margin: 0 0 1.6rem; max-width: 18ch;
}
.section h3 { font-family: var(--serif); font-weight: 700; font-size: 1.12rem; margin: 2.6rem 0 0.7rem; line-height: 1.3; }
.section h3 .h3-sub { display: block; font-weight: 400; font-style: italic; color: var(--ink-soft); }

/* Margin notes: plain-language glosses */
.plain { font-size: 0.93rem; line-height: 1.55; color: var(--ink-soft); padding-top: 0.25rem; }
.plain .plain-h { display: flex; align-items: center; gap: 0.5rem; font-style: italic; color: var(--ink); margin-bottom: 0.35rem; }
.plain .plain-h svg { width: 0.95rem; height: 0.95rem; flex: none; }
.plain p { margin-bottom: 0.7em; }
@media (max-width: 1040px) {
  .plain { background: var(--paper-raised); padding: 1rem 1.15rem 0.4rem; border-radius: 4px; }
}

/* Display maths */
.display-math {
  font-size: clamp(1.15rem, 2vw, 1.5rem); line-height: 1.5; margin: 1.6rem 0 1.8rem; padding: 0.2rem 0;
  font-variant-numeric: lining-nums; overflow-x: auto;
}
.display-math .row-eq { white-space: nowrap; }
.display-math .bar { display: inline-block; border-bottom: 3px solid; line-height: 1.15; }
.display-math .bar.b { border-color: var(--blue); }
.display-math .bar.r { border-color: var(--red); }
.display-math .bar.y { border-color: var(--yellow); }
.display-math .op { color: var(--ink-faint); padding: 0 0.25em; }

/* Code */
.code {
  position: relative; background: var(--paper-raised); border: 1px solid var(--rule); border-radius: 4px;
  margin: 1.4rem 0 1.6rem;
}
.code pre {
  margin: 0; padding: 1.1rem 1.2rem 1.2rem; overflow-x: auto; font-family: var(--mono);
  font-size: 13.4px; line-height: 1.62; tab-size: 2; color: var(--ink);
}
.code.statement pre { font-size: 14.2px; }
.code-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: 0.55rem 0.75rem 0.55rem 1.2rem; border-bottom: 1px solid var(--rule); font-size: 0.86rem; color: var(--ink-soft);
}
.code-bar .tools { display: flex; gap: 0.5rem; }
.code-bar .btn { padding: 0.45rem 0.75rem; font-size: 0.82rem; }
.full pre { max-height: min(78vh, 56rem); }
.ln { display: inline-block; width: 2.6em; margin-left: -0.3em; padding-right: 1em; text-align: right; color: var(--ink-faint); user-select: none; -webkit-user-select: none; }
.cl { display: block; border-radius: 2px; }
.cl.hl { background: rgba(225, 166, 20, 0.16); }
.tk-k { color: var(--tk-k); }              /* keywords */
.tk-t { color: var(--blue); }          /* tactics */
.tk-c { color: var(--tk-c); font-style: normal; }  /* comments */
.tk-d { color: var(--tk-d); }              /* docstrings */
.tk-n { color: var(--ink); font-weight: 700; } /* declared names */
.tk-s { color: var(--red); }
.ln-blue { box-shadow: inset 0 -2px 0 var(--blue); }
.ln-red { box-shadow: inset 0 -2px 0 var(--red); }
.ln-yellow { box-shadow: inset 0 -2px 0 var(--yellow); }

/* Declaration map */
.decls { list-style: none; padding: 0; margin: 1.4rem 0 0; }
.decls li { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.1rem; padding: 0.75rem 0; border-top: 1px solid var(--rule); }
.decls li:last-child { border-bottom: 1px solid var(--rule); }
.decls a { font-family: var(--mono); font-size: 0.86rem; text-decoration: none; color: var(--ink); word-break: break-all; }
.decls a:hover { text-decoration: underline; }
.decls span { color: var(--ink-soft); font-size: 0.95rem; }

/* Stepper (area proof) */
.stepper { margin-top: 1rem; }
.stepper .figure { max-width: 31rem; }
.steps { list-style: none; counter-reset: st; padding: 0; margin: 1.2rem 0 0; }
.steps li { counter-increment: st; position: relative; padding: 0.55rem 0 0.55rem 2.3rem; color: var(--ink-faint); transition: color 300ms ease; }
.steps li::before {
  content: counter(st); position: absolute; left: 0; top: 0.55rem; width: 1.55rem; height: 1.55rem;
  border-radius: 50%; border: 1px solid currentColor; display: grid; place-items: center; font-size: 0.85rem; line-height: 1;
}
.steps li.on { color: var(--ink); }
.steps li.on::before { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.step-controls { display: flex; gap: 0.6rem; margin-top: 0.9rem; align-items: center; }
.step-controls .count { margin-left: 0.4rem; color: var(--ink-soft); font-size: 0.9rem; font-style: italic; }

#area-fig .sub { transition: opacity 600ms ease; opacity: 0; }
#area-fig .join { transition: stroke-dashoffset 900ms ease, opacity 300ms ease; }
#area-fig .dist, #area-fig .ra, #area-fig .alab { transition: opacity 500ms ease; opacity: 0; }
#area-fig .bigalt { transition: opacity 500ms ease; opacity: 0; }
#area-fig[data-step="1"] .sub, #area-fig[data-step="2"] .sub, #area-fig[data-step="3"] .sub { opacity: 1; }
#area-fig[data-step="2"] .dist, #area-fig[data-step="2"] .ra, #area-fig[data-step="2"] .alab,
#area-fig[data-step="3"] .dist, #area-fig[data-step="3"] .ra { opacity: 1; }
#area-fig[data-step="3"] .bigalt { opacity: 1; }
#area-fig .alab { font-family: var(--serif); font-style: italic; font-size: 16px; }
.area-eq { min-height: 3.4em; font-size: 1.05rem; margin-top: 0.6rem; font-variant-numeric: lining-nums; }
.area-eq [data-for] { display: none; }
.area-eq [data-for].on { display: block; animation: rise 420ms cubic-bezier(.2,.7,.2,1); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Larger figure lettering on narrow screens, where the SVGs are scaled down */
@media (max-width: 620px) {
  #hero-fig .vx { font-size: 34px; }
  #hero-fig .pt-label { font-size: 32px; }
  #hero-fig .rod-label { font-size: 27px; }
  #hero-fig .drag-hint { display: none; }
  #hero-fig .dist { stroke-width: 7; }
  #area-fig .vx, #w-fig .vx { font-size: 28px; }
  #area-fig .pt-label, #w-fig .pt-label { font-size: 27px; }
  #area-fig .alab { font-size: 22px; }
}

/* Weights figure */
.weights { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.55rem; margin-top: 1rem; font-variant-numeric: tabular-nums lining-nums; }
.wrow { display: grid; grid-template-columns: 6.6rem minmax(0, 1fr) 3.4rem; align-items: center; gap: 0.8rem; font-size: 0.95rem; }
.wbar { height: 0.55rem; background: rgba(var(--ink-rgb), 0.08); border-radius: 1px; overflow: hidden; }
.wbar i { display: block; height: 100%; width: 0; transition: width 120ms linear; }
.wrow .wv { text-align: right; }
.formal-steps { counter-reset: fs; list-style: none; padding: 0; margin: 1.4rem 0 0; }
.formal-steps > li { counter-increment: fs; position: relative; padding-left: 2.3rem; margin-bottom: 1.1rem; }
.formal-steps > li::before {
  content: counter(fs); position: absolute; left: 0; top: 0.08rem; width: 1.55rem; height: 1.55rem; border-radius: 50%;
  border: 1px solid var(--ink); display: grid; place-items: center; font-size: 0.85rem; line-height: 1;
}
.formal-steps .lemma { display: block; font-family: var(--mono); font-size: 0.8rem; color: var(--ink-soft); margin-top: 0.2rem; }
.figure-split { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 2rem; align-items: center; margin: 1.6rem 0 0.6rem; }
@media (max-width: 720px) { .figure-split { grid-template-columns: minmax(0, 1fr); } }

/* Verification */
.checks { width: 100%; border-collapse: collapse; margin: 1.4rem 0 1.8rem; font-size: 0.95rem; }
.checks th, .checks td { text-align: left; vertical-align: top; padding: 0.85rem 1rem 0.85rem 0; border-top: 1px solid var(--rule); }
.checks tr:last-child td { border-bottom: 1px solid var(--rule); }
.checks th { font-weight: 400; font-style: italic; color: var(--ink-soft); font-size: 0.88rem; border-top: 0; padding-bottom: 0.4rem; }
.checks td:first-child { font-weight: 700; width: 26%; }
.checks td:last-child { width: 30%; }
.ok { display: inline-flex; gap: 0.45rem; align-items: baseline; }
.ok svg { width: 0.85em; height: 0.85em; color: var(--blue); flex: none; transform: translateY(0.06em); }
@media (max-width: 680px) {
  .checks thead { display: none; }
  .checks, .checks tbody, .checks tr, .checks td { display: block; width: auto !important; }
  .checks tr { border-top: 1px solid var(--rule); padding: 0.8rem 0; }
  .checks td { border: 0 !important; padding: 0.1rem 0; }
}
.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 0.45rem 1.2rem; margin: 1.2rem 0; font-size: 0.95rem; }
.facts dt { color: var(--ink-soft); font-style: italic; }
.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.facts code { font-size: 0.8rem; }
.transcript pre { font-size: 12.6px; }
.transcript .tk-p { color: var(--ink-faint); }

/* History */
.timeline { list-style: none; padding: 0; margin: 1.4rem 0 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 4.6rem; top: 0.6rem; bottom: 0.6rem; width: 1px; background: var(--rule); }
.timeline li { display: grid; grid-template-columns: 4.6rem minmax(0, 1fr); column-gap: 1.6rem; padding: 0.5rem 0; position: relative; }
.timeline li::after { content: ""; position: absolute; left: calc(4.6rem - 3.5px); top: 1.05rem; width: 8px; height: 8px; border-radius: 50%; background: var(--paper); border: 1px solid var(--ink); }
.timeline li.now::after { background: var(--ink); }
.timeline .yr { font-variant-numeric: lining-nums; color: var(--ink-soft); text-align: left; }
.timeline .gap-row { padding: 0.9rem 0; }
.timeline .gap-row .yr { color: transparent; }
.timeline .gap-row::after { display: none; }
.timeline .gap-row span:last-child { font-style: italic; color: var(--ink-faint); }

/* Priority */
.search-list { padding-left: 1.2rem; margin: 0 0 1.2rem; }
.search-list li { margin-bottom: 0.45rem; }

/* Reproduce */
.repro { counter-reset: rp; list-style: none; padding: 0; margin: 1.2rem 0 0; }
.repro > li { counter-increment: rp; position: relative; padding-left: 2.3rem; margin-bottom: 1.2rem; }
.repro > li::before { content: counter(rp); position: absolute; left: 0; top: 0.08rem; width: 1.55rem; height: 1.55rem; border-radius: 50%; border: 1px solid var(--ink); display: grid; place-items: center; font-size: 0.85rem; line-height: 1; }
.repro .code { margin: 0.6rem 0 0; }
.repro .code pre { font-size: 12.8px; padding: 0.8rem 1rem; }
.files { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.6rem 0 0; }

/* Glossary terms */
.term {
  font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: help;
  text-decoration: underline dotted; text-decoration-color: var(--ink-faint); text-underline-offset: 0.2em;
}
.term:hover, .term[aria-expanded="true"] { text-decoration-color: var(--ink); }
.pop {
  position: absolute; z-index: 20; max-width: min(22rem, calc(100vw - 2rem));
  background: var(--ink); color: var(--paper); font-size: 0.88rem; line-height: 1.5;
  padding: 0.75rem 0.9rem; border-radius: 4px; pointer-events: none;
  opacity: 0; transform: translateY(4px); transition: opacity 140ms ease, transform 140ms ease;
}
.pop.show { opacity: 1; transform: none; }
.pop b { font-weight: 700; display: block; margin-bottom: 0.15rem; font-style: italic; }

/* Footer */
.foot {
  position: relative;
  max-width: 82rem; margin: clamp(4rem, 9vw, 8rem) auto 0; padding: 2.2rem var(--pad) 3rem;
  color: var(--ink-soft); font-size: 0.9rem;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.5rem 3rem;
}
.foot::before { content: ""; position: absolute; top: 0; left: var(--pad); right: var(--pad); border-top: 1px solid var(--rule); }
.foot p { margin: 0 0 0.5rem; }
.foot code { font-size: 0.74rem; overflow-wrap: anywhere; }
@media (max-width: 760px) { .foot { grid-template-columns: minmax(0, 1fr); } }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 1.4rem; transform: translate(-50%, 8px); background: var(--ink); color: var(--paper); padding: 0.55rem 0.95rem; border-radius: 3px; font-size: 0.88rem; opacity: 0; transition: opacity 160ms ease, transform 160ms ease; pointer-events: none; z-index: 30; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}

@media print {
  .top nav, .actions, .figcap button, .code-bar .tools, .step-controls { display: none !important; }
  body { background: #fff; }
  .full pre { max-height: none; }
}

/* ================= Second edition: chapters, explorable figures ================= */
.c-ink { color: var(--ink); }
.f-ink { fill: var(--ink); }
.kicker { font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-faint); margin: 0 0 0.5rem; }

/* Figures scroll with the page; only the handles capture touches. */
.figure svg { touch-action: pan-y; }
.figure svg .pt-hit, .figure svg .hd, .figure svg #h-P, .figure svg #w-P, .tt-pad { touch-action: none; }
.figure.narrow { max-width: 30rem; margin-inline: auto; }
.hd { cursor: grab; outline: none; }
.hd[data-drag] { cursor: grabbing; }
.hd:focus-visible .pt, .hd:focus-visible .corner-dot, #h-P:focus-visible .pt, #w-P:focus-visible .pt { stroke: var(--blue); stroke-width: 3; paint-order: stroke; }
.hd:focus-visible, #h-P:focus-visible, #w-P:focus-visible { outline: none; }
.corner-dot { fill: var(--paper); stroke: var(--ink); stroke-width: 2.2; }
.hd.corner:hover .corner-dot, .hd.corner[data-drag] .corner-dot { fill: var(--paper-raised); stroke-width: 3; }

.contour { stroke: var(--ink); stroke-width: 1; opacity: 0.2; }
.ext { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 5 5; opacity: 0.45; fill: none; }
.alt-c { stroke-width: 1.3; stroke-dasharray: 2 4; fill: none; opacity: 0.85; }
.alt-c.strong { stroke-width: 2; stroke-dasharray: 5 4; opacity: 1; }
.band { fill: rgba(var(--ink-rgb), 0.09); }
.sum-mark { stroke: var(--ink); stroke-width: 2.2; fill: none; }
.h-tick { stroke-width: 2.2; }
.h-lab, .dim, .tick, .wlab { font-family: var(--serif); font-style: italic; font-size: 16px; fill: var(--ink-soft); }
.tick { font-style: normal; font-size: 11px; font-family: var(--mono); }
.wlab { font-style: normal; font-size: 15px; font-variant-numeric: tabular-nums; paint-order: stroke; stroke: var(--paper); stroke-width: 4px; }
.dim-note { font-family: var(--serif); font-style: italic; font-size: 14px; fill: var(--ink-soft); }
.frame { fill: none; stroke: var(--ink); stroke-width: 1.4; }
.piece { stroke-width: 1.4; stroke-linejoin: round; }
.join { stroke: var(--ink); stroke-width: 1.3; }
.grid { stroke-width: 1; opacity: 0.32; }
.dist.neg { stroke-dasharray: 7 5; }
.walk { stroke-width: 4; fill: none; }
.walk.neg { stroke-dasharray: 6 4; }
.link { stroke: var(--ink-faint); stroke-width: 1; stroke-dasharray: 2 3; }
.edge { stroke: var(--ink); stroke-width: 2; stroke-linecap: round; }
.edge.hid { stroke-width: 1.1; stroke-dasharray: 4 5; opacity: 0.55; }
.face { stroke: none; }
.tt-pad { fill: transparent; cursor: move; }
.footmark { fill: var(--paper); stroke-width: 2.5; }
.side-hi { stroke-width: 6; stroke-linecap: round; opacity: 0.55; }

.sum.small { font-size: 0.95rem; color: var(--ink-soft); margin-top: 0.25rem; }
.sum.small .total { color: var(--ink); }
.status { font-size: 0.95rem; color: var(--ink-soft); margin: 0.9rem 0 0; min-height: 4.6em; }
.status strong { color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1rem 0 0; }
.chips .btn { padding: 0.45rem 0.85rem; font-size: 0.92rem; }
.chips .btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.figcap.block { display: block; margin-top: 1rem; }
.wide-split { grid-template-columns: minmax(0, 1.25fr) minmax(0, 0.75fr); align-items: start; margin-top: 1.5rem; }
@media (max-width: 860px) { .wide-split { grid-template-columns: minmax(0, 1fr); } .status { min-height: 0; } }
.fineprint { font-size: 0.86rem; color: var(--ink-soft); }
.dims td:last-child { font-variant-numeric: tabular-nums; }
cite { font-style: italic; }

/* Lean, line by line */
.linked { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--gap); align-items: start; margin-top: 1.5rem; }
.linked-fig { position: sticky; top: 1rem; }
.live { min-height: 3.2em; font-size: 0.98rem; font-variant-numeric: tabular-nums lining-nums; margin: 0.4rem 0 0; }
.cards { display: grid; gap: 0.7rem; min-width: 0; }
.card { min-width: 0; }
.card .code pre { overflow-x: auto; }
.card { border: 1px solid var(--rule); border-radius: 4px; padding: 0.8rem 0.95rem; cursor: pointer; background: transparent; transition: background 160ms ease, border-color 160ms ease; }
.card:hover { border-color: var(--ink-faint); }
.card.on { background: var(--paper-raised); border-color: var(--ink); box-shadow: inset 3px 0 0 var(--ink); }
.card-h { font-family: var(--display); font-size: 1.12rem; line-height: 1.3; display: flex; gap: 0.6rem; align-items: baseline; }
.card-n { font-family: var(--mono); font-size: 0.72rem; color: var(--ink-faint); }
.card .code { margin: 0.6rem 0 0.5rem; display: none; }
.card p { margin: 0.35rem 0 0; font-size: 0.93rem; color: var(--ink-soft); display: none; }
.card.on .code { display: block; } .card.on p { display: block; }
.card .code pre { font-size: 0.74rem; max-height: none; }
.card-src { font-family: var(--mono); font-size: 0.74rem !important; }
.lk-controls { display: none; }
@media (max-width: 900px) {
  .linked { grid-template-columns: minmax(0, 1fr); gap: 1rem; }
  .linked-fig { position: static; }
  .card:not(.on) { display: none; }
  .lk-controls { display: flex; }
}

/* code tabs */
.tabs { display: flex; flex-wrap: wrap; gap: 0.15rem; }
.tab, .filelink { font-family: var(--mono); font-size: 0.78rem; background: none; border: 0; padding: 0.3rem 0.55rem; border-radius: 3px; color: var(--ink-soft); cursor: pointer; }
.tab[aria-selected="true"] { background: var(--ink); color: var(--paper); }
.tab:hover:not([aria-selected="true"]) { background: rgba(var(--ink-rgb), 0.07); }
.filelink { padding: 0; color: var(--ink); text-decoration: underline; text-decoration-color: var(--ink-faint); text-underline-offset: 0.18em; font-size: 0.86rem; }
.code-bar { flex-wrap: wrap; gap: 0.5rem; }
.transcript-wrap { margin-top: 1.2rem; }
.transcript-wrap summary { cursor: pointer; color: var(--ink-soft); font-size: 0.95rem; }
.transcript-wrap .code { margin-top: 0.8rem; }

/* compact contents menu for narrow screens */
.menu { display: none; position: relative; }
.menu summary { list-style: none; cursor: pointer; font-size: 0.95rem; padding: 0.35rem 0.75rem; border: 1px solid var(--ink); border-radius: 3px; }
.menu summary::-webkit-details-marker { display: none; }
.menu[open] summary { background: var(--ink); color: var(--paper); }
.menu ol { position: absolute; right: 0; top: calc(100% + 0.4rem); z-index: 20; margin: 0; padding: 0.5rem 0; list-style: none; background: var(--paper-raised); border: 1px solid var(--ink); border-radius: 4px; min-width: 13rem; counter-reset: mn; box-shadow: 0 10px 30px var(--shadow); }
.menu li a { display: block; padding: 0.5rem 1rem; text-decoration: none; }
.menu li a:hover { background: rgba(var(--ink-rgb), 0.06); }
@media (max-width: 900px) { .top nav { display: none; } .menu { display: block; } .top { position: sticky; top: 0; z-index: 30; background: var(--paper); border-bottom: 1px solid var(--rule); } }
@media (max-width: 620px) {
  .steps li { font-size: 0.95rem; }
  .card .code pre { font-size: 0.68rem; }
}
@media (max-width: 620px) {
  .h-lab, .dim, .wlab { font-size: 21px; }
  .tick { font-size: 15px; }
  .vx { font-size: 26px; } .vx-sm { font-size: 23px; } .pt-label { font-size: 25px; }
  .dim-note { font-size: 19px; }
}
p > .lemma { display: block; margin-top: 0.25rem; }
.stepper { margin-bottom: 1.8rem; }
.code.statement pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.decls .filelink { text-align: left; justify-self: start; }

/* ================= Night edition =================
   The same rule as by day: each side keeps one colour everywhere. The three primaries are
   lifted so they hold their own against dark paper; ink and paper trade places. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
  --paper: #11151d;
  --paper-raised: #181e29;
  --ink: #e6e8e1;
  --ink-soft: #a7afbd;
  --ink-faint: #6c7586;
  --ink-rgb: 230, 232, 225;
  --rule: rgba(var(--ink-rgb), 0.16);
  --blue: #6c9cec;
  --red: #ee6c54;
  --yellow: #f0b93b;
  --yellow-ink: #f0b93b;
  --tk-k: #c59be6; --tk-c: #8b9685; --tk-d: #a3ad9c;
  --shadow: rgba(0, 0, 0, 0.5);
  color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #11151d;
  --paper-raised: #181e29;
  --ink: #e6e8e1;
  --ink-soft: #a7afbd;
  --ink-faint: #6c7586;
  --ink-rgb: 230, 232, 225;
  --rule: rgba(var(--ink-rgb), 0.16);
  --blue: #6c9cec;
  --red: #ee6c54;
  --yellow: #f0b93b;
  --yellow-ink: #f0b93b;
  --tk-k: #c59be6; --tk-c: #8b9685; --tk-d: #a3ad9c;
  --shadow: rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}
.tri-fill { fill: rgba(var(--ink-rgb), 0.045); }
.theme { display: inline-flex; align-items: center; justify-content: center; width: 2.1rem; height: 2.1rem; border-radius: 50%; border: 1px solid var(--rule); background: none; color: var(--ink); cursor: pointer; flex: none; }
.theme:hover { border-color: var(--ink); }
.theme svg { width: 1.05rem; height: 1.05rem; }
.top { gap: 1.1rem; align-items: center; justify-content: flex-start; }
.top .spacer { flex: 1; }
html { background: var(--paper); }
body, .card, .btn, .code, .menu ol { transition: background-color 240ms ease, color 240ms ease, border-color 240ms ease; }
@media (prefers-reduced-motion: reduce) { body, .card, .btn, .code, .menu ol { transition: none; } }
