/* ===== DESIGN TOKENS ===== */
:root {
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.8125rem);
  --text-sm: clamp(0.8125rem, 0.78rem + 0.2vw, 0.875rem);
  --text-base: clamp(0.9375rem, 0.9rem + 0.2vw, 1rem);
  --text-lg: clamp(1.125rem, 1rem + 0.5vw, 1.375rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1vw, 2rem);
  --text-2xl: clamp(2rem, 1.4rem + 2vw, 3rem);
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;
  --transition-fast: 150ms cubic-bezier(0.16, 1, 0.3, 1);
  --transition-med: 250ms cubic-bezier(0.16, 1, 0.3, 1);
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  --sidebar-w: 280px;
  --topbar-h: 56px;
}

/* ===== DARK THEME (default) ===== */
[data-theme="dark"] {
  --bg: #0f1017;
  --bg-raised: #161822;
  --surface: #1c1e2c;
  --surface-2: #252838;
  --surface-3: #2f3345;
  --border: #3a3e52;
  --border-subtle: #2a2e40;
  --text: #eaeaf2;
  --text-muted: #a8a8be;
  --text-faint: #6e6e88;
  --accent-orange: #f97316;
  --accent-purple: #a855f7;
  --accent-gradient: linear-gradient(135deg, #f97316, #e8525a, #a855f7);
  --accent-gradient-h: linear-gradient(90deg, #f97316, #e8525a, #a855f7);
  --xp-bar: linear-gradient(90deg, #f97316, #a855f7);
  --code-bg: #111118;
  --code-border: #2a2a3a;
  --success: #34d399;
  --error: #f87171;
  --warning: #fbbf24;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.6);
  --quiz-correct: #065f46;
  --quiz-wrong: #7f1d1d;
  --glow-orange: 0 0 20px rgba(249,115,22,0.3);
  --glow-purple: 0 0 20px rgba(168,85,247,0.3);
}

/* ===== LIGHT THEME ===== */
[data-theme="light"] {
  --bg: #f5f5f7;
  --bg-raised: #ffffff;
  --surface: #ffffff;
  --surface-2: #f0f0f4;
  --surface-3: #e8e8ee;
  --border: #d8d8e2;
  --border-subtle: #e8e8f0;
  --text: #1a1a2e;
  --text-muted: #64648a;
  --text-faint: #9898b0;
  --accent-orange: #ea580c;
  --accent-purple: #9333ea;
  --accent-gradient: linear-gradient(135deg, #ea580c, #dc2626, #9333ea);
  --accent-gradient-h: linear-gradient(90deg, #ea580c, #dc2626, #9333ea);
  --xp-bar: linear-gradient(90deg, #ea580c, #9333ea);
  --code-bg: #f8f8fc;
  --code-border: #e2e2ea;
  --success: #059669;
  --error: #dc2626;
  --warning: #d97706;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.1);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.12);
  --quiz-correct: #d1fae5;
  --quiz-wrong: #fee2e2;
  --glow-orange: 0 0 20px rgba(234,88,12,0.15);
  --glow-purple: 0 0 20px rgba(147,51,234,0.15);
}

/* ===== BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-h) + var(--space-4));
}
body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  overflow-x: hidden;
}
::selection {
  background: rgba(168,85,247,0.25);
  color: var(--text);
}
:focus-visible {
  outline: 2px solid var(--accent-purple);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
a { color: var(--accent-orange); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--accent-purple); }
button { cursor: pointer; background: none; border: none; color: inherit; font: inherit; }
img { max-width: 100%; height: auto; display: block; }
h1,h2,h3,h4,h5,h6 { line-height: 1.2; text-wrap: balance; }
p, li, figcaption { text-wrap: pretty; }
code { font-family: var(--font-mono); }

/* ===== LAYOUT ===== */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 100;
  transition: transform var(--transition-med);
  overflow: hidden;
}
.main {
  margin-left: var(--sidebar-w);
  min-height: 100dvh;
  display: flex; flex-direction: column;
}
.topbar {
  position: sticky; top: 0;
  height: var(--topbar-h);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; gap: var(--space-4);
  padding: 0 var(--space-6);
  z-index: 50;
}
.hamburger { display: none; }
.content-area {
  flex: 1;
  padding: var(--space-8) var(--space-8) var(--space-16);
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

@media (max-width: 840px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .main { margin-left: 0; }
  .hamburger { display: flex; }
  .content-area { padding: var(--space-6) var(--space-4) var(--space-12); }
}

/* ===== SIDEBAR COMPONENTS ===== */
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4) var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}
.logo {
  display: flex; align-items: center; gap: var(--space-2);
  cursor: pointer; user-select: none;
}
.logo-text {
  font-size: var(--text-lg);
  font-weight: 700;
  background: var(--accent-gradient-h);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.sidebar-close { display: none; padding: var(--space-1); border-radius: var(--radius-sm); }
.sidebar-close:hover { background: var(--surface-2); }
@media (max-width: 840px) { .sidebar-close { display: flex; } }

.sidebar-xp {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}
.xp-level-row { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2); }
.xp-badge { font-size: 1.4rem; }
.xp-info { display: flex; flex-direction: column; }
.xp-level-name { font-size: var(--text-sm); font-weight: 600; color: var(--text); }
.xp-points { font-size: var(--text-xs); color: var(--text-muted); font-weight: 500; }
.xp-bar-bg {
  height: 6px; border-radius: var(--radius-full);
  background: var(--surface-3); overflow: hidden;
}
.xp-bar-fill {
  height: 100%; border-radius: var(--radius-full);
  background: var(--xp-bar);
  transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
.xp-next { font-size: var(--text-xs); color: var(--text-faint); margin-top: var(--space-1); display: block; }

.sidebar-nav {
  flex: 1; overflow-y: auto; padding: var(--space-3) var(--space-2);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.nav-section-label {
  font-size: var(--text-xs); font-weight: 600; color: var(--text-faint);
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: var(--space-1) var(--space-3); margin-bottom: var(--space-1);
}
.nav-track {
  margin-bottom: var(--space-1);
}
.nav-track-btn {
  display: flex; align-items: center; gap: var(--space-2);
  width: 100%; padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm); font-weight: 500;
  color: var(--text-muted);
  text-align: left;
  transition: all var(--transition-fast);
}
.nav-track-btn:hover { background: var(--surface-2); color: var(--text); }
.nav-track-btn.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.nav-track-btn .track-num {
  width: 22px; height: 22px; border-radius: var(--radius-full);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 700;
  background: var(--surface-3); color: var(--text-faint);
  flex-shrink: 0;
}
.nav-track-btn.active .track-num,
.nav-track-btn.completed .track-num {
  background: var(--accent-gradient);
  color: #fff;
}
.nav-track-btn .track-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-track-btn .track-progress {
  font-size: 0.65rem; color: var(--text-faint); font-weight: 600;
  font-family: var(--font-mono);
}
.nav-lessons {
  padding-left: calc(var(--space-3) + 22px + var(--space-2));
  max-height: 0; overflow: hidden;
  transition: max-height 0.3s ease;
}
.nav-track.expanded .nav-lessons { max-height: 1000px; }
.nav-lesson-btn {
  display: flex; align-items: center; gap: var(--space-2);
  width: 100%; padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs); color: var(--text-faint);
  text-align: left; border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}
.nav-lesson-btn:hover { color: var(--text-muted); background: var(--surface); }
.nav-lesson-btn.active { color: var(--accent-orange); }
.nav-lesson-btn.done { color: var(--success); }
.nav-lesson-btn .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--border); flex-shrink: 0;
}
.nav-lesson-btn.active .dot { background: var(--accent-orange); }
.nav-lesson-btn.done .dot { background: var(--success); }

.sidebar-footer {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-subtle);
  display: flex; gap: var(--space-2);
}
.search-btn {
  flex: 1; display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--surface-2); border-radius: var(--radius-md);
  font-size: var(--text-xs); color: var(--text-muted);
  transition: all var(--transition-fast);
}
.search-btn:hover { background: var(--surface-3); color: var(--text); }
.search-btn kbd, .cmd-input-wrap kbd {
  font-family: var(--font-mono); font-size: 0.65rem;
  padding: 2px 5px; background: var(--surface-3);
  border: 1px solid var(--border); border-radius: 3px;
  color: var(--text-faint); margin-left: auto;
}
.theme-toggle {
  padding: var(--space-2);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  transition: all var(--transition-fast);
}
.theme-toggle:hover { background: var(--surface-2); color: var(--text); }

