/* mjbench's design, self-contained. The language, which every rule below follows:

   - Paper. One page colour per theme, barely warm, and hairlines rather than boxes of colour.
   - Type. The serif only for the page name, section titles and headline numbers. Everything else is IBM Plex Sans
     at three sizes: --fs (data), --fs-sm (secondary, captions, cards), --fs-xs in Plex Mono (marks: ticks, shas,
     units). Two weights: 400, and 600 for emphasis.
   - Colour by role. --ink primary, --ink-2 secondary, --muted quiet marks, --hairline rules, --wash fills.
     --fast and --slow mean direction and nothing else; --accent marks B and the selection; stage colours appear
     only where stages are drawn.
   - Stages. Collision red, setup green and solver blue, the hues of MuJoCo Studio's timers; kinematics amber,
     velocity lavender, the rest grey. Dark and light alternate so that every pair stays apart under protan, deutan
     and tritan vision (OKLab dE x100 of at least 8; 15 under normal vision).
   - Space. Steps of 8 px, each kind of gap always the same one: --s1 within a group, --s2 a heading to its content,
     --s3 between siblings, --s5 between sections, --s6 the end of the page; --s0 (4 px) inside components. One
     radius, --r.
   - Components, each defined once: link, segmented control, panel, table, card, chip, chart text. */

:root {
  color-scheme: light;
  --paper: #faf9f6;
  --ink: #1c1b1a;
  --ink-2: #5c5b57;
  --muted: #87867f;
  --hairline: #e6e4dd;
  --line: #cfccc3;
  --serif: "Source Serif 4", "Iowan Old Style", Charter, Georgia, serif;
  --text-lg: 1.5rem;
  --name: 1.8rem;
  --fs: 0.9rem;
  --fs-sm: 0.82rem;
  --fs-xs: 0.72rem;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --s0: 0.25rem;
  --s1: 0.5rem;
  --s2: 1rem;
  --s3: 1.5rem;
  --s4: 2rem;
  --s5: 3rem;
  --s6: 4rem;
  --gutter: 1.25rem;
  --bar: 5.5rem;
  --r: 6px;
  --wide: 76rem;
  --surface: var(--paper);
  --wash: #f1efe9;
  --wash-2: #e9e7e0;
  --grid: #ebe9e3;
  --fast: #1f66bd;
  --slow: #b8362d;
  --fast-ink: #1f66bd;
  --slow-ink: #b8362d;
  --accent: var(--fast);
  --st-kinematics: #dc9741;
  --st-collision: #b03e38;
  --st-setup: #5fb88a;
  --st-solver: #375e9e;
  --st-velocity: #b3a1db;
  --st-other: #83817a;
  --shadow: 0 4px 16px rgba(31, 30, 29, 0.12);
}
/* Dark: the reader's choice if they made one, else the system's. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #181817; --ink: #f1f0ec; --ink-2: #aeada8; --hairline: #353533; --line: #575754;
    --wash: #222221; --wash-2: #323230; --grid: #2a2a28;
    --fast: #4a91e6; --slow: #e5655a; --fast-ink: #7fb1ee; --slow-ink: #ef8b82;
    --st-kinematics: #d8a04d; --st-collision: #a64832; --st-setup: #81d1b3; --st-solver: #4460a2; --st-velocity: #b6a0da; --st-other: #878682; --shadow: 0 4px 18px rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #181817; --ink: #f1f0ec; --ink-2: #aeada8; --hairline: #353533; --line: #575754;
  --wash: #222221; --wash-2: #323230; --grid: #2a2a28;
  --fast: #4a91e6; --slow: #e5655a; --fast-ink: #7fb1ee; --slow-ink: #ef8b82;
  --st-kinematics: #d8a04d; --st-collision: #a64832; --st-setup: #81d1b3; --st-solver: #4460a2; --st-velocity: #b6a0da; --st-other: #878682; --shadow: 0 4px 18px rgba(0, 0, 0, 0.5);
}

@media (max-width: 760px) { :root { --bar: 5rem; --name: 1.5rem; } }

/* Base */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 400 var(--fs)/1.5 var(--sans); font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; overflow-x: hidden; }
h1, h2, p, figure { margin: 0; }
h2 { font: 600 var(--text-lg)/1.2 var(--serif); letter-spacing: -0.01em; font-variation-settings: "opsz" 36; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: var(--gutter); top: -40px; background: var(--paper); padding: var(--s0); border: 1px solid var(--hairline); z-index: 20; }
.skip:focus { top: var(--s0); }
.mono { font-family: var(--mono); }
.muted { color: var(--ink-2); }
.strong { font-weight: 600; }
.fast { color: var(--fast-ink); }
.slow { color: var(--slow-ink); }
.r, .num { text-align: right; white-space: nowrap; }

