:root {
  --bg: #0f1024;
  --bg2: #1a1b3a;
  --card: #1e1f42;
  --primary: #7c5cff;
  --primary2: #ff5c9d;
  --text: #f4f3ff;
  --muted: #9b9bc4;
  --good: #34d399;
  --bad: #f87171;
  --gold: #ffc94a;
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at top, var(--bg2), var(--bg) 70%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  overflow-x: hidden;
}

#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 999;
}

.power-toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(-120%);
  z-index: 1000;
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  color: white;
  padding: 12px 20px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  max-width: 90vw;
  text-align: center;
  transition: transform 0.4s cubic-bezier(.34,1.56,.64,1);
  pointer-events: none;
}
.power-toast.show { transform: translateX(-50%) translateY(0); }

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  gap: 14px;
}

.screen { display: none; width: 100%; }
.screen.active { display: flex; justify-content: center; }

.live-leaderboard {
  width: 100%;
  max-width: 480px;
  background: var(--card);
  border-radius: 14px;
  padding: 10px 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
.live-leaderboard.hidden { display: none; }
.live-leaderboard-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 8px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.live-leaderboard-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.lb-chip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  background: #14152e;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
  transition: transform 0.3s ease;
  border: 1px solid transparent;
}
.lb-chip.rank-0 { border-color: var(--gold); background: linear-gradient(135deg, rgba(255,201,74,0.25), rgba(255,92,157,0.15)); }
.lb-chip .lb-score { color: var(--muted); font-weight: 600; }
.lb-chip.rank-0 .lb-score { color: var(--gold); }
.lb-chip.bump { animation: lb-bump 0.5s ease; }
.lb-chip.offline { opacity: 0.45; }
.lb-chip .lb-icons { font-size: 0.7rem; }
@keyframes lb-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 32px 24px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  text-align: center;
}

h1 { font-size: 1.9rem; margin: 0 0 4px; }
h2 { font-size: 1.3rem; margin: 0 0 16px; }
.subtitle { color: var(--muted); margin-bottom: 24px; font-size: 0.95rem; }
.hint { color: var(--muted); font-size: 0.85rem; margin-top: 16px; }
.error { color: var(--bad); min-height: 1.2em; font-size: 0.9rem; }

input {
  width: 100%;
  padding: 14px 16px;
  margin-bottom: 12px;
  border-radius: 12px;
  border: 1px solid #34345c;
  background: #14152e;
  color: var(--text);
  font-size: 1rem;
  outline: none;
}
input:focus { border-color: var(--primary); }

.btn {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 8px;
  transition: transform 0.1s ease, opacity 0.2s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary2)); color: white; }
