/* ═══════════════════════════════════════════════════════════════
   PRICE SCHOOL — Complete stylesheet
   Mobile-first · Light/dark theme · Collapsible sidebar
   ═══════════════════════════════════════════════════════════════ */

/* ── THEME TOKENS ───────────────────────────────────────────── */
:root {
  color-scheme: dark;
  --bg:        #0c0c10;
  --bg2:       #121218;
  --surface:   #18181f;
  --surface2:  #1f1f28;
  --border:    #2c2c3a;
  --border2:   #3a3a4c;
  --text:      #ede8df;
  --text2:     #a8a299;
  --muted:     #686478;
  --bull:      #3ecf7a;
  --bull-bg:   rgba(62,207,122,.10);
  --bear:      #f2495e;
  --bear-bg:   rgba(242,73,94,.10);
  --gold:      #f5b500;
  --gold2:     #ffd050;
  --gold-bg:   rgba(245,181,0,.12);
  --violet:    #a78bfa;
  --violet-bg: rgba(167,139,250,.12);
  --cyan:      #5eead4;
  --cyan-bg:   rgba(94,234,212,.12);
  --shadow-sm: 0 2px 8px rgba(0,0,0,.35);
  --shadow:    0 4px 24px rgba(0,0,0,.5);
  --shadow-lg: 0 12px 48px rgba(0,0,0,.7);
  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 16px;
  --ease:      cubic-bezier(.4,0,.2,1);
  --sidebar-w: 300px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg:        #f3f0ea;
  --bg2:       #e8e4db;
  --surface:   #ffffff;
  --surface2:  #f0ece4;
  --border:    #ddd8ce;
  --border2:   #cac4b8;
  --text:      #1c1c24;
  --text2:     #4e4b5a;
  --muted:     #8e8a98;
  --bull:      #16a34a;
  --bull-bg:   rgba(22,163,74,.08);
  --bear:      #dc2626;
  --bear-bg:   rgba(220,38,38,.08);
  --gold:      #b87500;
  --gold2:     #d4960a;
  --gold-bg:   rgba(184,117,0,.10);
  --violet:    #7c3aed;
  --violet-bg: rgba(124,58,237,.10);
  --cyan:      #0891b2;
  --cyan-bg:   rgba(8,145,178,.10);
  --shadow-sm: 0 2px 8px rgba(0,0,0,.06);
  --shadow:    0 4px 24px rgba(0,0,0,.10);
  --shadow-lg: 0 12px 48px rgba(0,0,0,.18);
}

/* ── RESET + BASE ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  height: 100%;
  overflow: hidden;
}
h1,h2,h3,h4,h5,h6 { margin: 0; line-height: 1.2; }
p { margin: 0 0 1em; }
p:last-child { margin-bottom: 0; }
button { font-family: inherit; cursor: pointer; }
svg { display: block; }

/* ── LAYOUT ──────────────────────────────────────────────────── */
body { display: flex; }

/* Sidebar overlay (mobile) — sits above the genie when shown so the
   modal sidebar appears layered correctly. */
.nav-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 99;
  backdrop-filter: blur(2px);
}
.nav-overlay.show { display: block; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  transition: width .28s var(--ease), transform .28s var(--ease);
  z-index: 91;
}
.sidebar.collapsed { width: 0; border-right-width: 0; }

/* App body */
.app-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
}

/* Topbar (mobile mainly) */
.topbar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: 52px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-title {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-right { display: flex; align-items: center; gap: 4px; }
.topbar-pos {
  font-size: 12px;
  color: var(--muted);
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
}

/* Sidebar tab (desktop, when collapsed) */
.sidebar-tab {
  display: none;
  position: fixed;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 12px 8px;
  color: var(--muted);
  transition: color .15s, background .15s;
  z-index: 10;
}
.sidebar-tab:hover { color: var(--gold); background: var(--surface2); }
.sidebar-tab svg { width: 18px; height: 18px; }
.sidebar.collapsed ~ .app-body .sidebar-tab { display: flex; }

/* Stage */
.stage {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.stage::-webkit-scrollbar { width: 6px; }
.stage::-webkit-scrollbar-track { background: transparent; }
.stage::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

.lesson-frame {
  max-width: 820px;
  margin: 0 auto;
  padding: 40px 32px 80px;
  position: relative;
}

/* ── ICON BUTTONS ────────────────────────────────────────────── */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text2);
  transition: color .15s, background .15s, border-color .15s;
  flex-shrink: 0;
}
.icon-btn:hover { color: var(--text); background: var(--surface2); border-color: var(--border); }
.icon-btn svg { width: 18px; height: 18px; }

