/* AniMuse project page — Nerfies-shaped layout, hand-rolled so the page ships
   as one small stylesheet with no framework and no webfont round-trip. */

:root {
  --fg: #1a1a1a;
  --muted: #5f6672;
  --faint: #8b919b;
  --line: #e3e5e8;
  --bg: #ffffff;
  --soft: #f7f8fa;
  --link: #1a56db;
  --accent: #b3261e;
  --stage1: #0f766e;
  --stage2: #6d28d9;
  --control: #b45309;
  --col: 980px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
          "PingFang SC", "Hiragino Sans GB", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 64px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.72 var(--sans);
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: var(--col); margin: 0 auto; padding: 0 24px; }
.narrow { max-width: 760px; margin-left: auto; margin-right: auto; }
/* The demos are the argument; the prose is the caption on it. So they get a
   column of their own, wider than the text that introduces them. */
.wide { max-width: 1100px; }

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- top nav ---------- */

.nav {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255,255,255,.88);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.nav .wrap { display: flex; align-items: center; gap: 20px; height: 52px; }
.nav .brand { font-weight: 700; letter-spacing: -.01em; margin-right: auto; }
.nav a { color: var(--muted); font-size: 14.5px; }
.nav a:hover { color: var(--fg); text-decoration: none; }
.nav a.on { color: var(--fg); font-weight: 600; }

/* ---------- title block ---------- */

.hero { padding: 64px 0 8px; text-align: center; }
.hero h1 {
  font: 700 42px/1.22 var(--serif);
  letter-spacing: -.015em;
  margin: 0 0 6px;
  max-width: 880px; margin-inline: auto;
}
.hero .subtitle { color: var(--muted); font-size: 18px; margin: 0 0 24px; }
.hero .venue {
  display: inline-block; font-size: 13.5px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 99px; padding: 3px 14px; margin-bottom: 22px;
}
.authors { font-size: 17.5px; margin: 0 0 6px; }
.authors sup { color: var(--muted); font-size: 12px; }
.affil { color: var(--muted); font-size: 15px; margin: 0 0 26px; }

