/* Nilradical: one stylesheet for every page.
   Every colour, size and spacing value is a token declared in :root.
   scripts/check_site.py refuses any literal outside the :root blocks. */

:root {
  --paper: #ffffff;
  --ink: #17202a;
  --ink-2: #5b6674;
  --rule: #e3e6eb;
  --surface: #f4f5f7;
  --accent: #2e50dc;
  --accent-ink: #1f3bb5;

  --serif: 'Source Serif 4', 'Source Serif 4 Fallback', Georgia, serif;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;

  --fs-meta: 13px;    --lh-meta: 20px;
  --fs-small: 15px;   --lh-small: 24px;
  --fs-body: 17px;    --lh-body: 28px;
  --fs-lede: 20px;    --lh-lede: 30px;
  --fs-h3: 24px;      --lh-h3: 32px;
  --fs-h2: 30px;      --lh-h2: 38px;
  --fs-title: 40px;   --lh-title: 46px;
  --fs-display: 52px; --lh-display: 56px;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s6: 24px;
  --s8: 32px; --s12: 48px; --s16: 64px; --s24: 96px; --s32: 128px;

  --hair: 1px;
  --focus: 2px;
  --container: 1040px;
  --measure: 640px;
  --id-col: 96px;
  --gutter: 48px;
  --section: 96px;
  --mark-w: 56px; --mark-h: 32px;
  --mark-w-small: 42px; --mark-h-small: 24px;
  --ext: 10px;
  --tap: 32px;
  --math-scale: 1.1em;
}
@media (max-width: 640px) {
  :root {
    --gutter: 24px;
    --section: 64px;
    --fs-display: 40px; --lh-display: 46px;
    --fs-title: 32px;   --lh-title: 38px;
    --fs-h2: 26px;      --lh-h2: 32px;
  }
}

/* Fonts: self-hosted, Latin subset. A metric-matched fallback avoids reflow. */
@font-face {
  font-family: 'Source Serif 4';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url(/assets/fonts/source-serif-4-roman.woff2?v=2a24bad466f0) format('woff2');
}
@font-face {
  font-family: 'Source Serif 4';
  font-style: italic;
  font-weight: 400 600;
  font-display: swap;
  src: url(/assets/fonts/source-serif-4-italic.woff2?v=011e0ca2bd14) format('woff2');
}
@font-face {
  font-family: 'Source Serif 4 Fallback';
  src: local('Georgia');
  size-adjust: 94%;
  ascent-override: 103%;
  descent-override: 33%;
  line-gap-override: 0%;
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/assets/fonts/ibm-plex-mono-400.woff2?v=c36f509c0a8f) format('woff2');
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(/assets/fonts/ibm-plex-mono-600.woff2?v=ad4580d8cb4b) format('woff2');
}

/* Base */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: var(--s6); }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  font-optical-sizing: auto;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, p, ul, ol, dl, dd, figure, pre { margin: 0; }
h1, h2, h3 { font-weight: 400; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 0.15em; }
a, button { transition: color 120ms; }
:focus-visible { outline: var(--focus) solid var(--accent); outline-offset: var(--focus); }
[hidden] { display: none !important; }
code, kbd, pre { font-family: var(--mono); }
code { font-size: 0.88em; }
strong { font-weight: 600; }
::selection { background: var(--surface); }

.skip {
  position: absolute; left: var(--gutter); top: calc(-1 * var(--s24));
  padding: var(--s2) var(--s3); background: var(--paper); color: var(--accent);
}
.skip:focus { top: var(--s2); }

.wrap { width: min(var(--container), calc(100% - 2 * var(--gutter))); margin-inline: auto; }
.measure { max-width: var(--measure); }

/* Type roles */
.meta { font-size: var(--fs-meta); line-height: var(--lh-meta); color: var(--ink-2); }
.small { font-size: var(--fs-small); line-height: var(--lh-small); }
.lede { font-size: var(--fs-lede); line-height: var(--lh-lede); }
h1.display { font-size: var(--fs-display); line-height: var(--lh-display); letter-spacing: -0.01em; }
h1.title, .title { font-size: var(--fs-title); line-height: var(--lh-title); letter-spacing: -0.01em; }
h2 { font-size: var(--fs-h2); line-height: var(--lh-h2); }
h3 { font-size: var(--fs-h3); line-height: var(--lh-h3); }
.id { font-family: var(--mono); font-size: 0.88em; }

/* External-link mark: the only link ornament on the site, added by the build. */
.ext { width: var(--ext); height: var(--ext); margin-left: 0.3em; vertical-align: baseline; stroke: currentColor; fill: none; }