/* Theme toggle icons */
[data-theme="dark"]  .svg-light { display: none; }
[data-theme="dark"]  .svg-dark  { display: block; }
[data-theme="light"] .svg-dark  { display: none; }
[data-theme="light"] .svg-light { display: block; }

/* ── SIDEBAR HEADER ──────────────────────────────────────────── */
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-dot {
  width: 10px; height: 10px;
  background: var(--gold);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--gold);
  flex-shrink: 0;
}
.brand-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}
.brand-sub { font-size: 11px; color: var(--muted); }
.sidebar-hdr-right { display: flex; gap: 4px; }
.sidebar-x { /* only visible on mobile */ }

/* ── PROGRESS STRIP ──────────────────────────────────────────── */
.progress-strip {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.prog-track {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 8px;
}
.prog-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--gold2));
  border-radius: 2px;
  transition: width .5s var(--ease);
  width: 0%;
}
.prog-label {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--muted);
}
.prog-label b { color: var(--text2); font-weight: 500; }

/* ── LESSON LIST ─────────────────────────────────────────────── */
.lesson-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}
.lesson-list::-webkit-scrollbar { width: 4px; }
.lesson-list::-webkit-scrollbar-thumb { background: var(--border2); }

.chapter-header {
  padding: 14px 16px 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex; align-items: center; gap: 8px;
}
.chapter-header::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}

.nav-item {
  display: flex; align-items: center;
  gap: 10px;
  padding: 9px 16px;
  cursor: pointer;
  border-left: 2px solid transparent;
  color: var(--text2);
  transition: background .12s, border-color .12s, color .12s;
  font-size: 13px;
  user-select: none;
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active {
  background: var(--gold-bg);
  border-left-color: var(--gold);
  color: var(--text);
}
.nav-item.done { color: var(--text2); }
.nav-num {
  font-size: 10px; color: var(--muted);
  min-width: 20px; text-align: right;
  font-variant-numeric: tabular-nums;
}
.nav-item.active .nav-num { color: var(--gold); }
.nav-title { flex: 1; line-height: 1.3; }
.nav-check {
  width: 16px; height: 16px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.nav-check svg { width: 14px; height: 14px; }
.nav-item.done .nav-check { color: var(--bull); }
.nav-item:not(.done) .nav-check { color: var(--border2); }

/* ── SIDEBAR FOOTER ──────────────────────────────────────────── */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.reset-btn {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 12px;
  padding: 8px;
  transition: color .15s, border-color .15s;
}
.reset-btn:hover { color: var(--bear); border-color: var(--bear); }

/* ── LESSON FRAME ────────────────────────────────────────────── */
.lesson-chapter-label {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 10px;
}
.lesson-chapter-label::before {
  content: ""; width: 6px; height: 6px;
  background: var(--gold); border-radius: 50%;
}

.lesson-title-hero {
  font-family: "Fraunces", serif;
  font-variation-settings: "opsz" 144, "SOFT" 60;
  font-weight: 500;
  font-size: clamp(34px, 5.2vw, 56px);
  line-height: 1.05;
  letter-spacing: -.025em;
  color: var(--text);
  margin-bottom: 12px;
}
.lesson-title-hero em {
  font-style: italic;
  color: var(--gold);
  font-weight: 600;
}

.lesson-tagline {
  font-size: 16px;
  color: var(--text);
  font-weight: 400;
  max-width: 640px;
  margin-bottom: 28px;
  line-height: 1.6;
  opacity: 0.92;
}

.lesson-body p { color: var(--text); max-width: 680px; opacity: 0.92; }
.lesson-body p strong { color: var(--text); font-weight: 600; opacity: 1; }

/* ── CHART CARD ──────────────────────────────────────────────── */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  position: relative;
  margin-bottom: 16px;
}
.chart-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
  gap: 8px;
  flex-wrap: wrap;
}
.chart-sym { display: flex; align-items: baseline; gap: 8px; }
.chart-sym .sym { font-size: 13px; font-weight: 600; color: var(--text); letter-spacing: .03em; }
.chart-sym .tf {
  font-size: 10px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 3px;
  padding: 1px 5px; font-family: monospace;
}
.chart-sym .price { font-size: 12px; font-weight: 500; }
.price.bull { color: var(--bull); }
.price.bear { color: var(--bear); }
.chart-actions { display: flex; gap: 6px; flex-wrap: wrap; }

