/* ── Design tokens ────────────────────────────────────────────────── */
:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface-2: #25253d;
  --primary: #7c3aed;
  --primary-hover: #6d28d9;
  --accent: #f59e0b;
  --success: #10b981;
  --danger: #ef4444;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Space Grotesk', system-ui, sans-serif;
}

/* ── Reset & base ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
}

#app {
  width: 100%;
  max-width: 600px;
  padding: 24px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ── Screens ─────────────────────────────────────────────────────── */
.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  animation: fadeIn 0.3s ease;
}
.screen.active { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Typography ──────────────────────────────────────────────────── */
.logo {
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -1px;
  text-align: center;
}
.logo-q { color: var(--primary); }

.tagline {
  color: var(--text-muted);
  font-size: 1.1rem;
  margin-bottom: 16px;
}

h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
}

h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  padding: 14px 28px;
  cursor: pointer;
  transition: all 0.15s ease;
  width: 100%;
  max-width: 320px;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 2px solid var(--primary);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { color: var(--text); }

.btn-small { padding: 8px 16px; font-size: 0.85rem; }

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 320px;
}

/* ── Inputs ───────────────────────────────────────────────────────── */
.input-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  align-self: flex-start;
  margin-left: calc((100% - 320px) / 2);
}

.input {
  font-family: var(--font);
  font-size: 1rem;
  padding: 14px 16px;
  border: 2px solid var(--surface-2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  width: 100%;
  max-width: 320px;
  outline: none;
  transition: border-color 0.15s;
}
.input:focus { border-color: var(--primary); }

.input-code {
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 8px;
  font-size: 1.5rem;
  font-weight: 700;
}

/* ── Room code display ───────────────────────────────────────────── */
.room-code {
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: 10px;
  color: var(--accent);
  background: var(--surface);
  padding: 16px 32px;
  border-radius: var(--radius);
  text-align: center;
}

/* ── Player list / cards ─────────────────────────────────────────── */
.player-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  width: 100%;
  margin: 12px 0;
}

.player-card {
  background: var(--surface);
  border: 2px solid var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.player-card.is-host::before {
  content: '\2605';
  color: var(--accent);
}

/* ── Filter badge ────────────────────────────────────────────────── */
.filter-badge {
  display: inline-block;
  padding: 8px 20px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  background: var(--surface-2);
  color: var(--accent);
  border: 1px solid var(--accent);
}

/* ── Timer ────────────────────────────────────────────────────────── */
.timer {
  font-size: 2.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  text-align: center;
}
.timer.urgent {
  color: var(--danger);
  animation: timerPulse 1s ease-in-out infinite;
}

@keyframes timerPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ── Anonymous player grid ───────────────────────────────────────── */
.anon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  width: 100%;
  margin: 12px 0;
}

.anon-player-card {
  background: var(--surface);
  border: 2px solid var(--surface-2);
  border-radius: var(--radius);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.anon-player-card.is-me {
  border-color: var(--primary);
}

.anon-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-muted);
}

.anon-label {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}

.anon-me-tag {
  font-size: 0.8rem;
  color: var(--primary);
  font-weight: 600;
}

/* ── Voice indicator ─────────────────────────────────────────────── */
.voice-indicator {
  display: flex;
  gap: 3px;
  align-items: flex-end;
  height: 20px;
}

.wave-bar {
  width: 4px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 2px;
  transition: background 0.15s;
}

.voice-indicator.active .wave-bar {
  background: var(--success);
  animation: waveAnim 0.5s ease-in-out infinite alternate;
}
.voice-indicator.active .wave-bar:nth-child(1) { animation-delay: 0s; }
.voice-indicator.active .wave-bar:nth-child(2) { animation-delay: 0.1s; }
.voice-indicator.active .wave-bar:nth-child(3) { animation-delay: 0.2s; }
.voice-indicator.active .wave-bar:nth-child(4) { animation-delay: 0.3s; }
.voice-indicator.active .wave-bar:nth-child(5) { animation-delay: 0.4s; }

@keyframes waveAnim {
  from { height: 6px; }
  to { height: 20px; }
}

/* ── Guess dropdown ──────────────────────────────────────────────── */
.guess-dropdown {
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--surface-2);
  outline: none;
  width: 100%;
  cursor: pointer;
  transition: border-color 0.15s;
}
.guess-dropdown:focus { border-color: var(--primary); }

/* ── Guess status ────────────────────────────────────────────────── */
.guess-status {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
}

/* ── Results columns ─────────────────────────────────────────────── */
.results-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  width: 100%;
}

.results-reveal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
}

.results-reveal .answer-filter {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 4px 0 12px;
}

.reveal-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--surface-2);
  font-size: 0.9rem;
  gap: 8px;
}
.reveal-row:last-child { border-bottom: none; }

.reveal-number {
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}
.reveal-name {
  color: var(--accent);
  font-weight: 700;
  flex: 1;
  text-align: center;
}
.reveal-pts {
  color: var(--success);
  font-weight: 600;
  white-space: nowrap;
}

.results-leaderboard {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
}

/* ── Score table ─────────────────────────────────────────────────── */
.score-table {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  font-weight: 600;
}
.score-row .rank { color: var(--accent); margin-right: 8px; }
.score-row .score-val { color: var(--primary); }
.score-row:first-child {
  background: var(--surface-2);
  border: 2px solid var(--accent);
}

/* ── Round info ──────────────────────────────────────────────────── */
.round-info {
  background: var(--surface);
  padding: 8px 20px;
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* ── Help button ─────────────────────────────────────────────────── */
.help-btn {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 50;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--surface-2);
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.help-btn:hover {
  border-color: var(--primary);
  color: var(--text);
}

/* ── Help overlay ────────────────────────────────────────────────── */
.help-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 200;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.help-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}
.help-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 440px;
  padding: 32px 28px;
}
.help-title {
  color: #fbbf24;
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 4px;
}
.help-content p {
  font-size: 0.95rem;
  line-height: 1.5;
  color: #fff;
  text-align: center;
}
.help-content .help-dismiss {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 8px;
}

/* ── Test mode banner ────────────────────────────────────────────── */
.test-mode-banner {
  color: #fbbf24;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
}

/* ── Toast ────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--surface-2);
  color: var(--text);
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid var(--primary);
  transition: transform 0.3s ease;
  z-index: 100;
  white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 520px) {
  #app { padding: 16px; }
  .logo { font-size: 2rem; }
  .room-code { font-size: 2rem; letter-spacing: 8px; padding: 12px 24px; }
  .results-columns {
    grid-template-columns: 1fr;
  }
  .anon-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }
}
