:root {
  /* Dark theme — #1C1E21 family. Never pure black (#000000 = transparent on additive waveguide). */
  --bg-primary: #1c1e21;
  --bg-secondary: #242629;
  --bg-tertiary: #2d2f33;
  --bg-card: #34373b;
  --text-primary: #ffffff;
  --text-secondary: #e4e6eb;
  --text-muted: #b0b3b8;
  --accent-primary: #00d4ff;
  --accent-secondary: #00ff88;
  --accent-warm: #ff9f43;
  --danger: #ff4466;
  --focus-ring: #00d4ff;
  --focus-glow: rgba(0, 212, 255, 0.4);
  --correct: #2ecc71;
  --correct-bg: rgba(46, 204, 113, 0.22);
  --wrong: #ff4d5e;
  --wrong-bg: rgba(255, 77, 94, 0.22);
  --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: 16px 20px;
  background: var(--bg-secondary);
  gap: 12px;
  flex-shrink: 0;
  min-height: 64px;
}
.header h1 {
  font-size: 26px;
  font-weight: 700;
  flex: 1;
}
.header-meta {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent-warm);
}
.back-btn {
  background: transparent;
  color: var(--text-primary);
  font-size: 24px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  flex-shrink: 0;
}

/* --- Content Area --- */
.content {
  flex: 1;
  padding: 16px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* --- Focus States (critical for D-pad) --- */
.focusable {
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, background 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);
}

/* ============ MENU ============ */
.menu-tagline {
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.menu-list,
#menu-list.list-container {
  gap: 10px;
}
.cat-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 600;
  text-align: left;
  width: 100%;
}
.cat-btn:focus {
  background: var(--bg-card);
  transform: scale(1.02);
}
.cat-btn.primary {
  background: var(--accent-primary);
  color: #0d0f11;
}
.cat-btn.primary:focus {
  background: #33ddff;
}
.cat-emoji {
  font-size: 26px;
  flex-shrink: 0;
  width: 32px;
  text-align: center;
}
.cat-label { flex: 1; }

/* ============ QUIZ HEADER ============ */
.quiz-counter {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-secondary);
}
.quiz-score {
  flex: 1;
  text-align: center;
  font-size: 20px;
  font-weight: 800;
  color: var(--accent-secondary);
}
.quiz-streak {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent-warm);
  flex-shrink: 0;
}

/* ============ QUIZ CONTENT ============ */
.quiz-content {
  padding: 14px 20px 18px;
  gap: 14px;
}
.question-area {
  flex-shrink: 0;
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}
.question-category {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-primary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}
.question-text {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text-primary);
}
.question-text.long { font-size: 17px; }
.question-text.xlong { font-size: 15px; }

/* --- Answers --- */
.answers-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}
.answer-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 17px;
  font-weight: 500;
  text-align: left;
  width: 100%;
  line-height: 1.3;
}
.answer-btn:focus {
  background: var(--bg-card);
  transform: scale(1.015);
}
.answer-key {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.answer-text { flex: 1; min-width: 0; }

.answer-btn.correct {
  background: var(--correct-bg);
  border-color: var(--correct);
  color: #ffffff;
}
.answer-btn.correct .answer-key {
  background: var(--correct);
  color: #0d0f11;
}
.answer-btn.wrong {
  background: var(--wrong-bg);
  border-color: var(--wrong);
  color: #ffffff;
}
.answer-btn.wrong .answer-key {
  background: var(--wrong);
  color: #ffffff;
}
.answers-list.locked .answer-btn { cursor: default; }

/* ============ LOADING ============ */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 40px;
  flex: 1;
}
.loading-spinner {
  width: 48px;
  height: 48px;
  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-muted);
}

/* ============ ERROR ============ */
.error-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px 40px;
  flex: 1;
  text-align: center;
}
.error-icon { font-size: 48px; }
.error-message {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  max-width: 420px;
}
.error-sub {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.error-btn { width: 260px; }

/* ============ NAV ITEM BUTTONS ============ */
.nav-item {
  padding: 14px 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 600;
  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: #0d0f11;
}
.nav-item.primary:focus { background: #33ddff; }

/* ============ RESULTS ============ */
.results-content {
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px 40px;
}
.results-score {
  font-size: 72px;
  font-weight: 800;
  color: var(--accent-secondary);
  line-height: 1;
}
.results-label {
  font-size: 16px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.results-correct {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-secondary);
}
.results-best {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent-warm);
  margin-bottom: 20px;
  min-height: 20px;
}
.results-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  margin-top: 8px;
}
.results-btn { width: 280px; }

/* --- List container --- */
.list-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}

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