canvas.chart {
  display: block; width: 100%;
  height: clamp(220px, 38vw, 360px);
  cursor: crosshair;
  touch-action: none;
  background: var(--surface);
}

/* ── STEP GUIDE CARD ─────────────────────────────────────────── */
.step-guide {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 0;
  box-shadow: var(--shadow-sm);
  transition: opacity .25s;
}
.step-guide-inner {
  padding: 16px 18px;
}
.step-dot-row {
  display: flex; gap: 4px; margin-bottom: 12px;
}
.step-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--border2); transition: background .25s;
}
.step-dot.active { background: var(--gold); }
.step-dot.done { background: var(--bull); }

.step-text {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  margin-bottom: 14px;
}
.step-text strong { color: var(--text); }
.step-sub {
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 14px;
  margin-top: -8px;
  line-height: 1.55;
}

.step-action-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.step-hint {
  font-size: 12px; color: var(--muted);
  display: flex; align-items: center; gap: 5px;
}
.step-hint .finger { font-size: 15px; }

.step-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--gold);
  color: #0a0a0a;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  padding: 9px 18px;
  transition: background .15s, transform .1s;
}
.step-btn:active { transform: scale(.97); }
.step-btn:hover { background: var(--gold2); }
.step-btn.secondary {
  background: var(--surface2);
  color: var(--text2);
  border: 1px solid var(--border);
}
.step-btn.secondary:hover { color: var(--text); border-color: var(--border2); }

.step-feedback {
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.55;
  border-top: 1px solid var(--border);
  display: none;
  color: var(--text2);
}
.step-feedback.show { display: block; }
.step-feedback.ok { border-top-color: var(--bull); background: var(--bull-bg); }
.step-feedback.ok strong, .step-feedback.ok b { color: var(--bull); }
.step-feedback.no { border-top-color: var(--bear); background: var(--bear-bg); }
.step-feedback.no strong, .step-feedback.no b { color: var(--bear); }

/* ── CONCEPT TILES ───────────────────────────────────────────── */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin: 16px 0;
}
.concept-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.concept-tile h4 {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 6px;
}
.concept-tile p { font-size: 13px; color: var(--text2); margin: 0; line-height: 1.5; }

/* ── MCQ ─────────────────────────────────────────────────────── */
.mcq-wrap { display: grid; gap: 8px; margin: 14px 0; }
.mcq-opt {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  text-align: left;
  font-size: 14px;
  color: var(--text2);
  transition: border-color .15s, background .15s, color .15s;
}
.mcq-opt:hover { border-color: var(--gold); color: var(--text); }
.mcq-opt::before {
  content: "";
  width: 16px; height: 16px;
  border: 1.5px solid var(--border2);
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 1px;
}
.mcq-opt.correct { border-color: var(--bull); background: var(--bull-bg); color: var(--text); }
.mcq-opt.correct::before { background: var(--bull); border-color: var(--bull); }
.mcq-opt.wrong   { border-color: var(--bear); background: var(--bear-bg); }
.mcq-opt.wrong::before   { background: var(--bear); border-color: var(--bear); }
.mcq-opt:disabled { cursor: not-allowed; }

/* ── CHIP BUTTONS ────────────────────────────────────────────── */
.chip-btn {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 12px;
  transition: all .15s;
}
.chip-btn:hover { color: var(--text); border-color: var(--border2); }
.chip-btn.on { background: var(--gold); color: #0a0a0a; border-color: var(--gold); }
.chip-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── LESSON FOOTER NAV ───────────────────────────────────────── */
.lesson-footer {
  display: flex; justify-content: space-between; gap: 12px;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.nav-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-size: 13px;
  font-weight: 500;
  padding: 10px 18px;
  transition: all .15s;
}
.nav-btn:hover { border-color: var(--border2); color: var(--text); }
.nav-btn:disabled { opacity: .3; cursor: not-allowed; pointer-events: none; }
.nav-btn.advance {
  background: var(--gold);
  color: #0a0a0a;
  border-color: var(--gold);
  font-weight: 600;
}
.nav-btn.advance:hover { background: var(--gold2); border-color: var(--gold2); }
.nav-btn.advance:disabled { background: var(--surface2); color: var(--muted); border-color: var(--border); }
@keyframes pulse-ring {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245,181,0,.4); }
  50% { box-shadow: 0 0 0 6px rgba(245,181,0,0); }
}
.nav-btn.advance.glow { animation: pulse-ring 1.6s ease infinite; }

