/* site.css: the research-lab template. Layout, type and motion only.
   Every colour, face, size step and radius comes from brand.css. No raw brand values here. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-text);
  font-weight: var(--weight-text);
  font-size: var(--step-0);
  line-height: 1.6;
  font-feature-settings: "kern", "liga", "pnum";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
img, svg { display: block; max-width: 100%; }
h1, h2, h3, p, ol, ul, figure, table { margin: 0; }
ol, ul { padding: 0; list-style: none; }
::selection { background: var(--selection); }
.tnum { font-feature-settings: "kern", "tnum"; }

a {
  color: inherit;
  text-decoration-line: underline;
  text-decoration-color: var(--accent-tint);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
  transition: color 120ms ease, text-decoration-color 120ms ease;
}
a:hover { color: var(--accent); text-decoration-color: currentColor; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 2px; }

.skip {
  position: absolute; left: 1rem; top: -4rem; z-index: 10;
  background: var(--text); color: var(--surface);
  padding: 0.6rem 0.9rem; border-radius: var(--radius); text-decoration: none;
}
.skip:focus { top: 1rem; }

/* ---------- Frame and grid ---------- */
:root {
  --gutter: clamp(1rem, 4vw, 3rem);
  --rail: 8rem;
  --text-col: 40rem;
  --col-gap: 3rem;
  --section-gap: clamp(4.5rem, 9vw, 8.5rem);
}
.frame { width: min(100% - 2 * var(--gutter), 72rem); margin-inline: auto; }
.grid { display: grid; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 64rem) {
  .grid {
    grid-template-columns: [rail] var(--rail) [text] minmax(0, var(--text-col)) [note] minmax(0, 1fr) [end];
    column-gap: var(--col-gap);
  }
  .grid > * { grid-column: text / end; }
  .grid > .span-text { grid-column: text / note; }
  .grid > .span-wide { grid-column: text / end; }
  .grid > .note { grid-column: note / end; }
}

/* ---------- Lockup ---------- */
.lockup {
  --lockup-h: 20px;
  display: inline-flex; align-items: flex-start;
  gap: calc(var(--lockup-h) * var(--lockup-gap));
  color: inherit; text-decoration: none;
}
.lockup img { width: auto; filter: var(--logo-ink); }
.lockup__word { height: var(--lockup-h); }
.lockup__mark {
  height: calc(var(--lockup-h) * var(--lockup-mark-h));
  margin-top: calc(var(--lockup-h) * var(--lockup-mark-dy));
}
.lockup--small { --lockup-h: 17px; }

/* ---------- Masthead ---------- */
.masthead { border-bottom: var(--rule-w) solid var(--rule); }
.masthead__in {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 4rem; gap: 1.5rem;
}
.nav { display: flex; gap: clamp(1rem, 2.4vw, 2rem); font-size: var(--step--1); }
.nav a { color: var(--text-muted); text-decoration: none; padding-block: 0.5rem; }
.nav a:hover { color: var(--text); }
@media (max-width: 30rem) { .nav li:nth-child(3) { display: none; } }

/* ---------- Title ---------- */
.title { padding-top: clamp(2.75rem, 5vw, 4.25rem); }
.title__claim {
  font-family: var(--font-display);
  font-weight: var(--weight-display);
  font-size: var(--step-6);
  line-height: 0.98;
  letter-spacing: var(--tracking-display);
  text-wrap: balance;
  max-width: 11.5em;
}
.byline { line-height: 1.7; }
.byline a { color: var(--text); }
.abstract {
  margin-top: clamp(1.75rem, 3.5vw, 2.5rem);
  font-size: var(--step-1);
  line-height: 1.5;
  text-wrap: pretty;
}
.runin { font-weight: var(--weight-display); }

/* ---------- Figures ---------- */
.fig { margin-top: clamp(3rem, 5vw, 4.5rem); }
.caption {
  font-size: var(--step--1);
  line-height: 1.5;
  color: var(--text-muted);
  text-wrap: pretty;
}
.fig > .caption { margin-top: 1.25rem; }
.caption__n { color: var(--text); font-weight: var(--weight-display); }
.swatch {
  display: inline-block; width: 0.62em; height: 0.62em; margin-right: 0.3em;
  background: var(--bit-diff-one); vertical-align: 0.02em;
}

