/* ---------- reset ---------- */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html {
  color-scheme: light;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

/* ---------- palette ---------- */

:root {
  --paper: #FBFAF7;
  --ink: #16181C;
  --text: #33363C;
  --muted: #6B6F77;
  --line: #E4E1DA;
  --wash: #F2F0EA;
  --lake: #2F6B69;

  --sans:  "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Lora", Georgia, serif;
  --mono:  ui-monospace, SFMono-Regular, Menlo, monospace;

  --serif-scale: 1;

  --measure: 42rem;
  --gutter: 1.5rem;
}

/* ---------- page ---------- */

body {
  background: var(--paper);
  color: var(--text);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv11", "ss01";
}

/*
 * Every block is a three-lane grid: prose sits in `text`, figures may
 * break out into `wide`. Grid children don't collapse margins, so the
 * vertical rhythm is set once by the owl below rather than per element.
 */
.flow {
  display: grid;
  grid-template-columns:
    [full-start] minmax(var(--gutter), 1fr)
    [wide-start] minmax(0, 6rem)
    [text-start] min(var(--measure), 100% - 2 * var(--gutter))
    [text-end] minmax(0, 6rem)
    [wide-end] minmax(var(--gutter), 1fr)
    [full-end];
}

.flow > * { grid-column: text; }
.flow > .wide { grid-column: wide; }
.flow > * + * { margin-top: 1.25rem; }

/* Figures and callouts get the same, larger gap above and below. */
.flow > :is(.figure, .note, .pull),
.flow > :is(.figure, .note, .pull) + * { margin-top: 2.25rem; }

/* Pull quotes have little padding so their rule hugs the text, so give them more margin. */
.flow > .pull,
.flow > .pull + * { margin-top: 3.5rem; }

/* ---------- site bar ---------- */

.site-bar {
  padding-block: 1.5rem;
  font-size: 0.875rem;
  color: var(--muted);
}

.site-bar a {
  color: var(--ink);
  font-weight: 500;
  text-decoration: none;
}

.site-bar a:hover { color: var(--lake); }

/* ---------- header ---------- */

.masthead {
  padding-top: 5rem;
  padding-bottom: 3.5rem;
}

h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: calc(clamp(2.5rem, 6vw, 3.5rem) * var(--serif-scale));
  line-height: 1.05;
  letter-spacing: -0.025em;
  color: var(--ink);
  text-wrap: balance;
}

.flow > h1 + * { margin-top: 1.5rem; }

/* ---------- contents ---------- */

.contents {
  padding-block: 1.5rem 1.75rem;
  border-block: 1px solid var(--line);
}

.contents h2 {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.contents ol {
  list-style: none;
  padding: 0;
  margin-top: 1rem;
  columns: 2;
  column-gap: 2rem;
  counter-reset: toc;
}

.contents li {
  counter-increment: toc;
  break-inside: avoid;
  display: flex;
  gap: 0.75rem;
  padding-block: 0.2rem;
  font-size: 0.9375rem;
  line-height: 1.45;
}

.contents li::before {
  content: counter(toc, decimal-leading-zero);
  flex: none;
  width: 1.5rem;
  padding-top: 0.1em;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
}

.contents a {
  color: var(--text);
  text-decoration: none;
}

.contents a:hover { color: var(--lake); }

@media (max-width: 34rem) {
  .contents ol { columns: 1; }
}

/* ---------- sections ---------- */

article { counter-reset: section; padding-bottom: 2rem; }

article > section {
  padding-top: 10rem;
  scroll-margin-top: 1rem;
}

article > section > h2 {
  counter-increment: section;
  font-family: var(--serif);
  font-weight: 400;
  font-size: calc(2rem * var(--serif-scale));
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-wrap: balance;
}

article > section > h2::before {
  content: counter(section, decimal-leading-zero);
  display: block;
  margin-bottom: 0.75rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.flow > h2 + * { margin-top: 1.5rem; }

p { text-wrap: pretty; }

strong { font-weight: 600; color: var(--ink); }

/* Named concepts, at the point the text introduces them. */
dfn {
  font-style: italic;
  font-weight: 500;
  color: var(--ink);
}

a {
  color: var(--lake);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in oklab, var(--lake) 40%, transparent);
  text-underline-offset: 3px;
  transition: text-decoration-color 150ms;
}

a:hover { text-decoration-color: var(--lake); }

/* Numbers still to be filled in: loud enough to spot, quiet enough to read past. */
.tbc {
  font-family: var(--mono);
  font-size: 0.8em;
  padding: 0.1em 0.4em;
  border-radius: 0.25rem;
  background: #FFF1C2;
  color: #7A5B00;
  white-space: nowrap;
}

/* ---------- figures ---------- */

.placeholder {
  display: grid;
  place-items: center;
  min-height: 9rem;
  padding: 1.5rem;
  border: 1px dashed #CFCBC1;
  border-radius: 0.75rem;
  background:
    repeating-linear-gradient(-45deg, transparent 0 10px, rgb(0 0 0 / 0.018) 10px 20px),
    var(--wash);
  text-align: center;
}

.placeholder span {
  max-width: 28rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--muted);
}