/* ── REFERENCES ──────────────────────────────────────────────── */
.references {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.references h5 {
  font-size: 10px; font-weight: 600; letter-spacing: .15em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 10px;
}
.references ul { list-style: none; padding: 0; margin: 0; }
.references li { padding: 3px 0; }
.references a {
  font-size: 12px; color: var(--text2);
  text-decoration: none;
  border-bottom: 1px dashed var(--border2);
  transition: color .15s, border-color .15s;
}
.references a:hover { color: var(--gold2); border-bottom-color: var(--gold); }
.references a::before { content: "→ "; color: var(--gold); }

/* ── ANIMATED CANDLE LESSON ──────────────────────────────────── */
.candle-stage {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  position: relative;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  overflow: hidden;
}
.candle-stage canvas {
  max-width: 280px;
  width: 100%;
}
.candle-caption {
  font-size: 13px; color: var(--text2); max-width: 360px;
  line-height: 1.55;
  text-align: center;
}

/* ── VOCABULARY TABLE (lesson 23) ────────────────────────────── */
.vocab-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 16px 0;
}
.vocab-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 10px; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.vocab-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  line-height: 1.5;
}
.vocab-table td:first-child { color: var(--text); font-weight: 500; }
.vocab-table td:nth-child(2) { color: var(--gold2); font-weight: 600; font-size: 12px; font-family: monospace; }
.vocab-table td:last-child { color: var(--text2); }
.vocab-table tr:last-child td { border-bottom: none; }

/* ── FINALE SCREEN ───────────────────────────────────────────── */
.finale-score {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px; margin: 20px 0;
}
.score-cell {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
}
.score-cell .sc-lab {
  font-size: 10px; font-weight: 600; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 6px;
}
.score-cell .sc-val {
  font-family: "Fraunces", serif; font-size: 28px;
  font-weight: 300; color: var(--gold2);
}

/* ── SECTION RULE ────────────────────────────────────────────── */
.section-rule {
  display: flex; align-items: center; gap: 12px;
  margin: 28px 0 16px;
}
.section-rule::before { content: ""; width: 14px; height: 1.5px; background: var(--gold); }
.section-rule h3 {
  font-size: 17px; font-weight: 500; color: var(--text);
  letter-spacing: -.01em;
}
.section-rule .sr-sub {
  flex: 1; text-align: right;
  font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ── INLINE FEEDBACK ─────────────────────────────────────────── */
.feedback {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.55;
  margin-top: 10px;
  display: none;
  color: var(--text2);
  border-left: 2px solid var(--border);
}
.feedback.show { display: block; animation: fadein .25s; }
.feedback.ok { border-left-color: var(--bull); background: var(--bull-bg); }
.feedback.ok b, .feedback.ok strong { color: var(--bull); }
.feedback.no { border-left-color: var(--bear); background: var(--bear-bg); }
.feedback.no b, .feedback.no strong { color: var(--bear); }

@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

/* ── FINAL MISSION GATES ─────────────────────────────────────── */
.gate-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px dashed var(--border);
}
.gate-label {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted); margin-bottom: 10px;
}
.gate-label.unlocked { color: var(--gold); }
.gate-label .gate-icon { font-size: 13px; }

/* ── MOBILE ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
  body { overflow: hidden; }

  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100dvh;
    width: min(85vw, 320px) !important;
    transform: translateX(-100%);
    transition: transform .28s var(--ease);
    box-shadow: var(--shadow-lg);
    z-index: 91;
    border-right: 1px solid var(--border);
  }
  .sidebar.open {
    transform: translateX(0);
    /* When the menu is open it acts as a modal — must sit above the
       genie (z-index 95) so the lesson list isn't obscured. */
    z-index: 100;
  }
  .sidebar.collapsed {
    transform: translateX(-100%);
  }

  .topbar { display: flex; }
  .sidebar-tab { display: none !important; }

  .app-body { height: 100dvh; overflow: hidden; }
  .stage { height: calc(100dvh - 52px); }

  .lesson-frame { padding: 20px 16px 80px; }
  .lesson-title-hero { font-size: 28px; }
  .lesson-tagline { font-size: 14px; margin-bottom: 20px; }

  canvas.chart { height: clamp(210px, 50vw, 280px); }

  .step-text { font-size: 14px; }
  .tile-grid { grid-template-columns: 1fr; }

  .finale-score { grid-template-columns: 1fr 1fr; }
  .mcq-opt { font-size: 13px; }

  .lesson-footer { flex-direction: column; gap: 8px; }
  .nav-btn { justify-content: center; padding: 13px 18px; }

  .section-rule h3 { font-size: 15px; }
}

