:root {
  --bg: #f0f4f8;
  --card: #ffffff;
  --text: #1a202c;
  --primary: #6b46c1;
  --primary-hover: #553c9a;
  --secondary: #3182ce;
  --danger: #e53e3e;
  --success: #38a169;
  --border: #e2e8f0;
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
  --answer-a: #e53e3e;
  --answer-b: #3182ce;
  --answer-c: #d69e2e;
  --answer-d: #38a169;
}

[data-theme="dark"] {
  --bg: #1a202c;
  --card: #2d3748;
  --text: #f7fafc;
  --primary: #9f7aea;
  --primary-hover: #b794f4;
  --secondary: #63b3ed;
  --danger: #fc8181;
  --success: #68d391;
  --border: #4a5568;
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.4);
}

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

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

.theme-btn {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 1000;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.screen { display: none; min-height: 100vh; padding: 20px 12px; }
.screen.active { display: block; }

.container {
  max-width: 640px;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
  margin-top: 40px;
}

h1 { font-size: 2.2rem; text-align: center; margin-bottom: 8px; }
h2 { font-size: 1.5rem; margin-bottom: 16px; }
.subtitle { text-align: center; opacity: 0.7; margin-bottom: 32px; }
.hint { font-size: 0.85rem; opacity: 0.6; text-align: center; margin-top: 12px; }

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.btn {
  display: inline-block;
  padding: 12px 24px;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, background 0.2s;
  text-align: center;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--primary); color: white; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.secondary { background: var(--secondary); color: white; }
.btn.danger { background: var(--danger); color: white; }
.btn.text { background: transparent; color: var(--primary); }
.btn.small { padding: 8px 14px; font-size: 0.875rem; }
.btn.large { padding: 16px 32px; font-size: 1.15rem; width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-group { display: flex; flex-direction: column; gap: 12px; margin: 20px 0; }
@media (min-width: 480px) {
  .btn-group { flex-direction: row; justify-content: center; }
}

.input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 12px;
}
.input:focus { outline: none; border-color: var(--primary); }

.quiz-list { margin-top: 20px; }
.quiz-item {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.quiz-item h3 { flex: 1; min-width: 150px; }
.quiz-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.pin-box {
  text-align: center;
  background: var(--card);
  border-radius: 16px;
  padding: 24px;
  margin: 20px 0;
  box-shadow: var(--shadow);
}
.pin-box h1 { font-size: 3rem; letter-spacing: 8px; color: var(--primary); }

#qrcode { display: flex; justify-content: center; margin: 16px 0; }
#qrcode canvas, #qrcode img { max-width: 200px; border-radius: 8px; }

.player-list {
  list-style: none;
  background: var(--card);
  border-radius: 12px;
  padding: 12px;
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 20px;
}
.player-list li {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
}
.player-list li:last-child { border-bottom: none; }

.question-header {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  margin-bottom: 16px;
  font-size: 1.1rem;
}
#timerDisplay, #playerTimer {
  background: var(--primary);
  color: white;
  padding: 4px 14px;
  border-radius: 20px;
}

.answers-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 20px 0;
}
.answer-btn {
  padding: 20px 12px;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  color: white;
  cursor: pointer;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  transition: transform 0.15s, opacity 0.2s;
}
.answer-btn:active { transform: scale(0.96); }
.answer-btn.a { background: var(--answer-a); }
.answer-btn.b { background: var(--answer-b); }
.answer-btn.c { background: var(--answer-c); }
.answer-btn.d { background: var(--answer-d); }
.answer-btn.selected { outline: 4px solid white; box-shadow: 0 0 0 4px var(--primary); }
.answer-btn.correct { outline: 4px solid #68d391; }
.answer-btn.wrong { opacity: 0.5; }

.answers-grid.player .answer-btn { min-height: 70px; font-size: 0.95rem; }

.stats { background: var(--card); padding: 16px; border-radius: 12px; margin: 12px 0; }
.hidden { display: none !important; }

.leaderboard {
  background: var(--card);
  border-radius: 12px;
  padding: 12px;
  margin-top: 16px;
}
.leaderboard-item {
  display: flex;
  justify-content: space-between;
  padding: 8px;
  border-bottom: 1px solid var(--border);
}
.leaderboard-item:last-child { border-bottom: none; }

.podium {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 24px 0;
}
.podium-item {
  background: var(--card);
  border-radius: 12px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
}
.podium-item.rank-1 { border-left: 6px solid gold; }
.podium-item.rank-2 { border-left: 6px solid silver; }
.podium-item.rank-3 { border-left: 6px solid #cd7f32; }
.rank-badge {
  font-size: 1.5rem;
  font-weight: bold;
  min-width: 40px;
  text-align: center;
}

.question-editor {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.question-editor textarea, .question-editor input {
  width: 100%;
  margin-bottom: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
.option-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.option-row input[type="text"] { flex: 1; }
.option-row input[type="radio"] { width: 20px; height: 20px; }

.feedback {
  text-align: center;
  font-size: 1.2rem;
  font-weight: 600;
  margin-top: 16px;
  min-height: 1.5em;
}
.feedback.correct { color: var(--success); }
.feedback.wrong { color: var(--danger); }

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 20px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.settings-row {
  margin: 16px 0;
  text-align: center;
}
.settings-row select {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

@media (max-width: 480px) {
  h1 { font-size: 1.8rem; }
  .answers-grid { grid-template-columns: 1fr; }
  .pin-box h1 { font-size: 2.4rem; letter-spacing: 4px; }
}
