:root {
  --bg: #0d0d0f;
  --surface: #17171b;
  --surface-2: #222228;
  --text: #f4f4f6;
  --muted: #9a9aa6;
  --accent: #e5322d;
  --accent-ink: #ffffff;
  --gold: #f2c14e;
  --line: #2c2c33;
  --danger: #ff6b6b;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }

.screen { display: none; min-height: 100dvh; }
.screen.active { display: flex; flex-direction: column; }
#home.active { display: block; max-width: 560px; margin: 0 auto; padding: 24px 16px 48px; }

/* Hero */
.hero { text-align: center; padding: 24px 0 8px; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: 12px; color: var(--muted); margin: 0; }
h1 { font-size: clamp(64px, 20vw, 112px); line-height: .9; margin: 8px 0; letter-spacing: -.02em; font-weight: 900; }
.sub { margin: 0 0 16px; color: var(--muted); }
.moves { list-style: none; padding: 0; margin: 0 auto 16px; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.moves li { background: var(--surface); border: 1px solid var(--line); padding: 8px 14px; border-radius: 999px; }
.moves b { color: var(--accent); font-variant-numeric: tabular-nums; }
.bench { margin: 0 0 20px; }
.bench b { color: var(--gold); }

/* Buttons */
.btn { border: 0; border-radius: var(--radius); padding: 12px 18px; cursor: pointer; font-weight: 600; transition: transform .06s, opacity .2s; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 14px; }
.btn.big { width: 100%; padding: 16px; font-size: 18px; }
.btn.huge { width: 100%; padding: 28px 16px; font-size: 24px; font-weight: 800; }
.row { display: flex; gap: 10px; }
.row > .btn { flex: 1; }
.chip { background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 14px; }

.banner { margin: 16px 0 0; padding: 10px 14px; border-radius: var(--radius); background: #2a2310; color: var(--gold); font-size: 14px; }

/* Leaderboard */
.board { margin-top: 28px; }
.board-head { display: flex; align-items: center; justify-content: space-between; }
.board-head h2 { font-size: 20px; margin: 0; }
.leaderboard { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 6px; }
.leaderboard li { display: grid; grid-template-columns: 36px 1fr auto auto; align-items: center; gap: 10px; background: var(--surface); padding: 10px 12px; border-radius: 12px; }
.leaderboard .rank { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.leaderboard .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard .when { display: block; font-size: 12px; color: var(--muted); }
.leaderboard .score { font-weight: 800; font-variant-numeric: tabular-nums; }
.leaderboard .score small { font-weight: 500; color: var(--muted); }
.leaderboard .play { background: var(--surface-2); border: 0; border-radius: 8px; width: 36px; height: 32px; cursor: pointer; }
.leaderboard .play[disabled] { visibility: hidden; }
.leaderboard li.top1 .rank { color: var(--gold); font-weight: 800; }
.leaderboard li.tom { background: transparent; border: 1px dashed var(--gold); color: var(--gold); }
.leaderboard li.mine { outline: 2px solid var(--accent); }
.leaderboard li.empty { display: block; text-align: center; color: var(--muted); }

/* Camera stage */
.stage { position: relative; flex: 1; min-height: 45dvh; background: #000; overflow: hidden; }
.cam { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.mirror { transform: scaleX(-1); }
.no-cam { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.countdown { position: absolute; inset: 0; display: grid; place-items: center; font-size: 160px; font-weight: 900; background: rgba(0,0,0,.45); font-variant-numeric: tabular-nums; }
.panel { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; background: var(--bg); }
.panel.scroll { max-width: 560px; width: 100%; margin: 0 auto; padding-top: 32px; }
.toggle { display: flex; gap: 10px; align-items: center; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }
.hint { margin: 0; color: var(--muted); font-size: 14px; }
.error { margin: 0; color: var(--danger); font-size: 14px; }

/* HUD */
.hud { position: absolute; inset: 0; padding: 16px; display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto 1fr; pointer-events: none; text-shadow: 0 2px 8px rgba(0,0,0,.7); }
.clock { font-size: clamp(56px, 18vw, 120px); font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1; }
.clock.warn { color: var(--accent); }
.rounds { text-align: right; font-size: clamp(48px, 14vw, 96px); font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.rounds small { display: block; font-size: 14px; font-weight: 600; color: #ddd; }
.pace { grid-column: 1 / -1; color: var(--gold); font-weight: 600; margin-top: 8px; }
.rec { position: absolute; bottom: 12px; left: 16px; color: var(--accent); font-weight: 700; font-size: 13px; }
.moves-inline { margin: 0; text-align: center; color: var(--muted); }

/* Finish */
.result { font-size: 44px; margin: 4px 0 0; line-height: 1.05; }
.result .plus { display: block; font-size: 22px; color: var(--muted); }
.vs { margin: 0; color: var(--gold); font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 8px; }
.label { font-size: 14px; color: var(--muted); }
.field input { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper .btn { width: 56px; font-size: 22px; padding: 10px 0; }
.stepper output { min-width: 48px; text-align: center; font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.presets { display: flex; gap: 8px; flex-wrap: wrap; }
.playback { width: 100%; max-height: 50dvh; border-radius: var(--radius); background: #000; }

dialog { background: var(--surface); color: var(--text); border: 0; border-radius: var(--radius); padding: 12px; width: min(560px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.75); }
dialog video { width: 100%; max-height: 70dvh; background: #000; border-radius: 10px; }
dialog form { margin-top: 10px; display: flex; justify-content: flex-end; }
