/* Layout: a filter rail beside a grid of stage tiles. A motion opens on a full-screen stage. */
:root {
  --paper: #edf0f4;
  --surface: #ffffff;
  --ink: #141b26;
  --muted: #586477;
  --line: #d5dbe4;
  --accent: #0d3b6e;
  --accent-ink: #ffffff;
  --accent-soft: #dbe6f3;
  --gold: #e8a612;
  /* The stage is the same room in either theme: a deep blue that the white robot shows against. */
  --stage: #12233a;
  --stage-ink: #e6edf7;
  --stage-muted: #9fb1c9;
  --stage-panel: rgba(9, 19, 33, 0.78);
  --font-ui: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-md: 0.9375rem;
  --text-lg: 1.25rem;
  --text-xl: 1.75rem;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0b1119;
    --surface: #121a25;
    --ink: #e5eaf1;
    --muted: #92a0b4;
    --line: #243246;
    --accent: #8ab8f0;
    --accent-ink: #0b1119;
    --accent-soft: #1b2b40;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--text-md)/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
body.locked { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ── Masthead ─────────────────────────────────────────────────────────────── */

.masthead {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 16px 32px;
  padding: 28px 24px 20px;
  border-bottom: 1px solid var(--line);
}
.brand { min-width: 0; max-width: 62ch; }
.brand h1 {
  margin: 0;
  font-size: var(--text-xl); font-weight: 800; font-stretch: 118%;
  letter-spacing: -0.01em; line-height: 1.1;
  text-wrap: balance;
}
.search { flex: 1 1 280px; max-width: 420px; }
.search input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface);
}
.search input::placeholder { color: var(--muted); }
.account {
  display: flex; align-items: center; gap: 8px;
  font-size: var(--text-sm); color: var(--muted);
}
.account img { width: 28px; height: 28px; border-radius: 50%; }
.account button {
  padding: 9px 14px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); cursor: pointer; white-space: nowrap;
}
.account button:hover { border-color: var(--accent); }

/* ── Filters and grid ─────────────────────────────────────────────────────── */

.layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 28px;
  padding: 20px 24px 48px;
}
.filters {
  display: flex; flex-direction: column; gap: 24px;
  align-self: start; position: sticky; top: 16px;
  /* A rail taller than the window scrolls on its own, so its end stays in reach. */
  max-height: calc(100vh - 32px); overflow-y: auto; scrollbar-width: thin;
}
.filters h2 {
  margin: 0 0 8px;
  font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted);
}
.filter-list { display: flex; flex-direction: column; gap: 2px; scrollbar-width: thin; }
.filter-row {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 6px 10px;
  border: 0; border-radius: 8px;
  background: none; text-align: left; cursor: pointer;
  font-size: var(--text-sm);
}
.filter-row:hover { background: var(--accent-soft); }
.filter-row:not(.check)[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.filter-row .box { display: none; }
.filter-row.check .box {
  display: grid; place-items: center; flex: none;
  width: 14px; height: 14px;
  border: 1.5px solid var(--muted); border-radius: 4px;
}
.filter-row.check[aria-pressed="true"] .box { background: var(--accent); border-color: var(--accent); }
.filter-row.check[aria-pressed="true"] .box::after {
  content: ""; width: 6px; height: 3px; margin-top: -2px;
  border: solid var(--accent-ink); border-width: 0 0 1.5px 1.5px;
  transform: rotate(-45deg);
}
.group-label {
  margin: 10px 10px 2px;
  font-size: var(--text-xs); color: var(--muted);
}
.filter-row .label { flex: 1; min-width: 0; line-height: 1.3; }
.filter-row .tally {
  font-family: var(--font-mono); font-size: var(--text-xs); font-variant-numeric: tabular-nums;
  opacity: 0.75;
}

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px;
  margin-bottom: 14px;
}
.count { margin: 0; font-size: var(--text-sm); color: var(--muted); font-variant-numeric: tabular-nums; }
.count strong { color: var(--ink); font-weight: 600; }
.toolbar-end { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.sort { font-size: var(--text-sm); color: var(--muted); display: flex; align-items: center; gap: 8px; }
/* Two buttons, one pressed: which figure plays the motions. */
.figure-choice {
  display: flex; padding: 2px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
}
.figure-choice button {
  padding: 3px 12px;
  border: 0; border-radius: 999px; background: none; cursor: pointer;
  font-size: var(--text-sm); color: var(--muted);
}
.figure-choice button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.sort select, .controls select {
  padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(208px, 1fr));
  gap: 18px 16px;
}
.card {
  display: flex; flex-direction: column; gap: 8px;
  min-width: 0;
  padding: 0; border: 0; background: none; text-align: left; cursor: pointer;
}
.tile {
  position: relative;
  display: block;
  aspect-ratio: 4 / 3;
  max-width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--stage);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.04);
  transition: box-shadow 140ms ease;
}
.tile canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.tile::before {
  /* A faint floor line until the card draws its figure, so an empty tile still looks like a stage. */
  content: ""; position: absolute; left: 18%; right: 18%; bottom: 22%;
  height: 1px; background: var(--stage-muted); opacity: 0.25;
}
.tile::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(120% 90% at 50% 40%, transparent 55%, rgba(4, 10, 20, 0.45));
}
.card:hover .tile, .card:focus-visible .tile { box-shadow: 0 0 0 2px var(--gold); }
.card:focus-visible { outline: none; }
.tag, .length {
  position: absolute; z-index: 1;
  padding: 2px 7px; border-radius: 6px;
  background: var(--stage-panel); color: var(--stage-ink);
  font: 500 0.6875rem/1.5 var(--font-mono); letter-spacing: 0.04em;
}
.tag { top: 8px; left: 8px; text-transform: uppercase; }
.length { bottom: 8px; right: 8px; font-variant-numeric: tabular-nums; }
.playing .length { color: var(--gold); }
.label { display: flex; flex-direction: column; min-width: 0; padding: 0 2px; }
.name {
  font: 500 var(--text-sm)/1.35 var(--font-mono);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.meta {
  font-size: var(--text-xs); color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.more { height: 1px; }
.notice {
  max-width: 62ch; margin: 32px auto; padding: 20px 24px;
  border: 1px dashed var(--line); border-radius: var(--radius);
  color: var(--muted); font-size: var(--text-sm);
}
.notice h2 { margin: 0 0 6px; color: var(--ink); font-size: var(--text-md); }
.notice code { font-family: var(--font-mono); color: var(--ink); }

/* ── Viewer ───────────────────────────────────────────────────────────────── */

.viewer {
  position: fixed; inset: 0; z-index: 10;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  background: var(--stage);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.viewer-stage { position: relative; min-width: 0; min-height: 0; }
.viewer-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.viewer-loading {
  position: absolute; inset: 0; margin: 0;
  display: grid; place-items: center;
  color: var(--stage-muted); font: 500 var(--text-sm) var(--font-mono);
}
.controls {
  position: absolute; left: 16px; right: 16px; bottom: 16px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--stage-panel); color: var(--stage-ink);
  backdrop-filter: blur(6px);
}
.controls select { background: transparent; border-color: rgba(159, 177, 201, 0.35); color: var(--stage-ink); }
.controls select option { background: var(--stage); color: var(--stage-ink); }
.play {
  display: grid; place-items: center;
  width: 36px; height: 36px; flex: none;
  border: 0; border-radius: 50%;
  background: var(--gold); color: #1a1405; cursor: pointer;
}
.play svg { width: 16px; height: 16px; fill: currentColor; }
.play .icon-play { display: none; }
.play.paused .icon-play { display: inline; }
.play.paused .icon-pause { display: none; }
#scrub { flex: 1 1 200px; min-width: 120px; accent-color: var(--gold); }
.clock {
  font: 500 var(--text-xs) var(--font-mono); font-variant-numeric: tabular-nums;
  color: var(--stage-muted); white-space: nowrap;
}
.toggle { display: flex; align-items: center; gap: 6px; font-size: var(--text-sm); cursor: pointer; }
.toggle input { accent-color: var(--gold); margin: 0; }
.controls .figure-choice { background: transparent; border-color: rgba(159, 177, 201, 0.35); }
.controls .figure-choice button { color: var(--stage-muted); }
.controls .figure-choice button[aria-pressed="true"] { background: var(--gold); color: #1a1405; }

.viewer-info {
  display: flex; flex-direction: column; gap: 16px;
  min-width: 0; overflow-y: auto;
  padding: 20px 22px 24px;
  background: var(--surface); color: var(--ink);
  border-left: 1px solid var(--line);
}
.viewer-nav { display: flex; gap: 8px; }
.viewer-nav button, .command button, .button {
  padding: 6px 12px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); cursor: pointer;
  font-size: var(--text-sm); text-decoration: none; color: var(--ink);
}
.viewer-nav button:hover, .command button:hover { border-color: var(--accent); }
.viewer-nav button:disabled { opacity: 0.4; cursor: default; border-color: var(--line); }
.viewer-nav .close { margin-left: auto; }
.eyebrow {
  margin: 0;
  font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted);
}
.viewer-name {
  margin: -8px 0 0;
  font: 500 var(--text-lg)/1.3 var(--font-mono);
  overflow-wrap: anywhere;
}
.stats {
  display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 16px;
  margin: 0; font-size: var(--text-sm);
}
.stats dt { color: var(--muted); }
.stats dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stats .mono { font-family: var(--font-mono); font-size: var(--text-xs); }
.stats a { color: var(--accent); }
.actions { display: flex; flex-direction: column; gap: 8px; }
.button.primary {
  align-self: start;
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
  font-weight: 600;
}
.command-label { margin: 8px 0 0; font-size: var(--text-xs); color: var(--muted); }
.command {
  display: flex; align-items: start; gap: 8px;
  padding: 10px; border-radius: 8px; background: var(--paper);
}
.command code {
  flex: 1; min-width: 0;
  font: 400 var(--text-xs)/1.5 var(--font-mono);
  overflow-wrap: anywhere; user-select: all;
}
.keys { margin: auto 0 0; font-size: var(--text-xs); color: var(--muted); }
kbd {
  display: inline-block; min-width: 1.6em; margin-right: 2px; padding: 0 4px;
  border: 1px solid var(--line); border-radius: 4px;
  font: 500 0.6875rem/1.5 var(--font-mono); text-align: center; color: var(--ink);
}

/* ── Narrow screens ───────────────────────────────────────────────────────── */

@media (max-width: 860px) {
  .masthead { padding: 20px 16px 16px; }
  .layout { grid-template-columns: minmax(0, 1fr); gap: 16px; padding: 16px 16px 40px; }
  .filters { position: static; gap: 12px; max-height: none; overflow: visible; }
  .filter-list { flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  .filter-row { width: auto; flex: none; border: 1px solid var(--line); border-radius: 999px; }
  .group-label { flex: none; align-self: center; margin: 0 0 0 6px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px 12px; }

  .viewer { grid-template-columns: minmax(0, 1fr); grid-template-rows: 58% minmax(0, 1fr); }
  .viewer-info { border-left: 0; border-top: 1px solid var(--line); padding: 16px; }
  .controls { left: 8px; right: 8px; bottom: 8px; gap: 6px 10px; padding: 8px 10px; }
  .controls #scrub { order: -1; flex-basis: 100%; }
  .play { width: 32px; height: 32px; }
  .clock { flex: 1; }
  .clock .frame { display: none; }
  .keys { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .tile { transition: none; }
}
