:root {
  --ground: #f3eee3;
  --sheet: #fbf8f1;
  --ink: #1f1c17;
  --muted: #5b5549;
  --rule: #d9d0bd;
  --red: #b8361d;
  --red-soft: #b8361d1f;
  --bar-h: 60px;
  --font: 'Inter Tight', system-ui, sans-serif;
  --font-mark: 'Bricolage Grotesque', system-ui, sans-serif;
  --ease: cubic-bezier(.16, 1, .3, 1);
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--ground);
  color: var(--ink);
  font: 300 16px/1.5 var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--red); outline-offset: 3px; border-radius: 4px; }
svg { display: block; }

/* ---------- Top bar ---------- */
.bar {
  height: var(--bar-h);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 28px;
}
.brand { display: inline-flex; align-items: center; gap: 5px; font-family: var(--font-mark); font-weight: 600; font-size: 19px; letter-spacing: -0.01em; text-decoration: none; justify-self: start; }
.brand svg { width: 26px; height: 26px; fill: none; stroke: var(--ink); stroke-width: 1.6; stroke-linejoin: miter; stroke-miterlimit: 10; stroke-linecap: butt; }
.bar-title { font-weight: 400; font-size: 17px; }
.bar-h1 { font: inherit; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Skip link: off screen until it has keyboard focus. */
.skip { position: fixed; left: 12px; top: 10px; z-index: 10; padding: 10px 16px; border-radius: 999px; background: var(--ink); color: var(--sheet); font-size: 14px; font-weight: 500; text-decoration: none; transform: translateY(-150%); }
.skip:focus { transform: none; }
.bar-count .red { color: var(--red); }
.bar-count .cs { display: none; }
.bar-count { color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }
.bar-end { justify-self: end; display: flex; align-items: center; gap: 20px; }

/* ---------- Menu ---------- */
.menu-btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 15px 0 12px; border-radius: 999px;
  border: 1.5px solid var(--ink); font-size: 13px; font-weight: 500;
  transition: background 150ms ease, color 150ms ease, transform 160ms var(--ease-out);
}
.menu-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.menu-btn:active { transform: scale(.96); }
.menu-btn[aria-expanded="true"] { background: var(--ink); color: var(--sheet); }
.menu {
  position: fixed; inset: calc(var(--bar-h) - 4px) 28px auto auto; margin: 0;
  width: min(340px, calc(100vw - 32px)); max-height: calc(100dvh - var(--bar-h) - 16px);
  padding: 0; border: 1px solid var(--rule); border-radius: 10px;
  background: var(--sheet); color: var(--ink);
  box-shadow: 0 18px 40px -18px #1f1c1759, 0 2px 6px -2px #1f1c171f;
}
.menu::backdrop { background: #1f1c1714; }
.menu[open] { animation: menu-in 220ms var(--ease-out); }
@keyframes menu-in { from { opacity: 0; transform: translateY(-6px); } }
.menu-in { padding: 10px 10px 12px; }
/* Buy me a coffee: same pill and panel as the menu */
.coffee-body { padding: 4px 12px 4px; display: grid; gap: 12px; }
.coffee-body p { font-size: 15px; line-height: 1.5; }
.coffee-body ul { display: grid; gap: 8px; }
.coffee-body li a { justify-content: center; border: 1.5px solid var(--ink); border-radius: 999px; font-size: 15px; font-weight: 500; }
.coffee-body li:first-child a { background: var(--ink); color: var(--sheet); }
.coffee-note { font-size: 13px !important; color: var(--muted); }
.coffee-note a { color: var(--muted); }
.menu-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 8px 12px; border-bottom: 1px solid var(--rule); margin-bottom: 6px; }
.menu-head h2 { font-size: 13px; font-weight: 500; color: var(--muted); }
.menu-close { width: 36px; height: 36px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; }
.menu-close svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.menu ul { list-style: none; }
.menu li a { display: flex; align-items: center; min-height: 48px; padding: 0 12px; border-radius: 6px; text-decoration: none; font-size: 17px; font-weight: 400; }
.menu li a[aria-current] { color: var(--red); }

/* ---------- Pages behind the menu ---------- */
.doc {
  display: grid; grid-template-rows: minmax(0, 1fr) auto; gap: 18px;
  padding: 40px 28px 28px; max-width: 760px; margin: 0 auto;
}
.doc-sheet { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 22px; min-height: 0; touch-action: pan-y; }
.doc h1 { font-family: var(--font-mark); font-weight: 600; font-size: clamp(28px, 3vw, 38px); line-height: 1.1; letter-spacing: -0.02em; text-wrap: balance; }
.doc h1:focus { outline: none; }
.doc-body.scrolls { overflow-y: auto; }
.doc-body { min-height: 0; overflow: hidden; font-size: 17px; line-height: 1.6; max-width: 66ch; }
.doc-body > * + * { margin-top: 14px; }
.doc-body h2 { font-size: 17px; font-weight: 500; margin-top: 28px; }
.doc-body h2 + * { margin-top: 6px; }
.doc-body p, .doc-body li { text-wrap: pretty; }
.doc-body ul { padding-left: 1.2em; }
.doc-body li + li { margin-top: 4px; }
.doc-body a { color: var(--red); text-underline-offset: 3px; text-decoration-thickness: 1px; }
.doc-body .src-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 4px 24px; padding: 9px 0; border-top: 1px solid var(--rule); font-size: 15px; line-height: 1.45; margin-top: 0; }
.doc-body h2 + .src-row { margin-top: 10px; }
.doc-body .src-row + :not(.src-row) { border-top: 1px solid var(--rule); padding-top: 14px; }
.doc-body .src-row + h2 { margin-top: 0; padding-top: 28px; }
.src-models { font-weight: 400; }
.src-line { color: var(--muted); }

