/* ============================================================
   BLINK·60 — UI v2
   Mobile-first, full-bleed camera stage with overlay HUD
   ============================================================ */

/* ---------- RESET & TOKENS ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { height: 100%; }
body {
  min-height: 100dvh;
  font-family: 'Space Grotesk', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: #f5f3ff;
  background: #07060f;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input { font-family: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
input { outline: none; }

:root {
  --c-bg:        #07060f;
  --c-text:      #f5f3ff;
  --c-muted:     #94a3b8;
  --c-cyan:      #67e8f9;
  --c-pink:      #f0abfc;
  --c-amber:     #fbbf24;
  --c-rose:      #fb7185;
  --c-yellow:    #fef08a;
  --c-green:     #34d399;
  --grad-hot:    linear-gradient(135deg, #fef08a 0%, #f0abfc 50%, #67e8f9 100%);
  --grad-btn:    linear-gradient(135deg, #f0abfc 0%, #818cf8 50%, #67e8f9 100%);
  --r-card:      24px;
  --r-pill:      999px;
  --shadow-lg:   0 30px 80px rgba(0,0,0,0.45);
}

/* ---------- BACKGROUND ---------- */
.bg-orbs {
  position: fixed; inset: 0; z-index: -2; overflow: hidden;
  background:
    radial-gradient(1200px 800px at 10% -10%, #1a0b3d 0%, transparent 60%),
    radial-gradient(900px 700px at 110% 10%, #3d0b2e 0%, transparent 60%),
    radial-gradient(900px 700px at 50% 120%, #0b2a3d 0%, transparent 60%),
    var(--c-bg);
}
.orb {
  position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.55;
  animation: float 18s ease-in-out infinite alternate;
}
.orb-1 { width: 480px; height: 480px; background: #7c3aed; top: -120px; left: -120px; }
.orb-2 { width: 520px; height: 520px; background: #ec4899; top: 30%; right: -160px; animation-delay: -6s; }
.orb-3 { width: 420px; height: 420px; background: #06b6d4; bottom: -120px; left: 20%; animation-delay: -12s; }
@keyframes float {
  0%   { transform: translate(0,0) scale(1); }
  50%  { transform: translate(40px,-30px) scale(1.08); }
  100% { transform: translate(-30px,40px) scale(0.95); }
}
.particles { position: fixed; inset: 0; z-index: -1; pointer-events: none; }

/* ---------- LAYOUT ROOTS ---------- */
#app {
  width: 100%;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.screen { display: none; width: 100%; max-width: 1200px; }
.screen.active { display: block; animation: fadeUp .45s ease both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px);} to { opacity: 1; transform: none; } }

/* ============================================================
   START SCREEN — clean hierarchy
   ============================================================ */
.hero {
  max-width: 480px;
  margin: 0 auto;
  padding: 48px 28px 36px;
  text-align: center;
  background: rgba(255,255,255,0.04);
  backdrop-filter: blur(24px) saturate(140%);
  -webkit-backdrop-filter: blur(24px) saturate(140%);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 32px;
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,0.08);
  position: relative;
}
.hidden { display: none !important; }

/* Rank badge — top-left corner of the hero card */
.my-rank-badge {
  position: absolute; top: 14px; left: 16px;
  display: flex; align-items: center; gap: 5px;
  background: rgba(103,232,249,0.12);
  border: 1px solid rgba(103,232,249,0.30);
  border-radius: 999px;
  padding: 4px 12px 4px 10px;
  font-size: 12px; font-weight: 600; color: var(--c-cyan);
  letter-spacing: 0.03em;
}
.my-rank-badge span { font-family: 'Bricolage Grotesque'; font-weight: 800; font-size: 14px; }

.brand {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  margin-bottom: 18px;
}
.brand-title {
  font-family: 'Bricolage Grotesque', 'Space Grotesk', sans-serif;
  font-weight: 800;
  font-size: clamp(40px, 9vw, 64px);
  letter-spacing: -0.04em;
  margin: 0;
  background: var(--grad-hot);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 8px 30px rgba(244, 114, 182, 0.25);
}
.brand-title .accent { color: transparent; -webkit-text-stroke: 2px var(--c-pink); }

.eye-mark {
  position: relative; width: 52px; height: 52px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff, #c4b5fd 60%, #7c3aed);
  display: inline-block; overflow: hidden;
  box-shadow: 0 0 40px rgba(124, 58, 237, 0.7);
}
.eye-mark .iris {
  position: absolute; inset: 13px; border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #0f172a 35%, #6366f1 70%);
}
.eye-mark .lid {
  position: absolute; inset: 0; background: var(--c-bg);
  transform-origin: top; transform: scaleY(0);
  animation: blink 4s ease-in-out infinite;
}
@keyframes blink {
  0%, 92%, 100% { transform: scaleY(0); }
  95%, 97%      { transform: scaleY(1); }
}

.brand-tag {
  color: #cbd5e1; font-size: 16px; line-height: 1.5;
  margin: 0 0 6px;
}
.brand-tag b { color: var(--c-yellow); font-weight: 700; }

/* Standalone games-played counter (between tagline and form) */
.total-plays-line {
  margin: 0 0 20px;
  font-size: 13px; color: var(--c-muted); letter-spacing: 0.03em;
}
.total-plays-line b { color: var(--c-cyan); font-weight: 700; font-size: 15px; }

/* Form row */
.start-form {
  display: flex; flex-direction: column; gap: 12px;
  margin-bottom: 16px;
}
.name-wrap {
  position: relative; display: flex; align-items: center;
}
#player-name {
  width: 100%; padding: 18px 48px 18px 20px;
  font-size: 18px; text-align: center; letter-spacing: 0.04em;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
#player-name.locked {
  background: rgba(255,255,255,0.03);
  border-color: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.85);
  cursor: default;
}
.name-edit-btn {
  position: absolute; right: 12px;
  background: none; border: none; cursor: pointer;
  font-size: 16px; line-height: 1; padding: 4px;
  opacity: 0.6; transition: opacity .15s;
}
.name-edit-btn:hover { opacity: 1; }
#player-name::placeholder { color: rgba(255,255,255,0.4); }
#player-name:focus {
  border-color: var(--c-pink);
  box-shadow: 0 0 0 4px rgba(240, 171, 252, 0.15);
  background: rgba(255,255,255,0.08);
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  padding: 14px 24px;
  font-weight: 700; font-size: 14px; letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 14px;
  transition: transform .12s ease, box-shadow .25s, filter .2s, background .2s;
}
.btn-xl { padding: 18px 32px; font-size: 16px; }
.btn-primary {
  background: var(--grad-btn);
  color: #0b0420;
  box-shadow: 0 12px 40px rgba(168, 85, 247, 0.45), inset 0 1px 0 rgba(255,255,255,0.5);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 18px 50px rgba(168, 85, 247, 0.6); }