/* ===== TOPBAR ===== */
.topbar-xp {
  flex: 1; display: flex; align-items: center; gap: var(--space-3);
  font-size: var(--text-xs); font-weight: 600; color: var(--text-muted);
  font-family: var(--font-mono);
}
.topbar-bar-bg {
  flex: 1; max-width: 200px; height: 4px;
  background: var(--surface-3); border-radius: var(--radius-full);
  overflow: hidden;
}
.topbar-bar-fill {
  height: 100%; border-radius: var(--radius-full);
  background: var(--xp-bar);
  transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
.search-btn-top {
  padding: var(--space-2); border-radius: var(--radius-md);
  color: var(--text-muted); transition: all var(--transition-fast);
}
.search-btn-top:hover { background: var(--surface-2); color: var(--text); }

/* ===== COMMAND PALETTE ===== */
.cmd-palette { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: flex-start; justify-content: center; padding-top: 15vh; }
.cmd-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); }
.cmd-dialog {
  position: relative; width: 90%; max-width: 560px;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.cmd-input-wrap {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4); border-bottom: 1px solid var(--border-subtle);
  color: var(--text-muted);
}
.cmd-input-wrap input {
  flex: 1; background: none; border: none; outline: none;
  font-size: var(--text-base); color: var(--text);
}
.cmd-results { max-height: 400px; overflow-y: auto; }
.cmd-result-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  cursor: pointer; transition: background var(--transition-fast);
  border-bottom: 1px solid var(--border-subtle);
}
.cmd-result-item:hover, .cmd-result-item.selected { background: var(--surface-2); }
.cmd-result-track { font-size: var(--text-xs); color: var(--accent-purple); font-weight: 600; }
.cmd-result-title { font-size: var(--text-sm); color: var(--text); }