main { height: calc(100dvh - var(--bar-h)); }
/* Faint cutting-mat grid behind every page. */
body {
  background-image:
    linear-gradient(to right, #1f1c1708 1px, transparent 1px),
    linear-gradient(to bottom, #1f1c1708 1px, transparent 1px);
  background-size: 32px 32px;
  background-position: -1px -1px;
}

/* ---------- Diagram strokes ---------- */
.face { stroke-width: 1; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.edge { stroke: var(--ink); stroke-width: 1.4; stroke-linecap: round; fill: none; vector-effect: non-scaling-stroke; }
.shadow { stroke: #1f1c17; stroke-opacity: .2; stroke-width: 12; stroke-linecap: round; fill: none; vector-effect: non-scaling-stroke; }
.shadow-core { stroke-opacity: .32; stroke-width: 5; }
.stack { stroke-opacity: .3; stroke-width: 6; stroke-linecap: butt; }
.crease { stroke: #1f1c1766; stroke-width: 1; vector-effect: non-scaling-stroke; }
.valley, .mountain { stroke: var(--red); stroke-width: 2; fill: none; vector-effect: non-scaling-stroke; }
.valley { stroke-dasharray: 9 6; }
.cut { stroke: var(--red); stroke-width: 3; stroke-linecap: round; fill: none; vector-effect: non-scaling-stroke; }
.mountain { stroke-dasharray: 12 5 2 5 2 5; }
.arrow { stroke: var(--red); stroke-width: 2.2; fill: none; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.head { fill: var(--red); stroke: var(--red); stroke-width: 1; stroke-linejoin: miter; vector-effect: non-scaling-stroke; }
.halo { fill: none; stroke: var(--sheet); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.halo-fill { fill: var(--sheet); }
.head.hollow { fill: var(--sheet); stroke-width: 2; }

/* ---------- Gallery ---------- */
.gallery {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 24px;
  padding: 32px 28px 28px;
  max-width: 1320px;
  margin: 0 auto;
}
.intro { display: flex; align-items: flex-start; justify-content: space-between; gap: 4px 32px; flex-wrap: wrap; }
.intro h1 { font-size: 16px; font-weight: 500; line-height: 1.5; }
.intro p { color: var(--muted); max-width: 46ch; text-wrap: pretty; }
.grid {
  list-style: none;
  display: grid;
  gap: 16px;
  min-height: 0;
  touch-action: pan-y;
}

/* Collections: in the header on wide screens, as a row above the grid on phones. */
.coll-nav { display: flex; gap: 10px; align-items: center; }
.coll-nav a {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 13px; border-radius: 999px;
  border: 1px solid var(--rule);
  text-decoration: none; color: var(--muted); font-weight: 400; font-size: 14px; white-space: nowrap;
  transition: color 150ms ease, border-color 150ms ease, background 150ms ease, transform 160ms var(--ease-out);
}
.coll-nav a:active { transform: scale(.97); }
.coll-nav a[aria-current] { background: var(--ink); border-color: var(--ink); color: var(--sheet); }
.coll-nav .count { font-size: 12px; font-variant-numeric: tabular-nums; }
.coll-nav a[aria-current] .count { opacity: .7; } /* 8.4:1 on the dark pill; at full strength on the light ones (12px text needs 4.5:1) */
.coll-nav-inline { display: none; }

.pager { display: flex; align-items: center; justify-content: center; gap: 14px; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pager[hidden] { display: none; }
.page-btn {
  width: 40px; height: 40px; border-radius: 999px; border: 1.5px solid var(--ink);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 150ms ease, color 150ms ease, transform 160ms var(--ease-out), opacity 150ms ease;
}
.page-btn svg { width: 7.5px; height: 12.5px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.page-btn:active:not(:disabled) { transform: scale(.95); }
.page-btn:disabled { opacity: .3; cursor: default; }
.grid li { min-height: 0; }
.tile {
  height: 100%;
  display: grid;
  grid-template-rows: 1fr auto auto;
  padding: 14px 18px 16px;
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: 6px;
  text-decoration: none;
  transition: border-color 200ms ease, transform 220ms var(--ease-out), box-shadow 220ms var(--ease-out);
}
.tile svg { width: 100%; height: 100%; min-height: 0; }
.tile-name { font-weight: 400; font-size: 18px; }
.tile-meta { color: var(--muted); font-size: 14px; }
.tile:active { transform: scale(.98); transition-duration: 120ms; }
.tile svg { transition: transform 260ms var(--ease-out); }

/* ---------- Player ---------- */
.player { display: grid; grid-template-rows: minmax(0, 1fr) auto; }
.stage { position: relative; min-height: 0; touch-action: pan-y; }
#svg { width: 100%; height: 100%; }
.legend { position: absolute; top: 20px; left: 28px; display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.credit { position: absolute; left: 28px; bottom: 14px; font-size: 13px; color: var(--muted); }
.legend div { display: flex; align-items: center; gap: 10px; }
.legend svg { width: 40px; height: 8px; overflow: visible; }
/* Replay: a filled ink pill, so it reads apart from the outlined header pills (Buy me a coffee, Menu).
   Its right edge sits flush with the Menu button's right edge (the header's 28px padding). */
.replay {
  position: absolute; top: 14px; right: 28px;
  display: inline-flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 15px 0 12px; border-radius: 999px;
  background: var(--ink); color: var(--sheet); font-size: 13px; font-weight: 500;
  transition: background 150ms ease, transform 160ms var(--ease-out);
}
.replay:active { transform: scale(.96); }
.replay svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.replay[hidden] { display: none; }

.panel {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 28px;
  padding: 22px 28px 26px;
  border-top: 1px solid var(--rule);
  background: var(--sheet);
}
.say { display: grid; grid-template-columns: auto 1fr; column-gap: 10px; row-gap: 14px; align-items: baseline; max-width: 900px; width: 100%; justify-self: center; }
.num { font-size: clamp(20px, 1.9vw, 27px); font-weight: 300; line-height: 1.3; color: var(--red); font-variant-numeric: tabular-nums; }
.text { font-size: clamp(20px, 1.9vw, 27px); font-weight: 300; line-height: 1.3; text-wrap: balance; }
.ticks { grid-column: 1 / -1; list-style: none; display: flex; gap: 5px; }
.ticks li { flex: 1; }
.ticks button { display: block; width: 100%; height: 26px; position: relative; }
.ticks button::after { content: ''; position: absolute; left: 0; right: 0; top: 8px; height: 10px; border-radius: 999px; background: var(--rule); transition: background 200ms ease, transform 160ms var(--ease-out); }
.ticks button:active::after { transform: scaleY(.8); }
.ticks span { display: block; height: 26px; position: relative; }
.ticks span::after { content: ''; position: absolute; left: 0; right: 0; top: 8px; height: 10px; border-radius: 999px; background: var(--rule); }
.ticks span.past::after { background: var(--ink); }
.ticks span[aria-current]::after { background: var(--red); }
/* While the skip link has focus it stands in for the logo. */
.skip:focus + .brand { visibility: hidden; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.ticks button.past::after { background: var(--ink); }
.ticks button[aria-current]::after { background: var(--red); }

.nav {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  height: 64px; min-width: 150px; padding: 0 26px;
  border-radius: 999px;
  font-weight: 500; font-size: 18px;
  transition: background 150ms ease, transform 160ms var(--ease-out), opacity 200ms ease;
}
.nav svg { width: 8.25px; height: 13.75px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.nav:active { transform: scale(.97); }
.prev { border: 1.5px solid var(--ink); }
.prev:disabled { opacity: .3; cursor: default; }
.next { background: var(--red); color: #fff; }
.nav svg { transition: transform 200ms var(--ease-out); }
.nav:disabled:active { transform: none; }

/* ---------- Phones ---------- */
@media (max-width: 720px) {
  :root { --bar-h: 52px; }
  .bar { padding: 0 16px; grid-template-columns: auto 1fr auto; gap: 12px; }
  .bar-title { justify-self: stretch; min-width: 0; text-align: center; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .bar-count { font-size: 13px; }
  body:has(main.player) .menu-btn { display: none; } /* the step player keeps its header for the step count */
  .coffee-btn { padding: 0; width: 34px; justify-content: center; } /* icon only on phones; the name stays in aria-label */
  .coffee-btn span { display: none; }
  .coffee-btn svg { width: 18px; height: 18px; flex: none; }
  .menu-btn { height: 34px; padding: 0 13px 0 10px; }
  .menu { inset: calc(var(--bar-h) - 2px) 8px auto 8px; width: auto; }
  .doc { padding: 22px 16px 16px; gap: 12px; }
  .doc-sheet { gap: 14px; }
  .doc-body { font-size: 16px; line-height: 1.55; }
  .doc-body .src-row { grid-template-columns: 1fr; font-size: 14px; padding: 7px 0; }
  .brand { font-size: 17px; }
  .gallery { padding: 18px 16px 16px; gap: 14px; }
  .intro h1, .intro p { font-size: 14px; }
  .grid { gap: 10px; }
  .bar .coll-nav { display: none; }
  .coll-nav-inline { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: -4px -16px 0; padding: 0 16px; }
  .coll-nav-inline::-webkit-scrollbar { display: none; }
  .gallery { grid-template-rows: auto auto minmax(0, 1fr) auto; }
  .tile { padding: 8px 12px 10px; }
  .tile-name { font-size: 16px; }
  .tile-meta { font-size: 13px; }
  .legend { top: 10px; left: 16px; right: 68px; font-size: 12px; }
  .credit { left: 16px; right: 16px; bottom: 6px; font-size: 12px; }
  .replay { top: 8px; right: 16px; width: 36px; padding: 0; justify-content: center; } /* flush with the header's 16px edge */
  .replay span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .panel { grid-template-columns: 1fr 1fr; gap: 12px 10px; padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); }
  .say { grid-column: 1 / -1; grid-row: 1; column-gap: 8px; row-gap: 10px; }
  .num { font-size: 18px; }
  .text { font-size: 18px; }
  .nav { height: auto; min-height: 56px; min-width: 0; padding: 6px 16px; font-size: 17px; line-height: 1.15; text-align: center; } /* big text wraps instead of being cut off */
}
@media (max-width: 720px) and (max-height: 700px) {
  .legend { display: none; }
}
@media (max-width: 400px) {
  .bar-count .cw { display: none; }
  .bar-count .cs { display: inline; }
}
@media (max-height: 420px) {
  .legend, .credit { display: none; }
}
/* Hover only where a real pointer hovers; taps on phones would stick. */
@media (hover: hover) and (pointer: fine) {
  .coll-nav a:not([aria-current]):hover { color: var(--ink); border-color: var(--ink); }
  .page-btn:hover:not(:disabled) { background: var(--ink); color: var(--sheet); }
  .tile:hover { border-color: var(--ink); transform: translateY(-2px); box-shadow: 0 10px 24px -14px #1f1c1740; }
  .tile:hover svg { transform: scale(1.03); }
  .menu-btn:hover { background: var(--ink); color: var(--sheet); }
  .replay:hover { background: #3a352d; }
  .menu li a:hover, .menu-close:hover { background: #1f1c170d; }
  .ticks button:not([aria-current]):hover::after { background: var(--muted); }
  .prev:hover:not(:disabled) { background: #1f1c170d; }
  .prev:hover:not(:disabled) svg { transform: translateX(-2px); }
  .next:hover { background: #9e2d17; }
  .next:hover svg { transform: translateX(2px); }
}

/* Gallery tiles arrive in a short cascade on first view. */
.grid li { animation: tile-in 320ms var(--ease-out) both; }
.grid li:nth-child(2) { animation-delay: 40ms; }
.grid li:nth-child(3) { animation-delay: 80ms; }
.grid li:nth-child(4) { animation-delay: 120ms; }
.grid li:nth-child(5) { animation-delay: 160ms; }
.grid li:nth-child(6) { animation-delay: 200ms; }
@keyframes tile-in { from { opacity: 0; transform: translateY(8px); } }

/* Reduced motion keeps fades and color, drops movement. */
@media (prefers-reduced-motion: reduce) {
  .grid li { animation: none; }
  .tile:hover, .tile:active, .nav:active, .replay:active, .tile:hover svg, .nav:hover svg { transform: none !important; }
  .menu[open] { animation: none; }
}

/* Trim label line boxes to cap height so labels center on icons. */
.nav span, .replay span, .menu-btn span, .brand { text-box: trim-both cap alphabetic; }
.nav span, .replay span, .menu-btn span, .bar-count, .tile-meta { text-transform: uppercase; letter-spacing: 0.06em; }
.bar-count, .tile-meta { font-size: 13px; font-weight: 400; }
/* Letter-spacing adds space after the last letter; pull it back so the label centers on its ink. */
.nav span, .replay span, .menu-btn span { margin-right: -0.06em; }