/* ── DESKTOP sidebar toggle ─────────────────────────────────── */
@media (min-width: 769px) {
  .topbar { display: none; }
  .sidebar-x { display: none; }
  .nav-overlay { display: none !important; }

  .sidebar-tab {
    display: flex;
  }
  .sidebar:not(.collapsed) ~ .app-body .sidebar-tab {
    display: none;
  }
}

/* ── TRANSITIONS ─────────────────────────────────────────────── */
.sidebar, .app-body { transition: none; }

/* ── MISC UTILITIES ──────────────────────────────────────────── */
.text-gold { color: var(--gold2); }
.text-bull { color: var(--bull); }
.text-bear { color: var(--bear); }
.text-muted { color: var(--muted); }
.mono { font-family: monospace; }
.mt-0 { margin-top: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

/* ══════════════════════════════════════════════════════════════
   GENIE  ·  fixed on viewport, free-roaming, with extending stick
   ══════════════════════════════════════════════════════════════ */

/* Highlight applied to the element the genie is currently pointing at —
   so the user can SEE what to click. A pulsing gold ring + soft glow.
   Doesn't change the element's size or layout. */
.toon-highlight {
  position: relative;
  z-index: 5;
  outline: 2px solid var(--gold) !important;
  outline-offset: 3px;
  border-radius: 10px;
  box-shadow:
    0 0 0 4px rgba(245, 181, 0, 0.18),
    0 0 28px 4px rgba(245, 181, 0, 0.45) !important;
  animation: toon-highlight-pulse 1.4s ease-in-out infinite;
}
@keyframes toon-highlight-pulse {
  0%, 100% {
    box-shadow:
      0 0 0 4px rgba(245, 181, 0, 0.18),
      0 0 28px 4px rgba(245, 181, 0, 0.40);
  }
  50% {
    box-shadow:
      0 0 0 6px rgba(245, 181, 0, 0.30),
      0 0 36px 8px rgba(245, 181, 0, 0.65);
  }
}

/* Stick layer: full-viewport SVG that draws the wand from genie hand
   to whatever the genie is pointing at. MUST sit above the bubble so
   the wand is never obscured — the wand is the user's primary cue for
   where to look, and a thin gold line crossing some bubble text is
   far less broken than a wand that vanishes into the bubble. */
.genie-stick-layer {
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  pointer-events: none;
  z-index: 96;
  transition: opacity .25s var(--ease);
  overflow: visible;
}

/* The genie wrapper — fixed to viewport, moved with transform.
   Width/height are fixed; the bubble is absolute-positioned to
   one side without affecting the wrap's bounding box.
   z-index sits ABOVE the sidebar (91) so the bubble can overlay
   the sidebar when the layout is too tight to fit it elsewhere. */
.genie-wrap {
  position: fixed;
  top: 0; left: 0;
  width: 110px;
  height: 192px;
  z-index: 95;
  pointer-events: none;
  will-change: transform;
}
.genie-wrap > * { pointer-events: auto; }

/* The genie character SVG fills the wrap. */
.genie-char {
  width: 100%;
  height: 100%;
  cursor: pointer;
  filter: drop-shadow(0 6px 18px rgba(124,58,237,.55));
  transition: filter .2s;
}
.genie-char:hover { filter: drop-shadow(0 6px 24px rgba(124,58,237,.8)); }
.genie-svg {
  width: 100%; height: 100%;
  display: block;
  animation: genie-float 3.4s ease-in-out infinite;
  transform-origin: 50% 80%;
}

@keyframes genie-float {
  0%, 100% { transform: translateY(0) rotate(0); }
  30%       { transform: translateY(-6px) rotate(1.5deg); }
  70%       { transform: translateY(-3px) rotate(-1deg); }
}

/* Mood animations */
[data-mood="happy"] .genie-svg {
  animation: genie-joy .7s ease, genie-float 3.4s ease-in-out .7s infinite;
}
@keyframes genie-joy {
  0%   { transform: scale(1) rotate(0); }
  30%  { transform: scale(1.14) rotate(-5deg) translateY(-10px); }
  60%  { transform: scale(1.06) rotate(5deg) translateY(-5px); }
  100% { transform: scale(1) rotate(0) translateY(0); }
}
[data-mood="thinking"] .genie-svg {
  animation: genie-think 1.6s ease-in-out infinite;
}
@keyframes genie-think {
  0%, 100% { transform: rotate(-3deg); }
  50%       { transform: rotate(3deg) translateY(-4px); }
}
[data-mood="wrong"] .genie-svg { animation: genie-shake .55s ease; }
@keyframes genie-shake {
  0%,100% { transform: rotate(0); }
  20% { transform: rotate(-7deg); } 40% { transform: rotate(7deg); }
  60% { transform: rotate(-4deg); } 80% { transform: rotate(4deg); }
}

/* ── Speech bubble ─────────────────────────────────────────────
   Absolute positioned relative to the wrap. Pops out to whichever
   side the placement code decides (bubble-side-left/right). */
.genie-bubble {
  position: absolute;
  top: 8px;
  width: 280px;
  max-width: calc(100vw - 24px);
  background: var(--surface);
  border: 2px solid var(--gold);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow:
    0 0 0 4px rgba(245,181,0,.10),
    0 12px 36px rgba(0,0,0,.45);
  opacity: 0;
  transform: scale(.92) translateY(6px);
  transition: opacity .25s var(--ease), transform .25s var(--ease);
  pointer-events: auto;
}
.genie-bubble.show {
  opacity: 1;
  transform: scale(1) translateY(0);
}

/* Bubble side: left of the genie */
.genie-wrap.bubble-side-left .genie-bubble {
  right: calc(100% + 12px);
}
/* Bubble side: right of the genie */
.genie-wrap.bubble-side-right .genie-bubble {
  left: calc(100% + 12px);
}

/* Tail / pointer triangle on the bubble pointing toward the genie */
.genie-bubble::after {
  content: "";
  position: absolute;
  top: 28px;
  width: 0; height: 0;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
}
.genie-wrap.bubble-side-left  .genie-bubble::after {
  right: -10px;
  border-left: 10px solid var(--gold);
}
.genie-wrap.bubble-side-right .genie-bubble::after {
  left: -10px;
  border-right: 10px solid var(--gold);
}

/* Bubble text — BIG, BOLD, HIGH-CONTRAST so readers don't strain. */
.genie-bubble-text {
  font-size: 15.5px;
  line-height: 1.55;
  color: var(--text);
  font-weight: 500;
  letter-spacing: -0.005em;
}
.genie-bubble-text b,
.genie-bubble-text strong {
  color: var(--text);
  font-weight: 700;
  background: linear-gradient(transparent 70%, rgba(245,181,0,.30) 70%);
  padding: 0 2px;
}

.genie-btn-slot { margin-top: 10px; }
.genie-btn-slot:empty { margin-top: 0; }

/* Action button inside the bubble */
.genie-btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  background: var(--gold);
  color: #0a0a0a;
  border: none; border-radius: 8px;
  font-size: 14.5px; font-weight: 700; padding: 10px 18px;
  cursor: pointer; font-family: inherit;
  width: 100%;
  transition: background .15s, transform .1s, box-shadow .15s;
  box-shadow: 0 2px 0 rgba(0,0,0,.18);
}
.genie-btn:hover    { background: var(--gold2); }
.genie-btn:active   { transform: translateY(1px); box-shadow: 0 1px 0 rgba(0,0,0,.18); }
.genie-btn:disabled { opacity: .55; cursor: default; }