.placeholder span::before {
  content: "Illustration";
  display: block;
  margin-bottom: 0.25rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink);
  opacity: 0.55;
}

.illustration canvas {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 1;
}

.illustration canvas[data-snooker="shot"],
.illustration canvas[data-snooker="crowd"] { aspect-ratio: 1500 / 500; }
.illustration canvas[data-coffee="stages"] { aspect-ratio: 1000 / 230; }
.illustration canvas[data-coffee="ensemble"] { aspect-ratio: 1000 / 410; }
.illustration canvas[data-coffee="swirls"] { aspect-ratio: 1000 / 210; }
.illustration canvas[data-factory] { aspect-ratio: 1000 / 380; }
.illustration canvas[data-cascade] { aspect-ratio: 1000 / 200; }
/* The boxes set their own height once they know how their rows wrap. */
.illustration canvas[data-boxes] { aspect-ratio: auto; }
.illustration canvas[data-boxes="small"] { height: 78px; }
.illustration canvas[data-boxes="large"] { height: 128px; }
/* The trains figure sets its own height too, from its width. */
.illustration canvas[data-trains] { aspect-ratio: auto; height: 350px; }
/* The snowflakes also set their own height, once they know how they wrap. */
.illustration canvas[data-snowflakes] { aspect-ratio: auto; }
.illustration canvas[data-snowflakes="examples"] { height: 120px; }
.illustration canvas[data-snowflakes="average"] { height: 260px; }
.illustration canvas[data-snowflakes="symmetry"] { height: 244px; }
.illustration canvas[data-snowflakes="types"] { height: 260px; }
/* The Turing patterns set their own height too, from how their tiles wrap. */
.illustration canvas[data-turing] { aspect-ratio: auto; height: 380px; }
/* The climate scenarios set their own height from their width, like the trains. */
.illustration canvas[data-climate] { aspect-ratio: auto; height: 180px; }
.illustration canvas[data-climate="update"] { height: 376px; }
/* So do the coins, like the trains. */
.illustration canvas[data-coins] { aspect-ratio: auto; height: 160px; }

/* A single line under a figure. */
.caption {
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--muted);
  text-align: center;
  text-wrap: balance;
}

/* One label under each stage of a figure, three by default. */
.stages {
  display: grid;
  grid-template-columns: repeat(var(--stages, 3), 1fr);
  gap: 1rem;
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--muted);
  text-align: center;
  text-wrap: balance;
}

/* The cups take the left 76% of the ensemble figure and the averages the rest. */
.ensemble {
  grid-template-columns: 76fr 24fr;
  gap: 0;
}

.ensemble span { padding-inline: 0.5rem; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.75rem;
  margin-top: 0.75rem;
  padding-inline: 1.125rem;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--muted);
}

.legend span {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.legend span::before {
  content: "";
  flex: none;
  width: 1.25rem;
  transform: translateY(-0.2em);
}

.legend-bars::before {
  height: 0.6rem;
  border-radius: 2px 2px 0 0;
  background: #C9453B;
}

.legend-line::before { border-top: 2px dashed var(--ink); }
.legend-runs::before { border-top: 2px solid var(--lake); }
.legend-pooled::before { border-top: 3px solid #D9822B; }
.legend-window::before { height: 0.75rem; background: color-mix(in oklab, var(--lake) 12%, var(--paper)); }
.legend-caught::before { border-top: 4px solid var(--lake); border-radius: 2px; }
.legend-missed::before { border-top: 4px solid #C9453B; border-radius: 2px; }

/* ---------- asides and callouts ---------- */

/* A digression set off by hairlines, like a sidebar in a printed book. */
.note {
  padding-block: 1.5rem;
  border-block: 1px solid var(--line);
  font-size: 0.9688rem;
  line-height: 1.65;
}

.note p + p { margin-top: 0.75rem; }

/* The last line is the takeaway. */
.note p:last-child { color: var(--ink); }

.note-label {
  margin-bottom: 0.75rem;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: calc(1.25rem * var(--serif-scale));
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.pull {
  padding-block: 0.25rem;
  padding-right: 1.5rem;
  border-right: 2px solid var(--lake);
  font-family: var(--serif);
  font-style: italic;
  font-size: calc(1.625rem * var(--serif-scale));
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-align: right;
  text-wrap: balance;
}

/* ---------- footer ---------- */

.colophon {
  margin-top: 4rem;
  padding-block: 2rem 4rem;
  border-top: 1px solid var(--line);
  font-size: 0.875rem;
  color: var(--muted);
}

.colophon p + p { margin-top: 0.5rem; }

/* ---------- small screens ---------- */

@media (max-width: 40rem) {
  body { font-size: 1rem; }
  .masthead { padding-top: 3rem; }
  article > section { padding-top: 6rem; }
  .placeholder { min-height: 7rem; }
}