/* Link: a hairline underline that darkens on hover. */
a, .link { color: inherit; text-decoration: underline; text-decoration-color: var(--line); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.link { all: unset; cursor: pointer; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
a:hover, .link:hover { color: var(--ink); text-decoration-color: currentColor; }
.link:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Layout */
.wrap { max-width: calc(var(--wide) + 2 * var(--gutter)); margin: 0 auto; padding: 0 var(--gutter); }
main.wrap { display: flex; flex-direction: column; gap: var(--s5); padding-bottom: var(--s6); }
section { display: flex; flex-direction: column; gap: var(--s2); min-width: 0; }
.head { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s3); align-items: flex-end; justify-content: space-between; border-top: 1px solid var(--hairline); padding-top: var(--s2); }
.head .count { font: 400 var(--fs-xs) var(--mono); color: var(--ink-2); margin-left: var(--s1); vertical-align: 2px; }
.panel { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r); min-width: 0; }
.panel.pad { padding: var(--s2) var(--s2) var(--s1); }
.scroll { overflow: auto; }
.scroll.tall { max-height: 40rem; }
.empty { padding: var(--s5) var(--s2); text-align: center; color: var(--ink-2); }

/* The bar: the name, a status line (machine, freshness, newest commit) in caption size, the theme toggle. It slides
   away as the reader scrolls down and returns at the slightest scroll up. */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--paper); transition: transform 0.3s cubic-bezier(0.165, 0.84, 0.44, 1); }
.topbar.is-hidden:not(:has(:focus-visible)) { transform: translateY(-100%); }
.site-bar { height: var(--bar); display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.site-name { font: 600 var(--name)/1 var(--serif); letter-spacing: -0.01em; font-variation-settings: "opsz" 36; white-space: nowrap; }
.status { font: 400 var(--fs-sm)/1.4 var(--sans); color: var(--ink-2); margin-left: auto; margin-right: var(--s3); }
.status .on { color: var(--ink); cursor: help; }
.site-actions { display: flex; align-items: center; margin-right: -0.55rem; }  /* the icon, not its circle, meets the edge */
.icon-button { width: 2.75rem; height: 2.75rem; padding: 0; display: grid; place-items: center; border: 1px solid transparent; border-radius: 50%; background: none; color: var(--ink-2); cursor: pointer; transition: color 0.2s, border-color 0.2s; }
@media (hover: hover) { .icon-button:hover { color: var(--ink); border-color: var(--hairline); } }
.icon-button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.icon-button svg { width: 1.5rem; height: 1.5rem; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .icon-sun { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
}
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

/* Controls: a segmented control, and a search field in the same frame. */
.segmented { display: inline-flex; align-self: flex-start; border: 1px solid var(--hairline); border-radius: var(--r); overflow: hidden; }
.segmented button { height: 2rem; padding: 0 0.7rem; font: 400 var(--fs-sm) var(--sans); border: 0; background: none; color: var(--ink-2); cursor: pointer; white-space: nowrap; }
.segmented button + button { border-left: 1px solid var(--hairline); }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.segmented button:hover:not([aria-pressed="true"]) { color: var(--ink); }
.segmented b { margin-left: var(--s0); font: 400 var(--fs-xs) var(--mono); opacity: 0.8; }
input[type="search"] { height: 2rem; width: min(18rem, 100%); padding: 0 0.6rem; font: 400 var(--fs-sm) var(--sans); background: var(--paper); color: var(--ink); border: 1px solid var(--hairline); border-radius: var(--r); }
input[type="search"]:hover { border-color: var(--line); }

/* A and B tags. */
.tag { display: inline-flex; align-items: center; justify-content: center; min-width: 16px; height: 16px; padding: 0 3px; font: 600 10.5px/1 var(--mono); border-radius: 2px; color: var(--paper); }
.tag.a { background: var(--ink-2); }
.tag.b { background: var(--accent); }

/* Headline: each group's speedup from A to B, over its own span: a group starts where its first scene loads. */
.summary { padding-top: var(--s3); }
.stats { display: flex; flex-wrap: wrap; gap: var(--s3) var(--s5); }
.stat { all: unset; display: flex; align-items: flex-end; gap: var(--s3); cursor: pointer; }
.stat .fig { display: flex; flex-direction: column; gap: var(--s0); }
.stat .num { text-align: left; font: 600 clamp(2.2rem, 4.4vw, 3.25rem)/1 var(--serif); letter-spacing: -0.02em; font-variation-settings: "opsz" 60; font-variant-numeric: proportional-nums; color: var(--ink-2); transition: color 0.2s; }
.stat .name { color: var(--ink-2); }
.stat.on .num, .stat.on .name, .stat:hover .num, .stat:hover .name { color: var(--ink); }
.stat:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px; }
.spark { display: block; width: 13.75rem; height: 3rem; overflow: visible; }
.spark-line { fill: none; stroke: var(--ink-2); stroke-width: 1.5; stroke-linejoin: round; transition: stroke 0.2s; }
.stat.on .spark-line, .stat:hover .spark-line { stroke: var(--ink); }
.spark-dot { fill: var(--accent); }
.stat .span { margin-top: var(--s0); font: 400 var(--fs-xs)/1 var(--mono); color: var(--ink-2); }

/* Card: the one hover card. A mono caption title, then rows of label (secondary) and value (primary), a colour key
   in front only when the row has one, hairline dividers. */
.tip { position: fixed; z-index: 30; pointer-events: none; display: none; width: max-content; max-width: min(22rem, calc(100vw - 16px));
  background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r); box-shadow: var(--shadow); padding: var(--s1) var(--s2); font-size: var(--fs-sm); }