/* Header and footer share the container with everything else. */
.site-header {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: var(--s3) var(--s6);
  padding-block: var(--s6);
  border-bottom: var(--hair) solid var(--rule);
}
.brand { display: inline-flex; align-items: center; gap: var(--s3); color: var(--ink); }
.brand:hover { color: var(--ink); text-decoration: none; }
.brand .mark { width: var(--mark-w); height: var(--mark-h); color: var(--accent); }
.brand .wordmark { font-size: var(--fs-h3); line-height: var(--lh-h3); letter-spacing: -0.01em; }
.site-nav { display: flex; gap: var(--s6); font-size: var(--fs-small); line-height: var(--lh-small); }
.site-nav a { color: var(--ink); padding-block: var(--s1); min-height: var(--tap); display: inline-flex; align-items: center; }
.site-nav a:hover { color: var(--accent-ink); }

.site-footer {
  margin-top: var(--section);
  padding-block: var(--s8) var(--s16);
  border-top: var(--hair) solid var(--rule);
  font-size: var(--fs-small); line-height: var(--lh-small);
  color: var(--ink-2);
}
.site-footer .brand .mark { width: var(--mark-w-small); height: var(--mark-h-small); }
.site-footer .brand .wordmark { font-size: var(--fs-lede); line-height: var(--lh-lede); }
.site-footer p { max-width: var(--measure); margin-top: var(--s4); }
.site-footer .colophon .mark { width: var(--mark-w-small); height: var(--mark-h-small); vertical-align: middle; color: var(--accent); }

/* Homepage */
.section { margin-top: var(--section); }
.section > h2 { margin-bottom: var(--s6); }
.lede-block { margin-top: var(--s16); }
.lede-block p + p { margin-top: var(--s4); }

.guarantee { margin-bottom: var(--s6); max-width: var(--measure); }

.results { list-style: none; padding: 0; border-top: var(--hair) solid var(--rule); }
.result {
  display: grid; grid-template-columns: var(--id-col) minmax(0, 1fr);
  column-gap: var(--s6);
  padding-block: var(--s8);
  border-bottom: var(--hair) solid var(--rule);
}
.result .id { padding-top: var(--s1); font-weight: 600; color: var(--ink-2); }
.result h3 a { color: var(--ink); }
.result h3 a:hover { color: var(--accent-ink); }
.result .statement { max-width: var(--measure); margin-top: var(--s2); }
.result .meta { margin-top: var(--s3); }
.result .links { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s6); margin-top: var(--s3); font-size: var(--fs-small); line-height: var(--lh-small); }
.result .links a { min-height: var(--tap); display: inline-flex; align-items: center; }
@media (max-width: 640px) {
  .result { grid-template-columns: 1fr; row-gap: var(--s1); }
  .result .id { padding-top: 0; }
}

.stages { padding-left: 0; list-style: none; counter-reset: stage; max-width: var(--measure); }
.stages li { display: grid; grid-template-columns: var(--s12) 1fr; column-gap: var(--s3); padding-block: var(--s3); border-bottom: var(--hair) solid var(--rule); }
.stages li::before { counter-increment: stage; content: counter(stage); font-family: var(--mono); font-size: 0.88em; color: var(--ink-2); padding-top: 0.1em; }
.stages li:first-child { border-top: var(--hair) solid var(--rule); }
.stages b { font-weight: 600; }
.about { margin-top: var(--s8); max-width: var(--measure); }
.about p + p { margin-top: var(--s4); }
.prose { max-width: var(--measure); }
.prose p + p, .prose ul + p, .prose p + ul { margin-top: var(--s4); }
.prose ul { padding-left: var(--s6); }

