/* =============================================================
   The Serial Scaling Hypothesis — project site styles
   Bookish NYT-adjacent typography built around Fraunces variable
   ============================================================= */

html {
  font-size: 100%;
  hyphens: auto;
  hanging-punctuation: first last;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  font-feature-settings: "kern", "liga", "onum" 1;
  font-variation-settings: "opsz" 14;
  letter-spacing: var(--tr-body);
}

::selection {
  background: var(--accent);
  color: var(--paper);
}

/* Subtle page frame — a printer's mark on the top edge.
   One-pixel rule, nothing else. */
.page-frame {
  border-top: 4px solid var(--ink);
  height: 4px;
  margin-bottom: 0;
}

/* =============================================================
   Article layout
   ============================================================= */

.article {
  max-width: var(--article-max);
  margin: 0 auto;
  padding: var(--s-6) var(--s-3) var(--s-8);
  position: relative;
}

.article > * {
  max-width: var(--measure);
}

.article > .fig,
.article > .fig--wide,
.article > .pull,
.article > .theorem,
.article > details {
  /* Allow these to overflow the measure slightly when needed */
}

.fig--wide {
  max-width: var(--measure-wide);
}

/* Section dividers */
.section {
  margin-top: var(--s-7);
  scroll-margin-top: var(--s-3);
}

.section:first-of-type {
  margin-top: var(--s-6);
}

.section + .section {
  border-top: 1px solid var(--rule);
  padding-top: var(--s-6);
}

.section-label {
  display: block;
  font-size: var(--fs-small);
  font-weight: 500;
  font-variation-settings: "opsz" 14;
  letter-spacing: var(--tr-smcp);
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: var(--s-1);
}

/* =============================================================
   Headings
   ============================================================= */

h1, h2, h3, h4 {
  font-family: var(--font-serif);
  color: var(--ink);
}

h1.title {
  font-size: var(--fs-h1);
  font-weight: 500;
  line-height: var(--lh-tight);
  letter-spacing: var(--tr-display);
  font-variation-settings: "opsz" 144, "SOFT" 20;
  text-wrap: balance;
  margin-top: var(--s-5);
}

h2.section-title {
  font-size: var(--fs-h2);
  font-weight: 450;
  line-height: var(--lh-snug);
  letter-spacing: var(--tr-display);
  font-variation-settings: "opsz" 96;
  margin-top: var(--s-2);
  margin-bottom: var(--s-4);
  text-wrap: balance;
}

h3 {
  font-size: var(--fs-h3);
  font-weight: 500;
  line-height: var(--lh-snug);
  font-variation-settings: "opsz" 48;
  font-style: italic;
  margin-top: var(--s-5);
  margin-bottom: var(--s-2);
  color: var(--ink);
  text-wrap: balance;
}

h4 {
  font-size: var(--fs-h4);
  font-weight: 600;
  line-height: var(--lh-snug);
  font-variation-settings: "opsz" 24;
  margin-top: var(--s-4);
  margin-bottom: var(--s-1);
}

/* =============================================================
   Body text
   ============================================================= */

p {
  margin-bottom: var(--s-2);
  font-variation-settings: "opsz" 14;
}

p + p {
  margin-top: 0;
}

/* Drop cap — only on § 1's first paragraph */
.drop-cap::first-letter {
  font-family: var(--font-serif);
  font-variation-settings: "opsz" 144;
  font-weight: 500;
  font-style: normal;
  font-size: var(--fs-drop);
  line-height: 0.85;
  float: left;
  margin: 0.12em 0.08em 0 -0.04em;
  color: var(--ink);
  letter-spacing: -0.04em;
}

strong, b {
  font-weight: 600;
}

em, i {
  font-style: italic;
}

a {
  color: var(--accent-ink);
  text-decoration: underline;
  text-decoration-color: var(--rule-strong);
  text-underline-offset: 0.15em;
  text-decoration-thickness: 0.06em;
}
a:hover {
  text-decoration-color: var(--accent);
}

