/*
  Greyscale spine, soft pastels for state, one meaning per pastel. Dark by
  default; a light variant follows the same tokens under
  prefers-color-scheme. No transitions on the hot path (label keypress ->
  next clip): the only motion is the pending indicator's fade and the
  video's own loop.
*/

:root {
  --bg: #0e0e10;
  --grid-dot: #1c1c20;
  --surface: #17171b;
  --raised: #22222a;
  --border: #2c2c34;
  --text: #ecebe7;
  --text-secondary: #93938e;
  --text-tertiary: #5c5c58;

  --accent-mint: #bfe0cd;
  --accent-mint-ink: #0e2b1c;
  --accent-sand: #dfd3ae;
  --accent-sand-ink: #2b230f;
  --accent-peach: #e8c6ae;
  --accent-peach-ink: #2b1a0f;
  --accent-rose: #e2b8bd;
  --accent-rose-ink: #2b1417;

  /* Label-grid row categories only (owner ruling 2026-09-20): common
     events, invalidators, rare events. Same pastel family and lightness
     as the accents above, distinct hues so the three rows read apart at a
     glance; not reused for any other meaning. */
  --label-common: #b9d9a8;
  --label-invalidator: #e6b98a;
  --label-rare: #a9cbe6;

  --font-body: "Inter Tight", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --radius: 8px;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f3f0;
    --grid-dot: #e1dfd8;
    --surface: #ffffff;
    --raised: #edece7;
    --border: #d9d7d0;
    --text: #17171b;
    --text-secondary: #55554f;
    --text-tertiary: #8a8a83;
  }

  :root:not([data-theme="dark"]) body {
    /* A couple of percent darker than --grid-dot's original #e6e4de (owner
       ruling 2026-09-20): the light dot grid read as almost invisible. */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Ccircle cx='1' cy='1' r='1' fill='%23e1dfd8'/%3E%3C/svg%3E");
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background-color: var(--bg);
  /* One dot-grid data URI per --grid-dot value, since a fill colour baked
     into an SVG string cannot read a CSS custom property; switched by the
     same selectors that redefine the other tokens below. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Ccircle cx='1' cy='1' r='1' fill='%231c1c20'/%3E%3C/svg%3E");
  background-repeat: repeat;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
}

button {
  font-family: inherit;
  font-size: inherit;
}

.hidden {
  display: none;
}

/* Elements toggled by adding/removing the "hidden" class also carry a
   class that sets `display` on its own (`.players`, `.help-panel`); a
   same-specificity rule that comes later in the sheet wins the cascade
   regardless of class order in the DOM, so each such element needs its
   own compound hide rule here. */
.players.hidden,
.help-panel.hidden {
  display: none;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar .brand {
  font-weight: 600;
  letter-spacing: 0.01em;
}

.topbar nav {
  display: flex;
  gap: 16px;
  align-items: center;
}

.topbar nav a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
}

.topbar nav a.current {
  color: var(--text);
}

/* The help button lives in the topbar now (owner ruling 2026-09-20), only
   on the batch route; it reads like the nav links beside it. */
.topbar nav .help-toggle {
  color: var(--text-secondary);
  font-size: 14px;
}

.account-menu {
  position: relative;
}

.account-menu button {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 6px 12px;
  cursor: pointer;
}

.account-menu .menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  min-width: 160px;
  z-index: 20;
}

.account-menu .menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  padding: 8px 10px;
  border-radius: 6px;
}

.account-menu .menu button:hover {
  background: var(--border);
}

/* -- centered panels (login / invite) ------------------------------------ */

.center-panel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 360px;
  max-width: 100%;
}

.card h2 {
  font-size: 18px;
  margin: 0 0 18px;
}

/* -- landing hero (above the sign-in / signup card) ---------------------- */

.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 36px;
  width: 100%;
}

.hero {
  max-width: 480px;
  text-align: center;
}

.hero-title {
  font-size: 34px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 12px;
}

.hero-subtitle {
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-secondary);
  margin: 0;
}

@media (max-width: 480px) {
  .landing {
    gap: 28px;
  }

  .hero-title {
    font-size: 26px;
  }

  .hero-subtitle {
    font-size: 14px;
  }
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 9px 10px;
  font-size: 14px;
}

.field input:focus {
  outline: 2px solid var(--accent-sand);
  outline-offset: 1px;
}

.field-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 6px;
}

.form-switch {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 14px 0 0;
}

.form-switch a {
  color: var(--text);
}

.btn:focus-visible,
.label-btn:focus-visible,
.aux-btn:focus-visible,
.account-menu button:focus-visible {
  outline: 2px solid var(--accent-sand);
  outline-offset: 2px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--raised);
  color: var(--text);
  padding: 9px 16px;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--text-tertiary);
}

.btn-primary {
  background: var(--accent-mint);
  color: var(--accent-mint-ink);
  border-color: transparent;
  font-weight: 600;
}

.btn-block {
  width: 100%;
}

.error-text {
  color: var(--accent-rose);
  font-size: 13px;
  margin-top: 10px;
  min-height: 1em;
}

/* -- labelling view ------------------------------------------------------ */

