: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-count .red { color: var(--red); }
.bar-count { justify-self: end; color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }

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; }
.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; }
.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; opacity: .7; font-variant-numeric: tabular-nums; }
.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); }
.legend div { display: flex; align-items: center; gap: 10px; }
.legend svg { width: 40px; height: 8px; overflow: visible; }
.replay {
  position: absolute; top: 16px; right: 22px;
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 999px;
  border: 1.5px solid var(--ink); color: var(--ink); font-size: 14px; font-weight: 500;
  transition: background 150ms ease, color 150ms ease, transform 160ms var(--ease-out);
}
.replay:active { transform: scale(.96); }
.replay svg { width: 18px; height: 18px; 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 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: center; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .bar-count { font-size: 13px; }
  .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; font-size: 12px; }
  .replay { top: 10px; right: 16px; width: 40px; padding: 0; justify-content: center; }
  .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: 56px; min-width: 0; font-size: 17px; }
}
@media (max-width: 720px) and (max-height: 700px) {
  .legend { 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); }
  .replay:hover { background: var(--ink); color: var(--sheet); }
  .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-name: tile-fade; }
  @keyframes tile-fade { from { opacity: 0; } }
  .tile:hover, .tile:active, .nav:active, .replay:active, .tile:hover svg, .nav:hover svg { transform: none !important; }
}

/* Trim label line boxes to cap height so labels center on icons. */
.nav span, .replay span, .brand { text-box: trim-both cap alphabetic; }
.nav span, .replay 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 { margin-right: -0.06em; }