/* Hint text inside bubble (e.g. "👆 Tap a green bar") */
.genie-hint {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--gold2);
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  background: var(--gold-bg);
  border-radius: 6px;
  border-left: 3px solid var(--gold);
}

/* ── Light theme adjustments ─────────────────────────────────── */
:root[data-theme="light"] .genie-bubble {
  background: #ffffff;
  box-shadow:
    0 0 0 4px rgba(184,117,0,.10),
    0 12px 36px rgba(0,0,0,.18);
}
:root[data-theme="light"] .genie-bubble-text b,
:root[data-theme="light"] .genie-bubble-text strong {
  background: linear-gradient(transparent 70%, rgba(184,117,0,.28) 70%);
}
:root[data-theme="light"] .genie-char {
  filter: drop-shadow(0 6px 14px rgba(124,58,237,.30));
}

/* ── Mobile sizing ─────────────────────────────────────────────
   Smaller genie + smaller bubble so they fit narrow screens.
   Note: keep these in sync with the SIZE constants in toon.js. */
@media (max-width: 768px) {
  .genie-wrap {
    width: 80px;
    height: 140px;
  }
  .genie-bubble {
    width: 210px;
    padding: 11px 13px;
    border-radius: 12px;
  }
  .genie-bubble-text {
    font-size: 14px;
    line-height: 1.5;
  }
  .genie-btn {
    font-size: 13.5px;
    padding: 9px 14px;
  }
  .genie-hint {
    font-size: 12.5px;
    padding: 5px 8px;
  }
  .genie-bubble::after { top: 22px; }
}

/* On VERY narrow screens (e.g. 320px) prevent bubble overflow */
@media (max-width: 360px) {
  .genie-bubble { width: 180px; font-size: 13px; }
  .genie-bubble-text { font-size: 13px; }
}

/* ══════════════════════════════════════════════════════════════
   MAGNIFIER (opt-in icon button)
   ══════════════════════════════════════════════════════════════ */
.mag-glass {
  position: fixed;
  width: 148px; height: 148px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 9999;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity .2s var(--ease), transform .2s var(--ease);
  overflow: hidden;
  background: var(--surface);
}
.mag-glass.visible { opacity: 1; transform: scale(1); }
.mag-rim {
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 3px solid var(--gold);
  box-shadow: 0 0 0 6px rgba(245,181,0,.1), inset 0 0 20px rgba(245,181,0,.05), 0 8px 32px rgba(0,0,0,.5);
  z-index: 2; pointer-events: none;
}
.mag-rim::before, .mag-rim::after { content: ""; position: absolute; background: rgba(245,181,0,.12); }
.mag-rim::before { width: 1px; height: 100%; left: 50%; top: 0; }
.mag-rim::after  { width: 100%; height: 1px; top: 50%; left: 0; }
.mag-label {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; overflow: hidden; z-index: 1;
  word-break: break-word;
}

/* ══════════════════════════════════════════════════════════════
   CANDLE ILLUSTRATION (Lesson 02 · Paper.js)
   ══════════════════════════════════════════════════════════════ */
