:root {
  --bg: #1a1a2e;
  --bg-card: #16213e;
  --text: #eee;
  --text-dim: #888;
  --accent: #e94560;
  --correct: #2ecc71;
  --wrong: #e74c3c;
  --opt-a: #e74c3c;
  --opt-b: #3498db;
  --opt-c: #2ecc71;
  --opt-d: #f39c12;
  --opt-a-dark: #c0392b;
  --opt-b-dark: #2980b9;
  --opt-c-dark: #27ae60;
  --opt-d-dark: #d68910;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: radial-gradient(ellipse at 50% 30%, #1f2548 0%, #1a1a2e 50%, #111122 100%);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
.screen {
  display: none; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100dvh; padding: 16px; animation: fadeIn 0.3s ease;
}
.screen.active { display: flex; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeOut { to { opacity: 0; transform: translateY(10px); } }
.screen.exiting { animation: fadeOut 0.2s ease forwards; pointer-events: none; }
@keyframes slideUp { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: translateY(0); } }
@keyframes popIn { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
@keyframes scoreFloat { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-40px); } }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.05); } }
@keyframes avatarPulse {
  0%,100% { box-shadow: 0 0 0 2px var(--ring-color); }
  50% { box-shadow: 0 0 10px 3px var(--ring-color); }
}
@keyframes correctGlow {
  0%,100% { box-shadow: 0 0 8px rgba(46,204,113,0.4); }
  50% { box-shadow: 0 0 20px rgba(46,204,113,0.8); }
}
@keyframes deltaFadeIn { from { opacity: 0; transform: translateX(10px); } to { opacity: 1; transform: translateX(0); } }
@keyframes deltaFadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes growUp {
  0% { height: 0; } 70% { height: calc(var(--target-h) * 1.12); }
  85% { height: calc(var(--target-h) * 0.96); } 100% { height: var(--target-h); }
}
@keyframes confettiDrop {
  0% { transform: translateY(-100vh) translateX(0) rotate(0deg); opacity: var(--c-opacity, 1); }
  100% { transform: translateY(100vh) translateX(var(--drift, 0px)) rotate(720deg); opacity: 0; }
}
@keyframes timerPulse { 0%,100% { opacity: 1; box-shadow: 0 0 12px rgba(231, 76, 60, 0.6); } 50% { opacity: 0.6; box-shadow: 0 0 20px rgba(231, 76, 60, 0.9); } }
@keyframes tensionFlash { 0% { opacity: 0; } 50% { opacity: 0.6; } 100% { opacity: 0; } }
.tension-flash {
  position: fixed; inset: 0; background: black; z-index: 200;
  animation: tensionFlash 0.3s ease forwards; pointer-events: none;
}
@keyframes countdownPop { 0% { transform: scale(0.3); opacity: 0; } 60% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
@keyframes countdownBurst {
  0% { transform: scale(0.3); opacity: 0.6; }
  100% { transform: scale(2.5); opacity: 0; }
}
@keyframes rippleAnim { to { transform: scale(2); opacity: 0; } }

h1 { font-size: 1.6rem; font-weight: 700; margin-bottom: 8px; }
h2 { font-size: 1.3rem; font-weight: 600; margin-bottom: 6px; }
.subtitle { color: var(--text-dim); font-size: 0.9rem; margin-bottom: 16px; text-transform: uppercase; letter-spacing: 2px; }

/* ── Logo ── */
.logo { width: 160px; height: 160px; margin-bottom: 12px; }
.logo.logo-sm { width: 90px; height: 90px; margin-bottom: 8px; }
.logo svg { width: 100%; height: 100%; }

/* ── Lobby ── */
#lobby .room-code {
  font-size: 1.1rem; font-weight: 700; letter-spacing: 3px; color: var(--accent);
  margin: 10px 0; padding: 6px 18px; border-radius: 20px; cursor: pointer;
  background: rgba(233,69,96,0.12); border: 1px solid rgba(233,69,96,0.3);
  position: relative; transition: background 0.2s; user-select: all;
}
#lobby .room-code:active { background: rgba(233,69,96,0.25); }
#lobby .room-code .copied-flash {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--correct); color: white; border-radius: 20px; font-size: 0.85rem;
  font-weight: 600; letter-spacing: 1px; animation: fadeIn 0.15s ease;
}
#lobby .player-count { font-size: 1.1rem; color: var(--text-dim); margin-bottom: 16px; }