/* Record and note pages */
.crumbs { margin-top: var(--s8); font-size: var(--fs-small); line-height: var(--lh-small); color: var(--ink-2); }
.crumbs a { color: var(--ink-2); }
.crumbs a:hover { color: var(--accent-ink); }
.crumbs span + span::before { content: '/'; margin-inline: var(--s2); color: var(--rule); }
.page-title { margin-top: var(--s4); max-width: calc(var(--measure) + var(--s24)); }
.provenance { margin-top: var(--s3); max-width: calc(var(--measure) + var(--s24)); }
.provenance span + span::before { content: '\00b7'; margin-inline: var(--s2); }
.record .statement { margin-top: var(--s8); }
.record section { margin-top: var(--s12); max-width: var(--measure); }
.record section.wide { max-width: calc(var(--measure) + var(--s24)); }
.record section > h2 { font-size: var(--fs-h3); line-height: var(--lh-h3); margin-bottom: var(--s4); }
.record p + p { margin-top: var(--s4); }
.record ul { padding-left: var(--s6); }
dl.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); column-gap: var(--s6); row-gap: var(--s2); font-size: var(--fs-small); line-height: var(--lh-small); }
dl.facts dt { color: var(--ink-2); }
dl.facts dd { overflow-wrap: anywhere; }
dl.facts .id { font-size: 0.88em; }
@media (max-width: 640px) {
  dl.facts { grid-template-columns: 1fr; row-gap: 0; }
  dl.facts dd { margin-bottom: var(--s3); }
}
pre.bibtex, .note pre {
  font-size: var(--fs-meta); line-height: var(--lh-meta);
  padding: var(--s4); background: var(--surface);
  overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere;
}
.copy { font: inherit; font-size: var(--fs-small); line-height: var(--lh-small); color: var(--accent); background: none; border: 0; padding: 0; margin-top: var(--s3); min-height: var(--tap); cursor: pointer; }
.copy:hover { color: var(--accent-ink); text-decoration: underline; }
.copy[data-done] { color: var(--ink-2); }

/* Mathematical note */
.note { max-width: var(--measure); margin-top: var(--s8); }
.note h2 { font-size: var(--fs-h3); line-height: var(--lh-h3); margin: var(--s12) 0 var(--s4); }
.note h3 { font-size: var(--fs-body); line-height: var(--lh-body); font-weight: 600; margin: var(--s8) 0 var(--s3); }
.note p, .note ul, .note ol, .note table { margin-top: var(--s4); }
.note ul, .note ol { padding-left: var(--s6); }
.note li + li { margin-top: var(--s2); }
.note a { overflow-wrap: anywhere; }
.note code { overflow-wrap: anywhere; }
.note .thm, .note .proof { margin-top: var(--s6); margin-bottom: var(--s6); }
.note .thm .label { font-weight: 600; }
.note .thm .body { font-style: italic; }
.note .thm .body em { font-style: normal; }
.note .proof .label { font-style: italic; }
.note table { border-collapse: collapse; display: block; overflow-x: auto; font-size: var(--fs-small); line-height: var(--lh-small); }
.note th, .note td { padding: var(--s2) var(--s3); border-bottom: var(--hair) solid var(--rule); text-align: left; vertical-align: top; }
.note th { font-weight: 600; }
.note .contents { margin-top: var(--s6); padding: var(--s4) 0; border-block: var(--hair) solid var(--rule); font-size: var(--fs-small); line-height: var(--lh-small); }
.note .contents ol { list-style: none; padding: 0; margin: 0; }
.note .contents li + li { margin-top: 0; }
.note .refs { font-size: var(--fs-small); line-height: var(--lh-small); }
.note .refs li { padding-left: var(--s2); }
.note .refs li::marker { color: var(--ink-2); }
.note-foot { margin-top: var(--s12); padding-top: var(--s6); border-top: var(--hair) solid var(--rule); font-size: var(--fs-small); line-height: var(--lh-small); color: var(--ink-2); max-width: var(--measure); }
.note-foot p + p { margin-top: var(--s2); }

/* Math: KaTeX sized so its x-height matches the serif; display blocks scroll locally. */
.note .katex { font-size: var(--math-scale); }
.note .math.block {
  margin-block: var(--s6);
  max-width: 100%; overflow-x: auto; overflow-y: hidden;
  padding-inline: var(--s2);
  scrollbar-width: thin;
}
.note .math.block .katex-display { margin: 0; }
.note .math.block .katex-display > .katex { white-space: nowrap; }
@media (max-width: 640px) {
  .note .math.block { -webkit-mask-image: linear-gradient(to right, black calc(100% - var(--s6)), transparent); mask-image: linear-gradient(to right, black calc(100% - var(--s6)), transparent); }
  .note .math.block[data-fits] { -webkit-mask-image: none; mask-image: none; }
  .note .katex-display > .katex > .katex-html > .katex-tag { position: static; display: block; text-align: right; padding-top: var(--s1); }
}

/* 404 */
.notfound { margin-top: var(--s16); max-width: var(--measure); }

/* Print */
@media print {
  :root { --gutter: 0px; --section: 32px; }
  .site-nav, .skip, .copy, .site-footer .colophon { display: none; }
  a { text-decoration: none; }
  .note .math.block { overflow: visible; mask-image: none; -webkit-mask-image: none; }
  .note .katex { font-size: 1em; }
  .result, .stages li, .note h2 { break-inside: avoid; }
}
@media (prefers-reduced-motion: reduce) {
  a, button { transition: none; }
}