.btn-primary:active { transform: translateY(0); filter: brightness(0.95); }
.btn-ghost {
  background: rgba(255,255,255,0.06); color: var(--c-text);
  border: 1px solid rgba(255,255,255,0.12);
}
.btn-ghost:hover { background: rgba(255,255,255,0.12); }

.btn-link {
  display: inline-block;
  padding: 10px 14px;
  font-size: 14px; color: var(--c-pink);
  border-radius: 10px;
  transition: background .2s, color .2s;
}
.btn-link:hover { background: rgba(240, 171, 252, 0.10); }
.btn-link.danger { color: var(--c-rose); }
.btn-link.danger:hover { background: rgba(244, 63, 94, 0.10); }

/* ---- Mini leaderboard on start screen ---- */
.start-lb-wrap {
  margin: 4px 0 8px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 18px;
  padding: 14px 16px 10px;
  text-align: left;
}
.mini-lb-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 6px;
  min-height: 28px;
}
.mini-lb-row {
  display: flex; align-items: center; gap: 9px;
  font-size: 14px; font-weight: 500;
  padding: 5px 6px; border-radius: 10px;
  transition: background .15s;
}
.mini-lb-row:hover { background: rgba(255,255,255,0.05); }
.mini-lb-medal { font-size: 17px; width: 22px; text-align: center; flex-shrink: 0; }
.mini-lb-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  object-fit: cover; border: 1px solid rgba(255,255,255,0.18);
  flex-shrink: 0;
}
.mini-lb-avatar-ph {
  width: 26px; height: 26px; border-radius: 50%;
  background: linear-gradient(135deg, #7c3aed, #06b6d4);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.mini-lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #e2e8f0; }
.mini-lb-score { font-weight: 700; color: var(--c-yellow); font-size: 15px; flex-shrink: 0; }
.mini-lb-empty { color: var(--c-muted); font-size: 13px; text-align: center; padding: 8px 0; }
.mini-lb-more {
  display: block; width: 100%; text-align: center;
  margin-top: 8px; padding: 6px;
  font-size: 13px; color: var(--c-pink);
}
.lb-tagline {
  margin: 6px 0 0;
  text-align: center; font-size: 12px;
  color: rgba(255,255,255,0.25); letter-spacing: 0.04em;
}
.lb-tagline b { color: rgba(255,255,255,0.38); font-weight: 600; }

/* "How to play" — progressive disclosure */
.how-details {
  margin: 22px 0 16px;
  text-align: left;
  border-top: 1px solid rgba(255,255,255,0.08);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  padding: 4px 0;
}
.how-details summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 4px;
  font-size: 13px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--c-muted);
  display: flex; justify-content: space-between; align-items: center;
}
.how-details summary::-webkit-details-marker { display: none; }
.how-details summary::after {
  content: "+"; font-size: 18px; color: var(--c-pink);
  transition: transform .2s;
}
.how-details[open] summary::after { transform: rotate(45deg); }
.how-list {
  margin: 4px 0 12px; padding-left: 22px;
  font-size: 14px; line-height: 1.7; color: #cbd5e1;
}
.how-list li::marker { color: var(--c-pink); font-weight: 700; }