/* ===== HOME ===== */
.home-hero {
  text-align: center;
  padding: var(--space-12) 0 var(--space-8);
}
.home-hero h1 {
  font-size: var(--text-2xl); font-weight: 800;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: var(--space-3);
}
.home-hero .subtitle {
  font-size: var(--text-lg); color: var(--text-muted);
  max-width: 600px; margin: 0 auto var(--space-6);
}
.home-stats {
  display: flex; justify-content: center; gap: var(--space-8);
  margin-bottom: var(--space-8);
  flex-wrap: wrap;
}
.home-stat {
  text-align: center;
}
.home-stat .num {
  font-size: var(--text-xl); font-weight: 800;
  background: var(--accent-gradient-h);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  display: block;
  font-family: var(--font-mono);
}
.home-stat .label { font-size: var(--text-xs); color: var(--text-faint); font-weight: 500; }

.track-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-4);
}
.track-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  cursor: pointer;
  transition: all var(--transition-med);
  position: relative;
  overflow: hidden;
}
.track-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--accent-gradient-h);
  opacity: 0; transition: opacity var(--transition-med);
}
.track-card:hover { border-color: var(--accent-orange); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.track-card:hover::before { opacity: 1; }
.track-card-num {
  font-size: var(--text-xs); font-weight: 700; color: var(--accent-orange);
  font-family: var(--font-mono); margin-bottom: var(--space-1);
}
.track-card h3 {
  font-size: var(--text-lg); font-weight: 700; margin-bottom: var(--space-2);
  color: var(--text);
}
.track-card p {
  font-size: var(--text-sm); color: var(--text-muted);
  margin-bottom: var(--space-3); line-height: 1.5;
}
.track-card-meta {
  display: flex; align-items: center; gap: var(--space-3);
  font-size: var(--text-xs); color: var(--text-faint);
}
.track-card-progress-bar {
  flex: 1; height: 4px; background: var(--surface-3);
  border-radius: var(--radius-full); overflow: hidden;
}
.track-card-progress-fill {
  height: 100%; background: var(--xp-bar); border-radius: var(--radius-full);
  transition: width 0.4s ease;
}

/* ===== OVERALL PROGRESS ===== */
.overall-progress {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-6);
}
.overall-progress h3 {
  font-size: var(--text-sm); font-weight: 600; color: var(--text-muted);
  margin-bottom: var(--space-2);
}
.overall-bar-bg {
  height: 8px; background: var(--surface-3);
  border-radius: var(--radius-full); overflow: hidden;
  margin-bottom: var(--space-2);
}
.overall-bar-fill {
  height: 100%; background: var(--xp-bar);
  border-radius: var(--radius-full);
  transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
.overall-text { font-size: var(--text-xs); color: var(--text-faint); font-family: var(--font-mono); }

/* ===== ACHIEVEMENTS ===== */
.achievements-section {
  margin-top: var(--space-6);
}
.achievements-section h3 {
  font-size: var(--text-sm); font-weight: 600; color: var(--text-muted);
  margin-bottom: var(--space-3);
}
.achievements-grid {
  display: flex; flex-wrap: wrap; gap: var(--space-2);
}
.ach-chip {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: var(--text-xs); color: var(--text-faint);
  transition: all var(--transition-fast);
}
.ach-chip.unlocked {
  background: var(--surface);
  border-color: var(--accent-orange);
  color: var(--text);
  box-shadow: var(--glow-orange);
}
.ach-chip .ach-icon { font-size: 1rem; }

/* ===== TRACK VIEW ===== */
.track-header {
  margin-bottom: var(--space-8);
  padding-bottom: var(--space-6);
  border-bottom: 1px solid var(--border);
}
.track-header .track-num {
  font-size: var(--text-sm); font-weight: 700; color: var(--accent-orange);
  font-family: var(--font-mono); margin-bottom: var(--space-1);
}
.track-header h1 {
  font-size: var(--text-xl); font-weight: 800; margin-bottom: var(--space-2);
}
.track-header p {
  font-size: var(--text-sm); color: var(--text-muted); max-width: 65ch;
}
.track-progress-info {
  display: flex; align-items: center; gap: var(--space-4); margin-top: var(--space-4);
}
.track-progress-bar {
  flex: 1; max-width: 300px; height: 6px;
  background: var(--surface-3); border-radius: var(--radius-full); overflow: hidden;
}
.track-progress-fill {
  height: 100%; background: var(--xp-bar); border-radius: var(--radius-full);
  transition: width 0.4s ease;
}
.track-progress-text {
  font-size: var(--text-xs); color: var(--text-faint); font-family: var(--font-mono);
}

/* ===== LESSON ===== */
.lesson {
  margin-bottom: var(--space-8);
  padding-bottom: var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
}
.lesson:last-child { border-bottom: none; }
.lesson-header {
  display: flex; align-items: flex-start; gap: var(--space-3);
  margin-bottom: var(--space-4);
  cursor: pointer;
}
.lesson-toggle {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-muted);
  flex-shrink: 0;
  margin-top: 2px;
  transition: all var(--transition-fast);
}
.lesson-toggle:hover { background: var(--surface-3); }
.lesson-toggle svg { transition: transform var(--transition-fast); }
.lesson.expanded .lesson-toggle svg { transform: rotate(90deg); }
.lesson-title-area { flex: 1; }
.lesson-title {
  font-size: var(--text-lg); font-weight: 700;
  display: flex; align-items: center; gap: var(--space-2);
}
.lesson-title .check {
  color: var(--success); opacity: 0;
  transition: opacity var(--transition-fast);
}
.lesson.completed .lesson-title .check { opacity: 1; }
.lesson-subtitle {
  font-size: var(--text-xs); color: var(--text-faint); margin-top: 2px;
}
.lesson-body {
  max-height: 0; overflow: hidden;
  transition: max-height 0.4s ease;
  padding-left: calc(28px + var(--space-3));
}
.lesson.expanded .lesson-body { max-height: 50000px; }
.lesson-content {
  font-size: var(--text-base);
  color: var(--text-muted);
  line-height: 1.75;
}
.lesson-content h4 {
  font-size: var(--text-base); font-weight: 700; color: var(--text);
  margin: var(--space-5) 0 var(--space-2);
}
.lesson-content p { margin-bottom: var(--space-3); max-width: 72ch; }
.lesson-content ul, .lesson-content ol {
  margin-bottom: var(--space-3); padding-left: var(--space-5);
}
.lesson-content li { margin-bottom: var(--space-1); }
.lesson-content strong { color: var(--text); font-weight: 600; }

