/* The long-form pages: How it works and Benchmarks.
   Loaded after styles.css, which sets the type, the colours and the top bar. */

:root {
  --line: #e7e7e4;
  --underline: #c2c2be;
  --rule: #a9a9a5;
  --bar: #d5d5d1;
  --code: #1c1c1c;
  --code-ink: #ecebe7;
  --code-dim: #8f8e89;
  --good: #1d6f6e;
  --bad: #e8651f;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

:root[data-theme="dark"] {
  --line: #2b2b29;
  --underline: #5a5a57;
  --rule: #6a6a66;
  --bar: #3a3a38;
  --code: #1b1b1b;
  --code-ink: #e4e3df;
  --code-dim: #8a8984;
  --good: #3fa3a0;
  --bad: #f07a3a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --line: #2b2b29;
    --underline: #5a5a57;
    --rule: #6a6a66;
    --bar: #3a3a38;
    --code: #1b1b1b;
    --code-ink: #e4e3df;
    --code-dim: #8a8984;
    --good: #3fa3a0;
    --bad: #f07a3a;
  }
}

.page {
  /* One column down the middle of the window holds everything: the title, the artwork, the figures
     and the article. The contents sit in the margin to its left, against it, and that margin is
     never narrower than they need; while the window is wide enough, the column is centred. */
  --col: 48rem;
  --toc-w: 13rem;
  --toc-gap: clamp(2rem, 4vw, 4rem);
  display: grid;
  grid-template-columns:
    [full-start] minmax(calc(var(--toc-w) + var(--toc-gap)), 1fr)
    [col-start] minmax(0, var(--col))
    [col-end] minmax(0, 1fr) [full-end];
  align-content: start;
  flex: 1;
  min-width: 0;
  padding: 0 var(--gutter);
}

.page > * {
  grid-column: col;
}

/* Title block */

.intro {
  padding: clamp(2rem, 5vw, 4.75rem) 0 clamp(1.5rem, 2.8vw, 2.5rem);
  /* The title block is centred over the column. */
  text-align: center;
}

.intro__kicker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
  justify-content: center;
  margin: 0 0 1.1rem;
  color: var(--soft);
  font-size: 0.9375rem;
}

.intro__kicker b {
  color: var(--ink);
  font-weight: 500;
}

.intro__kicker > * + *::before {
  content: "·";
  margin-right: 0.75rem;
}

.intro__title {
  margin: 0;
  font-size: clamp(2rem, 4.1vw, 4.25rem);
  font-weight: 400;
  line-height: 1.08;
  letter-spacing: -0.03em;
}

.intro__lede {
  max-width: 36em;
  margin: 1.1rem auto 0;
  color: var(--soft);
  font-size: clamp(1.125rem, 1.5vw, 1.375rem);
  line-height: 1.4;
  letter-spacing: -0.01em;
  text-wrap: pretty;
}

/* The artwork as a band. Its picture and crop come from the hero rules in styles.css. */

/* The box takes the picture's own shape, 1600 by 700, so the whole of it shows. */
.banner {
  flex: 0 0 auto;
  height: auto;
  aspect-ratio: 16 / 7;
  min-height: 0;
  margin: 0;
  border-radius: 16px;
}

/* Figures at a glance */

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1.75rem clamp(1rem, 2vw, 1.75rem);
  margin: 0;
  padding: clamp(1.75rem, 3vw, 2.75rem) 0 0;
}

.stats > div {
  display: grid;
  align-content: start;
  gap: 0.15rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--line);
}

.stats dt {
  color: var(--soft);
  font-size: 0.9375rem;
}

.stats dd {
  margin: 0;
  color: var(--soft);
  font-size: 0.875rem;
}

.stats dd:first-of-type {
  color: var(--ink);
  font-size: clamp(2rem, 3.4vw, 3.25rem);
  line-height: 1.15;
  letter-spacing: -0.035em;
}

/* Contents beside the article */

/* The article in the column, the contents beside it at the inner edge of the left margin. */
.body {
  display: grid;
  grid-column: full;
  grid-template-columns: subgrid;
  align-items: start;
  padding: clamp(2.25rem, 4.5vw, 4rem) 0 clamp(3rem, 6vw, 6rem);
}

.toc {
  grid-row: 1;
  grid-column: 1;
  justify-self: end;
  width: var(--toc-w);
  margin-right: var(--toc-gap);
}