.tip .tt { color: var(--ink); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tip .tm { margin-top: 2px; font: 400 var(--fs-xs) var(--mono); color: var(--ink-2); }
.tip .th { font: 400 var(--fs-xs) var(--mono); color: var(--ink-2); }
.tip .m { font: 400 var(--fs-xs) var(--mono); }
.tip .q { color: var(--ink-2); font-weight: 400; }
.tip .tt.split { display: flex; justify-content: space-between; gap: var(--s3); }
.tip .cols { display: grid; grid-template-columns: auto auto; gap: 0 var(--s3); }
.tip .tg { display: grid; gap: 1px var(--s2); align-items: baseline; }
.tip .tg + .tg { margin-top: var(--s1); }
.tip .tg .hd { font-size: var(--fs-xs); color: var(--ink-2); }
.tip .tg span { color: var(--ink-2); white-space: nowrap; }
.tip .tg span .tk { display: inline-block; margin-right: var(--s0); vertical-align: -1px; }
.tip .tg b { font-weight: 600; color: var(--ink); text-align: right; }
.tip .ts { margin: 2px 0 var(--s0); line-height: 1.35; color: var(--ink); overflow-wrap: anywhere; }
.tip .tr { display: grid; grid-template-columns: auto 1fr auto; gap: var(--s1); align-items: baseline; }
.tip .tr.nk { grid-template-columns: auto 1fr; }
.tip .tr span { color: var(--ink-2); }
.tip .tr b { font-weight: 600; text-align: right; color: var(--ink); }
.tip .tk { width: 10px; height: 10px; border-radius: 2px; align-self: center; }
.tip .sc { display: grid; grid-template-columns: auto auto; gap: 1px var(--s2); margin-top: var(--s0); font: 400 var(--fs-xs)/1.35 var(--mono); }
.tip .sc span { color: var(--ink-2); }
.tip .sc b { font-weight: 400; text-align: right; color: var(--ink); }
.tip hr { border: 0; border-top: 1px solid var(--hairline); margin: var(--s0) 0; }

/* Table: sans caption headers, hairline rows, washed group rows; a picked row is washed and marked in accent. */
table { border-collapse: collapse; width: 100%; }
th, td { padding: var(--s0) var(--s1); text-align: left; vertical-align: middle; font-weight: 400; border-bottom: 1px solid var(--grid); }
th.num, td.num { text-align: right; }
thead th { position: sticky; top: 0; z-index: 2; background: var(--surface); font: 400 var(--fs-sm)/1.3 var(--sans); color: var(--ink-2); white-space: nowrap; border-bottom: 1px solid var(--hairline); vertical-align: bottom; }
tbody tr:last-child > * { border-bottom: 0; }
tr.grp > * { background: var(--wash); font-size: var(--fs-sm); color: var(--ink-2); border-bottom: 1px solid var(--hairline); }
tr.grp .n { margin-left: var(--s1); font: 400 var(--fs-xs) var(--mono); }
tr.pick { cursor: pointer; }
tr.pick:hover > * { background: color-mix(in oklab, var(--wash) 55%, var(--surface)); }
tr.on > * { background: var(--wash); }
tr.on > :first-child { box-shadow: inset 2px 0 0 var(--accent); }
tr.isa > :first-child { box-shadow: inset 2px 0 0 var(--ink-2); }
.scn { all: unset; cursor: pointer; font: 400 var(--fs) var(--mono); }
.scn:hover { text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
.scn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.unit { font: 400 var(--fs-xs) var(--mono); color: var(--ink-2); }

/* Chip: a scene with its change, keyed on the left by direction. */
.chips { display: flex; flex-wrap: wrap; gap: var(--s0); }
.chip { all: unset; cursor: pointer; display: inline-flex; gap: var(--s0); align-items: baseline; font-size: var(--fs-sm); line-height: 1.4; padding: 0 6px; border: 1px solid var(--hairline); border-radius: 2px; white-space: nowrap; color: var(--ink-2); }
.chip:hover { border-color: var(--line); }
.chip:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }
.chip.cf { box-shadow: inset 2px 0 0 var(--fast); }
.chip.cs { box-shadow: inset 2px 0 0 var(--slow); }
.chip.cn { box-shadow: inset 2px 0 0 var(--muted); }
.chip b { font-weight: 600; color: var(--ink); }
.chip .cl { font-size: var(--fs-xs); color: var(--ink-2); }

/* Chart text roles: track titles in sans, ticks, values and row labels in mono. */
.chart { position: relative; width: 100%; outline-offset: 4px; }
.chart svg { display: block; width: 100%; touch-action: pan-y; -webkit-user-select: none; user-select: none; }
.chart text { font: 400 var(--fs-xs) var(--mono); fill: var(--ink-2); }
.chart text.t { font: 400 var(--fs-sm) var(--sans); fill: var(--ink); }
.chart text.ts, .chart tspan.ts { font: 400 var(--fs-xs) var(--sans); fill: var(--ink-2); }
.chart text.row { cursor: pointer; }
.chart text.row.on { fill: var(--ink); font-weight: 600; }
.chart text.note { font: 400 var(--fs-xs) var(--sans); }
.chart text.val { fill: var(--ink); }
.chart text.val, .chart text.note, .chart text.halo { paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; }
.chart text.flagtx { font: 600 9.5px var(--mono); fill: var(--paper); }
.g-grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.g-axis { stroke: var(--hairline); stroke-width: 1; shape-rendering: crispEdges; }
.g-one { stroke: var(--muted); stroke-width: 1; shape-rendering: crispEdges; }
.g-noise { fill: var(--wash); }
.g-mean { stroke: var(--ink); stroke-width: 2; fill: none; stroke-linejoin: round; stroke-linecap: round; }
.g-band { fill: var(--ink); opacity: 0.1; }
.g-ctx { stroke: var(--muted); stroke-width: 1; fill: none; stroke-linejoin: round; opacity: 0.75; }
.g-raw { stroke: var(--ink-2); stroke-width: 1; fill: none; stroke-linejoin: round; opacity: 0.45; }
.g-sel { stroke: var(--accent); stroke-width: 1.75; fill: none; stroke-linejoin: round; stroke-linecap: round; }
.g-stage { stroke: none; }
.g-dot { stroke: var(--surface); stroke-width: 2; }
.g-leader { stroke: var(--muted); stroke-width: 1; }
.g-hair { stroke: var(--ink-2); stroke-width: 1; pointer-events: none; shape-rendering: crispEdges; }
.g-a { stroke: var(--ink-2); stroke-width: 1; shape-rendering: crispEdges; }
.g-b { stroke: var(--accent); stroke-width: 1; shape-rendering: crispEdges; }
.g-cellsel { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.g-rowsel { fill: var(--accent); }
.f-a { fill: var(--ink-2); } .f-b { fill: var(--accent); } .f-ink { fill: var(--ink); }
.f-fast { fill: var(--fast); } .f-slow { fill: var(--slow); } .f-neutral { fill: var(--muted); }
.handle { cursor: ew-resize; outline: none; }
.handle .grip { fill: transparent; }
.handle:focus-visible .grip { stroke: var(--ink); stroke-width: 1.5; }
.hit { fill: transparent; cursor: crosshair; }
.zoomband { fill: var(--accent); opacity: 0.12; pointer-events: none; }

/* Scenes: a row per scene; time per stage at A (upper bar) and B (lower), on one scale per row. */
.scenes .tcell { width: 5.5rem; padding: var(--s0) var(--s1) var(--s0) var(--s2); }
.scenes .thumb { display: block; width: 5rem; height: 2.8rem; border-radius: 3px; object-fit: cover; background: var(--wash); }
.scenes .thumb.none { background: none; }
.scenes .sim { color: var(--ink-2); cursor: help; }
.scenes .bcell { width: 42%; padding-right: var(--s2); }
.scenes svg.bars { display: block; width: 100%; height: 22px; }
.scenes tr.open > td { padding: 0; background: var(--surface); }
.stagekey { display: flex; flex-wrap: wrap; gap: 2px var(--s2); font: 400 var(--fs-sm) var(--sans); color: var(--ink-2); }
.stagekey i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: var(--s0); vertical-align: -1px; }

/* A scene, opened under its row: the run, its numbers, one chart. */
.detail { padding: var(--s3) var(--s2); }
.scene-meta { display: flex; gap: var(--s3); align-items: flex-start; margin-bottom: var(--s2); }
.scene-meta .hero { width: 20rem; max-width: 45%; aspect-ratio: 16 / 9; border-radius: var(--r); background: var(--wash); flex: none; }
.scene-meta .facts { display: flex; flex-direction: column; gap: var(--s1); min-width: 0; }
.scene-meta .big { font: 400 2.5rem/1 var(--serif); color: var(--ink); }
.scene-meta .ab { font-size: var(--fs-sm); color: var(--ink-2); }
#stage-key { display: none; }
.scene-meta .options { flex-wrap: wrap; width: fit-content; gap: 1px; background: var(--hairline); }
.scene-meta .options button { flex: 1 0 auto; border-left: 0; }
.scene-meta .options button[aria-pressed="false"] { background: var(--paper); }
.scene-meta .run { font: 400 var(--fs-xs) var(--mono); color: var(--ink-2); overflow-wrap: anywhere; }
details.alt > summary { cursor: pointer; color: var(--ink-2); font-size: var(--fs-sm); padding: var(--s0) 0; width: max-content; }
details.alt .scroll { max-height: 22rem; margin-top: var(--s0); }
details.alt table { font-size: var(--fs-sm); }

/* Changes. */
.ledger td { vertical-align: top; }
.ledger td.subj { min-width: 17rem; max-width: 32rem; overflow-wrap: anywhere; }
.ledger .subj .who { display: block; color: var(--ink-2); font-size: var(--fs-sm); }
.ledger .sha { font: 400 var(--fs-xs) var(--mono); }

footer.wrap { padding-bottom: var(--s4); font-size: var(--fs-sm); color: var(--ink-2); }

@media (max-width: 640px) {
  .site-bar { flex-wrap: wrap; row-gap: var(--s1); height: auto; padding-block: var(--s2); }
  .status { order: 2; flex-basis: 100%; margin: 0; }
  .stats { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s3); }
  .stat { display: grid; grid-template-columns: subgrid; grid-column: 1 / -1; }
  .spark { width: 100%; max-width: 13.75rem; }
  #stage-key { display: flex; }
  .scenes th.b, .scenes td.b, .scenes thead .stagekey { display: none; }
  .scenes .tcell { width: 3.25rem; padding-left: var(--s1); }
  .scenes .thumb { width: 3rem; height: 1.7rem; }
  .scenes .bcell { width: 34%; }
  .scenes .scn { font-size: var(--fs-sm); }
  .scene-meta { flex-direction: column; }
  .scene-meta .hero { max-width: 100%; width: 100%; }
}
@media (prefers-reduced-motion: no-preference) {
  .chip, .segmented button, input[type="search"] { transition: border-color 0.12s, background-color 0.12s, color 0.12s; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
@media print { .tip, .skip { display: none !important; } }