.candle-illustration {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.candle-toggle-row {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
#paperCanvas { display: block; width: 100%; height: 310px; background: var(--surface); }

/* ══════════════════════════════════════════════════════════════
   PAIR SELECTOR
   ══════════════════════════════════════════════════════════════ */
.pair-selector { display: flex; gap: 6px; flex-wrap: wrap; }
@keyframes sym-pulse {
  0%, 100% { color: var(--text); }
  25%, 65% { color: var(--gold); text-shadow: 0 0 14px rgba(245,181,0,.7); }
}
.sym-pulse { animation: sym-pulse 2s ease; }

/* ══════════════════════════════════════════════════════════════
   STEP GUIDE — hide the old bottom card when genie is active
   ══════════════════════════════════════════════════════════════ */
.step-guide.genie-mode .step-dot-row { display: none; }
.step-guide.genie-mode .step-guide-inner { padding-top: 0; }
.step-guide.genie-mode .step-feedback { border-top: none; border-left: 2px solid var(--border); border-radius: var(--radius-sm); margin: 4px 0; }
.step-guide.genie-mode { background: none; border: none; box-shadow: none; }


/* ══════════════════════════════════════════════════════════════
   GENIE EDIT MODE
   ══════════════════════════════════════════════════════════════ */
.genie-edit-toggle {
  font-size: 18px;
  line-height: 1;
  color: var(--text2);
}
.genie-edit-toggle:hover { color: var(--gold); }

.genie-edit-active .genie-char,
.genie-edit-active .genie-bubble {
  outline: 2px dashed rgba(245,181,0,.7);
  outline-offset: 2px;
  cursor: grab;
  /* CRITICAL on mobile: stops the browser from scrolling the page
     when the user starts a touch on the genie / bubble. Without
     this the drag gesture is interpreted as a scroll, the page
     moves under the finger, and the captured scrollY at drag-end
     reflects an accidental scroll rather than the user's intent. */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.genie-edit-active .genie-char:active,
.genie-edit-active .genie-bubble:active { cursor: grabbing; }

.genie-edit-tip-handle {
  /* Tip handle is only created in edit mode — same anti-scroll
     treatment as the genie body. */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  position: fixed;
  top: 0; left: 0;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(245,181,0,0.18);
  border: 2px dashed rgba(245,181,0,0.9);
  z-index: 200;
  cursor: grab;
  pointer-events: auto;
  box-shadow: 0 0 0 4px rgba(245,181,0,0.08);
  transition: opacity .15s ease;
}
.genie-edit-tip-handle:active { cursor: grabbing; background: rgba(245,181,0,0.28); }

.genie-edit-panel {
  position: fixed;
  bottom: 16px; right: 16px;
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 18px 40px rgba(0,0,0,.4);
  padding: 14px;
  z-index: 250;
  font-family: -apple-system, sans-serif;
  font-size: 13px;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.genie-edit-panel .ge-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  color: var(--gold);
  letter-spacing: .02em;
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  width: 100%;
}
.genie-edit-panel .ge-caret {
  font-size: 12px;
  color: var(--text2);
  transition: transform .18s;
}
.genie-edit-panel.ge-collapsed .ge-caret { transform: rotate(-90deg); }
.genie-edit-panel .ge-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
  max-height: 600px;
  transition: max-height .22s ease, opacity .15s ease, margin-top .22s ease;
  margin-top: 4px;
}
.genie-edit-panel.ge-collapsed .ge-body {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
  pointer-events: none;
}
.genie-edit-panel.ge-collapsed { padding: 10px 14px; gap: 0; }
.genie-edit-panel .ge-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text2);
}
.genie-edit-panel .ge-row code {
  font-family: ui-monospace, SFMono-Regular, monospace;
  color: var(--text);
  background: var(--surface2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  max-width: 65%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.genie-edit-panel .ge-actions {
  display: flex;
  gap: 6px;
}
.genie-edit-panel .ge-btn {
  flex: 1;
  padding: 6px 8px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  font-weight: 500;
}
.genie-edit-panel .ge-btn:hover { border-color: var(--gold); color: var(--gold); }
.genie-edit-panel .ge-btn-primary {
  background: var(--gold);
  border-color: var(--gold);
  color: #000;
}
.genie-edit-panel .ge-btn-primary:hover { color: #000; opacity: .9; }
.genie-edit-panel .ge-help {
  font-size: 11px;
  color: var(--text2);
  line-height: 1.4;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

@media (max-width: 768px) {
  .genie-edit-panel { width: calc(100vw - 32px); right: 16px; bottom: 80px; }
}

/* Edit button active state — visible while edit mode is on */
body.genie-edit-active .genie-edit-toggle {
  color: var(--gold);
  background: rgba(245,181,0,0.12);
  border-color: var(--gold);
}

/* Floating fallback (only used if neither sidebar header nor topbar exist) */
.genie-edit-toggle-floating {
  position: fixed;
  top: 12px; right: 12px;
  z-index: 250;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
}

/* ── MENTORSHIP CTA (lesson 22 + vocabulary close) ─────────────── */
.milestone-card {
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin: 8px 0 18px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.milestone-card .milestone-icon {
  font-size: 38px;
  line-height: 1;
  margin-bottom: 6px;
}
.milestone-card h3 {
  margin: 4px 0 6px;
  font-size: 22px;
  color: var(--text);
  font-weight: 600;
}
.milestone-card p {
  margin: 0;
  color: var(--text2);
  font-size: 14px;
  line-height: 1.55;
  max-width: 540px;
  margin-inline: auto;
}

.cta-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--gold);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin: 14px 0;
  box-shadow: var(--shadow-sm);
}
.cta-card.cta-card-secondary {
  border-left-color: var(--bull);
}
.cta-card .cta-pre {
  font-size: 11px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text2);
  margin-bottom: 6px;
  font-weight: 600;
}
.cta-card h3 {
  margin: 0 0 10px;
  font-size: 20px;
  color: var(--text);
  font-weight: 600;
}
.cta-card p {
  margin: 0 0 16px;
  color: var(--text);
  line-height: 1.6;
  font-size: 14.5px;
}

.cta-primary, .cta-secondary {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 12px 22px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
  font-size: 14.5px;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
  border: 1.5px solid transparent;
}
.cta-primary {
  background: var(--gold);
  color: #0a0a0a;
}
.cta-primary:hover {
  background: var(--gold2);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(245,181,0,.30);
}
.cta-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border2);
}
.cta-secondary:hover {
  border-color: var(--bull);
  color: var(--bull);
  transform: translateY(-1px);
}

.cta-inline-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}