.body__main {
  grid-row: 1;
  grid-column: 2;
}

.body__main {
  min-width: 0;
}

.toc {
  position: sticky;
  top: 2rem;
  font-size: 0.9375rem;
}

.toc h2 {
  margin: 0 0 0.75rem;
  color: var(--soft);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.toc ol {
  margin: 0;
  padding: 0;
  border-left: 1px solid var(--line);
  list-style: none;
}

.toc a {
  display: block;
  margin-left: -1px;
  padding: 0.3rem 0 0.3rem 0.9rem;
  border-left: 1px solid transparent;
  color: var(--soft);
  transition: color 0.2s, border-color 0.2s;
}

.toc a:hover,
.toc a[aria-current] {
  color: var(--ink);
}

.toc a[aria-current] {
  border-left-color: var(--ink);
}

/* Article text. Text keeps a readable measure; anything marked wide takes the whole column. */

.prose {
  font-size: 1.0625rem;
  line-height: 1.65;
  counter-reset: part;
}

.prose > section {
  counter-increment: part;
  scroll-margin-top: 2rem;
}

.prose > section + section {
  margin-top: clamp(3rem, 5vw, 4.25rem);
}

.prose > section > * {
  max-width: none;
  margin-top: 0;
  margin-bottom: 1.15rem;
}

.prose > section > :last-child {
  margin-bottom: 0;
}

.prose > section > .wide {
  max-width: none;
}

.prose > section > figure,
.prose > section > blockquote {
  margin: 2rem 0;
}

.prose h2 {
  margin: 0 0 1rem;
  font-size: clamp(1.5rem, 2.2vw, 1.875rem);
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: -0.025em;
}

.prose h2::before {
  content: counter(part, decimal-leading-zero);
  display: block;
  margin-bottom: 0.7rem;
  color: var(--soft);
  font: 500 0.8125rem/1 var(--mono);
}

/* The source file a section describes. */
.prose .where {
  margin: -0.5rem 0 1.1rem;
  color: var(--soft);
  font-size: 0.875rem;
}

.prose > section > :is(ul, ol) {
  padding-left: 1.25rem;
}

.prose > section > :is(ul, ol) > li + li {
  margin-top: 0.35rem;
}

.prose li::marker {
  color: var(--soft);
}

.prose :is(p, li, dd, figcaption) a {
  text-decoration: underline;
  text-decoration-color: var(--underline);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: text-decoration-color 0.2s;
}

.prose :is(p, li, dd, figcaption) a:hover {
  text-decoration-color: currentColor;
}

.prose code {
  padding: 0.1em 0.35em;
  border-radius: 3px;
  background: var(--tile);
  font: 0.875em var(--mono);
}

.prose pre {
  padding: 1rem 1.15rem;
  border-radius: 4px;
  background: var(--code);
  color: var(--code-ink);
  font: 0.875rem/1.6 var(--mono);
  overflow-x: auto;
}

.prose pre code {
  padding: 0;
  background: none;
  font: inherit;
}

.prose pre .dim {
  color: var(--code-dim);
}

.prose blockquote {
  padding-left: 1.25rem;
  border-left: 2px solid var(--ink);
  font-size: clamp(1.25rem, 1.8vw, 1.5rem);
  line-height: 1.35;
  letter-spacing: -0.015em;
}

.prose blockquote p {
  margin: 0;
}

.prose figcaption {
  margin-top: 0.8rem;
  color: var(--soft);
  font-size: 0.875rem;
  line-height: 1.45;
}

.note {
  padding: 0.9rem 1.1rem;
  border-radius: 4px;
  background: var(--tile);
}

.note strong {
  font-weight: 600;
}

/* A list of terms and what they mean. The spec variant has the label quiet and the value in ink. */

.terms {
  border-top: 1px solid var(--line);
}

.terms > div {
  display: grid;
  grid-template-columns: 10rem minmax(0, 1fr);
  gap: 0.2rem 1.5rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--line);
}

.terms dt {
  font-weight: 500;
}

.terms dd {
  margin: 0;
  color: var(--soft);
}

/* The loop, as a row of steps that ends in two outcomes */