.buttons { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-bottom: 12px; }
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: #16181d; color: #fff; border: 1px solid #16181d;
  border-radius: 99px; padding: 8px 19px; font-size: 15px; font-weight: 500;
}
.btn:hover { background: #33373f; text-decoration: none; }
.btn[aria-disabled="true"] { background: #fff; color: var(--faint); border-color: var(--line); cursor: default; }
.btn[aria-disabled="true"]:hover { background: #fff; }
.btn-note { color: var(--faint); font-size: 13px; margin: 0; }

/* ---------- sections ---------- */

section { padding: 44px 0; }
section + section { border-top: 1px solid var(--line); }
.stage-section { padding-top: 40px; }

h2 {
  font: 700 27px/1.3 var(--serif);
  letter-spacing: -.01em; text-align: center; margin: 0 0 26px;
}
h3 { font: 650 19px/1.4 var(--sans); margin: 34px 0 10px; letter-spacing: -.005em; }
h4 { font: 650 16px/1.4 var(--sans); margin: 24px 0 6px; color: var(--muted); }
p { margin: 0 0 16px; }

.lead { font-size: 18px; }
.eq {
  font-family: var(--mono); font-size: 15px; text-align: center;
  background: var(--soft); border: 1px solid var(--line); border-radius: 8px;
  padding: 14px 18px; margin: 18px 0; overflow-x: auto; white-space: nowrap;
}
.eq .where { display: block; font-family: var(--sans); font-size: 13px; color: var(--muted); margin-top: 8px; white-space: normal; }

/* Stage banner — this is the page's main divider, so it has to carry weight */
.stage-mark {
  display: flex; align-items: baseline; gap: 16px;
  max-width: var(--col); margin: 0 auto 30px; padding: 0 24px;
}
.stage-mark .tag {
  font: 700 12px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase;
  color: #fff; padding: 8px 13px; border-radius: 5px; align-self: center;
}
.stage-mark .rule { flex: 1; height: 1px; background: var(--line); align-self: center; }
.stage-mark .name { font: 700 30px/1.15 var(--serif); letter-spacing: -.015em; }
#stage1 .tag { background: var(--stage1); }
#stage2 .tag { background: var(--stage2); }
#control .tag { background: var(--control); }
.stage-section { background: var(--soft); }

/* ---------- callouts, cards, tables ---------- */

.tldr {
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 6px; background: #fff; padding: 16px 20px; margin: 0 0 26px;
  font-size: 16.5px;
}
.tldr b { color: var(--accent); }

.takeaway {
  background: #fff; border: 1px solid var(--line); border-left: 3px solid var(--link);
  border-radius: 6px; padding: 15px 20px; margin: 20px 0; font-size: 16px;
}
.takeaway strong { color: var(--link); }

.cards { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); margin: 22px 0; }
.card { border: 1px solid var(--line); border-radius: 8px; padding: 16px 18px; background: #fff; }
.card h5 { margin: 0 0 6px; font: 650 15.5px/1.4 var(--sans); }
.card p { margin: 0; font-size: 14.5px; color: var(--muted); line-height: 1.6; }

.stats { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin: 24px 0; text-align: center; }
.stat { border: 1px solid var(--line); border-radius: 8px; padding: 18px; }
.stat b { display: block; font: 700 30px/1.1 var(--serif); letter-spacing: -.02em; }
.stat span { font-size: 14px; color: var(--muted); }

.table-wrap { overflow-x: auto; margin: 22px 0; }
table { border-collapse: collapse; width: 100%; font-size: 14.5px; font-variant-numeric: tabular-nums; }
caption { caption-side: top; text-align: left; color: var(--muted); font-size: 14px; padding-bottom: 10px; }
th, td { padding: 8px 12px; text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { border-bottom: 1.5px solid var(--fg); font-weight: 600; }
tbody tr + tr td { border-top: 1px solid var(--line); }
tbody tr.rule-above td { border-top: 1.5px solid var(--fg); }
tbody tr.ours { background: #f4f7ff; }
td.best, th.best { font-weight: 700; }
tr.ref td { color: var(--muted); font-style: italic; }

.compare { width: 100%; font-size: 14.5px; }
/* Prose tables need to wrap; the nowrap above is for numeric result tables. */
.compare th, .compare td { white-space: normal; }
.compare td:first-child { color: var(--muted); width: 24%; white-space: nowrap; }

/* A rule between two things that belong to one section but are not the same
   thought -- the film, and then the diagram the rest of the page follows. */
.sep { border: 0; border-top: 1px solid var(--line); margin: 40px 0 34px; }

figure { margin: 26px 0; }
figure img { width: 100%; height: auto; border-radius: 6px; display: block; }
figcaption { font-size: 14px; color: var(--muted); margin-top: 10px; line-height: 1.6; }
figcaption b { color: var(--fg); }

/* Numbered parts. A section that is mostly demos needs its structure legible at
   a glance -- the badge says how many pieces there are and which one you are on. */
.step { display: flex; align-items: center; gap: 12px; font: 650 21px/1.35 var(--sans);
        margin: 40px 0 10px; letter-spacing: -.01em; }
.step .n, .metrics summary .n {
  flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--fg);
  color: #fff; font: 700 13px/26px var(--sans); text-align: center; letter-spacing: 0;
}
/* A section that opens on its first part does not need the gap that separates
   one part from the next. */
.stage-mark + .wrap > .step:first-child { margin-top: 4px; }
#stage1 .n { background: var(--stage1); }
#stage2 .n { background: var(--stage2); }
#control .n { background: var(--control); }

/* Numbers belong in the results, not in the way of them: the tables fold away so
   the demos carry the page, and open for anyone who came for them. */
.metrics { margin: 34px 0 8px; }
.metrics summary { display: flex; align-items: center; gap: 12px; font: 650 19px/1.4 var(--sans); padding: 16px 0; }
.metrics summary .sub { font: 400 15px/1.4 var(--sans); color: var(--muted); }
.metrics summary::before { color: var(--faint); font-size: 15px; }
.metrics .takeaway:last-child, .metrics .stats:last-child { margin-bottom: 16px; }

details { border: 1px solid var(--line); border-radius: 8px; padding: 0 18px; margin: 18px 0; background: #fff; }
details[open] { padding-bottom: 8px; }
summary { cursor: pointer; padding: 13px 0; font-weight: 600; font-size: 15.5px; list-style: none; }
summary::-webkit-details-marker { display: none; }
summary::before { content: "▸ "; color: var(--faint); }
details[open] summary::before { content: "▾ "; }

pre { background: var(--soft); border: 1px solid var(--line); border-radius: 8px;
      padding: 14px 16px; overflow-x: auto; font: 13px/1.6 var(--mono); }
code { font-family: var(--mono); font-size: .92em; background: var(--soft); padding: 1px 5px; border-radius: 4px; }
pre code { background: none; padding: 0; }

/* ---------- viewers ---------- */

.viewer { margin: 26px 0 8px; }
.viewer-frame {
  position: relative; border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; background: #fff;
}
.viewer-canvas { position: relative; width: 100%; height: 480px; touch-action: none; }
/* A row of animals is wide and short; a tall frame just adds whitespace. */
.viewer-canvas.h-sm { height: 350px; }
.viewer-canvas.h-md { height: 410px; }
.viewer-canvas.h-lg { height: 570px; }
/* Hairlines between the per-column viewports of a comparison row. */
.viewer-canvas[style*="--cols"]::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(to right,
    transparent, transparent calc(100% / var(--cols) - 1px),
    var(--line) calc(100% / var(--cols) - 1px), var(--line) calc(100% / var(--cols)));
}
.viewer-canvas canvas { display: block; width: 100%; height: 100%; }

.viewer-frame::after {
  content: "Loading…"; position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  font-size: 13px; letter-spacing: .1em; color: var(--faint);
  background: var(--soft); pointer-events: none;
}
.viewer.is-loading .viewer-frame::after { display: flex; }

.viewer-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.chip {
  font: 14px var(--sans); padding: 5px 14px; border-radius: 99px;
  border: 1px solid var(--line); background: #fff; color: var(--muted); cursor: pointer;
}
.chip:hover { border-color: var(--faint); color: var(--fg); }
.chip.on { background: #16181d; border-color: #16181d; color: #fff; }

.viewer-labels { display: grid; margin-top: 10px; text-align: center; font-size: 13.5px; color: var(--muted); }
.viewer-caption { text-align: center; font-size: 15px; color: var(--fg); margin-top: 12px; min-height: 1.6em; font-style: italic; }
/* Bold says what you are looking at, muted says how to work it -- a caption
   that only explains the controls never tells you what the thing is. */
.viewer-note { max-width: 720px; margin: 12px auto 0; text-align: center;
               font-size: 13.5px; line-height: 1.65; color: var(--muted); }
.viewer-note b { color: var(--fg); }

/* split divider */
.split-divider {
  position: absolute; top: 0; bottom: 0; left: 50%; width: 34px;
  margin-left: -17px; cursor: ew-resize; z-index: 3; touch-action: none;
  background: none; border: 0; padding: 0;
}
.split-divider::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: 16px; width: 2px;
  background: #16181d; opacity: .8;
}
.split-divider::after {
  content: "⟺"; position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 34px; height: 34px; border-radius: 50%;
  background: #16181d; color: #fff; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
}
.split-divider:focus-visible::after { outline: 3px solid var(--link); outline-offset: 2px; }
.split-label-left, .split-label-right {
  position: absolute; top: 14px; z-index: 2; font-size: 12.5px; font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
  background: rgba(255,255,255,.8); padding: 3px 10px; border-radius: 5px;
  transition: opacity .15s; pointer-events: none;
}
.split-label-left { left: 14px; }
.split-label-right { right: 14px; }

.corr-readout {
  text-align: center; margin-top: 12px; font-size: 14.5px; color: var(--muted);
  font-family: var(--mono);
}
.corr-readout.on { color: var(--fg); }

.viewer-controls { display: flex; align-items: center; gap: 18px; margin-top: 14px; flex-wrap: wrap; justify-content: center; }
.viewer-controls label { font-size: 14px; color: var(--muted); }
.edit-slider { width: min(420px, 70vw); accent-color: var(--link); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 99px; overflow: hidden; }
.seg button {
  font: 13.5px var(--sans); border: 0; background: #fff; color: var(--muted);
  padding: 6px 15px; cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: #16181d; color: #fff; }

/* Species names laid over the 3x2 grid, one per cell. */
.viewer-frame { position: relative; }
.grid-labels {
  position: absolute; inset: 0; display: grid; pointer-events: none;
  font-size: 12.5px; color: var(--muted); z-index: 2;
}
.grid-labels span { align-self: end; text-align: center; padding-bottom: 8px; }
/* Labels placed from projected cell centres rather than by the grid. */
.grid-labels.projected { display: block; }
.grid-labels.projected span {
  position: absolute; transform: translate(-50%, 0); white-space: nowrap;
  padding: 0; line-height: 1.35;
}
.grid-labels.projected em { display: block; font-style: normal; color: var(--faint); font-size: 11.5px; }
/* Under the frame rather than inside it. A row of animals standing on one floor
   puts every name at the same height, and that height is the floor -- which the
   frame clips. Only the horizontal position needs the projection. */
.grid-labels.below { position: relative; inset: auto; height: 18px; margin-top: 8px; }
/* Four names across a phone is ninety pixels each: let them wrap rather than
   run into one another, and cap each at its own quarter of the row so a long
   one cannot reach its neighbour. Nothing wraps at desktop width. */
.grid-labels.below span { white-space: normal; max-width: 23%; }

.video-embed { position: relative; padding-top: 56.25%; border-radius: 10px; overflow: hidden;
               border: 1px solid var(--line); background: var(--soft); }
.video-embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-placeholder {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px;
  color: var(--muted); font: inherit; font-size: 14.5px;
  border: 0; background: var(--soft); cursor: pointer; width: 100%;
}
.video-placeholder:hover { background: #eef0f4; }
.video-placeholder .play {
  width: 62px; height: 62px; border-radius: 50%; background: #16181d; color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 22px; padding-left: 4px;
}
.video-placeholder .hint { font-size: 12.5px; color: var(--faint); }

.todo { color: var(--accent); font-size: 13px; font-family: var(--mono); }

footer { border-top: 1px solid var(--line); padding: 30px 0 50px; color: var(--muted); font-size: 14px; text-align: center; }

@media (max-width: 720px) {
  .hero h1 { font-size: 31px; }
  .viewer-canvas, .viewer-canvas.h-sm, .viewer-canvas.h-md { height: 280px; }
  /* Two columns here, so the grids are tall rather than wide. */
  .viewer-canvas.h-lg { height: 520px; }
  .grid-labels.projected:not(.below) span { white-space: normal; width: 44%; transform: translate(-50%, 0); }
  .grid-labels.below { height: 34px; }
  .grid-labels.below span { font-size: 11.5px; line-height: 1.3; }
  /* The caption below says which half is which; the in-frame labels only
     collide with each other at this width. */
  .split-label-left, .split-label-right { display: none; }
  section { padding: 34px 0; }
  body { font-size: 16px; }

  /* Six links and a wordmark do not fit in 390px, and a nav that does not fit
     drags the whole page sideways with it. Let the row scroll instead. */
  .nav .wrap { gap: 16px; overflow-x: auto; scrollbar-width: none; }
  .nav .wrap::-webkit-scrollbar { display: none; }
  .nav a { white-space: nowrap; font-size: 14px; }

  .stage-mark .name { font-size: 25px; }
  .step { font-size: 19px; }
  .metrics summary { font-size: 17px; }
  .metrics summary .sub { display: none; }
}

/* Touch. A viewer that takes the vertical swipe for itself is a trap on a page
   with six of them -- the reader puts a finger on an animal and the page stops
   scrolling. Orbiting keeps the horizontal axis, which is the one that matters
   for turning an animal round; the page keeps the vertical. The divider is a
   separate element and still takes both, since dragging it is the whole point.

   Two feature queries rather than one, because a device can report either; and
   `[data-input="touch"]`, which main.js sets from the first real touch, because
   both of them can still be wrong -- a phone asked for the desktop site says it
   has a fine pointer. A touch that actually happened cannot be argued with. */
@media (hover: none), (pointer: coarse) {
  .viewer-canvas { touch-action: pan-y; }
  .split-divider { touch-action: none; }
}
:root[data-input="touch"] .viewer-canvas { touch-action: pan-y; }
:root[data-input="touch"] .split-divider { touch-action: none; }
