:root {
  --bg: #10131a;
  --panel: #171c26;
  --panel-2: #1e2533;
  --line: #2b3444;
  --ink: #e8edf6;
  --muted: #9aa7bd;
  --accent: #5b9cff;
  --accent-ink: #08111f;
  --warn: #ffb85c;
  --error: #ff7a7a;
  --ok: #6fdca0;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.wrap { max-width: 1240px; margin: 0 auto; padding: 28px 22px 60px; }
.wrap.narrow { max-width: 760px; }
.hidden { display: none !important; }

h1 { font-size: 1.9rem; line-height: 1.25; margin: 0 0 .5em; }
h2 { font-size: 1.15rem; margin: 1.8em 0 .5em; }
p { margin: 0 0 1em; }
code {
  background: var(--panel-2); padding: .12em .4em;
  border-radius: 4px; font-size: .9em;
}

.lede { font-size: 1.08rem; color: #cfd8e8; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }

/* ------------------------------------------------------------- controls */

button {
  font: inherit; cursor: pointer; border-radius: var(--radius);
  padding: .6em 1.25em; border: 1px solid transparent; transition: .15s;
}
button:disabled { opacity: .45; cursor: not-allowed; }

.primary { background: var(--accent); color: var(--accent-ink); font-weight: 650; }
.primary:not(:disabled):hover { filter: brightness(1.1); }

.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.ghost:not(:disabled):hover { background: var(--panel-2); }

button.small { padding: .35em .8em; font-size: .88rem; }

.field { display: block; margin: 0 0 1.4em; }
.field > span { display: block; margin-bottom: .4em; }
select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: var(--radius); padding: .6em .7em;
}
textarea { resize: vertical; }

.consent {
  display: flex; gap: .65em; align-items: flex-start;
  margin: 2em 0 1.4em; padding: 1em; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.consent input { margin-top: .35em; width: 1.05em; height: 1.05em; }

dl.criteria { margin: 0 0 1em; }
dl.criteria dt { font-weight: 650; margin-top: .9em; color: #fff; }
dl.criteria dd { margin: .15em 0 0; color: var(--muted); }

/* ------------------------------------------------------------ top bar */

.bar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(16,19,26,.94); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.bar-inner {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 20px; margin: 0 auto; max-width: 1500px;
}
.progress-text { white-space: nowrap; font-size: .92rem; color: var(--muted); }
.progress-text b { color: var(--ink); }
.progress-track {
  flex: 1; height: 6px; background: var(--panel-2);
  border-radius: 99px; overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0; background: var(--accent);
  border-radius: 99px; transition: width .3s;
}

/* --------------------------------------------------------------- stage
   The task screen is laid out to fit one viewport: a single row of seven
   square videos, then the three criteria side by side. Tile size is driven by
   both viewport width and height so neither dimension forces a scrollbar. */

.stage {
  max-width: 1500px; margin: 0 auto;
  padding: 14px 20px 18px;
  display: flex; flex-direction: column; gap: 10px;
}

/* Sources are 600x600. Columns are fractional so the row fills the width, but
   the strip is capped at 7 x --tile and each cell is forced square, so the
   frames are never cropped. --tile is bounded by height as well as width so a
   short window shrinks the videos instead of pushing controls off-screen. */
.strip {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  --tile: clamp(84px, min(13vw, 26vh), 200px);
  max-width: calc(7 * var(--tile) + 6 * 8px);
  margin: 0 auto; width: 100%;
}
.strip-note { margin: -2px 0 2px; }

.cell {
  position: relative; background: #000; aspect-ratio: 1;
  border: 1px solid var(--line); border-radius: 8px;
  overflow: hidden; cursor: zoom-in; transition: border-color .12s, transform .12s;
}
.cell:hover, .cell.hot { border-color: var(--accent); }
.cell.hot { transform: translateY(-2px); }
.cell.is-ref { border-color: var(--muted); }
/* The 600x600 renders carry a wide white margin. Measured over every frame of
   all 105 clips, content never leaves a 494px square at (80,56); these values
   crop to that box plus a 16px pad, so characters appear ~1.21x larger without
   any risk of clipping a limb. Recompute with scripts/measure_crop.sh if the
   stimuli are re-rendered. */
.cell video, .zoom video {
  position: absolute;
  width: 121.46%; height: 121.46%;
  left: -16.19%; top: -11.34%;
  display: block; background: #fff;
}
.tag {
  position: absolute; top: 5px; left: 5px; z-index: 2;
  background: rgba(8,17,31,.82); color: #fff;
  border: 1px solid var(--line); border-radius: 5px;
  font-weight: 700; font-size: .78rem; padding: .05em .45em;
  letter-spacing: .02em; pointer-events: none;
}
.cell.is-ref .tag { background: var(--muted); color: var(--accent-ink); }

/* ------------------------------------------------------------ ranking */

.matrix {
  display: grid; gap: 10px;
  grid-template-columns: repeat(3, 1fr);
}

.crit {
  margin: 0; padding: 8px 12px 11px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); min-width: 0;
}
.crit legend {
  padding: 0 .4em; font-weight: 650; color: #fff; font-size: .95rem;
}
.crit-head { font-size: .76rem; margin: 0 0 6px; }

/* Column 1 is the A-F label, then one column per rank. */
.crit-grid {
  display: grid;
  grid-template-columns: 1.7em repeat(var(--n), minmax(0, 1fr));
  gap: 4px; align-items: center;
}
.cg-row {
  font-weight: 700; font-size: .84rem; text-align: center;
  color: var(--muted); cursor: default;
}
.crit-grid input { position: absolute; opacity: 0; pointer-events: none; }
.cg-cell {
  display: grid; place-items: center;
  height: 1.85em; border-radius: 6px;
  background: var(--panel-2); border: 1px solid var(--line);
  cursor: pointer; user-select: none;
  font-size: .82rem; color: var(--muted);
  font-variant-numeric: tabular-nums; transition: .1s;
}
.cg-cell:hover { border-color: var(--accent); color: var(--ink); }
.crit-grid input:checked + .cg-cell {
  background: var(--accent); color: var(--accent-ink);
  border-color: var(--accent); font-weight: 700;
}
.crit-grid input:focus-visible + .cg-cell {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

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

.nav {
  display: flex; align-items: center; gap: 16px;
  flex-wrap: wrap;
}
.nav .primary { margin-left: auto; }
.validation { font-size: .9rem; color: var(--muted); }
.validation.warn { color: var(--warn); }

.status { margin-top: 1em; min-height: 1.4em; color: var(--muted); }
.status.error { color: var(--error); }

/* --------------------------------------------------------------- modal */

.modal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(5,8,14,.72); padding: 20px;
}
.modal-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 24px 26px; max-width: 560px;
}

/* ---------------------------------------------------------------- zoom */

.zoom {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background: rgba(4,7,12,.9); padding: 24px;
  cursor: zoom-out;
}
/* Same framing as the tiles, just larger. */
.zoom-inner {
  position: relative; overflow: hidden;
  width: min(74vh, 74vw); height: min(74vh, 74vw);
  border-radius: 10px; border: 1px solid var(--line); background: #fff;
}
.zoom-tag { font-size: 1rem; top: 10px; left: 10px; }
.zoom-close { position: fixed; top: 20px; right: 22px; cursor: pointer; }

/* Narrower screens: wrap the strip and stack the criteria rather than
   letting anything become unreadably small. */
@media (max-width: 1080px) {
  .strip {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    --tile: min(21vw, 150px);
    max-width: calc(4 * var(--tile) + 3 * 8px);
  }
  .matrix { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 680px) {
  .strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    --tile: min(29vw, 130px);
    max-width: calc(3 * var(--tile) + 2 * 8px);
  }
  .matrix { grid-template-columns: 1fr; }
  .bar-inner { gap: 8px; padding: 8px 12px; }
  .stage { padding: 10px 12px 16px; }
}