.flow {
  --ends-gap: 0.75rem;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  /* The steps are as tall as their words, centred on the two ends they lead to. */
  align-items: center;
  gap: 1.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.flow > li {
  position: relative;
}

.flow__step,
.flow__end {
  display: grid;
  align-content: start;
  gap: 0.2rem;
  padding: 1rem 1.1rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 4px;
}

/* The number, the name and the text, in that order. The text keeps four lines, so the three steps
   are the same height. */
.flow__step {
  counter-increment: step;
}

.flow__step span {
  min-height: calc(4 * 1.4em);
}

.flow__step::before {
  content: counter(step);
  margin-bottom: 0.75rem;
  color: var(--soft);
  font: 500 0.8125rem/1 var(--mono);
}

.flow b {
  font-weight: 600;
  letter-spacing: -0.01em;
}

.flow span {
  color: var(--soft);
  font-size: 0.9375rem;
  line-height: 1.4;
}

.flow__ends {
  display: grid;
  grid-auto-rows: 1fr;
  gap: var(--ends-gap);
}

/* Verdigris where the prediction held, orange where it did not: the two colours of the artwork. */
.flow__end b::before {
  content: "";
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  margin-right: 0.5rem;
  border-radius: 50%;
  background: var(--good);
}

.flow__end--off b::before {
  background: var(--bad);
}

/* The arrow into each step after the first: a 1px line and the same arrowhead as the fork's
   branches below, so every arrow in the diagram is drawn alike. */
.flow > .flow__step + .flow__step::after {
  content: "";
  position: absolute;
  top: calc(50% - 4px);
  right: 100%;
  width: 1.75rem;
  height: 8px;
  background:
    linear-gradient(var(--rule), var(--rule)) left 50% / calc(100% - 1px) 1px no-repeat,
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='5' height='8' fill='none' stroke='%23a9a9a5'%3E%3Cpath d='M.5 .5 4 4 .5 7.5'/%3E%3C/svg%3E") right 50% / 5px 8px no-repeat;
}

/* Into the ends the line forks: a stem out of the last step, then a branch with an arrow to the
   middle of each end. The middles are a quarter of the way in, less a quarter of the gap. */
.flow__ends {
  position: relative;
  --branch: calc((100% - var(--ends-gap)) / 4);
}

.flow__ends::before,
.flow__ends::after {
  content: "";
  position: absolute;
  right: 100%;
  pointer-events: none;
}

/* The stem, and the two branches as one bracket that opens towards the ends. */
.flow__ends::before {
  top: var(--branch);
  bottom: var(--branch);
  width: 0.875rem;
  border: 1px solid var(--rule);
  border-right: 0;
  border-radius: 3px 0 0 3px;
}

/* The stem, and an arrowhead at the end of each branch. */
.flow__ends::after {
  top: calc(var(--branch) - 4px);
  bottom: calc(var(--branch) - 4px);
  width: 1.75rem;
  background:
    linear-gradient(var(--rule), var(--rule)) left 50% / 0.875rem 1px no-repeat,
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='5' height='8' fill='none' stroke='%23a9a9a5'%3E%3Cpath d='M.5 .5 4 4 .5 7.5'/%3E%3C/svg%3E") right top / 5px 8px no-repeat,
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='5' height='8' fill='none' stroke='%23a9a9a5'%3E%3Cpath d='M.5 .5 4 4 .5 7.5'/%3E%3C/svg%3E") right bottom / 5px 8px no-repeat;
}

/* Bar charts */

.plate {
  padding: 1.75rem 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.charts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2rem clamp(1.5rem, 5vw, 4rem);
}

.charts--3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

/* Three charts side by side leave little room in a row: the bar goes under its name and value. */
.charts--3 .bars dd {
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "name value" "bar bar";
  row-gap: 0.2rem;
  line-height: 1.4;
}

.charts--3 .bars dd + dd {
  margin-top: 0.45rem;
}

.charts--3 .bars span {
  grid-area: name;
}

.charts--3 .bars b {
  grid-area: value;
}

.charts--3 .bars i {
  grid-area: bar;
}

.chart h3 {
  margin: 0 0 1rem;
  font-size: 0.9375rem;
  font-weight: 600;
}

.bars {
  margin: 0;
}

/* Groups of bars, one per model, each on its own scale: a rule between them. */
.bars > div + div {
  margin-top: 1.1rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--line);
}

.bars dt {
  margin-bottom: 0.35rem;
  color: var(--soft);
  font-size: 0.8125rem;
}

/* One row of a chart: the variant, its bar, and the value. */
.bars dd {
  display: grid;
  grid-template-columns: 4.75rem minmax(0, 1fr) 3.75rem;
  align-items: center;
  gap: 0.75rem;
  margin: 0;
  color: var(--soft);
  font-size: 0.875rem;
  line-height: 1.7;
}

.bars i {
  display: block;
  height: 0.625rem;
  border-radius: 2px;
  background: var(--bar);
}

.bars b {
  color: var(--ink);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.bars .is-sage {
  color: var(--ink);
}

.bars .is-sage i {
  background: var(--ink);
}

/* Results table */

.table-wrap {
  overflow-x: auto;
}

.prose table {
  width: 100%;
  min-width: 42rem;
  border-collapse: collapse;
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
}

.prose th,
.prose td {
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

.prose thead th {
  color: var(--soft);
  font-size: 0.8125rem;
  font-weight: 500;
}

.prose thead th:nth-child(-n + 2),
.prose tbody th,
.prose td:first-of-type {
  text-align: left;
}

.prose thead th:first-child,
.prose tbody th {
  padding-left: 0;
}

.prose th:last-child,
.prose td:last-child {
  padding-right: 0;
}

.prose tbody th {
  font-weight: 500;
  vertical-align: top;
}

.prose tbody td {
  color: var(--soft);
}

.prose .is-sage td {
  color: var(--ink);
  font-weight: 500;
}

.prose table small {
  color: var(--soft);
  font-size: inherit;
  font-weight: 400;
}

/* Previous and next */

.pager {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  max-width: none;
  margin-top: clamp(3rem, 5vw, 4.25rem);
}

.pager a {
  display: grid;
  gap: 0.1rem;
  padding: 0.9rem 1.15rem 1rem;
  border-radius: 4px;
  background: var(--tile);
  transition: background-color 0.25s;
}

.pager a:hover {
  background: var(--tile-hover);
}

.pager span {
  color: var(--soft);
  font-size: 0.875rem;
}

.pager b {
  font-size: 1.125rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.pager__next {
  text-align: right;
}

/* Footer */

.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 2rem;
  padding: 1.75rem var(--gutter);
  border-top: 1px solid var(--line);
  color: var(--soft);
  font-size: 0.9375rem;
}

.foot ul {
  display: flex;
  gap: 1.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.foot a {
  transition: color 0.2s;
}

.foot a:hover {
  color: var(--ink);
}

/* Smaller screens */

@media (max-width: 960px) {
  /* One column the width of the window, the contents above the article. */
  .page {
    grid-template-columns: [full-start col-start] minmax(0, 1fr) [col-end full-end];
  }

  .body {
    grid-template-columns: minmax(0, 1fr);
    gap: 2rem;
  }

  .toc,
  .body__main {
    grid-row: auto;
    grid-column: 1;
  }

  .toc {
    justify-self: stretch;
    width: auto;
    margin-right: 0;
  }

  /* The contents move above the article. */
  .toc {
    position: static;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--line);
  }

  .toc ol {
    border-left: 0;
    columns: 2;
    column-gap: 2rem;
  }

  .toc a {
    margin-left: 0;
    padding-left: 0;
    border-left: 0;
  }
}

@media (max-width: 700px) {
  .stats,
  .charts {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .charts,
  .flow,
  .terms > div {
    grid-template-columns: minmax(0, 1fr);
  }

  .flow {
    gap: 0.75rem;
  }

  .flow > .flow__step + .flow__step::after,
  .flow__ends::before,
  .flow__ends::after {
    display: none;
  }

  .flow__step span {
    min-height: 0;
  }

  .flow__step::before {
    margin-bottom: 0.75rem;
  }
}

@media (max-width: 460px) {
  /* The date takes its own line, without the dot that would lead it. */
  .intro__kicker > :last-child {
    flex-basis: 100%;
  }

  .intro__kicker > :last-child::before {
    display: none;
  }

  .toc ol {
    columns: 1;
  }

  .pager {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Motion */

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }

  .intro > * {
    animation: rise 0.8s var(--ease) both;
  }

  .intro__title {
    animation-delay: 0.06s;
  }

  .intro__lede {
    animation-delay: 0.12s;
  }
}