.privacy-note {
  margin: 8px 0 0;
  font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase;
  color: rgba(255,255,255,0.35);
}

/* ============================================================
   GAME SCREEN — full-bleed camera stage
   ============================================================ */
#screen-game.active { display: flex; }
#screen-game {
  max-width: 1100px;
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: calc(100dvh - 48px);
  margin: 0 auto;
  border-radius: 28px;
  overflow: hidden;
  background: #0b0420;
  border: 1px solid rgba(255,255,255,0.10);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,0.06);
}

#video, .overlay-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
#video { transform: scaleX(-1); }
.overlay-canvas { pointer-events: none; }

/* Subtle vignette so HUD pops */
.stage::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 50%, rgba(0,0,0,0.55) 100%),
    linear-gradient(to bottom, rgba(0,0,0,0.45) 0%, transparent 18%, transparent 80%, rgba(0,0,0,0.5) 100%);
}

/* Live ready ring — pulses when face detected, dim when not */
.ready-ring {
  position: absolute; inset: 0;
  pointer-events: none;
  border-radius: inherit;
  box-shadow:
    inset 0 0 0 2px rgba(103, 232, 249, 0.0),
    inset 0 0 40px rgba(103, 232, 249, 0.0);
  transition: box-shadow .3s ease;
}
.ready-ring.live {
  box-shadow:
    inset 0 0 0 2px rgba(52, 211, 153, 0.55),
    inset 0 0 40px rgba(52, 211, 153, 0.18);
  animation: readyPulse 2s ease-in-out infinite;
}
.ready-ring.searching {
  box-shadow:
    inset 0 0 0 2px rgba(251, 191, 36, 0.45),
    inset 0 0 30px rgba(251, 191, 36, 0.15);
}
@keyframes readyPulse {
  0%, 100% { box-shadow: inset 0 0 0 2px rgba(52,211,153,0.55), inset 0 0 40px rgba(52,211,153,0.15); }
  50%      { box-shadow: inset 0 0 0 2px rgba(52,211,153,0.85), inset 0 0 60px rgba(52,211,153,0.30); }
}

