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

:root {
  --primary: #6C5CE7;
  --primary-light: #A29BFE;
  --correct: #00B894;
  --wrong: #E17055;
  --bg: #F8F9FA;
  --card: #FFFFFF;
  --text: #2D3436;
  --text-light: #636E72;
  --border: #DFE6E9;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

/* Screens */
.screen { display: none; padding: 16px; min-height: 100vh; }
.screen.active { display: block; }

/* Loading */
#screen-loading.active { display: flex; flex-direction: column; align-items: center; justify-content: center; }
.loading-spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Header */
.header { text-align: center; padding: 20px 0 12px; }
.header h1 { font-size: 28px; }
.header p { color: var(--text-light); margin-top: 4px; }

/* Tabs */
.tabs {
  display: flex; gap: 4px;
  background: var(--border);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 16px;
}
.tab {
  flex: 1;
  border: none;
  background: none;
  padding: 10px 8px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-light);
  transition: all 0.2s;
}
.tab.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Quiz List */
.quiz-card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s;
  position: relative;
  overflow: hidden;
}
.quiz-card:active { transform: scale(0.97); }
.quiz-card.completed { border-left: 4px solid var(--correct); }
.quiz-card.pending { border-left: 4px solid var(--primary); }
.quiz-card h3 { font-size: 16px; margin-bottom: 4px; }
.quiz-card .meta { font-size: 13px; color: var(--text-light); display: flex; gap: 12px; }
.quiz-card .badge {
  position: absolute; top: 12px; right: 12px;
  font-size: 11px; padding: 4px 8px;
  border-radius: 8px; font-weight: 600;
}
.badge-done { background: #DFE6DA; color: #00B894; }
.badge-new { background: #E8E4FF; color: var(--primary); }

/* Buttons */
.btn {
  border: none; border-radius: 12px;
  padding: 14px 24px; font-size: 16px; font-weight: 600;
  cursor: pointer; width: 100%;
  transition: all 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-large { padding: 18px; font-size: 18px; margin-top: 16px; }

/* Quiz Screen */
.quiz-header {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 0 16px;
}
.progress-bar {
  flex: 1; height: 8px;
  background: var(--border);
  border-radius: 4px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: var(--primary);
  border-radius: 4px;
  transition: width 0.3s ease;
}
#quiz-counter { font-size: 14px; font-weight: 600; color: var(--text-light); white-space: nowrap; }

.quiz-question {
  background: var(--card);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  min-height: 100px;
}
.quiz-question p { font-size: 18px; line-height: 1.5; }
.question-img { max-width: 100%; border-radius: 8px; margin-top: 12px; }

.quiz-options { display: flex; flex-direction: column; gap: 10px; }
.option-btn {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 16px 20px;
  font-size: 16px;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s;
  display: flex; align-items: center; gap: 12px;
}
.option-btn:active { transform: scale(0.98); }
.option-btn .option-letter {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; color: var(--primary);
  flex-shrink: 0;
}
.option-btn.selected { border-color: var(--primary); background: #F0EDFF; }
.option-btn.correct { border-color: var(--correct); background: #E6FAF3; }
.option-btn.correct .option-letter { background: var(--correct); color: white; }
.option-btn.wrong { border-color: var(--wrong); background: #FFF0ED; }
.option-btn.wrong .option-letter { background: var(--wrong); color: white; }

/* Feedback */
#screen-feedback { text-align: center; padding-top: 60px; }
.feedback-icon { font-size: 72px; margin-bottom: 16px; }
.feedback-correct { margin: 16px 0; padding: 12px; background: #E6FAF3; border-radius: 12px; font-size: 14px; color: var(--text-light); }
#feedback-explanation { color: var(--text-light); margin: 8px 16px; line-height: 1.5; }

/* Results */
.results-header { text-align: center; padding: 40px 0 20px; }
.results-icon { font-size: 64px; margin-bottom: 12px; }
#results-score { font-size: 20px; color: var(--text-light); margin-top: 4px; }
#results-breakdown {
  margin: 16px 0;
}
.result-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: var(--card);
  margin-bottom: 2px;
  font-size: 14px;
}
.result-row:first-child { border-radius: 12px 12px 0 0; }
.result-row:last-child { border-radius: 0 0 12px 12px; }
.result-row .num { color: var(--text-light); width: 24px; }
.result-row .status { margin-left: auto; font-size: 18px; }

/* Live Join */
.live-join { text-align: center; padding-top: 40px; }
.live-join h2 { margin-bottom: 8px; }
.live-join p { color: var(--text-light); margin-bottom: 20px; }
#join-code {
  width: 200px; text-align: center;
  font-size: 36px; font-weight: 700;
  letter-spacing: 8px;
  padding: 16px;
  border: 2px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  outline: none;
}
#join-code:focus { border-color: var(--primary); }

/* Live Timer */
.live-timer-bar { height: 6px; background: var(--border); margin-bottom: 16px; border-radius: 3px; overflow: hidden; }
.live-timer-fill { height: 100%; background: var(--primary); transition: width 1s linear; border-radius: 3px; }
.live-timer-fill.urgent { background: var(--wrong); }

/* Live Waiting */
.live-waiting { text-align: center; padding-top: 100px; }
.pulse-circle {
  width: 80px; height: 80px;
  background: var(--primary-light);
  border-radius: 50%;
  margin: 0 auto 24px;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.6; }
  50% { transform: scale(1.2); opacity: 1; }
}

/* Live Leaderboard */
.leaderboard-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: var(--card);
  margin-bottom: 2px;
  font-size: 16px;
}
.leaderboard-item:first-child { border-radius: 12px 12px 0 0; }
.leaderboard-item:last-child { border-radius: 0 0 12px 12px; }
.leaderboard-item .rank {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
  background: var(--bg);
}
.leaderboard-item:nth-child(1) .rank { background: #FFD700; color: #8B6914; }
.leaderboard-item:nth-child(2) .rank { background: #C0C0C0; color: #666; }
.leaderboard-item:nth-child(3) .rank { background: #CD7F32; color: #5C3A1E; }
.leaderboard-item .name { flex: 1; font-weight: 600; }
.leaderboard-item .score { font-weight: 700; color: var(--primary); }

/* Progress Tab */
.progress-card {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.progress-card h3 { font-size: 14px; margin-bottom: 8px; }
.progress-mini-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.progress-mini-fill { height: 100%; border-radius: 3px; }
.progress-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-light); margin-top: 6px; }

.empty-state { text-align: center; padding: 40px; color: var(--text-light); }
.empty-state .emoji { font-size: 48px; margin-bottom: 12px; }
