/* ==================== BASE ==================== */
:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #14141f;
  --bg-tertiary: #1e1e2e;
  --bg-card: #1a1a2e;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --text-muted: #606070;
  --accent-primary: #00d4ff;
  --accent-secondary: #00ff88;
  --accent-warm: #ff9f43;
  --danger: #ff4466;
  --focus-ring: #00d4ff;
  --focus-glow: rgba(0, 212, 255, 0.4);
  --success: #00ff88;
  --warning: #ffaa00;
  --correct-bg: rgba(0, 255, 136, 0.18);
  --correct-border: #00ff88;
  --wrong-bg: rgba(255, 68, 102, 0.18);
  --wrong-border: #ff4466;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  width: 600px;
  height: 600px;
  overflow: hidden;
}

#app { width: 100%; height: 100%; position: relative; }

/* --- Screens --- */
.screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 0;
  left: 0;
}
.screen.hidden { display: none; }

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  background: var(--bg-secondary);
  gap: 12px;
  flex-shrink: 0;
}
.header h1 { font-size: 22px; font-weight: 600; flex: 1; }
.header-meta { font-size: 13px; color: var(--text-secondary); }

/* --- Content --- */
.content {
  flex: 1;
  padding: 14px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.content.center {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
}

/* --- Focus --- */
.focusable {
  transition: all 0.15s ease;
  border: 2px solid transparent;
  cursor: pointer;
  min-height: 44px;
}
.focusable:focus {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 20px var(--focus-glow);
}

/* --- Nav Bar --- */
.nav-bar {
  display: flex;
  gap: 8px;
  padding: 12px 18px;
  background: var(--bg-secondary);
  flex-shrink: 0;
}
.nav-item {
  flex: 1;
  padding: 14px 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.nav-item:focus { background: var(--bg-card); }
.nav-item.primary { background: var(--accent-primary); color: var(--bg-primary); }
.nav-item.primary:focus { background: #33ddff; }

/* --- Loading --- */
.loading-spinner {
  width: 56px;
  height: 56px;
  border: 4px solid var(--bg-tertiary);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 16px; color: var(--text-secondary); }

.error-icon { font-size: 48px; }
.error-message { font-size: 16px; color: var(--text-secondary); max-width: 440px; }

/* --- Utility --- */
.hidden { display: none !important; }

/* ==================== START SCREEN ==================== */
.selector-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.selector-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.selector-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  min-height: 40px;
  flex: 1 1 auto;
  min-width: 28%;
}
.chip:focus { background: var(--bg-card); }
.chip.selected {
  background: rgba(0, 212, 255, 0.18);
  color: var(--accent-primary);
  border-color: var(--accent-primary);
}
.chip.selected:focus { background: rgba(0, 212, 255, 0.28); }

/* ==================== QUIZ SCREEN ==================== */
.quiz-header {
  padding: 10px 16px;
  gap: 10px;
  justify-content: space-between;
}
.q-count {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}
.q-chip {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-primary);
  padding: 4px 10px;
  background: rgba(0, 212, 255, 0.15);
  border-radius: 20px;
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.q-score {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent-secondary);
  min-width: 28px;
  text-align: right;
}

.quiz-content {
  gap: 12px;
  padding: 12px 18px;
}

.timer-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}
.timer-bar-track {
  flex: 1;
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  overflow: hidden;
}
.timer-bar-fill {
  height: 100%;
  width: 100%;
  background: var(--accent-primary);
  border-radius: 4px;
  transition: width 0.25s linear, background-color 0.2s ease;
}
.timer-bar-fill.warn { background: var(--warning); }
.timer-num {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  min-width: 28px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.timer-num.warn { color: var(--warning); }

.question-text {
  font-size: 20px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--text-primary);
  padding: 4px 0;
}

.answers {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.answer-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 15px;
  text-align: left;
  min-height: 48px;
  width: 100%;
}
.answer-btn:focus { background: var(--bg-card); }
.answer-letter {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-primary);
}
.answer-text { flex: 1; line-height: 1.25; }

.answer-btn.correct {
  background: var(--correct-bg);
  border-color: var(--correct-border);
}
.answer-btn.correct .answer-letter {
  background: var(--correct-border);
  color: var(--bg-primary);
}
.answer-btn.wrong {
  background: var(--wrong-bg);
  border-color: var(--wrong-border);
}
.answer-btn.wrong .answer-letter {
  background: var(--wrong-border);
  color: var(--bg-primary);
}
.answer-btn[disabled] {
  cursor: default;
  opacity: 0.9;
}

.feedback-banner {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 16px 24px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 2px solid var(--accent-primary);
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  z-index: 50;
  pointer-events: none;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
}
.feedback-banner.correct { border-color: var(--correct-border); color: var(--correct-border); }
.feedback-banner.wrong { border-color: var(--wrong-border); color: var(--wrong-border); }
.feedback-banner.timeout { border-color: var(--warning); color: var(--warning); }

/* ==================== RESULTS SCREEN ==================== */
.score-block {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.score-big {
  font-size: 44px;
  font-weight: 700;
  color: var(--accent-primary);
  line-height: 1;
}
.score-sub {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}
.score-sub .best-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  background: rgba(0, 255, 136, 0.2);
  color: var(--accent-secondary);
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
}

.review-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.review-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.review-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  border-left: 4px solid var(--text-muted);
}
.review-item.correct { border-left-color: var(--correct-border); }
.review-item.wrong { border-left-color: var(--wrong-border); }
.review-q {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.3;
}
.review-a {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.3;
}
.review-a .you { color: var(--danger); }
.review-a .ans { color: var(--success); }