/* TOP HUD bar */
.hud-top {
  position: absolute; top: 16px; left: 16px; right: 16px; z-index: 5;
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 12px;
}
.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  background: rgba(7,6,15,0.65);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--r-pill);
  font-size: 12px; letter-spacing: 0.10em; text-transform: uppercase;
  font-weight: 600;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--c-muted);
  box-shadow: 0 0 0 0 rgba(148, 163, 184, 0.6);
}
.status-pill[data-state="loading"] .status-dot {
  background: var(--c-amber);
  animation: dotPulse 1.2s ease-in-out infinite;
}
.status-pill[data-state="searching"] .status-dot {
  background: var(--c-amber);
  animation: dotPulse 1s ease-in-out infinite;
}
.status-pill[data-state="ready"] {
  border-color: rgba(52, 211, 153, 0.4);
  background: rgba(6, 78, 59, 0.55);
}
.status-pill[data-state="ready"] .status-dot {
  background: var(--c-green);
  animation: dotPulse 1.6s ease-in-out infinite;
}
.status-pill[data-state="error"] {
  border-color: rgba(244, 63, 94, 0.4);
  background: rgba(76, 5, 25, 0.6);
}
.status-pill[data-state="error"] .status-dot { background: var(--c-rose); }
@keyframes dotPulse {
  0%, 100% { box-shadow: 0 0 0 0 currentColor; opacity: 1; }
  50%      { box-shadow: 0 0 0 6px rgba(255,255,255,0); opacity: 0.6; }
}

/* Mini timer ring (top-right) */
.timer-mini {
  position: relative; width: 56px; height: 56px;
}
.timer-mini-ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer-mini-ring circle { fill: none; stroke-width: 5; stroke-linecap: round; }
.ring-bg { stroke: rgba(0,0,0,0.5); }
.ring-fg {
  stroke: var(--c-cyan);
  stroke-dasharray: 163.36;   /* 2π·26 */
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear, stroke .3s;
  filter: drop-shadow(0 0 8px rgba(103, 232, 249, 0.55));
}
.timer-mini-text {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Bricolage Grotesque'; font-weight: 800;
  font-size: 22px;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

/* CENTER HUD — big counter (only when playing) */
.hud-center {
  position: absolute; inset: 0; z-index: 4;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  pointer-events: none;
  text-align: center;
  padding: 0 16px;
  opacity: 0;
  transition: opacity .3s ease;
}
.hud-center.show { opacity: 1; }
.big-counter-label {
  font-size: 12px; letter-spacing: 0.4em; color: rgba(255,255,255,0.7);
  text-shadow: 0 2px 12px rgba(0,0,0,0.6);
  margin-bottom: 4px;
}
.big-counter {
  font-family: 'Bricolage Grotesque'; font-weight: 800;
  font-size: clamp(110px, 22vw, 220px);
  line-height: 0.95; letter-spacing: -0.04em;
  background: var(--grad-hot);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 6px 24px rgba(240, 171, 252, 0.4));
  transition: transform .12s ease;
}
.big-counter.pop { transform: scale(1.16); }
.combo {
  display: inline-block;
  margin-top: 10px;
  padding: 6px 16px; border-radius: var(--r-pill);
  font-size: 13px; font-weight: 700; letter-spacing: 0.1em;
  background: rgba(7,6,15,0.6);
  border: 1px solid rgba(240, 171, 252, 0.35);
  color: var(--c-pink);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transition: transform .15s ease, background .2s, color .2s, border-color .2s;
}
.combo.fire   { color: #fb923c; border-color: rgba(251,146,60,0.5);   background: rgba(124, 45, 18, 0.5); }
.combo.insane { color: #fda4af; border-color: rgba(244,63,94,0.6);    background: rgba(76, 5, 25, 0.55); animation: shake .35s ease; }
@keyframes shake {
  0%,100% { transform: translateX(0);} 25% { transform: translateX(-3px);} 75% { transform: translateX(3px);}
}

/* BOTTOM HUD */
.hud-bottom {
  position: absolute; bottom: 16px; left: 16px; right: 16px; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px;
}
.state-msg {
  flex: 1;
  padding: 10px 16px;
  background: rgba(7,6,15,0.65);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--r-pill);
  font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase;
  font-weight: 600;
  text-align: center;
  color: #e2e8f0;
}
.bpm {
  flex-shrink: 0;
  padding: 10px 14px;
  background: rgba(7,6,15,0.65);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--r-pill);
  font-size: 12px; letter-spacing: 0.08em; font-weight: 600;
  color: var(--c-cyan);
}

/* Face hint (shown when no face) */
.face-hint {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  z-index: 6;
  padding: 12px 20px;
  background: rgba(244, 63, 94, 0.92);
  border-radius: var(--r-pill);
  font-size: 14px; font-weight: 700;
  box-shadow: 0 12px 30px rgba(244, 63, 94, 0.4);
  opacity: 0;
  transition: opacity .25s;
  pointer-events: none;
}
.face-hint.show { opacity: 1; }

/* Distance warning — amber, positioned below the center hint */
.face-hint-far {
  top: calc(50% + 56px);
  background: rgba(251, 191, 36, 0.92);
  box-shadow: 0 12px 30px rgba(251, 191, 36, 0.35);
  color: #1a1a1a;
}

/* Quit button */
.quit-btn {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 7;
  width: 36px; height: 36px;
  background: rgba(7,6,15,0.7);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 50%;
  font-size: 16px; color: rgba(255,255,255,0.7);
  display: none; align-items: center; justify-content: center;
  transition: background .2s, color .2s, transform .2s;
}
.quit-btn.show { display: flex; }
.quit-btn:hover { background: rgba(244, 63, 94, 0.6); color: #fff; transform: translateX(-50%) scale(1.1); }

/* Camera flip button (mobile only) */
.flip-btn {
  position: absolute; bottom: 100px; right: 16px;
  z-index: 7;
  width: 44px; height: 44px;
  background: rgba(7,6,15,0.70);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 50%;
  font-size: 20px;
  display: none; align-items: center; justify-content: center;
  transition: background .2s, transform .2s;
  -webkit-tap-highlight-color: transparent;
}
/* Only show on devices that support touch (mobile) */
@media (hover: none) and (pointer: coarse) {
  .flip-btn { display: flex; }
  .flip-btn.flipping { transform: rotate(180deg); background: rgba(103,232,249,0.2); }
}

/* Loading skeleton */
.cam-loading {
  position: absolute; inset: 0; z-index: 8;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1a0b3d, #3d0b2e);
  transition: opacity .4s ease;
}
.cam-loading.hide { opacity: 0; pointer-events: none; }
.shimmer {
  position: absolute; inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(255,255,255,0.08) 50%, transparent 70%);
  background-size: 200% 100%;
  animation: shimmer 2s linear infinite;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.loading-stack {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 24px;
  text-align: center;
}
.loading-spinner {
  width: 42px; height: 42px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: var(--c-pink);
  border-right-color: var(--c-cyan);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-title {
  font-family: 'Bricolage Grotesque'; font-size: 20px; font-weight: 800;
  letter-spacing: -0.01em;
  background: var(--grad-hot);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.loading-sub {
  font-size: 12px; color: var(--c-muted); letter-spacing: 0.04em;
  max-width: 280px; line-height: 1.5;
}
.loading-bar-wrap {
  width: 200px; max-width: 80%;
  height: 4px;
  background: rgba(255,255,255,0.10);
  border-radius: 99px;
  overflow: hidden;
}
.loading-bar {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--c-pink), var(--c-cyan));
  transition: width 0.4s ease;
  box-shadow: 0 0 10px rgba(103, 232, 249, 0.5);
}

/* Countdown */
.countdown {
  position: absolute; inset: 0; z-index: 9;
  display: flex; align-items: center; justify-content: center;
  background: rgba(7, 6, 15, 0.6);
  backdrop-filter: blur(8px);
}
.countdown.hidden { display: none; }
.cd-num {
  font-family: 'Bricolage Grotesque'; font-weight: 800;
  font-size: clamp(140px, 28vw, 280px); line-height: 1;
  background: var(--grad-hot);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: cdPop .9s ease forwards;
  text-shadow: 0 10px 60px rgba(240, 171, 252, 0.35);
}
@keyframes cdPop {
  0%   { transform: scale(0.4); opacity: 0; }
  20%  { transform: scale(1.1); opacity: 1; }
  80%  { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.4); opacity: 0; }
}