/* Internal section cross-references ("§ 3", "§ 5", …) — treated as
   academic callouts: no underline, accent color, dotted underline only
   on hover. They should read as part of the sentence, not as a
   hyperlink jammed in. */
a.section-ref {
  color: var(--accent-ink);
  text-decoration: none;
  font-variant-numeric: lining-nums;
  white-space: nowrap;
  padding-bottom: 0.05em;
  border-bottom: 1px dotted var(--rule-strong);
}
a.section-ref:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Lead paragraph — slightly larger, under subtitle */
.lead {
  font-size: var(--fs-lead);
  line-height: 1.4;
  color: var(--ink-soft);
  font-style: italic;
  font-variation-settings: "opsz" 36;
  margin-top: var(--s-1);
  margin-bottom: var(--s-3);
  text-wrap: pretty;
}

/* TL;DR block on the hero */
.tldr {
  margin: var(--s-3) 0 var(--s-4);
  padding: var(--s-3) var(--s-3);
  background: var(--paper-warm);
  border-left: 3px solid var(--ink);
}

.tldr-label {
  display: block;
  font-size: var(--fs-micro);
  letter-spacing: var(--tr-smcp);
  text-transform: uppercase;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: var(--s-1);
  font-feature-settings: "lnum" 1;
}

.tldr p {
  margin: 0;
  font-size: var(--fs-body);
  line-height: 1.5;
  color: var(--ink);
  text-wrap: pretty;
}

/* =============================================================
   Hero / title page
   ============================================================= */

.hero {
  padding-top: var(--s-5);
  padding-bottom: var(--s-6);
  border-bottom: 1px solid var(--rule);
  margin-bottom: var(--s-6);
}

.kicker {
  font-size: var(--fs-small);
  letter-spacing: var(--tr-smcp);
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: var(--s-3);
  font-weight: 500;
}

.byline {
  margin-top: var(--s-4);
  font-size: var(--fs-small);
  color: var(--ink-soft);
  line-height: 1.5;
}

.byline .authors {
  color: var(--ink);
  font-variation-settings: "opsz" 14;
}

.byline .affiliation {
  display: block;
  letter-spacing: var(--tr-smcp);
  text-transform: uppercase;
  font-size: var(--fs-micro);
  margin-top: var(--s-0);
}

.byline .date {
  display: block;
  font-style: italic;
  font-feature-settings: "onum" 1;
  margin-top: var(--s-0);
}

/* Epigraph — on the hero or at the top of a section */
.epigraph {
  margin: var(--s-3) 0 var(--s-4);
  padding-left: var(--s-2);
  border-left: 2px solid var(--rule-strong);
  font-style: italic;
  font-size: var(--fs-epigraph);
  line-height: 1.5;
  color: var(--ink-soft);
  max-width: 24rem;
}

.section > .epigraph {
  margin-top: 0;
  margin-bottom: var(--s-5);
}

.byline sup {
  font-feature-settings: "sups" 1;
  font-size: 0.72em;
  vertical-align: super;
  line-height: 0;
  color: var(--ink-soft);
}

.epigraph cite {
  display: block;
  font-style: normal;
  font-size: var(--fs-micro);
  letter-spacing: var(--tr-smcp);
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-top: var(--s-1);
}

/* =============================================================
   Pull quotes, theorem boxes
   ============================================================= */

.pull {
  margin: var(--s-5) 0;
  padding: var(--s-4) 0;
  border-top: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
  font-size: var(--fs-lead);
  line-height: 1.35;
  font-style: italic;
  font-variation-settings: "opsz" 48;
  text-align: center;
  text-wrap: balance;
  color: var(--ink);
}

.pull strong {
  font-style: normal;
  font-weight: 600;
}

.theorem {
  margin: var(--s-4) 0;
  padding: var(--s-3) var(--s-3);
  border: 1px solid var(--ink);
  position: relative;
  background: var(--paper);
}

.theorem .theorem-label {
  display: inline-block;
  font-size: var(--fs-small);
  letter-spacing: var(--tr-smcp);
  text-transform: uppercase;
  font-weight: 600;
  background: var(--ink);
  color: var(--paper);
  padding: 0.15em 0.6em 0.2em;
  margin-bottom: var(--s-2);
  position: relative;
  top: -0.1em;
}