.bitfield { display: grid; gap: clamp(1.25rem, 2.5vw, 2rem); }
.bitfield__row { display: grid; gap: 0.75rem; }
.bitfield__label {
  display: flex; justify-content: space-between; gap: 1rem;
  font-size: var(--step--1); line-height: 1.35; color: var(--text-muted);
}
.bitfield__label span:first-child { color: var(--text); font-weight: var(--weight-display); }
.bitfield__key { font-size: var(--step--1); color: var(--text-muted); }
@media (min-width: 64rem) {
  .fig--bits > .bitfield { grid-column: rail / end; }
  .bitfield__row, .bitfield__key { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); column-gap: var(--col-gap); }
  .bitfield__key { display: block; padding-left: calc(var(--rail) + var(--col-gap)); }
  .bitfield__label { flex-direction: column; justify-content: flex-start; gap: 0.15rem; padding-top: 0.6rem; border-top: var(--rule-w) solid var(--rule-strong); align-self: start; }
}
.bits { width: 100%; height: auto; }

/* Phones: Figure 1 turns a quarter. One row per result, bits left to right, as a float is written. */
.bitfield--rot, .for-rot { display: none; }
@media (max-width: 40rem) {
  .bitfield--wide, .for-wide { display: none; }
  .bitfield--rot { display: grid; }
  .for-rot { display: inline; }
}
.rot { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 1.5rem; }
.rot__col { display: grid; align-content: start; gap: 0.5rem; }
.rot__col .bitfield__label { flex-direction: column; gap: 0.1rem; padding-top: 0.55rem; border-top: var(--rule-w) solid var(--rule-strong); }
.rot__legend {
  display: grid; grid-template-columns: 10fr 40fr 30fr 6fr;
  font-size: var(--step--1); line-height: 1.2; color: var(--text-muted);
  padding-bottom: 0.45rem; border-bottom: var(--rule-w) solid var(--rule);
}
.rot__legend span { white-space: nowrap; }
.bits rect {
  transform-box: fill-box; transform-origin: 50% 50%;
  transition: fill 380ms cubic-bezier(.22, 1, .36, 1), transform 380ms cubic-bezier(.22, 1, .36, 1);
}
.bits .one { fill: var(--bit-one); }
.bits .zero { fill: var(--bit-zero); transform: scaleY(0.4); }
.bits .diff.one { fill: var(--bit-diff-one); }
.bits .diff.zero { fill: var(--bit-diff-zero); }
.bits .tick { fill: var(--bit-diff-one); }

/* Motion moment 1: the patched bits start equal to the baseline and settle, once. */
.motion-ok [data-motion="bits"]:not(.is-set) .diff[data-was="1"] { fill: var(--bit-one); transform: none; }
.motion-ok [data-motion="bits"]:not(.is-set) .diff[data-was="0"] { fill: var(--bit-zero); transform: scaleY(0.4); }
.motion-ok [data-motion="bits"]:not(.is-set) .tick { transform: scaleX(0); }
.motion-ok [data-motion="bits"]:not(.is-set) .tick--v { transform: scaleY(0); }
.motion-ok [data-motion="bits"].is-set .diff,
.motion-ok [data-motion="bits"].is-set .tick { transition-delay: calc(var(--i) * 110ms); }

/* Figure 2: the flow */
.flow { display: grid; gap: 0; counter-reset: step; }
.flow__step {
  counter-increment: step;
  display: grid; gap: 0.5rem; align-content: start;
  padding: 1rem 0 1.5rem;
  border-top: var(--rule-w) solid var(--rule-strong);
}
.flow__step--key { border-top: 3px solid var(--bit-diff-one); padding-top: calc(1rem - 2px); }
.flow__k { font-size: var(--step--1); color: var(--text-muted); }
.flow__k::before { content: counter(step) "  "; white-space: pre; color: var(--text); font-feature-settings: "tnum"; }
.flow__v {
  font-family: var(--font-display); font-weight: var(--weight-display);
  font-size: var(--step-2); line-height: 1.15; letter-spacing: -0.012em; text-wrap: balance;
}
@media (min-width: 48rem) {
  .flow { grid-template-columns: repeat(3, minmax(0, 1fr)); column-gap: clamp(1.25rem, 2.5vw, 2rem); }
  .flow__v { padding-right: 1rem; }
}