.btn-secondary { background: #2b2c56; color: var(--text); }

.or { color: var(--muted); margin: 12px 0; font-size: 0.85rem; }

.room-code {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 4px;
  background: #14152e;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 8px;
}

.player-list {
  list-style: none;
  padding: 0;
  margin: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.player-list li {
  display: flex;
  justify-content: space-between;
  background: #14152e;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
}
.player-list li .badge-host { color: var(--primary2); font-size: 0.75rem; margin-left: 6px; }
.player-list li.disconnected { opacity: 0.4; }
.player-list li .score { color: var(--muted); font-weight: 500; }
.player-list li.correct { outline: 2px solid var(--good); }
.player-list li.wrong { outline: 2px solid var(--bad); }

.round-badge {
  display: inline-block;
  background: #14152e;
  color: var(--muted);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  margin-bottom: 12px;
}

.theme-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}
.theme-btn {
  padding: 18px 10px;
  border-radius: 14px;
  border: none;
  background: #14152e;
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}
.theme-btn:hover { background: #23244a; }
.theme-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.theme-btn.used { opacity: 0.3; text-decoration: line-through; }

.powers-section {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid #2c2d55;
}
.powers-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}
.powers-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.power-btn {
  padding: 12px 8px;
  border-radius: 12px;
  border: 2px solid transparent;
  background: #14152e;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.power-btn:active { transform: scale(0.96); }
.power-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.power-sabotage.armed { border-color: var(--bad); background: rgba(248,113,113,0.15); }
.power-shield.armed { border-color: var(--good); background: rgba(52,211,153,0.15); }
.power-count { color: var(--muted); font-weight: 600; font-size: 0.75rem; }
.power-hint { color: var(--muted); font-size: 0.72rem; margin-top: 10px; line-height: 1.4; }
.power-target-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.power-target-list.hidden { display: none; }
.power-target-btn {
  padding: 10px 12px;
  border-radius: 10px;
  border: none;
  background: #23244a;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}
.power-target-btn:hover { background: #2f306a; }

.q-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 0.85rem;
  color: var(--muted);
}
.theme-tag {
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  color: white;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.75rem;
}

.timer-bar {
  height: 8px;
  background: #14152e;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 20px;
}
#timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--good), var(--primary2));
  transition: width 0.1s linear;
}
#timer-fill.urgent {
  background: linear-gradient(90deg, var(--bad), #ff8a5c);
  animation: timer-pulse 0.5s infinite;
}
@keyframes timer-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}
.choice-btn {
  padding: 16px 10px;
  border-radius: 14px;
  border: none;
  background: #14152e;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 64px;
}
.choice-btn:hover { background: #23244a; }
.choice-btn.selected { outline: 3px solid var(--primary); }
.choice-btn.correct { background: var(--good); color: #06281a; animation: pop-correct 0.4s ease; }
.choice-btn.wrong { background: var(--bad); color: #2b0a0a; animation: shake 0.4s ease; }
.choice-btn:disabled { cursor: not-allowed; }

@keyframes pop-correct {
  0% { transform: scale(1); }
  50% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.reveal-answer {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--good);
  background: #14152e;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 16px;
  animation: pop-correct 0.5s ease;
}

.player-list li { position: relative; overflow: visible; }
.player-list li.malus { outline: 2px solid var(--bad); background: repeating-linear-gradient(135deg, #14152e, #14152e 6px, #241419 6px, #241419 12px); }
.player-list li .points-pop {
  position: absolute;
  right: 12px;
  top: -14px;
  font-weight: 800;
  font-size: 0.8rem;
  color: var(--good);
  animation: float-up 1.1s ease forwards;
  pointer-events: none;
}
.player-list li.wrong .points-pop { color: var(--bad); }
@keyframes float-up {
  0% { opacity: 0; transform: translateY(6px); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-18px); }
}
.streak-flame { font-size: 0.75rem; margin-left: 4px; }
.malus-tag {
  display: inline-block;
  margin-left: 6px;
  font-size: 0.65rem;
  background: var(--bad);
  color: #2b0a0a;
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 800;
}

#reveal-scores li { flex-direction: column; align-items: stretch; gap: 2px; }
.result-row { display: flex; justify-content: space-between; }
.result-caption { font-size: 0.72rem; color: var(--muted); font-style: italic; text-align: left; }

.final-list {
  list-style: none;
  padding: 0;
  margin: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}
.final-list li {
  display: flex;
  justify-content: space-between;
  background: #14152e;
  padding: 14px 16px;
  border-radius: 12px;
  font-weight: 700;
}
.final-list li:first-child {
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  box-shadow: 0 0 24px rgba(255,201,74,0.5);
  animation: winner-glow 1.8s ease-in-out infinite;
}
@keyframes winner-glow {
  0%, 100% { box-shadow: 0 0 18px rgba(255,201,74,0.35); }
  50% { box-shadow: 0 0 34px rgba(255,201,74,0.7); }
}
h1 { animation: title-bounce 0.6s ease; }
@keyframes title-bounce {
  0% { transform: translateY(-10px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

@media (max-width: 380px) {
  .card { padding: 24px 16px; }
  h1 { font-size: 1.5rem; }
}