.theorem p {
  margin: 0;
  font-style: italic;
  font-size: var(--fs-body);
}

/* Proof sketch — <details> block */
details.proof {
  margin: var(--s-4) 0;
  border: 1px solid var(--rule-strong);
  padding: var(--s-2) var(--s-3);
  background: var(--paper-warm);
}

details.proof summary {
  cursor: pointer;
  font-size: var(--fs-small);
  letter-spacing: var(--tr-smcp);
  text-transform: uppercase;
  font-weight: 600;
  color: var(--ink-soft);
  list-style: none;
  padding: var(--s-1) 0;
  user-select: none;
}

details.proof summary::-webkit-details-marker {
  display: none;
}

details.proof summary::before {
  content: "＋ ";
  font-weight: 400;
  color: var(--ink-faint);
}

details.proof[open] summary::before {
  content: "− ";
}

details.proof summary:hover {
  color: var(--accent);
}

details.proof[open] summary {
  margin-bottom: var(--s-2);
  padding-bottom: var(--s-1);
  border-bottom: 1px solid var(--rule);
}

details.proof .proof-body {
  font-size: var(--fs-small);
  line-height: 1.5;
}

details.proof .proof-body p {
  margin-bottom: var(--s-2);
}

details.proof .katex-display {
  margin: var(--s-2) 0;
  font-size: 0.9em;
}

/* =============================================================
   Figures
   ============================================================= */

figure.fig,
figure.fig--wide {
  margin: var(--s-4) 0 var(--s-4);
}

figure.fig img,
figure.fig--wide img,
figure.fig video,
figure.fig--wide video {
  display: block;
  width: 100%;
  border: 1px solid var(--rule-strong);
  background: var(--paper-warm);
}

figure.fig figcaption,
figure.fig--wide figcaption {
  margin-top: var(--s-1);
  font-size: var(--fs-small);
  line-height: var(--lh-caption);
  color: var(--ink-soft);
  font-style: italic;
  font-variation-settings: "opsz" 14;
  text-wrap: pretty;
}

figure.fig figcaption .credit,
figure.fig--wide figcaption .credit {
  display: block;
  font-style: normal;
  font-size: var(--fs-micro);
  letter-spacing: var(--tr-smcp);
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-top: var(--s-1);
}

figure.fig figcaption .fig-num,
figure.fig--wide figcaption .fig-num {
  font-style: normal;
  letter-spacing: var(--tr-smcp);
  text-transform: uppercase;
  font-weight: 600;
  color: var(--ink);
  margin-right: 0.4em;
  font-size: var(--fs-micro);
}

/* Specific adjustments for figures where the source image runs edge-to-edge */
figure#fig-liyan {
  text-align: center;
}
figure#fig-liyan img {
  width: auto;
  max-width: 72%;
  display: block;
  margin: 0 auto;
  padding: var(--s-3) var(--s-4);
  background: #ffffff;
}

/* Two-list layout beside the venn diagram */
.two-lists {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s-3);
  margin: var(--s-3) 0;
}

@media (min-width: 48em) {
  .two-lists {
    grid-template-columns: 1fr 1fr;
    gap: var(--s-4);
  }
}

.two-lists .list-block h4 {
  margin-top: 0;
  margin-bottom: var(--s-1);
  font-size: var(--fs-small);
  letter-spacing: var(--tr-smcp);
  text-transform: uppercase;
  color: var(--ink);
  border-bottom: 1px solid var(--rule);
  padding-bottom: var(--s-0);
}

.two-lists p {
  font-size: var(--fs-small);
  line-height: 1.55;
  color: var(--ink);
  margin-bottom: var(--s-2);
}

.two-lists em {
  color: var(--ink-soft);
}

/* Inline symbols ✗ / ✓ — the one color accent */
.mark-fail { color: var(--accent); font-style: normal; font-weight: 700; }
.mark-pass { color: var(--ink);    font-style: normal; font-weight: 700; }

/* =============================================================
   Sidenotes — Tufte-style
   ============================================================= */