/* ---------- Sections and prose ---------- */
.section { margin-top: var(--section-gap); }
.prose h2, .index__head h2 {
  position: relative;
  font-family: var(--font-display); font-weight: var(--weight-display);
  font-size: var(--step-3); line-height: 1.1; letter-spacing: -0.018em;
  text-wrap: balance; margin-bottom: 1.4rem;
}
.secno {
  display: block; font-size: var(--step--1); letter-spacing: 0; line-height: 1;
  color: var(--text-muted); margin-bottom: 0.9rem;
}
@media (min-width: 64rem) {
  .secno {
    position: absolute; left: calc(-1 * (var(--rail) + var(--col-gap)));
    top: 0.62em; margin: 0; font-size: var(--step-0);
    width: var(--rail); padding-top: 0.6rem; border-top: var(--rule-w) solid var(--rule-strong);
  }
  .prose h2 .secno, .index__head h2 .secno { font-size: var(--step--1); top: 0.4em; }
}
.prose p { margin-bottom: 1em; max-width: var(--text-col); text-wrap: pretty; }
.prose p:last-child { margin-bottom: 0; }

.note { font-size: var(--step--1); line-height: 1.55; color: var(--text-muted); margin-top: 1.75rem; }
.note p { padding-left: 0.9rem; border-left: var(--rule-w) solid var(--rule); max-width: 34rem; }
.ref { font-size: 0.62em; line-height: 0; vertical-align: 0.55em; margin-left: 0.08em; color: var(--accent); font-weight: var(--weight-display); }
.note__n { color: var(--accent); margin-right: 0.45em; font-weight: var(--weight-display); }
@media (min-width: 64rem) {
  .fig > .fig__note { grid-row: 2; margin-top: 1.25rem; }
  .title > .byline { grid-row: 2; margin-top: clamp(1.75rem, 3.5vw, 2.5rem); padding-top: 0.35rem; }
  .section > .note { grid-row: 1; margin-top: calc(var(--step-3) * 1.1 + 1.4rem + 0.35rem); align-self: start; }
  .note p { padding-left: 0; border-left: 0; }
}

/* Table 1 */
.fig-table { margin-top: clamp(2.5rem, 5vw, 3.5rem); }
table { width: 100%; border-collapse: collapse; font-feature-settings: "kern", "tnum"; }
caption.caption { caption-side: top; text-align: left; padding-bottom: 1rem; }
thead th {
  font-size: var(--step--1); font-weight: var(--weight-text); color: var(--text-muted);
  text-align: left; padding: 0 0 0.6rem; border-bottom: var(--rule-w) solid var(--rule-strong);
}
tbody th, tbody td { padding: 1.05rem 0; border-bottom: var(--rule-w) solid var(--rule); vertical-align: baseline; text-align: left; }
tbody th { font-weight: var(--weight-display); width: 24%; }
.num { text-align: right; padding-right: clamp(1rem, 4vw, 3.5rem); white-space: nowrap; }
thead th.num { text-align: right; padding-right: clamp(1rem, 4vw, 3.5rem); }
tbody td.num {
  font-family: var(--font-display); font-weight: var(--weight-display);
  font-size: var(--step-3); line-height: 1; letter-spacing: -0.02em; width: 26%;
}
tbody td:last-child { color: var(--text-muted); }
@media (max-width: 40rem) {
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  table, tbody { display: block; }
  tbody tr {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 1rem; row-gap: 0.3rem;
    align-items: baseline; padding: 0.95rem 0; border-bottom: var(--rule-w) solid var(--rule);
  }
  tbody tr:first-child { border-top: var(--rule-w) solid var(--rule-strong); }
  tbody th, tbody td { padding: 0; border: 0; width: auto; }
  tbody td.num { font-size: var(--step-2); width: auto; padding-right: 0; }
  tbody td:last-child { grid-column: 1 / -1; font-size: var(--step--1); }
  caption.caption { display: block; }
}