/* Inline code */
.lesson-content code:not(.code-block code) {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.88em;
  font-family: var(--font-mono);
  color: var(--accent-orange);
  white-space: nowrap;
}

/* Code blocks */
.code-block {
  position: relative;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius-md);
  margin: var(--space-3) 0;
  overflow: hidden;
}
.code-block-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-2);
  border-bottom: 1px solid var(--code-border);
  font-size: var(--text-xs); color: var(--text-faint);
  font-family: var(--font-mono);
}
.copy-btn {
  display: flex; align-items: center; gap: var(--space-1);
  padding: 3px 8px; border-radius: var(--radius-sm);
  font-size: 0.7rem; color: var(--text-faint);
  font-family: var(--font-mono);
  transition: all var(--transition-fast);
}
.copy-btn:hover { background: var(--surface-3); color: var(--text); }
.copy-btn.copied { color: var(--success); }
.code-block pre {
  padding: var(--space-3) var(--space-4);
  overflow-x: auto;
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--text);
  -webkit-overflow-scrolling: touch;
}
.code-block code {
  font-family: var(--font-mono);
  background: none !important;
  border: none !important;
  padding: 0 !important;
  color: inherit !important;
  white-space: pre;
}

/* Code syntax colors */
.code-block .kw { color: #c084fc; }
.code-block .fn { color: #60a5fa; }
.code-block .str { color: #34d399; }
.code-block .cm { color: #5e5e72; font-style: italic; }
.code-block .num { color: #fbbf24; }
.code-block .op { color: #f87171; }
.code-block .dec { color: #fb923c; }

/* Complete button */
.complete-btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  margin-top: var(--space-4);
  padding: var(--space-2) var(--space-5);
  background: var(--accent-gradient);
  color: #fff; font-weight: 600; font-size: var(--text-sm);
  border-radius: var(--radius-full);
  transition: all var(--transition-med);
  box-shadow: var(--glow-orange);
}
.complete-btn:hover { transform: translateY(-1px); box-shadow: var(--glow-purple); }
.complete-btn:disabled {
  opacity: 0.4; cursor: default; transform: none;
  box-shadow: none;
}

/* Info boxes */
.info-box {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border-left: 3px solid var(--accent-purple);
  background: color-mix(in srgb, var(--accent-purple) 8%, var(--surface));
  margin: var(--space-3) 0;
  font-size: var(--text-sm);
}
.info-box.warn {
  border-left-color: var(--warning);
  background: color-mix(in srgb, var(--warning) 8%, var(--surface));
}
.info-box.tip {
  border-left-color: var(--success);
  background: color-mix(in srgb, var(--success) 8%, var(--surface));
}
.info-box strong { display: block; margin-bottom: var(--space-1); color: var(--text); }

/* Tables */
.lesson-content table {
  width: 100%; border-collapse: collapse;
  margin: var(--space-3) 0; font-size: var(--text-sm);
}
.lesson-content th, .lesson-content td {
  padding: var(--space-2) var(--space-3);
  text-align: left;
  border: 1px solid var(--border);
}
.lesson-content th {
  background: var(--surface-2);
  font-weight: 600; color: var(--text);
  font-size: var(--text-xs);
}
.lesson-content td { color: var(--text-muted); }

/* ===== QUIZ ===== */
.quiz-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-top: var(--space-8);
}
.quiz-section h3 {
  font-size: var(--text-lg); font-weight: 700;
  margin-bottom: var(--space-4);
  display: flex; align-items: center; gap: var(--space-2);
}
.quiz-question {
  margin-bottom: var(--space-6);
}
.quiz-question p {
  font-size: var(--text-base); font-weight: 600;
  margin-bottom: var(--space-3); color: var(--text);
}
.quiz-option {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-2);
  cursor: pointer; font-size: var(--text-sm);
  transition: all var(--transition-fast);
}
.quiz-option:hover:not(.selected):not(.disabled) {
  border-color: var(--accent-purple);
  background: var(--surface-2);
}
.quiz-option .opt-letter {
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-full);
  background: var(--surface-3);
  font-size: var(--text-xs); font-weight: 700;
  color: var(--text-faint); flex-shrink: 0;
}
.quiz-option.correct {
  border-color: var(--success);
  background: var(--quiz-correct);
}
.quiz-option.correct .opt-letter {
  background: var(--success); color: #fff;
}
.quiz-option.wrong {
  border-color: var(--error);
  background: var(--quiz-wrong);
}
.quiz-option.wrong .opt-letter {
  background: var(--error); color: #fff;
}
.quiz-option.disabled { cursor: default; opacity: 0.7; }
.quiz-explain {
  font-size: var(--text-sm); color: var(--text-muted);
  padding: var(--space-2) var(--space-3);
  margin-top: var(--space-1);
  border-left: 2px solid var(--border);
  display: none;
}
.quiz-explain.show { display: block; }
.quiz-score {
  text-align: center; padding: var(--space-4);
  font-size: var(--text-lg); font-weight: 700;
  color: var(--success);
}

/* ===== BTN PRIMARY ===== */
.btn-primary {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  background: var(--accent-gradient);
  color: #fff; font-weight: 600; font-size: var(--text-sm);
  border-radius: var(--radius-full);
  transition: all var(--transition-med);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: var(--glow-orange); }

/* ===== TOAST ===== */
.toast-container {
  position: fixed; bottom: var(--space-6); right: var(--space-6);
  z-index: 2000; display: flex; flex-direction: column; gap: var(--space-2);
}
.toast {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: var(--text-sm);
  animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: 340px;
}
.toast.xp { border-left: 3px solid var(--accent-orange); }
.toast.achieve { border-left: 3px solid var(--accent-purple); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-8px); }
}

/* ===== LEVEL MODAL ===== */
.level-modal {
  position: fixed; inset: 0; z-index: 3000;
  display: flex; align-items: center; justify-content: center;
}
.level-modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(8px); }
.level-modal-content {
  position: relative; text-align: center;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius-xl); padding: var(--space-10) var(--space-8);
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: 400px; width: 90%;
}
.level-modal-badge { font-size: 4rem; margin-bottom: var(--space-3); }
.level-modal-content h2 {
  font-size: var(--text-xl); font-weight: 800;
  background: var(--accent-gradient-h);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: var(--space-2);
}
.level-modal-content p {
  font-size: var(--text-sm); color: var(--text-muted); margin-bottom: var(--space-6);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.9) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* ===== ACHIEVEMENT MODAL ===== */
.achieve-modal {
  position: fixed; inset: 0; z-index: 3000;
  display: flex; align-items: center; justify-content: center;
}
.achieve-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.achieve-content {
  position: relative; text-align: center;
  background: var(--bg-raised); border: 1px solid var(--accent-purple);
  border-radius: var(--radius-xl); padding: var(--space-8);
  box-shadow: var(--glow-purple);
  animation: modalIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: 360px; width: 90%;
}
.achieve-icon { font-size: 3rem; margin-bottom: var(--space-2); }
.achieve-content h3 {
  font-size: var(--text-lg); font-weight: 700; margin-bottom: var(--space-2);
}
.achieve-content p { font-size: var(--text-sm); color: var(--text-muted); margin-bottom: var(--space-4); }

/* ===== CONFETTI ===== */
#confettiCanvas {
  position: fixed; inset: 0; z-index: 10000; pointer-events: none;
}

/* ===== TRACK NAV BUTTONS ===== */
.track-nav {
  display: flex; justify-content: space-between; gap: var(--space-4);
  margin-top: var(--space-8);
  padding-top: var(--space-6);
  border-top: 1px solid var(--border);
}
.track-nav-btn {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm); font-weight: 500;
  color: var(--text-muted);
  transition: all var(--transition-fast);
}
.track-nav-btn:hover {
  border-color: var(--accent-orange); color: var(--text);
  background: var(--surface-2);
}

/* ===== FLOW CHART ===== */
.flow-chart {
  display: flex; flex-direction: column; align-items: center;
  gap: var(--space-2); margin: var(--space-4) 0;
}
.flow-node {
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius-md);
  font-size: var(--text-sm); font-weight: 600;
  text-align: center; min-width: 200px;
}
.flow-node.start { background: var(--accent-orange); color: #fff; }
.flow-node.decision { background: var(--surface-2); border: 1px solid var(--accent-purple); color: var(--text); border-radius: 0; transform: rotate(0deg); }
.flow-node.end { background: var(--accent-purple); color: #fff; }
.flow-arrow { color: var(--text-faint); font-size: var(--text-lg); }

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  .home-stats { gap: var(--space-4); }
  .track-grid { grid-template-columns: 1fr; }
  .quiz-section { padding: var(--space-4); }
  .track-nav { flex-direction: column; }
  .toast-container { left: var(--space-4); right: var(--space-4); bottom: var(--space-4); }
  .toast { max-width: none; }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ===== ANIMATIONS ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
