/* === CSS Custom Properties === */
:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #16213e;
  --bg-card-hover: #1a2745;
  --bg-input: #0f0f1a;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0b8;
  --text-muted: #6a6a80;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --accent-dim: rgba(233, 69, 96, 0.15);
  --success: #2ecc71;
  --success-dim: rgba(46, 204, 113, 0.15);
  --warning: #f1c40f;
  --warning-dim: rgba(241, 196, 15, 0.15);
  --danger: #e74c3c;
  --danger-dim: rgba(231, 76, 60, 0.15);
  --info: #3498db;
  --info-dim: rgba(52, 152, 219, 0.15);
  --border: #2a2a4a;
  --border-light: #3a3a5a;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.4);
  --nav-height: 60px;
  --max-width: 900px;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* === Navigation === */
#main-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  z-index: 100;
  padding: 4px 0 env(safe-area-inset-bottom, 4px);
}

.nav-brand { display: none; }

.nav-links {
  display: flex;
  justify-content: space-around;
  max-width: 600px;
  margin: 0 auto;
}

.nav-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.7rem;
  transition: color 0.2s;
  gap: 2px;
  min-width: 48px;
}

.nav-link-icon { font-size: 1.3rem; }
.nav-link:hover, .nav-link.active { color: var(--accent); }

/* Desktop nav */
@media (min-width: 768px) {
  #main-nav {
    position: fixed;
    top: 0;
    bottom: auto;
    border-top: none;
    border-bottom: 1px solid var(--border);
    padding: 0 1rem;
    display: flex;
    align-items: center;
    height: var(--nav-height);
  }
  .nav-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: 2rem;
  }
  .nav-icon { font-size: 1.5rem; }
  .nav-title { font-size: 1.2rem; font-weight: 700; color: var(--accent); }
  .nav-links { justify-content: flex-start; gap: 4px; max-width: none; }
  .nav-link {
    flex-direction: row;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius);
    font-size: 0.85rem;
  }
  .nav-link-icon { font-size: 1rem; }
  .nav-link:hover { background: var(--bg-card); }
  .nav-link.active { background: var(--accent-dim); color: var(--accent); }
}

/* === Main Content === */
main {
  padding: 1rem;
  padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px));
  max-width: var(--max-width);
  margin: 0 auto;
  min-height: 100vh;
}

@media (min-width: 768px) {
  main {
    padding-top: calc(var(--nav-height) + 1.5rem);
    padding-bottom: 2rem;
  }
}

/* === Typography === */
h1 { font-size: 1.6rem; font-weight: 700; margin-bottom: 0.5rem; }
h2 { font-size: 1.3rem; font-weight: 600; margin-bottom: 0.5rem; color: var(--text-primary); }
h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.4rem; }
p { margin-bottom: 0.8rem; color: var(--text-secondary); }

/* === Cards === */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.2rem;
  margin-bottom: 1rem;
  transition: border-color 0.2s;
}
.card:hover { border-color: var(--border-light); }
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.8rem;
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  color: #fff;
}
.btn-primary { background: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-card); border: 1px solid var(--border); color: var(--text-primary); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-success { background: var(--success); }
.btn-danger { background: var(--danger); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* === Tags/Badges === */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-v { background: var(--info-dim); color: var(--info); }
.badge-b { background: var(--success-dim); color: var(--success); }
.badge-n { background: var(--warning-dim); color: var(--warning); }
.badge-e { background: var(--accent-dim); color: var(--accent); }
.badge-a { background: rgba(155, 89, 182, 0.15); color: #9b59b6; }
.badge-success { background: var(--success-dim); color: var(--success); }
.badge-danger { background: var(--danger-dim); color: var(--danger); }

/* === Progress Bar === */
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-primary);
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
  background: var(--accent);
}
.progress-bar-fill.success { background: var(--success); }
.progress-bar-fill.warning { background: var(--warning); }
.progress-bar-fill.danger { background: var(--danger); }

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* === Topic List === */
.topic-list { list-style: none; }
.topic-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
.topic-item:hover { border-color: var(--accent); background: var(--bg-card); }
.topic-item.completed { border-color: var(--success); }
.topic-item.locked { opacity: 0.5; cursor: not-allowed; }

.topic-status {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
}
.topic-status.available { background: var(--accent-dim); color: var(--accent); }
.topic-status.in_progress { background: var(--warning-dim); color: var(--warning); }
.topic-status.completed { background: var(--success-dim); color: var(--success); }
.topic-status.locked { background: var(--bg-primary); color: var(--text-muted); }