/* Notes index */
.index__head { display: flex; justify-content: space-between; align-items: baseline; gap: 0 1rem; flex-wrap: wrap; }
@media (max-width: 40rem) { .index__head { flex-direction: column; } .index__head h2 { margin-bottom: 0.4rem; } .index__all { margin-bottom: 1.4rem; } }
.index__head h2 { margin-bottom: 1.4rem; }
.index__all { font-size: var(--step--1); color: var(--text-muted); }
.index { counter-reset: note; border-bottom: var(--rule-w) solid var(--rule); }
.index__item {
  counter-increment: note;
  display: grid; grid-template-columns: 2.75rem minmax(0, 1fr) auto; column-gap: 1rem; align-items: baseline;
  padding: 1.1rem 0; border-top: var(--rule-w) solid var(--rule);
}
.index__item::before { content: "3." counter(note); font-size: var(--step--1); color: var(--text-muted); font-feature-settings: "tnum"; }
.index__link { text-decoration: none; }
.index__title { font-size: var(--step-1); line-height: 1.3; font-weight: var(--weight-display); text-wrap: balance; }
.index__link:hover .index__title { color: var(--accent); }
.index__meta {
  font-size: var(--step--1); color: var(--text-muted);
  border: var(--rule-w) solid var(--rule); border-radius: var(--radius); padding: 0.05rem 0.45rem;
}
@media (max-width: 40rem) {
  .index__item { grid-template-columns: 2.25rem minmax(0, 1fr); row-gap: 0.5rem; }
  .index__meta { grid-column: 2; justify-self: start; }
}

/* Team */
.people { margin-top: 1.75rem; border-bottom: var(--rule-w) solid var(--rule); }
.people li {
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap;
  padding: 0.95rem 0; border-top: var(--rule-w) solid var(--rule);
}
.people__name { font-size: var(--step-1); font-weight: var(--weight-display); }
.people a { color: var(--text-muted); }

/* ---------- Close: the one brand ground on the page ---------- */
.close {
  margin-top: var(--section-gap);
  background: var(--brand-plate) center / cover no-repeat, var(--brand-grad);
  color: var(--on-brand);
  padding-block: clamp(4.5rem, 10vw, 9rem);
}
@media (max-width: 48rem) { .close { background-image: var(--brand-plate-sm), var(--brand-grad); } }
.close__line {
  font-family: var(--font-display); font-weight: var(--weight-display);
  font-size: var(--step-5); line-height: 1.02; letter-spacing: var(--tracking-display);
  text-wrap: balance; max-width: 13em;
}
.close__act { margin-top: clamp(2rem, 4vw, 3rem); display: grid; gap: 1.25rem; justify-items: start; }
.close__act p { color: var(--on-brand-muted); max-width: 32rem; text-wrap: pretty; }
.button {
  display: inline-flex; align-items: center; min-height: 3rem;
  padding: 0.7rem 1.35rem; border-radius: var(--radius);
  background: var(--on-brand); color: var(--button-ink);
  font-weight: var(--weight-display); text-decoration: none;
  transition: background-color 140ms ease, color 140ms ease;
}
.button:hover { background: var(--brand-100); color: var(--brand-900); }
.close :focus-visible { outline-color: var(--on-brand); }

/* ---------- Colophon ---------- */
.colophon { padding-block: 2.5rem 3rem; font-size: var(--step--1); color: var(--text-muted); }
.colophon__in { display: grid; gap: 1rem; align-items: center; }
.colophon__links { display: flex; gap: 1.25rem; flex-wrap: wrap; }
@media (min-width: 64rem) {
  .colophon__in { grid-template-columns: var(--rail) minmax(0, var(--text-col)) minmax(0, 1fr); column-gap: var(--col-gap); }
  .colophon__in > .lockup { grid-row: 1 / span 2; align-self: start; }
  .colophon__links { grid-column: 3; grid-row: 1; justify-content: flex-end; }
  .colophon__small { grid-column: 3; grid-row: 2; text-align: right; }
}

/* Motion moment 2: Rim turns half a turn on load. Rim is symmetric under 180 degrees, so it lands where it began. */
@media (prefers-reduced-motion: no-preference) {
  .masthead [data-motion="rim"] { animation: rim-turn 1400ms cubic-bezier(.65, 0, .35, 1) 250ms both; }
  @keyframes rim-turn { from { transform: rotate(-180deg); } to { transform: rotate(0deg); } }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