.labelling {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px;
  gap: 18px;
}

.progress-line {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 13px;
}

.progress-bar {
  width: 220px;
  height: 6px;
  border-radius: 3px;
  background: var(--raised);
  overflow: hidden;
}

.progress-bar > span {
  display: block;
  height: 100%;
  background: var(--accent-mint);
}

.hint {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* .help-toggle is a <button> styled as a hint chip in the topbar: reset the
   browser's button chrome so it still reads as a chip, not a button. */
.help-toggle {
  background: none;
  border: none;
  padding: 2px;
  margin: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.help-toggle:focus-visible {
  outline: 2px solid var(--accent-sand);
  outline-offset: 2px;
}

/* Pose and context (owner ruling 2026-09-20): plain, matching buttons —
   the flat hint-chip look above reads as decoration, not something to
   tap. */
.aux-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}

.aux-btn:hover {
  border-color: var(--text-tertiary);
}

/* Off by default: an outlined chip. Filled sand once the overlay is on,
   matching the always-filled key-chip used elsewhere for the active state. */
.pose-chip .key-chip {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.pose-chip.on .key-chip {
  background: var(--accent-sand);
  color: var(--accent-sand-ink);
  border-color: transparent;
}

.players {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
}

.view-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
}

.view-card .view-label {
  position: absolute;
  top: 18px;
  left: 18px;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  padding: 2px 6px;
  border-radius: 4px;
}

/* Context and its pose toggle, grouped as one header row (owner ruling
   2026-09-20) instead of the "view-label" floating over the video used by
   the player card above: this one carries two interactive controls, so it
   sits in normal flow, not absolutely positioned over the video. */
.context-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

/* A plain CSS triangle (border trick), no glyph to keep synced with JS:
   down when expanded, right when collapsed, driven by the one class that
   also hides the video. */
.context-chevron {
  display: inline-block;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 5px 4px 0 4px;
  border-color: var(--text-secondary) transparent transparent transparent;
}

.view-card.context.collapsed .context-chevron {
  border-width: 4px 0 4px 5px;
  border-color: transparent transparent transparent var(--text-secondary);
}

/* The collapsed group is one compact line (owner ruling 2026-09-20): no
   video below to leave room for. */
.view-card.context.collapsed {
  padding-top: 8px;
  padding-bottom: 8px;
}

.view-card.context.collapsed .context-header {
  margin-bottom: 0;
}

/* aspect-ratio sits on the card itself, not on .video-frame or the video
   (both measured, reproducibly): a height:auto block whose only height
   contributor is a DESCENDANT sized by aspect-ratio comes out short of
   that descendant's real rendered height by a few percent in this
   browser, and it compounds with each extra wrapping level — one level
   (context's card auto-sizing straight to its aspect-ratio video) already
   showed a smaller version of it; two levels (card auto-sizing to
   .video-frame auto-sizing to the aspect-ratio video) overflowed the
   card's border outright. Declaring the ratio where the box is actually
   definite-sized (the card has a definite width already, from its own
   width rule below) sidesteps the auto-height computation entirely: frame
   and video below are trivial 100%-of-a-definite-parent fills, no
   aspect-ratio math left for an auto-height ancestor to get wrong. The
   card's own padding and border sit inside the ratio, so the video itself
   is a few percent off a pure 3:4 crop — imperceptible at this size. */
.view-card.player {
  width: 480px;
  max-width: 80vw;
  aspect-ratio: 3 / 4;
}

.view-card.player .video-frame {
  position: relative;
  width: 100%;
  height: 100%;
}

.view-card.player .video-frame video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 4px;
  background: var(--raised);
}

/* One canvas per pool slot, created with the slot and never rebuilt; sized
   in JS to the video's rendered box. Pose keypoints are drawn here when the
   overlay is on (V); the box is baked into the video at cut time. */
.pose-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.view-card.context video {
  width: 320px;
  max-width: 60vw;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 4px;
  background: var(--raised);
}

/* Collapsed by default on mobile, under the main clip (owner ruling
   2026-09-20): the context view starts hidden there, a tap on the header
   away. The video keeps playing muted while hidden — nothing to pause or
   resume on expand. */
.view-card.context.collapsed video {
  display: none;
}

.view-card.current-label {
  box-shadow: inset 0 0 0 2px var(--accent-mint);
}

.label-grid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 640px;
}

/* One row per category (owner ruling 2026-09-20), --cols set inline to the
   row's own button count so the invalidator row of four is never split
   across a wrap the way a flat flex-wrap grid would. */
.label-row {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 10px;
  width: 100%;
}

.label-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
}

/* Very light tint per category (owner ruling 2026-09-20): common events
   green, invalidators orange, rare events blue. Every rule below has the
   same specificity (one element, two classes or one class + a
   pseudo-class), so source order alone decides ties: category tint, then
   hover, then active — each stronger signal declared after the weaker one
   it must be able to override. */
.label-btn.category-common {
  border-color: var(--label-common);
}

.label-btn.category-invalidator {
  border-color: var(--label-invalidator);
}

.label-btn.category-rare {
  border-color: var(--label-rare);
}

.label-btn:hover {
  border-color: var(--text-tertiary);
}

.label-btn.active {
  border-color: var(--accent-mint);
  background: color-mix(in srgb, var(--accent-mint) 16%, var(--surface));
}

.key-chip {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--accent-sand);
  color: var(--accent-sand-ink);
  border-radius: 4px;
  padding: 1px 6px;
  min-width: 1.4em;
  text-align: center;
}

.throw-type-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* Shown in the labelling view itself while a throw is pending (T pressed,
   waiting for F/B/O); a two-class rule so it is not shadowed the way
   `.hidden` was (see `.players.hidden`, `.help-panel.hidden` above). */
.throw-prompt {
  display: none;
  gap: 10px;
  align-items: center;
  color: var(--text-secondary);
  font-size: 13px;
}

.throw-prompt.visible {
  display: flex;
}

.throw-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  min-height: 44px;
  cursor: pointer;
  font-size: 14px;
}

.throw-btn:hover {
  border-color: var(--text-tertiary);
}

.throw-btn:focus-visible {
  outline: 2px solid var(--accent-sand);
  outline-offset: 2px;
}

/* pending outbox indicator: the only motion besides video loops */

.pending-indicator {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--accent-peach);
  color: var(--accent-peach-ink);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 100ms ease;
}

.pending-indicator.visible {
  opacity: 1;
}

/* -- help panel ----------------------------------------------------------- */

.help-panel {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
}

.help-panel .card {
  width: 560px;
  max-width: 92vw;
  max-height: 84vh;
  overflow: auto;
}

.help-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.help-table th,
.help-table td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.help-table .key-chip {
  font-size: 12px;
}

/* -- admin view ------------------------------------------------------------ */

.admin {
  flex: 1;
  padding: 24px;
  max-width: 1080px;
  margin: 0 auto;
  width: 100%;
}

.admin section {
  margin-bottom: 32px;
}

.admin h2 {
  font-size: 15px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

.table-scroll {
  overflow-x: auto;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

table.data th,
table.data td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
}

table.data tr:last-child td {
  border-bottom: none;
}

.badge {
  display: inline-block;
  border-radius: 4px;
  padding: 1px 7px;
  font-size: 12px;
}

.badge-admin {
  background: var(--accent-sand);
  color: var(--accent-sand-ink);
}

.badge-disabled {
  background: var(--accent-rose);
  color: var(--accent-rose-ink);
}

.invite-link-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  word-break: break-all;
}

.inline-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: end;
  margin-bottom: 16px;
}

.inline-form .field {
  margin-bottom: 0;
  min-width: 160px;
}

@media (max-width: 720px) {
  .players {
    flex-direction: column;
    align-items: center;
  }

  .view-card.player,
  .view-card.context video {
    width: 82vw;
    max-width: 82vw;
  }
}

/* -- phone layout (owner ruling 2026-09-19, docs/event-label-clips-scope.md
   §2 "Mobile") --------------------------------------------------------- */

@media (max-width: 600px) {
  .topbar {
    flex-wrap: wrap;
    row-gap: 6px;
    padding: 6px 14px;
  }

  .topbar nav {
    flex-wrap: wrap;
    gap: 10px;
  }

  .labelling {
    padding: 12px;
    gap: 12px;
  }

  .progress-bar {
    width: 140px;
  }

  /* Stacks the player view above the context view, both full width;
     applies to the pool container and to each pool slot's wrapper, since
     both carry the "players" class (see #pool in app.js). */
  .labelling .players {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    max-width: 100%;
    gap: 12px;
  }

  .view-card.player,
  .view-card.context video {
    width: 100%;
    max-width: 100%;
  }

  .label-grid {
    width: 100%;
    max-width: 100%;
    gap: 8px;
  }

  .label-row {
    /* minmax(0, 1fr), not plain 1fr: a bare <flex> track's implicit minimum
       is "auto" (its content's min-content width), which can force the row
       wider than the viewport. 0 lets a track shrink to fit; the button's
       own min-width: 0 below does the same for the flex item inside it. */
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    gap: 8px;
    max-width: 100%;
  }

  .label-btn {
    min-height: 44px;
    min-width: 0;
    padding: 8px 6px;
    justify-content: center;
    text-align: center;
    flex-wrap: wrap;
    font-size: 13px;
  }

  .throw-prompt.visible {
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
  }

  .throw-btn {
    flex: 1 1 30%;
    justify-content: center;
  }

  .help-toggle {
    min-height: 44px;
    min-width: 44px;
    padding: 8px;
  }

  /* Thinner than a full 44px tap target on purpose (owner ruling
     2026-09-20): the collapsed context group reads as one compact line,
     not a full-height row; the whole header remains an easy target even
     at this height since it spans the card's full width. */
  .aux-btn {
    min-height: 32px;
    padding: 5px 8px;
    font-size: 12px;
  }

  .account-menu button {
    min-height: 44px;
    padding: 10px 14px;
  }
}

/* No physical keyboard below this width: the key-hint letters (label
   buttons, throw prompt, pose toggle, help toggle) no longer apply. */
@media (max-width: 480px) {
  .labelling .key-chip {
    display: none;
  }
}