/* The number that appears inline (after the anchor) */
.sn-number {
  vertical-align: super;
  font-size: 0.72em;
  line-height: 0;
  color: var(--accent);
  font-weight: 600;
  font-variant-numeric: lining-nums;
  cursor: pointer;
  padding: 0 0.15em;
}

/* The note body */
.sidenote {
  float: right;
  clear: right;
  width: var(--sidenote);
  margin-right: calc(-1 * (var(--sidenote) + var(--sidenote-gap)));
  margin-top: 0.25rem;
  margin-bottom: var(--s-2);
  font-size: var(--fs-small);
  line-height: var(--lh-caption);
  font-variation-settings: "opsz" 10;
  color: var(--ink-soft);
  font-style: normal;
  position: relative;
}

.sidenote strong {
  color: var(--ink);
}

.sidenote .sn-figure {
  display: block;
  width: 100%;
  max-width: 220px;
  margin: var(--s-1) auto 0;
  border: 1px solid var(--rule);
  background: #fff;
}

/* Sidenotes that live inside the two-column task/model lists fall back to
   inline click-to-expand, since floating would overlap the adjacent column. */
.two-lists .sidenote {
  display: none;
  float: none;
  clear: none;
  width: 100%;
  margin: var(--s-2) 0;
  padding: var(--s-2);
  background: var(--paper-warm);
  border-left: 2px solid var(--rule-strong);
  font-size: var(--fs-small);
}
.two-lists input.margin-toggle:checked + .sidenote {
  display: block;
}
.two-lists label.margin-toggle.sn-number {
  border-bottom: 1px dotted var(--accent);
}

.sidenote .sn-label {
  color: var(--accent);
  font-weight: 600;
  font-variant-numeric: lining-nums;
  margin-right: 0.3em;
}

/* Mobile toggle mechanism (checkbox hack).
   Only the checkbox input is hidden — the <label> marker is visible
   inline so the reader sees where each sidenote is anchored. */
input.margin-toggle {
  display: none;
}

label.margin-toggle.sn-number {
  /* inherits .sn-number above */
  cursor: pointer;
  user-select: none;
}

label.margin-toggle.sn-number:hover {
  color: var(--ink);
}

@media (max-width: 54em) {
  .sidenote {
    display: none;
    float: none;
    width: auto;
    margin: var(--s-2) 0;
    padding: var(--s-2) var(--s-2);
    background: var(--paper-warm);
    border-left: 2px solid var(--rule-strong);
  }

  .margin-toggle:checked + .sidenote {
    display: block;
  }

  .sn-number {
    border-bottom: 1px dotted var(--accent);
  }
}

/* =============================================================
   Bibliography block at the end
   ============================================================= */

.colophon {
  margin-top: var(--s-7);
  padding-top: var(--s-4);
  border-top: 4px solid var(--ink);
  font-size: var(--fs-small);
  color: var(--ink-soft);
}

.colophon h2 {
  font-size: var(--fs-h3);
  font-weight: 500;
  font-variation-settings: "opsz" 48;
  margin-bottom: var(--s-2);
  color: var(--ink);
}

.colophon .resources {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}

.colophon .resources a {
  padding: var(--s-1) var(--s-2);
  border: 1px solid var(--rule-strong);
  text-decoration: none;
  font-size: var(--fs-small);
  letter-spacing: var(--tr-smcp);
  text-transform: uppercase;
  color: var(--ink);
  transition: background 120ms ease;
}

.colophon .resources a:hover {
  background: var(--ink);
  color: var(--paper);
}

/* Table of contents — lives just under the hero, bookish. */
.toc {
  margin: var(--s-5) 0 0;
  padding: var(--s-3) 0;
  border-top: 2px solid var(--ink);
  border-bottom: 1px solid var(--rule-strong);
}

.toc-label {
  font-size: var(--fs-micro);
  letter-spacing: var(--tr-smcp);
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 600;
  margin: 0 0 var(--s-2);
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: none;
}

.toc-list li {
  margin: 0;
  padding: 0;
}

.toc-list li::before {
  content: none;
}