/* ── Lobby avatar grid (2.1) ── */
.avatar-grid {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 16px;
  width: 100%; max-width: 360px; margin-bottom: 8px;
}
.avatar-circle {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  animation: popIn 0.3s ease backwards;
}
.avatar-circle .av-ring {
  width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.1rem; color: white;
  --ring-color: var(--accent);
  animation: avatarPulse 2s ease-in-out infinite;
}
.avatar-circle .av-name {
  font-size: 0.7rem; color: var(--text-dim); max-width: 60px;
  text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.avatar-circle .you-badge {
  font-size: 0.6rem; color: var(--accent); font-weight: 600; margin-top: -2px;
}
.avatar-circle .ready-badge {
  font-size: 0.6rem; color: var(--correct); font-weight: 600; margin-top: -2px;
}
/* ── Profile photos ── */
.av-photo { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.av-ring.has-photo { padding: 0; overflow: hidden; }
.pip-photo { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.ps-pip.has-photo { padding: 0; overflow: hidden; font-size: 0; }
.podium-photo { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.podium-avatar.has-photo { padding: 0; overflow: hidden; font-size: 0; }

.avatar-circle.ready .av-ring {
  animation: avatarPulse 1s ease-in-out infinite;
  box-shadow: 0 0 12px rgba(46, 204, 113, 0.5);
}
.ready-count {
  font-size: 0.9rem; color: var(--text-dim); margin-bottom: 8px;
  letter-spacing: 1px;
}
#readyBtn.ready-active {
  background: var(--correct);
}
.lobby-countdown {
  font-size: 0.8rem; color: var(--text-dim); margin-top: 12px; opacity: 0.6;
}

.btn {
  background: var(--accent); color: white; border: none; border-radius: 12px;
  padding: 14px 32px; font-size: 1.1rem; font-weight: 600; cursor: pointer;
  margin-top: 20px; width: 100%; max-width: 360px; transition: transform 0.1s, opacity 0.2s;
  position: relative; overflow: hidden;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(circle at var(--x, 50%) var(--y, 50%), rgba(255,255,255,0.3) 0%, transparent 60%);
  opacity: 0; transition: opacity 0.3s;
}
.btn:active::after { opacity: 1; }

/* ── Pregame ── */
#pregame .countdown {
  font-size: 5rem; font-weight: 800; color: var(--accent);
  animation: countdownPop 0.5s ease; position: relative;
}
#pregame .countdown::after {
  content: ''; position: absolute; inset: -30px; border-radius: 50%;
  border: 3px solid var(--accent); animation: countdownBurst 0.6s ease forwards;
  pointer-events: none;
}
#pregame .topic-label { font-size: 1.2rem; margin-top: 12px; }

/* ── Question ── */
#question-screen { justify-content: center; padding: 16px 20px; }
.timer-bar-container {
  width: 100%; max-width: 500px; height: 10px; background: rgba(255,255,255,0.1);
  border-radius: 5px; margin-bottom: 14px; overflow: visible;
}
.timer-bar {
  height: 100%; width: 100%; border-radius: 5px;
  transition: background-color 0.3s, box-shadow 0.3s;
}
.timer-bar.ok { background: var(--correct); box-shadow: 0 0 12px rgba(46, 204, 113, 0.6); }
.timer-bar.warn { background: #f39c12; box-shadow: 0 0 12px rgba(243, 156, 18, 0.6); }
.timer-bar.critical { background: var(--wrong); box-shadow: 0 0 12px rgba(231, 76, 60, 0.6); animation: timerPulse 0.4s ease infinite; }
.q-counter { font-size: 0.8rem; color: var(--text-dim); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 2px; }
.q-text { font-size: 1.15rem; font-weight: 600; text-align: center; max-width: 500px; margin-bottom: 16px; line-height: 1.4; }
.options-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; max-width: 500px; }
.option-btn {
  border: none; border-radius: 12px; padding: 18px 12px;
  font-size: 1rem; font-weight: 600; color: white; cursor: pointer;
  transition: transform 0.1s, opacity 0.2s, filter 0.3s;
  min-height: 60px; display: flex; align-items: center; justify-content: center;
  text-align: center; line-height: 1.3; position: relative; overflow: hidden;
}
.option-btn:active { transform: scale(0.96); }
.ripple {
  position: absolute; border-radius: 50%; background: rgba(255,255,255,0.4);
  width: 60px; height: 60px; margin-left: -30px; margin-top: -30px;
  transform: scale(0); opacity: 1; animation: rippleAnim 0.4s ease forwards;
  pointer-events: none;
}
.option-btn.selected { outline: none; }
.option-btn.locked { cursor: default; opacity: 0.4; filter: saturate(0.5); }
.option-btn.selected.locked { opacity: 1; filter: none; }
.option-btn:nth-child(1) { background: linear-gradient(to bottom, var(--opt-a), var(--opt-a-dark)); }
.option-btn:nth-child(2) { background: linear-gradient(to bottom, var(--opt-b), var(--opt-b-dark)); }
.option-btn:nth-child(3) { background: linear-gradient(to bottom, var(--opt-c), var(--opt-c-dark)); }
.option-btn:nth-child(4) { background: linear-gradient(to bottom, var(--opt-d), var(--opt-d-dark)); }
.option-btn:nth-child(1).selected { box-shadow: 0 0 20px rgba(231, 76, 60, 0.4); }
.option-btn:nth-child(2).selected { box-shadow: 0 0 20px rgba(52, 152, 219, 0.4); }
.option-btn:nth-child(3).selected { box-shadow: 0 0 20px rgba(46, 204, 113, 0.4); }
.option-btn:nth-child(4).selected { box-shadow: 0 0 20px rgba(243, 156, 18, 0.4); }
.leave-btn {
  background: transparent; border: 1px solid rgba(255,255,255,0.15); color: var(--text-dim);
  font-size: 0.8rem; padding: 8px 16px; margin-top: 14px; opacity: 0.5;
}
.leave-btn:active { opacity: 1; }

/* ── Player status strip ── */
.player-strip {
  display: flex; align-items: center; gap: 5px; margin-bottom: 10px;
  max-width: 500px; width: 100%; justify-content: center; flex-wrap: wrap;
}
.ps-pip {
  width: 32px; height: 32px; border-radius: 50%; font-size: 0.7rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.1); color: var(--text-dim);
  transition: all 0.3s ease; position: relative; flex-shrink: 0;
}
.ps-pip.is-you { outline: 2px solid var(--accent); outline-offset: 1px; }
.ps-pip.answered {
  background: var(--accent); color: white; transform: scale(1.1);
  animation: popIn 0.25s ease; box-shadow: 0 0 8px rgba(233, 69, 96, 0.5);
}
.player-item.new-join { animation: popIn 0.35s ease backwards; }
.ps-counter {
  font-size: 0.75rem; color: var(--text-dim); margin-left: 4px; white-space: nowrap;
  text-transform: uppercase; letter-spacing: 2px;
}

