/* === Base Reset & Variables === */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #1a1a2e;
  --accent: #e63946;
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface-light: #252542;
  --text: #f1faee;
  --text-dim: #a8a8c0;
  --opt-g: #e63946;
  --opt-r: #457b9d;
  --opt-i: #e9c46a;
  --opt-p: #2a9d8f;
  --radius: 12px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
  font-size: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

/* === Screens === */
.screen {
  display: none;
  width: 100%;
  max-width: 480px;
  padding: 1.5rem;
  flex-direction: column;
  align-items: center;
  animation: fadeIn 0.4s ease;
}

.screen.active {
  display: flex;
}

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

/* === Join Screen === */
.logo {
  font-size: 3rem;
  font-weight: 900;
  margin-top: 3rem;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, var(--accent), #ff6b6b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-dim);
  font-size: 1rem;
  margin-bottom: 2.5rem;
}

.input-group {
  width: 100%;
  position: relative;
  margin-bottom: 1.5rem;
}

.input-group input {
  width: 100%;
  padding: 1rem 1.25rem;
  font-size: 1.15rem;
  border: 2px solid var(--surface-light);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition);
}

.input-group input:focus {
  border-color: var(--accent);
}

.input-group input::placeholder {
  color: var(--text-dim);
}

.btn {
  width: 100%;
  padding: 1rem;
  font-size: 1.2rem;
  font-weight: 700;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  text-transform: none;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: #ff4757;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(230, 57, 70, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* === Lobby === */
.lobby-count {
  font-size: 4rem;
  font-weight: 900;
  color: var(--accent);
  margin-top: 2rem;
}

.lobby-label {
  font-size: 1.1rem;
  color: var(--text-dim);
  margin-bottom: 2rem;
}

.lobby-waiting {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-dim);
  font-size: 1rem;
}

.lobby-waiting .dot-pulse {
  display: inline-flex;
  gap: 4px;
}

.dot-pulse span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}

.dot-pulse span:nth-child(2) {
  animation-delay: 0.2s;
}

.dot-pulse span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes pulse {
  0%,
  80%,
  100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  40% {
    opacity: 1;
    transform: scale(1.1);
  }
}

/* === Question === */
.question-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  margin-top: 1rem;
}

.q-counter {
  font-size: 0.9rem;
  color: var(--text-dim);
  font-weight: 600;
}

.timer {
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--accent);
  min-width: 3rem;
  text-align: right;
}

.timer.warning {
  animation: timerPulse 0.5s ease infinite;
}

@keyframes timerPulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.15);
  }
}

.timer-bar {
  width: 100%;
  height: 6px;
  background: var(--surface-light);
  border-radius: 3px;
  margin-bottom: 1.5rem;
  overflow: hidden;
}

.timer-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 1s linear;
}

.question-text {
  width: 100%;
  font-size: 1.15rem;
  line-height: 1.6;
  margin-bottom: 1.5rem;
  text-align: left;
}

.options {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.option-btn {
  width: 100%;
  padding: 1rem 1.25rem;
  font-size: 1.05rem;
  font-weight: 600;
  border: 3px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: white;
}

.option-btn .option-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.2);
  font-weight: 900;
  font-size: 1rem;
  flex-shrink: 0;
}

.option-btn.opt-G {
  background: var(--opt-g);
}
.option-btn.opt-R {
  background: var(--opt-r);
}
.option-btn.opt-I {
  background: var(--opt-i);
  color: #1a1a2e;
}
.option-btn.opt-I .option-label {
  background: rgba(0, 0, 0, 0.15);
}
.option-btn.opt-P {
  background: var(--opt-p);
}

.option-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.option-btn:active {
  transform: translateY(0);
}

.option-btn.selected {
  border-color: white;
  box-shadow: 0 0 0 2px white, 0 4px 15px rgba(0, 0, 0, 0.3);
}

.option-btn.disabled {
  pointer-events: none;
  opacity: 0.6;
}

/* === Quote styling === */
.quote-label {
  width: 100%;
  font-size: 0.85rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.quote-text {
  width: 100%;
  font-size: 1.2rem;
  line-height: 1.6;
  margin-bottom: 1.25rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-style: italic;
}

.category-hint {
  width: 100%;
  font-size: 0.95rem;
  color: var(--text-dim);
  margin-bottom: 0.75rem;
  text-align: center;
}

.result-next-hint {
  margin-top: 1.5rem;
  font-size: 0.95rem;
  color: var(--text-dim);
  text-align: center;
}

/* === Result === */
.result-icon {
  font-size: 4rem;
  margin-top: 2rem;
  margin-bottom: 0.5rem;
}

.result-correct {
  color: #2ecc71;
}

.result-wrong {
  color: var(--accent);
}

.result-score {
  font-size: 2rem;
  font-weight: 900;
  margin-bottom: 0.5rem;
}

.result-total {
  color: var(--text-dim);
  margin-bottom: 1.5rem;
}

.explanation {
  width: 100%;
  background: var(--surface);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
  line-height: 1.5;
}

.result-waiting {
  color: var(--text-dim);
  font-size: 0.95rem;
}

/* === Leaderboard (Player) === */
.leaderboard-title {
  font-size: 1.8rem;
  font-weight: 900;
  margin-top: 2rem;
  margin-bottom: 1.5rem;
}

.podium {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.podium-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border-radius: var(--radius);
  animation: slideIn 0.4s ease backwards;
}

.podium-item:nth-child(1) {
  background: linear-gradient(135deg, #ffd700 0%, #b8860b 100%);
  color: #1a1a2e;
}

.podium-item:nth-child(2) {
  background: linear-gradient(135deg, #c0c0c0 0%, #808080 100%);
  color: #1a1a2e;
}

.podium-item:nth-child(3) {
  background: linear-gradient(135deg, #cd7f32 0%, #8b4513 100%);
}

.podium-item:nth-child(n) {
  animation-delay: calc(var(--i, 0) * 0.1s);
}

.podium-rank {
  font-size: 1.3rem;
  font-weight: 900;
  min-width: 2rem;
  text-align: center;
}

.podium-name {
  flex: 1;
  font-weight: 600;
  font-size: 1rem;
}

.podium-score {
  font-weight: 900;
  font-size: 1.1rem;
}

.my-rank {
  margin-top: 1.5rem;
  padding: 1rem;
  background: var(--surface-light);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  text-align: center;
  width: 100%;
}

.my-rank-label {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.my-rank-value {
  font-size: 2rem;
  font-weight: 900;
  color: var(--accent);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* === Host Styles === */
.host-body {
  max-width: 100%;
  padding: 2rem 3rem;
}

.host-body .screen {
  max-width: 100%;
}

.host-title {
  font-size: 2.5rem;
  font-weight: 900;
  margin-bottom: 0.5rem;
}

.host-subtitle {
  color: var(--text-dim);
  font-size: 1.2rem;
  margin-bottom: 2rem;
}

.host-player-count {
  font-size: 6rem;
  font-weight: 900;
  color: var(--accent);
  line-height: 1;
}

.host-player-label {
  font-size: 1.5rem;
  color: var(--text-dim);
  margin-bottom: 2rem;
}

.host-player-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-bottom: 2rem;
  max-height: 200px;
  overflow-y: auto;
}

.host-player-chip {
  padding: 0.4rem 1rem;
  background: var(--surface-light);
  border-radius: 20px;
  font-size: 0.9rem;
}

.host-btn {
  padding: 1.2rem 3rem;
  font-size: 1.5rem;
  font-weight: 700;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--accent);
  color: white;
  transition: all var(--transition);
}

.host-btn:hover {
  background: #ff4757;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(230, 57, 70, 0.4);
}

/* Host live leaderboard */
.host-live-header {
  text-align: center;
  margin-bottom: 2rem;
}

.host-live-title {
  font-size: 2.5rem;
  font-weight: 900;
  margin-bottom: 0.5rem;
}

.host-live-stats {
  font-size: 1.3rem;
  color: var(--text-dim);
}

.podium-progress {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.7);
  min-width: 3rem;
  text-align: center;
}

/* Host leaderboard */
.host-podium {
  width: 100%;
  max-width: 700px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.host-podium .podium-item {
  padding: 1.2rem 1.5rem;
  font-size: 1.2rem;
}

.host-podium .podium-rank {
  font-size: 1.8rem;
}

.host-podium .podium-score {
  font-size: 1.4rem;
}

.host-actions {
  margin-top: 2rem;
  display: flex;
  gap: 1rem;
}

.host-btn-secondary {
  padding: 0.8rem 2rem;
  font-size: 1.1rem;
  font-weight: 600;
  border: 2px solid var(--surface-light);
  border-radius: var(--radius);
  cursor: pointer;
  background: transparent;
  color: var(--text-dim);
  transition: all var(--transition);
}

.host-btn-secondary:hover {
  border-color: var(--text);
  color: var(--text);
}

/* Host timer bar */
.host-timer-bar {
  width: 100%;
  max-width: 900px;
  height: 10px;
  background: var(--surface-light);
  border-radius: 5px;
  margin-bottom: 2rem;
  overflow: hidden;
}

.host-timer-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 5px;
  transition: width 1s linear;
}

/* === Final screen confetti placeholder === */
.final-trophy {
  font-size: 5rem;
  margin-top: 2rem;
  margin-bottom: 1rem;
  animation: bounce 1s ease infinite;
}

@keyframes bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

/* === Responsive === */
@media (max-width: 400px) {
  .screen {
    padding: 1rem;
  }
  .logo {
    font-size: 2.2rem;
  }
  .question-text {
    font-size: 1rem;
  }
  .option-btn {
    padding: 0.85rem 1rem;
    font-size: 0.95rem;
  }
}
