* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #0f172a;
  --bg2: #1e293b;
  --bg3: #334155;
  --text: #f1f5f9;
  --text2: #94a3b8;
  --accent: #6366f1;
  --accent2: #818cf8;
  --green: #22c55e;
  --red: #ef4444;
  --orange: #f59e0b;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

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

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 12px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen.active { display: flex; }

/* Home */
.home-header { text-align: center; padding: 32px 0 16px; }
.home-header h1 { font-size: 28px; font-weight: 800; line-height: 1.2; }
.accent { color: var(--accent2); }
.subtitle { color: var(--text2); margin-top: 8px; font-size: 14px; }

.stats-bar {
  display: flex;
  gap: 8px;
  margin: 16px 0;
}
.stat {
  flex: 1;
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 12px 8px;
  text-align: center;
}
.stat-num { display: block; font-size: 22px; font-weight: 700; color: var(--accent2); }
.stat-label { font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; }

.home-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }

.home-footer {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-top: auto;
  padding: 16px 0;
}

/* Buttons */
.btn {
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-appearance: none;
}
.btn:active { transform: scale(0.97); }
.btn-lg { padding: 16px 24px; width: 100%; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:active { background: var(--accent2); }
.btn-secondary { background: var(--bg2); color: var(--text); border: 1px solid var(--bg3); }
.btn-text { background: none; border: none; color: var(--text2); font-size: 13px; cursor: pointer; padding: 8px; }

/* Screen Header */
.screen-header {
  display: flex;
  align-items: center;
  padding: 8px 0 16px;
  gap: 12px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.screen-header h2 { font-size: 20px; font-weight: 700; }
.back-btn {
  background: var(--bg2);
  border: none;
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.spacer { flex: 1; }

/* Topic List */
.topic-list { display: flex; flex-direction: column; gap: 8px; padding-bottom: 24px; }
.topic-card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background 0.15s;
}
.topic-card:active { background: var(--bg3); }
.topic-info { flex: 1; }
.topic-name { font-size: 15px; font-weight: 600; }
.topic-meta { font-size: 12px; color: var(--text2); margin-top: 2px; }
.topic-count {
  background: var(--bg3);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
}
.topic-progress {
  height: 3px;
  background: var(--bg3);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}
.topic-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
}

/* Quiz */
.quiz-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0 12px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.quiz-progress { flex: 1; }
.quiz-progress span { font-size: 13px; color: var(--text2); }
.progress-bar {
  height: 4px;
  background: var(--bg3);
  border-radius: 2px;
  margin-top: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
}
.flag-btn {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text2);
  padding: 4px;
  transition: color 0.15s;
}
.flag-btn.flagged { color: var(--orange); }

.quiz-body { flex: 1; overflow-y: auto; padding-bottom: 80px; }

.topic-badge {
  display: inline-block;
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.question-text {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.5;
  margin-bottom: 20px;
}

.options { display: flex; flex-direction: column; gap: 10px; }

.option-btn {
  background: var(--bg2);
  border: 2px solid var(--bg3);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
  font-size: 15px;
  line-height: 1.4;
  color: var(--text);
  transition: all 0.15s;
  display: flex;
  gap: 10px;
  -webkit-appearance: none;
}
.option-btn:active { background: var(--bg3); }

.option-letter {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  margin-top: 1px;
}
.option-text { flex: 1; }

.option-btn.correct {
  border-color: var(--green);
  background: rgba(34, 197, 94, 0.1);
}
.option-btn.correct .option-letter { background: var(--green); color: white; }

.option-btn.incorrect {
  border-color: var(--red);
  background: rgba(239, 68, 68, 0.1);
}
.option-btn.incorrect .option-letter { background: var(--red); color: white; }

.option-btn.revealed {
  border-color: var(--bg3);
  opacity: 0.6;
}
.option-btn.revealed.correct {
  border-color: var(--green);
  opacity: 1;
}

.option-btn.disabled { pointer-events: none; }

/* Streak */
.streak-display {
  font-size: 12px;
  font-weight: 700;
  color: var(--orange);
  margin-left: 8px;
}

/* Result Banner */
.result-banner {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 16px;
}
.result-correct { background: rgba(34, 197, 94, 0.15); color: var(--green); }
.result-incorrect { background: rgba(239, 68, 68, 0.15); color: var(--red); }

/* Knowledge Page */
.explanation { margin-top: 20px; }

.knowledge-page {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 20px 16px;
  margin-bottom: 16px;
  border-left: 3px solid var(--accent);
}
.kp-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent2);
  margin-bottom: 14px;
  line-height: 1.3;
}
.kp-body {
  font-size: 14px;
  line-height: 1.75;
  color: var(--text);
}
.kp-body p { margin-bottom: 10px; }
.kp-body p:last-child { margin-bottom: 0; }
.kp-body strong { color: var(--accent2); }
.kp-body em { color: var(--text2); font-style: italic; }