/* ── Reveal ── */
#reveal { gap: 12px; }
.reveal-question { font-size: 1.1rem; text-align: center; max-width: 450px; color: var(--text-dim); }
.reveal-options { width: 100%; max-width: 450px; }
.reveal-opt {
  background: rgba(22, 33, 62, 0.7); border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px; padding: 14px; margin-bottom: 8px; font-weight: 500;
  display: flex; align-items: center; gap: 10px; transition: all 0.3s;
}
.reveal-opt.correct-opt {
  background: var(--correct); color: white;
  animation: popIn 0.3s ease, correctGlow 1.5s ease-in-out infinite;
}
.reveal-opt.wrong-opt { background: rgba(255,255,255,0.05); color: var(--text-dim); }
.reveal-opt.your-wrong { background: var(--wrong); color: white; animation: shake 0.3s ease; }
.reveal-opt .indicator { font-size: 1.2rem; }
.score-popup {
  font-size: 2rem; font-weight: 800; color: var(--correct);
  text-shadow: 0 0 20px currentColor;
  animation: scoreFloat 1.8s ease forwards;
}
.score-popup.zero { color: var(--wrong); }
.streak-text { font-size: 0.95rem; font-weight: 600; }
.streak-text.streak-warm { color: #f39c12; }
.streak-text.streak-hot { color: #e74c3c; }
.streak-text.streak-fire { color: #e74c3c; text-shadow: 0 0 8px rgba(231,76,60,0.5); }
.fun-fact {
  background: rgba(22, 33, 62, 0.7); border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px; padding: 12px 16px;
  max-width: 450px; font-size: 0.95rem; color: var(--text); line-height: 1.4; margin-top: 10px;
}
.commentary {
  background: rgba(233, 69, 96, 0.1);
  border-radius: 10px; padding: 10px 14px;
  max-width: 450px; font-size: 0.95rem; font-style: italic; line-height: 1.3;
}

/* ── Leaderboard ── */
#leaderboard-screen { gap: 8px; }
.standings { width: 100%; max-width: 400px; }
.standing-item {
  display: flex; align-items: center; gap: 10px;
  background: rgba(22, 33, 62, 0.7); border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px; padding: 12px 14px; margin-bottom: 6px;
  animation: slideUp 0.3s ease backwards; transition: transform 0.3s, background 0.3s;
}
.standing-item.top1 { background: linear-gradient(135deg, #f39c12 0%, #d68910 100%); }
.standing-item.top2 { background: linear-gradient(135deg, #95a5a6 0%, #7f8c8d 100%); }
.standing-item.top3 { background: linear-gradient(135deg, #cd6133 0%, #a04000 100%); }
.standing-item.you { box-shadow: 0 0 12px rgba(233,69,96,0.5), 0 0 4px rgba(233,69,96,0.3); }
.standing-rank { font-weight: 800; font-size: 1.1rem; width: 28px; text-align: center; }
.standing-name { flex: 1; font-weight: 500; }
.standing-score { font-weight: 700; font-size: 1rem; }
.standing-correct { font-size: 0.75rem; color: rgba(255,255,255,0.6); }
.score-delta {
  font-size: 0.8rem; font-weight: 700; color: var(--correct); margin-left: 6px;
  animation: deltaFadeIn 0.3s ease;
}
.score-delta.fade-out { animation: deltaFadeOut 0.5s ease forwards; }

/* ── Podium ── */
#podium { gap: 16px; }
.podium-display {
  display: flex; align-items: flex-end; justify-content: center; gap: 12px; margin: 20px 0;
}
.podium-place {
  display: flex; flex-direction: column; align-items: center; animation: slideUp 0.5s ease backwards;
}
.podium-place:nth-child(1) { animation-delay: 0.3s; }
.podium-place:nth-child(2) { animation-delay: 0.1s; }
.podium-place:nth-child(3) { animation-delay: 0.5s; }
.podium-avatar {
  width: 52px; height: 52px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-weight: 700; font-size: 1.2rem;
  margin-bottom: 6px;
}
.podium-name { font-weight: 600; font-size: 0.9rem; max-width: 90px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.podium-score { font-size: 0.8rem; color: var(--text-dim); }
.podium-bar {
  width: 80px; border-radius: 8px 8px 0 0; margin-top: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; font-weight: 800; overflow: hidden;
  height: 0; animation: growUp 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
.p1 .podium-avatar {
  background: #f39c12; width: 64px; height: 64px; font-size: 1.4rem;
  box-shadow: 0 0 16px rgba(243,156,18,0.6), 0 0 6px rgba(243,156,18,0.4);
}
.p1 .podium-bar { background: #f39c12; --target-h: 120px; animation-delay: 0.8s; }
.p2 .podium-avatar { background: #95a5a6; }
.p2 .podium-bar { background: #95a5a6; --target-h: 90px; animation-delay: 0.5s; }
.p3 .podium-avatar { background: #cd6133; }
.p3 .podium-bar { background: #cd6133; --target-h: 65px; animation-delay: 0.2s; }
.your-rank { font-size: 1rem; color: var(--text-dim); margin: 8px 0; }
.summary-text {
  background: rgba(22, 33, 62, 0.7); border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px; padding: 16px;
  max-width: 400px; font-size: 0.95rem; line-height: 1.5; white-space: pre-line;
}
.cost-line {
  font-size: 0.75rem; margin-top: 14px; color: var(--text-dim); opacity: 0.7;
  text-align: center; max-width: 360px; line-height: 1.5; white-space: pre-line;
}
.donate-btn {
  background: #0070ba; text-decoration: none; text-align: center; margin-top: 16px;
  font-size: 0.95rem; padding: 12px 24px;
}
.donate-btn:active { background: #005ea6; }
.close-btn { background: var(--bg-card); margin-top: 8px; }

/* ── Confetti ── */
.confetti-container { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 100; }
.confetti-piece {
  position: absolute; width: 10px; height: 10px; top: -20px;
  animation: confettiDrop linear forwards;
}

/* ── Error ── */
#error-screen .error-msg { font-size: 1.1rem; text-align: center; max-width: 360px; color: var(--wrong); margin-bottom: 16px; }

/* ── Connection status ── */
.conn-status {
  position: fixed; top: 10px; right: 10px; font-size: 0.7rem;
  padding: 4px 10px; border-radius: 20px; background: var(--correct); color: white;
  transition: background 0.3s; z-index: 50; opacity: 0.7;
}
.conn-status.disconnected { background: var(--wrong); }

/* ── Mute toggle ── */
.mute-btn {
  position: fixed; top: 10px; left: 10px; z-index: 50; background: rgba(255,255,255,0.1);
  border: none; border-radius: 50%; width: 36px; height: 36px; font-size: 1.1rem;
  cursor: pointer; opacity: 0.6; color: var(--text); transition: opacity 0.2s;
}
.mute-btn:active { opacity: 1; }

/* ── Dot grid background ── */
@keyframes dotDrift1 { 0%,100% { transform: translate(0,0); } 50% { transform: translate(30px,-20px); } }
@keyframes dotDrift2 { 0%,100% { transform: translate(0,0); } 50% { transform: translate(-25px,30px); } }
@keyframes dotDrift3 { 0%,100% { transform: translate(0,0); } 50% { transform: translate(20px,25px); } }
.dot-grid { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.dot-grid .dot {
  position: absolute; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); opacity: 0.12;
}
.dot-grid .dot:nth-child(3n) { animation: dotDrift1 22s ease-in-out infinite; }
.dot-grid .dot:nth-child(3n+1) { animation: dotDrift2 26s ease-in-out infinite; }
.dot-grid .dot:nth-child(3n+2) { animation: dotDrift3 30s ease-in-out infinite; }

/* ── Answer button watermarks ── */
.option-btn::before {
  content: ''; position: absolute; opacity: 0.1; z-index: 0;
  left: 50%; top: 50%; transform: translate(-50%, -50%);
}
.option-btn:nth-child(1)::before {
  width: 0; height: 0; border-left: 20px solid transparent;
  border-right: 20px solid transparent; border-bottom: 36px solid white;
}
.option-btn:nth-child(2)::before {
  width: 28px; height: 28px; background: white; transform: translate(-50%,-50%) rotate(45deg);
}
.option-btn:nth-child(3)::before { width: 36px; height: 36px; border-radius: 50%; background: white; }
.option-btn:nth-child(4)::before { width: 32px; height: 32px; background: white; border-radius: 4px; }

/* ── Countdown overlay ── */
#question-screen { position: relative; }
.countdown-overlay {
  position: absolute; font-size: 5rem; font-weight: 800; color: var(--text);
  opacity: 0.08; z-index: 0; pointer-events: none; user-select: none;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
}
@keyframes cdPulse { 0%,100% { transform: translate(-50%,-50%) scale(1); } 50% { transform: translate(-50%,-50%) scale(1.1); } }
.countdown-overlay.pulse-red { color: var(--wrong); opacity: 0.15; animation: cdPulse 0.5s ease infinite; }