/* Flash on blink */
.flash {
  position: absolute; inset: 0; z-index: 3;
  background: radial-gradient(ellipse at center, rgba(240,171,252,0.45), transparent 65%);
  opacity: 0; pointer-events: none;
  transition: opacity .12s ease-out;
}
.flash.on { opacity: 1; }

/* ============================================================
   RESULT SCREEN
   ============================================================ */
#screen-result { position: relative; }
.confetti-canvas {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
}
.result {
  position: relative; z-index: 2;
  max-width: 560px; margin: 0 auto;
  padding: 44px 32px 32px;
  text-align: center;
  background: rgba(255,255,255,0.05);
  backdrop-filter: blur(24px) saturate(140%);
  -webkit-backdrop-filter: blur(24px) saturate(140%);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 32px;
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,0.08);
}
.result-medal {
  font-size: 64px; line-height: 1;
  margin-bottom: 4px;
  animation: medalDrop .6s cubic-bezier(.34, 1.56, .64, 1) both;
}
@keyframes medalDrop {
  0%   { transform: scale(0) rotate(-180deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
.result-title {
  font-family: 'Bricolage Grotesque'; font-weight: 800;
  font-size: clamp(24px, 4vw, 36px);
  margin: 0 0 6px;
  letter-spacing: -0.02em;
  background: var(--grad-hot);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.result-score-wrap { margin: 14px 0 24px; }
.result-score {
  font-family: 'Bricolage Grotesque'; font-weight: 800;
  font-size: clamp(96px, 18vw, 160px);
  line-height: 0.95; letter-spacing: -0.04em;
  background: var(--grad-hot);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 12px 50px rgba(240, 171, 252, 0.3));
}
.result-score-sub {
  font-size: 11px; letter-spacing: 0.25em; text-transform: uppercase;
  color: var(--c-muted); margin-top: 2px;
}

.result-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin: 18px 0 28px;
}
.stat {
  padding: 16px 8px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  transition: transform .2s, background .2s;
}
.stat:hover { background: rgba(255,255,255,0.08); transform: translateY(-2px); }
.stat-num {
  font-family: 'Bricolage Grotesque'; font-weight: 800;
  font-size: clamp(22px, 4vw, 32px); line-height: 1;
  color: var(--c-pink);
  margin-bottom: 6px;
}
.stat-label {
  font-size: 10px; letter-spacing: 0.18em; color: var(--c-muted);
  text-transform: uppercase;
}

.result-actions {
  display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;
  margin-bottom: 28px;
}
.result-actions .btn { flex: 1; min-width: 140px; }

/* Leaderboard */
.leaderboard { text-align: left; }
.leaderboard h3 {
  margin: 0 0 12px;
  font-size: 13px; letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--c-muted);
}
.leaderboard ol, #lb-list-modal {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 6px;
}
.lb-row {
  display: grid;
  grid-template-columns: 32px 1fr auto auto;
  gap: 12px; align-items: center;
  padding: 12px 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 12px;
  transition: background .2s, transform .2s;
}
.lb-row:hover { background: rgba(255,255,255,0.08); transform: translateX(2px); }
.lb-row.you {
  background: linear-gradient(90deg, rgba(240,171,252,0.18), rgba(103,232,249,0.10));
  border-color: rgba(240,171,252,0.4);
  box-shadow: 0 4px 20px rgba(240, 171, 252, 0.15);
}
.lb-rank { font-family: 'Bricolage Grotesque'; font-weight: 800; color: var(--c-pink); font-size: 14px; }
.lb-rank.gold   { color: #fde047; }
.lb-rank.silver { color: #e5e7eb; }
.lb-rank.bronze { color: #fdba74; }
.lb-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 7px; }
.lb-av { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; border: 1px solid rgba(255,255,255,0.2); flex-shrink: 0; }
.lb-av-ph { width: 22px; height: 22px; border-radius: 50%; background: linear-gradient(135deg,#7c3aed,#06b6d4); display: inline-flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; flex-shrink: 0; }
.lb-score {
  font-family: 'Bricolage Grotesque'; font-weight: 800;
  color: var(--c-cyan); font-size: 16px;
}
.lb-date { font-size: 11px; color: #64748b; letter-spacing: 0.04em; }

/* ============================================================
   MODAL
   ============================================================ */
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(7, 6, 15, 0.75);
  backdrop-filter: blur(8px);
  padding: 16px;
  animation: fadeIn .2s ease;
}
.modal.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  width: 100%; max-width: 480px; max-height: 80vh; overflow-y: auto;
  padding: 24px;
  background: rgba(15, 10, 35, 0.95);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.modal-head h3 {
  margin: 0;
  font-family: 'Bricolage Grotesque'; font-size: 22px; letter-spacing: -0.01em;
}
.icon-btn {
  width: 34px; height: 34px; border-radius: 10px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.10);
  display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.icon-btn:hover { background: rgba(255,255,255,0.12); }
#lb-clear { margin-top: 16px; display: block; width: 100%; text-align: center; }

/* ============================================================
   MOBILE — under 700px
   ============================================================ */
@media (max-width: 700px) {
  #app { padding: 12px; }
  .screen { max-width: 100%; }
  .hero { padding: 40px 24px 32px; }

  .stage {
    aspect-ratio: 3 / 4;
    max-height: calc(100dvh - 24px);
  }

  .hud-top   { top: 12px; left: 12px; right: 12px; }
  .hud-bottom { bottom: 12px; left: 12px; right: 12px; flex-direction: column; gap: 8px; }
  .state-msg { width: 100%; }
  .bpm       { width: 100%; text-align: center; }

  .timer-mini { width: 50px; height: 50px; }
  .timer-mini-text { font-size: 18px; }

  .big-counter { font-size: clamp(96px, 28vw, 180px); }

  .quit-btn { top: 12px; }

  .result { padding: 32px 24px 24px; }
  .result-stats { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .stat { padding: 12px 4px; }
  .result-actions { flex-direction: column; }
  .result-actions .btn { width: 100%; }
}

@media (max-width: 380px) {
  .stage { aspect-ratio: 9 / 14; }
  .brand-title { font-size: 36px; }
}

/* Tall screens — keep stage from getting cropped */
@media (min-aspect-ratio: 1/1) and (min-width: 701px) {
  .stage { max-height: calc(100dvh - 48px); }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Utilities */
.hidden { display: none !important; }