.kp-remember {
  margin-top: 14px;
  padding: 12px 14px;
  background: rgba(99, 102, 241, 0.1);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.6;
}
.kp-remember strong { color: var(--accent2); display: block; margin-bottom: 6px; }
.kp-remember ul { margin: 0; padding-left: 18px; }
.kp-remember li { margin-bottom: 4px; color: var(--text); }
.kp-remember li:last-child { margin-bottom: 0; }

.kp-comparison { margin-top: 14px; font-size: 13px; }
.kp-comparison strong { color: var(--text); display: block; margin-bottom: 8px; }
.kp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.kp-table th {
  background: var(--bg3);
  padding: 6px 8px;
  text-align: left;
  font-weight: 600;
  color: var(--accent2);
}
.kp-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--bg3);
  color: var(--text);
}

/* Option Explanations */
.option-explanations { margin-top: 12px; }
.exp-option {
  margin: 8px 0;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
}
.exp-option.exp-correct { background: rgba(34, 197, 94, 0.1); border-left: 3px solid var(--green); }
.exp-option.exp-wrong { background: rgba(239, 68, 68, 0.05); border-left: 3px solid var(--bg3); }
.exp-option strong { display: block; margin-bottom: 4px; font-size: 13px; }
.exp-option p { margin: 0; }

.hidden { display: none !important; }

/* Quiz Footer */
.quiz-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px calc(var(--safe-bottom) + 12px);
  background: linear-gradient(transparent, var(--bg) 30%);
}

/* Stats */
.stats-body { padding-bottom: 24px; }
.stats-section { margin-bottom: 24px; }
.stats-section h3 {
  font-size: 14px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}
.stats-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--bg2);
}
.stats-row:last-child { border-bottom: none; }
.stats-row-label { font-size: 14px; }
.stats-row-value { font-size: 14px; font-weight: 600; color: var(--accent2); }

.stats-topic-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
}
.stats-topic-name { flex: 1; font-size: 13px; }
.stats-topic-pct { font-size: 13px; font-weight: 600; min-width: 40px; text-align: right; }
.stats-mini-bar {
  width: 60px;
  height: 6px;
  background: var(--bg3);
  border-radius: 3px;
  overflow: hidden;
}
.stats-mini-fill { height: 100%; border-radius: 3px; }

/* Results */
.results-body { text-align: center; padding: 32px 0; }
.results-score { margin-bottom: 32px; }
.results-pct { display: block; font-size: 64px; font-weight: 800; color: var(--accent2); }
.results-label { font-size: 14px; color: var(--text2); text-transform: uppercase; letter-spacing: 1px; }
.results-breakdown { text-align: left; margin-bottom: 32px; }

/* Module accent button */
.btn-accent { background: linear-gradient(135deg, var(--accent), #8b5cf6); color: white; }
.btn-accent:active { background: linear-gradient(135deg, var(--accent2), #a78bfa); }

.module-intro {
  color: var(--text2);
  font-size: 13px;
  padding: 0 0 12px;
  line-height: 1.5;
}

.module-body {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 80px;
  font-size: 15px;
  line-height: 1.8;
  color: var(--text);
}
.module-body h2 { font-size: 20px; font-weight: 700; color: var(--accent2); margin: 24px 0 12px; }
.module-body h3 { font-size: 16px; font-weight: 700; color: var(--text); margin: 20px 0 8px; }
.module-body p { margin-bottom: 14px; }
.module-body ul, .module-body ol { margin: 0 0 14px 20px; }
.module-body li { margin-bottom: 6px; }
.module-body strong { color: var(--accent2); }
.module-body em { color: var(--text2); }
.module-body blockquote {
  border-left: 3px solid var(--accent);
  margin: 16px 0;
  padding: 12px 16px;
  background: var(--bg2);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-style: italic;
  color: var(--text2);
}
.module-body .analogy {
  background: rgba(99, 102, 241, 0.08);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 16px 0;
  border-left: 3px solid var(--accent);
}
.module-body .analogy strong { color: var(--accent2); }
.module-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.module-badge-beginner { background: rgba(34,197,94,0.15); color: var(--green); }
.module-badge-intermediate { background: rgba(245,158,11,0.15); color: var(--orange); }
.module-badge-advanced { background: rgba(239,68,68,0.15); color: var(--red); }

.module-card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: background 0.15s;
}
.module-card:active { background: var(--bg3); }
.module-card-title { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.module-card-desc { font-size: 13px; color: var(--text2); line-height: 1.4; margin-bottom: 6px; }
.module-card-meta { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--text2); }

/* Learn/Read */
.learn-topic-header {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 16px 0 6px;
}
.read-body {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 80px;
}
.read-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px calc(var(--safe-bottom) + 12px);
  background: linear-gradient(transparent, var(--bg) 30%);
}

/* Animations */
@keyframes slideIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.screen.active { animation: slideIn 0.2s ease-out; }