.topic-info { flex: 1; min-width: 0; }
.topic-title { font-weight: 600; font-size: 0.9rem; }
.topic-subtitle { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topic-meta { font-size: 0.75rem; color: var(--text-muted); flex-shrink: 0; text-align: right; }

/* === Lesson View === */
.lesson-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.lesson-goals {
  list-style: none;
  margin: 0.5rem 0;
}
.lesson-goals li {
  padding: 4px 0;
  padding-left: 1.2rem;
  position: relative;
  color: var(--text-secondary);
  font-size: 0.9rem;
}
.lesson-goals li::before {
  content: "\2713";
  position: absolute;
  left: 0;
  color: var(--success);
}

.lesson-section {
  margin-bottom: 1.5rem;
}
.lesson-section h3 {
  color: var(--accent);
  margin-bottom: 0.6rem;
}
.lesson-content {
  color: var(--text-secondary);
  line-height: 1.8;
  font-size: 0.95rem;
}

.key-points {
  background: var(--info-dim);
  border-left: 3px solid var(--info);
  padding: 0.8rem 1rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 0.8rem 0;
}
.key-points h4 { color: var(--info); font-size: 0.85rem; margin-bottom: 0.4rem; }
.key-points ul { list-style: disc; padding-left: 1.2rem; }
.key-points li { color: var(--text-secondary); font-size: 0.9rem; padding: 2px 0; }

.formula-box {
  background: var(--warning-dim);
  border-left: 3px solid var(--warning);
  padding: 0.8rem 1rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 0.8rem 0;
  font-family: var(--font-mono);
  font-size: 1rem;
}

.mnemonic-box {
  background: rgba(155, 89, 182, 0.12);
  border-left: 3px solid #9b59b6;
  padding: 0.8rem 1rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 0.8rem 0;
}
.mnemonic-box h4 { color: #9b59b6; font-size: 0.85rem; margin-bottom: 0.3rem; }

/* === Question Component === */
.question-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1rem;
}
.question-number {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.question-text {
  font-size: 1.05rem;
  font-weight: 500;
  margin-bottom: 1rem;
  line-height: 1.5;
}
.answer-list { list-style: none; }
.answer-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
}
.answer-item:hover { border-color: var(--accent); background: var(--accent-dim); }
.answer-item.selected { border-color: var(--accent); background: var(--accent-dim); }
.answer-item.correct { border-color: var(--success); background: var(--success-dim); }
.answer-item.wrong { border-color: var(--danger); background: var(--danger-dim); }
.answer-item.disabled { pointer-events: none; }
.answer-key {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}
.answer-text { font-size: 0.9rem; line-height: 1.4; }

.explanation-box {
  background: var(--success-dim);
  border: 1px solid var(--success);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  margin-top: 0.8rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* === Exam === */
.exam-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
}
@media (min-width: 768px) {
  .exam-header { top: var(--nav-height); }
}

.exam-timer {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
}
.exam-timer.warning { color: var(--warning); }
.exam-timer.danger { color: var(--danger); animation: pulse 1s infinite; }

.exam-progress-text {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* === Exam Result === */
.result-score {
  text-align: center;
  padding: 2rem;
}
.result-score .score-big {
  font-size: 4rem;
  font-weight: 700;
  line-height: 1;
}
.result-score .score-big.passed { color: var(--success); }
.result-score .score-big.failed { color: var(--danger); }
.result-label {
  font-size: 1.2rem;
  margin-top: 0.5rem;
}

/* === Flashcard === */
.flashcard {
  perspective: 1000px;
  width: 100%;
  max-width: 400px;
  height: 250px;
  margin: 1rem auto;
  cursor: pointer;
}
.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s;
  transform-style: preserve-3d;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-front, .flashcard-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  border-radius: var(--radius-lg);
  text-align: center;
  font-size: 1.1rem;
  line-height: 1.5;
}
.flashcard-front {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
}
.flashcard-back {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--text-primary);
  transform: rotateY(180deg);
}
.flashcard-controls {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 1rem;
}

/* === Search === */
.search-box {
  position: relative;
  margin-bottom: 1rem;
}
.search-box input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}
.search-box input:focus { border-color: var(--accent); }
.search-box input::placeholder { color: var(--text-muted); }
.search-box::before {
  content: "\1F50D";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
}

/* === Stats === */
.stat-number {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}
.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}

/* === Trend Chart (CSS only) === */
.trend-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 100px;
  padding: 0.5rem 0;
}
.trend-bar {
  flex: 1;
  min-width: 20px;
  border-radius: 3px 3px 0 0;
  transition: height 0.3s;
  position: relative;
}
.trend-bar.passed { background: var(--success); }
.trend-bar.failed { background: var(--danger); }
.trend-bar-label {
  position: absolute;
  bottom: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* === Exam Selection === */
.exam-type-card {
  padding: 1.5rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.exam-type-card:hover { border-color: var(--accent); }
.exam-type-card.selected { border-color: var(--accent); background: var(--accent-dim); }
.exam-type-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 0.3rem; }
.exam-type-desc { font-size: 0.85rem; color: var(--text-secondary); }

/* === Part Tabs === */
.part-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.part-tab {
  padding: 8px 16px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  transition: all 0.2s;
}
.part-tab:hover { border-color: var(--accent); }
.part-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.part-tab.dimmed { opacity: 0.4; border-style: dashed; }
.part-tab.dimmed:hover { opacity: 0.7; }

/* === Target Class Selector === */
.target-class-selector {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* === Control Questions === */
.control-question {
  padding: 0.8rem 1rem;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
  cursor: pointer;
  border: 1px solid transparent;
  transition: border-color 0.2s;
}
.control-question:hover { border-color: var(--border-light); }
.control-answer {
  display: none;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border);
  color: var(--success);
  font-size: 0.88rem;
  line-height: 1.6;
}
.control-question.revealed {
  border-color: var(--success);
  background: var(--success-dim);
}
.control-question.revealed .control-answer {
  display: block;
}

/* === Loading === */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: var(--text-muted);
}

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state-text { font-size: 1rem; }

/* === Utility === */
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.hidden { display: none !important; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }
