/* ===== ROOT VARIABLES ===== */
:root {
  --nav-w: 230px;
  --viz-w: 460px;

  --bg: #ffffff;
  --bg-alt: #f8fafc;
  --bg-viz: #f1f5f9;
  --nav-bg: #0f172a;
  --nav-border: #1e293b;
  --nav-text: #94a3b8;
  --nav-text-active: #f1f5f9;
  --nav-accent: #6366f1;

  --text: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border: #e2e8f0;
  --border-dark: #cbd5e1;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 4px 16px rgba(0,0,0,.08), 0 1px 4px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 40px rgba(0,0,0,.12), 0 4px 16px rgba(0,0,0,.07);

  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --font-serif: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

  /* Chapter accent colors */
  --c-limits:       #3b82f6;
  --c-limits-light: #eff6ff;
  --c-limits-dark:  #1d4ed8;

  --c-deriv:        #f59e0b;
  --c-deriv-light:  #fffbeb;
  --c-deriv-dark:   #b45309;

  --c-integ:        #10b981;
  --c-integ-light:  #ecfdf5;
  --c-integ-dark:   #047857;

  --c-series:       #8b5cf6;
  --c-series-light: #f5f3ff;
  --c-series-dark:  #6d28d9;

  --c-multi:        #ef4444;
  --c-multi-light:  #fef2f2;
  --c-multi-dark:   #b91c1c;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; font-size: 16px; }

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ===== INDEX PAGE ===== */
.index-page { overflow-x: hidden; }

/* Top nav */
/* ── Top nav — 3-zone grid layout ─────────────────────────────────────────── */
.top-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 2.5rem;
  height: 64px;
  background: transparent;
  border-bottom: none;
  box-shadow: none;
}

.top-nav .site-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1.1rem;
  font-family: var(--font-mono);
  font-weight: 700;
  color: #ffffff;
  text-decoration: none;
  justify-self: start;
}

.top-nav .brand-icon {
  width: 32px;
  height: 32px;
  background: transparent;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1rem;
}

/* Center links */
.top-nav .nav-links {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.top-nav .nav-links > li > a {
  display: block;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.75);
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
}

.top-nav .nav-links > li > a:hover {
  color: #ffffff;
  background: rgba(255,255,255,0.1);
}

/* Right auth zone */
.nav-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Scrolled state */
.top-nav.scrolled {
  background: #000000;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  box-shadow: var(--shadow-sm);
  transition: background 0.3s ease, box-shadow 0.3s ease;
}
.top-nav.scrolled .site-brand { color: #ffffff; }
.top-nav.scrolled .nav-links > li > a { color: rgba(255,255,255,0.7); }
.top-nav.scrolled .nav-links > li > a:hover { color: #ffffff; background: rgba(255,255,255,0.08); }

/* ── Subjects dropdown ─────────────────────────────────────────────────────── */
.nav-dropdown { position: relative; }

.nav-dropdown-btn {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  color: rgba(255,255,255,0.75);
  background: none;
  border: none;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.nav-dropdown-btn:hover,
.nav-dropdown-btn.open {
  color: #ffffff;
  background: rgba(255,255,255,0.1);
}

.nav-dropdown-btn svg { transition: transform 0.2s ease; }
.nav-dropdown-btn.open svg { transform: rotate(180deg); }

.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  padding: 0.375rem;
  list-style: none;
  min-width: 180px;
  box-shadow: var(--shadow-lg);
  z-index: 200;
}

.nav-dropdown-menu.open { display: block; }

/* Section group label (non-clickable) */
.nav-dropdown-group-label {
  padding: 0.4rem 0.875rem 0.2rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
  cursor: default;
}

/* Divider between groups */
.nav-dropdown-divider {
  height: 1px;
  background: rgba(255,255,255,0.08);
  margin: 0.3rem 0.5rem;
}

.nav-dropdown-menu li a {
  display: block;
  padding: 0.45rem 0.875rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
}

.nav-dropdown-menu li a:hover {
  color: #ffffff;
  background: rgba(255,255,255,0.08);
}

/* Dashboard link in nav right */
.nav-dashboard-link {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  border: 1px solid rgba(255,255,255,0.18);
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.nav-dashboard-link:hover {
  color: #ffffff;
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.35);
}

/* Hero */
.hero {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.hero-bg {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #0f0c29 0%, #000000 50%, #24243e 100%);
}

.hero-canvas {
  position: absolute;
  inset: 0;
  opacity: 0.5;
}

.hero-content {
  position: relative;
  z-index: 1;
  max-width: 680px;
  padding: 3rem 2.5rem;
  text-align: center;
}

.hero-kicker {
  display: inline-flex;
  align-items: center;
  background: transparent;
  border: none;
  color: #ffffff;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 1.5rem;
}

.hero-title {
    font-family: var(--font-mono);
  font-size: clamp(2.5rem, 6vw, 4.5rem);
  font-weight: 700;
  line-height: 1.1;
  color: #ffffff;
  margin-bottom: 1.25rem;
}

.hero-title .accent {
  color: #f4f6ff;
  display: block;
}

.hero-desc {
  font-size: 1.125rem;
  line-height: 1.75;
  color: #ffffff;
  max-width: 520px;
  margin: 0 auto 2.5rem;
}

.hero-cta {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all 0.15s ease;
}

.btn-primary {
  background: #233ea7;
  color: white;
}

.btn-primary:hover {
  background: #4f46e5;
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(99,102,241,0.4);
}

.btn-ghost {
  background: rgba(255,255,255,0.08);
  color: #e2e8f0;
  border: 1px solid rgba(255,255,255,0.15);
}

.btn-ghost:hover {
  background: rgba(255,255,255,0.14);
}

/* Chapters section */
.chapters-section {
  padding: 6rem 2.5rem;
  max-width: 1200px;
  margin: 0 auto;
}

.section-header {
  text-align: center;
  margin-bottom: 3.5rem;
}

.section-label {
  display: inline-block;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #000000;
  margin-bottom: 0.75rem;
}

.section-title {
  font-family: var(--font-mono);
  font-size: clamp(1.75rem, 4vw, 2.75rem);
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.75rem;
}

.section-desc {
  font-size: 1.0625rem;
  color: var(--text-muted);
  max-width: 560px;
  margin: 0 auto;
}

/* ── Chapter carousel ─────────────────────────────────────────────────────── */
.chapters-carousel {
  position: relative;
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.carousel-track-wrap {
  flex: 1;
  overflow-x: scroll;
  overflow-y: visible;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
  -ms-overflow-style: none;
  border-radius: var(--radius-lg);
}
.carousel-track-wrap::-webkit-scrollbar { display: none; }

.carousel-track {
  display: flex;
  gap: 24px;
}

.chapter-card {
  position: relative;
  flex: 0 0 84%;
  scroll-snap-align: center;
  display: block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 3rem 3.5rem;
  text-decoration: none;
  overflow: hidden;
  cursor: pointer;
  min-height: 320px;
  box-sizing: border-box;
  opacity: 0.35;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.3s ease;
}

.chapter-card.active {
  opacity: 1;
}

.chapter-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--card-color, #6366f1);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.25s ease;
}

.chapter-card.active:hover {
  border-color: var(--card-color, #6366f1);
  box-shadow: var(--shadow);
}

.chapter-card.active:hover::before { transform: scaleX(1); }

.chapter-card .card-num {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--card-color, #6366f1);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.chapter-card .card-title {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.875rem;
}

.chapter-card .card-desc {
  font-size: 1rem;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 2rem;
  max-width: 640px;
}

.chapter-card .card-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.card-topic {
  padding: 0.3rem 0.75rem;
  background: var(--card-color-light, #eff6ff);
  color: #ffffff;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
}

.chapter-card .card-arrow {
  position: absolute;
  bottom: 2.5rem;
  right: 3rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--card-color, #3b82f6);
  transition: gap 0.15s ease;
}

.chapter-card:hover .card-arrow { gap: 0.65rem; }

.chapter-card.coming-soon {
  opacity: 0.6;
  cursor: default;
  pointer-events: none;
}

.coming-soon-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.625rem;
  background: #f1f5f9;
  color: var(--text-muted);
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
}

/* Carousel nav buttons */
.carousel-btn {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  user-select: none;
}

.carousel-btn:hover {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.carousel-btn:disabled {
  opacity: 0.25;
  cursor: default;
  pointer-events: none;
}

/* Dots */
.carousel-dots {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

.carousel-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.2s, transform 0.2s;
  cursor: pointer;
}

.carousel-dot.active {
  background: var(--text);
  transform: scale(1.25);
}

/* ── Practice / Quiz ─────────────────────────────────────────────────────── */
.practice-wrapper {
  margin-left: var(--nav-w);
  padding: 4rem 3rem;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.practice-content { width: 100%; max-width: 700px; }

.quiz-start-prompt { text-align: center; padding: 6rem 2rem; color: var(--text-muted); }
.quiz-start-prompt h2 { font-size: 2rem; color: var(--text); margin-bottom: 0.75rem; font-family: var(--font-mono); }

.quiz-chapter-title {
  font-size: 1.5rem; font-weight: 700; color: var(--text);
  font-family: var(--font-mono); margin-bottom: 1.25rem;
}
.quiz-progress-bar { height: 5px; background: var(--border); border-radius: 3px; margin-bottom: 0.5rem; }
.quiz-progress-fill { height: 100%; background: var(--chapter-color, #8b5cf6); border-radius: 3px; transition: width 0.4s ease; }
.quiz-count { font-size: 0.8125rem; color: var(--text-muted); font-weight: 600; margin-bottom: 1.5rem; }

.quiz-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 2.25rem 2.5rem; margin-bottom: 1rem;
}
.quiz-question { font-size: 1.0625rem; color: var(--text); line-height: 1.75; margin-bottom: 1.75rem; font-weight: 500; }

.quiz-options { display: flex; flex-direction: column; gap: 0.625rem; }
.quiz-option {
  display: flex; align-items: center; gap: 0.875rem;
  padding: 0.875rem 1.125rem; background: var(--bg-alt);
  border: 1.5px solid var(--border); border-radius: var(--radius);
  cursor: pointer; text-align: left; font-size: 0.9375rem; color: var(--text);
  transition: border-color 0.15s, background 0.15s; font-family: inherit; width: 100%;
}
.quiz-option:hover:not(:disabled) { border-color: var(--chapter-color, #8b5cf6); background: #fff; }
.quiz-option:disabled { cursor: default; }
.quiz-option.correct { border-color: #10b981; background: #ecfdf5; color: #065f46; }
.quiz-option.wrong   { border-color: #ef4444; background: #fef2f2; color: #991b1b; }

.opt-letter {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.625rem; height: 1.625rem; border-radius: 50%;
  background: var(--border); font-size: 0.7rem; font-weight: 700; flex-shrink: 0; color: var(--text);
}
.quiz-option.correct .opt-letter { background: #10b981; color: #fff; }
.quiz-option.wrong   .opt-letter { background: #ef4444; color: #fff; }

.quiz-explanation {
  margin-top: 1.25rem; padding: 1rem 1.25rem;
  background: var(--bg-alt); border-left: 3px solid var(--chapter-color, #8b5cf6);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.9rem; color: var(--text-muted); line-height: 1.75;
}
.quiz-next {
  display: inline-flex; align-items: center; gap: 0.5rem;
  margin-top: 1.25rem; padding: 0.7rem 1.5rem;
  background: var(--chapter-color, #8b5cf6); color: #fff;
  border: none; border-radius: var(--radius); font-size: 0.9375rem;
  font-weight: 600; cursor: pointer; font-family: inherit; transition: opacity 0.15s;
}
.quiz-next:hover { opacity: 0.88; }

.quiz-score-card { text-align: center; padding: 4rem 2rem; }
.quiz-score-number { font-size: 5rem; font-weight: 700; color: var(--chapter-color, #8b5cf6); line-height: 1; font-family: var(--font-mono); }
.quiz-score-label { font-size: 1.125rem; color: var(--text-muted); margin-top: 0.75rem; }
.quiz-score-actions { margin-top: 2rem; display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }
.quiz-btn-ghost {
  background: transparent; border: 1.5px solid var(--border); color: var(--text);
  padding: 0.7rem 1.5rem; border-radius: var(--radius); font-family: inherit;
  font-size: 0.9375rem; font-weight: 600; cursor: pointer; transition: border-color 0.15s;
}
.quiz-btn-ghost:hover { border-color: var(--chapter-color, #8b5cf6); }

/* ── AP Mode (AB / BC buttons) ────────────────────────────────── */
.ap-mode-btn {
  display: inline-flex; align-items: center; gap: 0.45rem;
  padding: 0.42rem 1rem;
  border: 1.5px solid var(--border-dark);
  border-radius: var(--radius-full);
  background: transparent; color: var(--text-muted);
  font-size: 0.85rem; font-weight: 600; cursor: pointer;
  font-family: var(--font); transition: all 0.18s;
  letter-spacing: 0.01em;
}
.ap-mode-btn:hover { border-color: #dc2626; color: #dc2626; }
.ap-mode-btn.active { background: #dc2626; border-color: #dc2626; color: #fff; }
.ap-badge-icon {
  display: inline-flex; align-items: center; justify-content: center;
  background: #dc2626; color: #fff;
  font-size: 0.6rem; font-weight: 800; letter-spacing: 0.06em;
  padding: 0.1rem 0.3rem; border-radius: 3px; line-height: 1.4;
}
.ap-mode-btn.active .ap-badge-icon { background: #fff; color: #dc2626; }
.ap-block-icon {
  display: inline-flex; align-items: center; justify-content: center;
  background: #dc2626; color: #fff;
  font-size: 1.1rem; font-weight: 900; letter-spacing: 0.08em;
  width: 3rem; height: 3rem; border-radius: var(--radius);
  margin: 0 auto 1.25rem;
}
/* Dim linear-algebra sidebar items when an AP filter is active */
.sidebar-nav-item.ap-dim { opacity: 0.3; pointer-events: none; cursor: default; }

/* About / footer */
.about-section {
  background: var(--nav-bg);
  color: #94a3b8;
  padding: 4rem 2.5rem;
  text-align: center;
}

.about-section h2 {
  font-family: var(--font-mono);
  color: #f1f5f9;
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

.about-section p {
  max-width: 600px;
  margin: 0 auto 0.5rem;
  line-height: 1.75;
  font-size: 0.9375rem;
}

.site-footer {
  background: #020617;
  color: #475569;
  text-align: center;
  padding: 1.5rem;
  font-size: 0.875rem;
}

/* ===== CHAPTER PAGE LAYOUT ===== */
.chapter-page {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  position: fixed;
  left: 0; top: 0;
  width: var(--nav-w);
  height: 100vh;
  background: var(--nav-bg);
  border-right: 1px solid var(--nav-border);
  display: flex;
  flex-direction: column;
  z-index: 50;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 1.5rem 1.25rem 1rem;
  border-bottom: 1px solid var(--nav-border);
}

.sidebar-brand a {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  color: #f1f5f9;
  text-decoration: none;
}

.sidebar-brand .brand-icon {
  width: 28px;
  height: 28px;
  background: transparent;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 0.75rem;
  flex-shrink: 0;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
}

.sidebar-nav-label {
  padding: 0.5rem 1.25rem 0.375rem;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #475569;
}

.sidebar-nav-item {
  display: block;
  padding: 0.5rem 1.25rem;
  color: var(--nav-text);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  border-left: 2px solid transparent;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.sidebar-nav-item:hover {
  color: #e2e8f0;
  background: rgba(255,255,255,0.04);
}

.sidebar-nav-item.active {
  color: #f1f5f9;
  border-left-color: var(--chapter-color, #6366f1);
  background: rgba(255,255,255,0.05);
}

.sidebar-nav-item .nav-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
  flex-shrink: 0;
}

.sidebar-nav-item.active .nav-dot { opacity: 1; background: var(--chapter-color, #6366f1); }

.sidebar-divider {
  height: 1px;
  background: var(--nav-border);
  margin: 0.75rem 1.25rem;
}

.sidebar-section-nav {
  padding: 0.5rem 0;
}

.sidebar-section-nav .section-link {
  display: block;
  padding: 0.4rem 1.25rem 0.4rem 2.5rem;
  color: #475569;
  text-decoration: none;
  font-size: 0.8125rem;
  transition: color 0.15s;
}

.sidebar-section-nav .section-link:hover { color: #94a3b8; }

.sidebar-section-nav .section-link.active {
  color: var(--chapter-color, #818cf8);
  font-weight: 600;
}

/* Chapter wrapper (content + viz) */
.chapter-wrapper {
  margin-left: var(--nav-w);
  display: flex;
  min-height: 100vh;
  flex: 1;
}

/* Main text content */
.chapter-content {
  flex: 1;
  min-width: 0;
  padding: 0 3rem;
  max-width: 660px;
}

/* Chapter header */
.chapter-header {
  padding: 4rem 0 3rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}

.chapter-num {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--chapter-color, #6366f1);
  margin-bottom: 0.875rem;
}

.chapter-header h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 700;
  line-height: 1.15;
  color: var(--text);
  margin-bottom: 1rem;
}

.chapter-header .chapter-intro {
  font-size: 1.0625rem;
  color: var(--text-muted);
  line-height: 1.75;
  max-width: 520px;
}

/* Content sections */
.content-section {
  padding: 3.5rem 0;
  border-bottom: 1px solid var(--border);
  min-height: 80vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.content-section:last-child { border-bottom: none; }

.content-section h2 {
  font-family: var(--font-serif);
  font-size: 1.625rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1.125rem;
  line-height: 1.3;
}

.content-section p {
  font-size: 1rem;
  line-height: 1.8;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.content-section p:last-child { margin-bottom: 0; }

.content-section strong { color: var(--text); font-weight: 600; }

.math-display {
  display: block;
  text-align: center;
  padding: 1.25rem;
  background: var(--bg-alt);
  border-left: 3px solid var(--chapter-color, #6366f1);
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 1.25rem 0;
  font-size: 1.05rem;
  overflow-x: auto;
}

.insight-box {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin: 1.5rem 0;
  position: relative;
  padding-left: 1.75rem;
}

.insight-box::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--chapter-color, #6366f1);
  border-radius: 3px 0 0 3px;
}

.insight-box p {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--text);
}

.insight-box .insight-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--chapter-color, #6366f1);
  margin-bottom: 0.5rem;
  display: block;
}

/* Visualization panel */
.viz-panel {
  width: var(--viz-w);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-viz);
  border-left: 1px solid var(--border);
  overflow: hidden;
}

.viz-header {
  padding: 1rem 1.5rem;
  background: white;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
}

.viz-title {
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.viz-section-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--chapter-color, #6366f1);
}

.viz-body {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#viz-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#viz-container svg {
  width: 100%;
  height: 100%;
}

.viz-controls {
  padding: 1rem 1.5rem;
  background: white;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  min-height: 120px;
}

/* Control elements */
.control-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.control-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 80px;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.control-label .math-inline {
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.control-slider {
  flex: 1;
  -webkit-appearance: none;
  height: 4px;
  border-radius: 4px;
  background: var(--border-dark);
  outline: none;
  cursor: pointer;
}

.control-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--chapter-color, #6366f1);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 0 0 1px var(--chapter-color, #6366f1), var(--shadow-sm);
  transition: transform 0.1s;
}

.control-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.control-value {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  min-width: 52px;
  text-align: right;
}

.control-btn-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.ctrl-btn {
  padding: 0.375rem 0.875rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: white;
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
}

.ctrl-btn:hover {
  border-color: var(--chapter-color, #6366f1);
  color: var(--chapter-color, #6366f1);
}

.ctrl-btn.active {
  background: var(--chapter-color, #6366f1);
  border-color: var(--chapter-color, #6366f1);
  color: white;
}

.ctrl-btn.play-btn {
  background: var(--chapter-color, #6366f1);
  border-color: var(--chapter-color, #6366f1);
  color: white;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.ctrl-btn.play-btn:hover {
  filter: brightness(1.1);
}

/* Stats display */
.viz-stats {
  display: flex;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: white;
  border-top: 1px solid var(--border);
}

.stat-item {
  flex: 1;
  text-align: center;
}

.stat-label {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-light);
  margin-bottom: 0.25rem;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.stat-value.positive { color: #10b981; }
.stat-value.negative { color: #ef4444; }
.stat-value.highlight { color: var(--chapter-color, #6366f1); }

/* ===== D3 STYLES ===== */
.axis path, .axis line {
  stroke: #cbd5e1;
  stroke-width: 1;
}

.axis text {
  fill: #94a3b8;
  font-family: var(--font);
  font-size: 11px;
}

.grid line {
  stroke: #e2e8f0;
  stroke-width: 0.75;
}

.grid path { display: none; }

.curve-main {
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.curve-secondary {
  fill: none;
  stroke-width: 2;
  stroke-dasharray: 5 4;
  stroke-linecap: round;
}

.point-dot {
  cursor: pointer;
  transition: r 0.1s;
}

.tangent-line {
  fill: none;
  stroke-width: 2;
  stroke-dasharray: 6 4;
  stroke-linecap: round;
}

.shaded-area {
  opacity: 0.18;
}

/* ===== AUTH STYLES ===== */

/* Modal overlay */
.auth-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

/* Auth card */
.auth-card {
  position: relative;
  background: #ffffff;
  max-width: 420px;
  width: 100%;
  border-radius: 1rem;
  padding: 2.5rem;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

.auth-close {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem;
  border-radius: var(--radius);
  transition: color 0.15s, background 0.15s;
}
.auth-close:hover { color: var(--text); background: var(--bg-alt); }

.auth-logo { text-align: center; margin-bottom: 1rem; }

.auth-title {
  font-family: var(--font-mono);
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  margin-bottom: 0.375rem;
}

.auth-sub {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 1.5rem;
  line-height: 1.5;
}

/* Google button */
.auth-google-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: box-shadow 0.15s, border-color 0.15s;
}
.auth-google-btn:hover {
  border-color: var(--border-dark);
  box-shadow: var(--shadow-sm);
}

/* Divider */
.auth-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.25rem 0;
  color: var(--text-muted);
  font-size: 0.8125rem;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Tabs */
.auth-tabs {
  display: flex;
  background: var(--bg-alt);
  border-radius: var(--radius);
  padding: 0.25rem;
  margin-bottom: 1.25rem;
}

.auth-tab {
  flex: 1;
  padding: 0.5rem;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  font-family: var(--font);
}
.auth-tab.active {
  background: var(--chapter-color, #8b5cf6);
  color: #ffffff;
}

/* Fields / inputs */
.auth-field { margin-bottom: 0.75rem; }

.auth-input {
  display: block;
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-family: var(--font);
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color 0.15s;
}
.auth-input:focus { border-color: var(--chapter-color, #8b5cf6); }

.auth-error {
  font-size: 0.8125rem;
  color: #ef4444;
  min-height: 1.2em;
  margin-bottom: 0.5rem;
}

.auth-submit {
  display: block;
  width: 100%;
  padding: 0.75rem;
  background: var(--chapter-color, #8b5cf6);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: opacity 0.15s;
}
.auth-submit:hover { opacity: 0.88; }

/* Sign-in button (subtle, works on dark backgrounds) */
.auth-signin-btn {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.9rem;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: var(--radius);
  background: transparent;
  color: rgba(255,255,255,0.8);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.auth-signin-btn:hover {
  border-color: rgba(255,255,255,0.55);
  color: #ffffff;
  background: rgba(255,255,255,0.08);
}

/* User pill */
.auth-user-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background 0.15s;
}
.auth-user-pill:hover { background: rgba(255,255,255,0.08); }

.auth-avatar {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--chapter-color, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.auth-avatar-initial {
  font-size: 0.75rem;
  font-weight: 700;
  color: #ffffff;
}

.auth-user-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-chevron { color: rgba(255,255,255,0.5); flex-shrink: 0; }

/* Dropdown menu */
.auth-user-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 170px;
  background: #0f172a;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  padding: 0.375rem;
  box-shadow: var(--shadow-lg);
  z-index: 200;
}
.auth-user-menu.open { display: block; }

/* Sidebar menu opens upward */
.auth-user-menu.sidebar-menu {
  top: auto;
  bottom: calc(100% + 6px);
}

.auth-menu-item {
  display: block;
  width: 100%;
  padding: 0.5rem 0.875rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  text-align: left;
  transition: color 0.15s, background 0.15s;
}
.auth-menu-item:hover {
  color: #ffffff;
  background: rgba(255,255,255,0.07);
}

.auth-menu-signout {
  color: rgba(239,68,68,0.85);
}
.auth-menu-signout:hover {
  color: #ef4444;
  background: rgba(239,68,68,0.08);
}

/* Nav auth widget (index.html top nav) */
.nav-auth-widget {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Sidebar auth widget */
.sidebar-auth-widget {
  position: relative;
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,0.08);
  margin-top: auto;
}

/* ===== PROFILE PAGE STYLES ===== */

.profile-wrapper {
  margin-left: var(--nav-w);
  padding: 3rem;
  min-height: 100vh;
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2rem;
}

.profile-avatar-lg {
  width: 4.5rem;
  height: 4.5rem;
  border-radius: 50%;
  background: var(--chapter-color, #8b5cf6);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.profile-name {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.profile-email {
  font-size: 0.9375rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.profile-joined {
  font-size: 0.8125rem;
  color: var(--text-light);
}

.profile-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 2.5rem;
}

.stat-card {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  text-align: center;
}

.stat-card-num {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  color: var(--chapter-color, #8b5cf6);
  margin-bottom: 0.375rem;
  line-height: 1;
}

.stat-card-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-weight: 500;
}

.profile-section-title {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1rem;
  letter-spacing: 0.02em;
}

/* Chapter progress */
.chapter-progress-list {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.chapter-progress-item {}

.chapter-progress-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.375rem;
}

.chapter-progress-name {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
}

.chapter-progress-pct {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--chapter-color, #8b5cf6);
}

.chapter-progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.chapter-progress-fill {
  height: 100%;
  background: var(--chapter-color, #8b5cf6);
  border-radius: 3px;
  transition: width 0.5s ease;
}

/* Quiz history */
.quiz-history-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.quiz-history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.625rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}
.quiz-history-item:last-child { border-bottom: none; }

.quiz-history-chapter {
  color: var(--text);
  font-weight: 500;
  flex: 1;
}

.quiz-history-date {
  color: var(--text-muted);
  font-size: 0.8125rem;
  margin: 0 1rem;
}

.quiz-history-score {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--chapter-color, #8b5cf6);
}

.profile-loading {
  color: var(--text-muted);
  padding: 4rem 2rem;
  text-align: center;
  font-size: 1rem;
}

.profile-signin-prompt {
  padding: 6rem 2rem;
  text-align: center;
}

/* ── Dropdown divider inside auth pill menu ──────────────────────────────── */
.auth-menu-divider {
  height: 1px;
  background: rgba(255,255,255,0.08);
  margin: 0.25rem 0.5rem;
}

/* ===== SETTINGS PAGE STYLES ===== */

.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  margin-bottom: 1.5rem;
}

.settings-section-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 0.35rem;
}

.settings-section-desc {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin: 0 0 1.5rem;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.settings-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.settings-input-row {
  display: flex;
  gap: 0.625rem;
  align-items: center;
}

.settings-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.875rem;
  font-size: 0.9375rem;
  color: var(--text);
  font-family: var(--font-sans);
  transition: border-color 0.15s;
  width: 100%;
}
.settings-input:focus {
  outline: none;
  border-color: var(--chapter-color, #8b5cf6);
  box-shadow: 0 0 0 3px rgba(139,92,246,0.15);
}

.settings-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0;
}
.settings-hint code {
  font-family: var(--font-mono);
  background: rgba(255,255,255,0.06);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  font-size: 0.8em;
}

.settings-save-btn {
  padding: 0.55rem 1.25rem;
  background: var(--chapter-color, #8b5cf6);
  color: #ffffff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s;
}
.settings-save-btn:hover { opacity: 0.88; }
.settings-save-btn:disabled { opacity: 0.5; cursor: default; }

.settings-msg {
  font-size: 0.875rem;
  min-height: 1.25rem;
  margin-top: 0.25rem;
}
.settings-msg-ok  { color: #22c55e; }
.settings-msg-err { color: #ef4444; }

/* Danger zone */
.settings-danger-zone {
  border-color: rgba(239,68,68,0.25);
}
.danger-title { color: #ef4444; }

.settings-delete-btn {
  padding: 0.55rem 1.25rem;
  background: transparent;
  color: #ef4444;
  border: 1.5px solid #ef4444;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.settings-delete-btn:hover {
  background: #ef4444;
  color: #ffffff;
}
.settings-delete-btn:disabled { opacity: 0.5; cursor: default; }

.settings-cancel-btn {
  padding: 0.55rem 1.25rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.settings-cancel-btn:hover { background: rgba(255,255,255,0.06); }

/* Delete confirmation overlay */
.sett-confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 500;
  align-items: center;
  justify-content: center;
}
.sett-confirm-overlay.open { display: flex; }

.sett-confirm-card {
  background: var(--surface);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius-lg);
  padding: 2rem;
  max-width: 420px;
  width: 90%;
  box-shadow: var(--shadow-lg);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1280px) {
  :root { --viz-w: 400px; }
}

@media (max-width: 1100px) {
  .viz-panel { display: none; }
  .chapter-wrapper { flex-direction: column; }
  .chapter-content { max-width: 100%; padding: 0 2rem; }
}

@media (max-width: 768px) {
  :root { --nav-w: 0px; }

  /* ── Sidebar → slide-in drawer ──────────────────────────────── */
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    z-index: 300;
    width: min(260px, 85vw);
    box-shadow: none;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 32px rgba(0,0,0,.4);
  }

  /* ── Dim overlay ────────────────────────────────────────────── */
  .mobile-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 299;
    cursor: pointer;
  }
  .mobile-overlay.visible { display: block; }

  /* ── Hamburger button ───────────────────────────────────────── */
  .mobile-ham-btn {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    position: fixed;
    top: 0.875rem; left: 0.875rem;
    z-index: 298;
    width: 40px; height: 40px;
    padding: 9px;
    background: var(--nav-bg);
    border: 1px solid var(--nav-border);
    border-radius: var(--radius);
    cursor: pointer;
  }
  .mobile-ham-btn span {
    display: block;
    height: 2px; width: 100%;
    background: #94a3b8;
    border-radius: 2px;
    transition: transform 0.2s, opacity 0.2s;
    transform-origin: center;
  }
  .mobile-ham-btn.is-open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .mobile-ham-btn.is-open span:nth-child(2) { opacity: 0; }
  .mobile-ham-btn.is-open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  /* ── Push content down to clear the hamburger ───────────────── */
  .chapter-page > div { padding-top: 3.75rem; }

  /* ── Chapter layout ─────────────────────────────────────────── */
  .chapter-wrapper { margin-left: 0; flex-direction: column; }
  .chapter-content { padding: 1rem 1.25rem 2rem; max-width: 100%; }
  .chapter-num { font-size: 0.75rem; }
  .chapter-content h1 { font-size: 1.75rem; }

  /* ── Practice layout ─────────────────────────────────────────── */
  .practice-wrapper { margin-left: 0; padding: 3.75rem 1.25rem 3rem; }
  .practice-content { max-width: 100%; }

  /* ── Quiz components ─────────────────────────────────────────── */
  .quiz-card { padding: 1.375rem 1.125rem; }
  .quiz-question { font-size: 0.9375rem; line-height: 1.65; margin-bottom: 1.25rem; }
  .quiz-options { gap: 0.5rem; }
  .quiz-option { padding: 0.75rem 0.875rem; font-size: 0.875rem; gap: 0.625rem; }
  .opt-letter { width: 1.375rem; height: 1.375rem; font-size: 0.65rem; }
  .quiz-chapter-title { font-size: 1.25rem; margin-bottom: 0.875rem; }
  .quiz-count { font-size: 0.75rem; }
  .quiz-next { width: 100%; justify-content: center; }
  .quiz-score-card { padding: 2.5rem 1rem; }
  .quiz-score-number { font-size: 3.25rem; }
  .quiz-score-actions { flex-direction: column; align-items: stretch; }
  .quiz-btn-ghost { width: 100%; justify-content: center; text-align: center; }
  .quiz-start-prompt { padding: 3.5rem 1.5rem; }
  .quiz-start-prompt h2 { font-size: 1.5rem; }

  /* ── AP mode buttons ─────────────────────────────────────────── */
  .ap-mode-btn { font-size: 0.8rem; padding: 0.38rem 0.75rem; }

  /* ── Index page ──────────────────────────────────────────────── */
  .top-nav .nav-links { display: none; }
  .top-nav { padding: 0 1.25rem; }
  .hero-content { padding: 5rem 1.5rem 3rem; }
  .hero-content h1 { font-size: 2.5rem !important; }
  .chapters-section { padding: 3rem 1.25rem; }
  .chapters-grid { grid-template-columns: 1fr; }
}
