:root {
  --primary: #1a56db;
  --primary-dark: #1e429f;
  --accent: #f59e0b;
  --success: #059669;
  --danger: #dc2626;
  --bg: #f3f4f6;
  --card-bg: #ffffff;
  --text: #1f2937;
  --text-light: #6b7280;
  --border: #e5e7eb;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --radius: 12px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 2rem;
}

.hidden {
  display: none !important;
}

/* Setup / Join Cards */
.setup-card, .join-card {
  max-width: 500px;
  margin: auto;
  background: var(--card-bg);
  padding: 2.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}

.setup-card h1, .join-card h1 {
  font-size: 1.75rem;
  margin-bottom: 0.5rem;
  color: var(--primary);
}

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

.setup-form, .join-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1rem;
}

input {
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.2s;
}

input:focus {
  outline: none;
  border-color: var(--primary);
}

button {
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: white;
  padding: 0.75rem 1.5rem;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.help-text {
  color: var(--text-light);
  font-size: 0.875rem;
}

.error-message {
  color: var(--danger);
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

/* Game Header */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card-bg);
  padding: 1rem 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.room-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.room-label {
  font-size: 0.875rem;
  color: var(--text-light);
}

.room-code {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  font-family: monospace;
  letter-spacing: 0.05em;
}

.player-count {
  font-size: 0.875rem;
  color: var(--text-light);
}

.header-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.timer-display {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  font-family: monospace;
  transition: color 0.3s;
}

.timer-display.urgent {
  color: var(--danger);
  animation: pulse 1s infinite;
}

.answer-count {
  font-size: 0.875rem;
  color: var(--text-light);
  font-weight: 500;
}

.answer-count.all-answered {
  color: var(--success);
  font-weight: 700;
}

/* Game Main */
.game-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.question-panel {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
  flex: 1;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  margin-bottom: 1.5rem;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.3s;
  width: 0%;
}

.question-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  color: var(--text-light);
}

.question-title {
  font-weight: 600;
  color: var(--primary);
}

.question-text {
  font-size: 1.75rem;
  line-height: 1.4;
  margin-bottom: 2rem;
  font-weight: 600;
}

/* Choices */
.choices-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.choice-btn {
  padding: 1.25rem;
  font-size: 1.125rem;
  text-align: left;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 8px;
  cursor: default;
  transition: all 0.2s;
}

.choice-btn:hover {
  border-color: var(--primary);
}

.choice-btn.correct {
  background: #d1fae5;
  border-color: var(--success);
  color: var(--success);
}

.choice-btn.wrong {
  background: #fee2e2;
  border-color: var(--danger);
  color: var(--danger);
  opacity: 0.6;
}

.choice-btn.host-highlight {
  border-color: var(--accent);
  background: #fffbeb;
}

/* Stats Panel */
.stats-panel, .leaderboard-panel {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.stats-panel h3, .leaderboard-panel h3 {
  margin-bottom: 1.5rem;
  font-size: 1.25rem;
}

.stats-bars {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.stat-label {
  min-width: 120px;
  font-size: 0.875rem;
  font-weight: 500;
}

.stat-track {
  flex: 1;
  height: 32px;
  background: var(--bg);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.stat-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 6px;
  transition: width 0.5s;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 0.5rem;
  color: white;
  font-size: 0.875rem;
  font-weight: 600;
  min-width: 40px;
}

.stat-fill.correct-bar {
  background: var(--success);
}

.correct-answer {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--success);
  margin-bottom: 1rem;
  padding: 1rem;
  background: #d1fae5;
  border-radius: 8px;
  text-align: center;
}

.explanation-text {
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text-light);
}

/* Leaderboard */
.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.leaderboard-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border-radius: 8px;
  font-size: 1rem;
}

.leaderboard-item.top-3 {
  background: #eff6ff;
  border-left: 4px solid var(--primary);
}

.leaderboard-rank {
  font-weight: 700;
  color: var(--primary);
  min-width: 30px;
}

.leaderboard-name {
  flex: 1;
  font-weight: 500;
}

.leaderboard-score {
  font-weight: 700;
  color: var(--success);
}

/* Top Controls */
.top-controls {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.btn-top {
  padding: 0.5rem 1rem;
  background: var(--primary);
  color: white;
  font-size: 0.875rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-top:hover {
  background: var(--primary-dark);
}

.btn-top.hidden {
  display: none;
}

/* Game Controls */
.game-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card-bg);
  padding: 1rem 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-top: 1.5rem;
  gap: 1rem;
}

.control-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-control {
  padding: 0.625rem 1.25rem;
  background: var(--primary);
  color: white;
  font-size: 0.875rem;
}

.btn-control:hover {
  background: var(--primary-dark);
}

.btn-control.hidden {
  display: none;
}

.qr-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

#qr-code {
  width: 80px;
  height: 80px;
}

#qr-code img {
  width: 100%;
  height: 100%;
}

.join-url {
  font-size: 0.75rem;
  color: var(--text-light);
  font-family: monospace;
  word-break: break-all;
  max-width: 200px;
  text-align: center;
}

/* Player View */
.player-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card-bg);
  padding: 1rem 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

#player-nickname-display {
  font-weight: 600;
  color: var(--primary);
}

#player-score {
  font-weight: 700;
  color: var(--success);
}

.player-main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.state-panel {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 1rem;
}

.waiting-animation {
  font-size: 4rem;
  animation: pulse 1.5s infinite;
}

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

.state-panel h2 {
  font-size: 1.5rem;
  color: var(--text);
}

.state-panel p {
  color: var(--text-light);
  max-width: 400px;
}

#player-choices .choice-btn {
  cursor: pointer;
}

#player-choices .choice-btn:hover {
  background: #eff6ff;
  border-color: var(--primary);
}

#player-choices .choice-btn.selected {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

#player-choices .choice-btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--border);
}

.player-header .timer-display {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
  font-family: monospace;
}

.player-header .timer-display.urgent {
  color: var(--danger);
  animation: pulse 1s infinite;
}

.submitted-check {
  font-size: 4rem;
  color: var(--success);
}

#reveal-result {
  font-size: 2rem;
}

#reveal-result.correct-text {
  color: var(--success);
}

#reveal-result.wrong-text {
  color: var(--danger);
}

.score-update {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
}

.final-score {
  font-size: 3rem;
  font-weight: 700;
  color: var(--primary);
}

.final-rank {
  font-size: 1.25rem;
  color: var(--text-light);
}

/* Responsive */
@media (max-width: 768px) {
  .screen {
    padding: 1rem;
  }
  
  .question-text {
    font-size: 1.25rem;
  }
  
  .choices-container {
    grid-template-columns: 1fr;
  }
  
  .choice-btn {
    padding: 1rem;
    font-size: 1rem;
  }
  
  .game-controls {
    flex-direction: column;
    align-items: stretch;
  }
  
  .control-group {
    justify-content: center;
  }
  
  .qr-section {
    order: -1;
  }
  
  .setup-card, .join-card {
    padding: 1.5rem;
  }
  
  .game-header {
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
  }
  
  .stat-label {
    min-width: 80px;
    font-size: 0.75rem;
  }
}

@media (min-width: 1200px) {
  .question-text {
    font-size: 2.25rem;
  }
  
  .choice-btn {
    font-size: 1.25rem;
  }
}