.toc-list a {
  display: grid;
  grid-template-columns: 4rem 1fr;
  gap: var(--s-2);
  padding: 0.55rem 0;
  border-top: 1px solid var(--rule);
  text-decoration: none;
  color: var(--ink);
  align-items: baseline;
  transition: color 120ms ease, background 120ms ease;
}

.toc-list li:first-child a {
  border-top: none;
}

.toc-list a:hover {
  color: var(--accent);
}

.toc-list a:hover .toc-num {
  color: var(--accent);
}

.toc-num {
  font-size: var(--fs-small);
  letter-spacing: var(--tr-smcp);
  text-transform: uppercase;
  color: var(--ink-soft);
  font-variant-numeric: lining-nums;
  font-weight: 600;
  transition: color 120ms ease;
}

.toc-title {
  font-size: var(--fs-body);
  font-family: var(--font-serif);
  font-variation-settings: "opsz" 14;
  line-height: 1.3;
  text-wrap: pretty;
}

@media (max-width: 40em) {
  .toc-list a {
    grid-template-columns: 3rem 1fr;
    gap: var(--s-1);
  }
  .toc-title {
    font-size: var(--fs-small);
  }
}

/* Same resource row inside the hero — a touch smaller, spaced a bit
   further down from the byline, so it doesn't compete with the title. */
.hero-resources {
  margin-top: var(--s-3);
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.hero-resources a {
  padding: var(--s-1) var(--s-2);
  border: 1px solid var(--rule-strong);
  text-decoration: none;
  font-size: var(--fs-micro);
  letter-spacing: var(--tr-smcp);
  text-transform: uppercase;
  color: var(--ink);
  transition: background 120ms ease;
}

.hero-resources a:hover {
  background: var(--ink);
  color: var(--paper);
}

.references {
  font-size: var(--fs-micro);
  line-height: 1.5;
  columns: 2;
  column-gap: var(--s-4);
  margin-top: var(--s-3);
}

@media (max-width: 40em) {
  .references {
    columns: 1;
  }
}

.references p {
  margin-bottom: var(--s-2);
  break-inside: avoid;
  font-variation-settings: "opsz" 10;
}

.bibtex {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  line-height: 1.5;
  background: var(--paper-warm);
  padding: var(--s-2);
  overflow-x: auto;
  border: 1px solid var(--rule);
  margin-top: var(--s-2);
}

/* =============================================================
   Lists
   ============================================================= */

.article ul, .article ol {
  margin: var(--s-2) 0 var(--s-3);
  padding-left: var(--s-3);
}

.article li {
  margin-bottom: var(--s-1);
  line-height: var(--lh-body);
}

.article ul li {
  list-style: none;
  position: relative;
}

.article ul li::before {
  content: "\2014";
  position: absolute;
  left: -1.4em;
  color: var(--ink-faint);
}

/* =============================================================
   KaTeX tuning
   ============================================================= */

.katex {
  font-size: 1.05em;
}

.katex-display {
  margin: var(--s-3) 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.eq-number {
  float: right;
  color: var(--ink-faint);
  font-size: var(--fs-small);
  margin-top: 0.4em;
}

/* =============================================================
   Responsive
   ============================================================= */

@media (max-width: 48em) {
  .article {
    padding: var(--s-4) var(--s-3) var(--s-6);
  }
  .hero {
    padding-top: var(--s-3);
    padding-bottom: var(--s-4);
  }
}

@media (prefers-reduced-motion: reduce) {
  video.motion-required {
    display: none;
  }
  figure.fig .still-fallback {
    display: block;
  }
}

/* =============================================================
   Print
   ============================================================= */

@media print {
  body { background: white; color: black; }
  .article { max-width: 100%; padding: 0; }
  .sidenote {
    float: none;
    width: 100%;
    margin: 0.5em 0;
    padding: 0.5em;
    background: #f7f4ed;
    border-left: 2px solid #888;
    display: block !important;
  }
  video { display: none; }
  .colophon .resources a { border: 1px solid #888; }
  .section + .section { page-break-before: auto; }
}
