/* ═══════════════════════════════════════════════
   StatLearn — Apple-inspired Design System
   ═══════════════════════════════════════════════ */

/* ── Sidebar as an on-demand drawer at ALL widths (no permanent left column) ── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  transform: translateX(-100%);
  box-shadow: var(--shadow-lg);
  z-index: 250;
}
.sidebar.open { transform: translateX(0); }
.sidebar-overlay.visible { display: block; }
.sidebar-close-btn { display: flex !important; }
#menuBtn { display: flex !important; }
.main { width: 100%; }

/* ── Welcome / cover screen ── */
.welcome {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  background: linear-gradient(140deg, #06203f 0%, #0a4ea3 42%, #0071e3 70%, #8b46d6 120%);
  overflow: hidden;
  transition: opacity 0.55s ease;
}
.welcome.hide { opacity: 0; pointer-events: none; }
/* daily web cover image */
.welcome-bg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; z-index: 0; opacity: 0;
  transition: opacity 0.8s ease;
}
.welcome-bg.loaded { opacity: 1; }
.welcome-scrim {
  position: absolute; inset: 0; z-index: 1;
  background: radial-gradient(120% 95% at 50% 22%, rgba(0,0,0,0.12), rgba(0,0,0,0.30) 55%, rgba(0,0,0,0.62) 100%);
}
.welcome::before, .welcome::after {
  content: ""; position: absolute; border-radius: 50%; filter: blur(60px); opacity: 0.5; z-index: 0;
}
.welcome::before { width: 360px; height: 360px; background: #2bb3ff; top: -90px; right: -60px; }
.welcome::after { width: 320px; height: 320px; background: #b266ff; bottom: -100px; left: -70px; }
.welcome-card {
  position: relative; z-index: 2; max-width: 500px; width: 100%; text-align: center; color: #fff;
  background: rgba(255,255,255,0.10);
  backdrop-filter: blur(20px) saturate(1.3); -webkit-backdrop-filter: blur(20px) saturate(1.3);
  border: 1px solid rgba(255,255,255,0.20);
  border-radius: 28px; padding: 38px 32px 32px;
  box-shadow: 0 30px 90px rgba(0,0,0,0.45);
  animation: welcomeIn 0.6s cubic-bezier(0.2,0.8,0.2,1) both;
}
@keyframes welcomeIn { from { opacity: 0; transform: translateY(22px) scale(0.97); } to { opacity: 1; transform: none; } }
.welcome-logo {
  width: 62px; height: 62px; margin: 0 auto 16px; border-radius: 18px;
  background: rgba(255,255,255,0.18); border: 1px solid rgba(255,255,255,0.25);
  display: flex; align-items: center; justify-content: center; font-size: 32px; font-weight: 700;
}
.welcome-meta { display: flex; flex-direction: column; gap: 3px; font-size: 13px; opacity: 0.9; }
.welcome-meta .material-symbols-outlined { font-size: 15px; vertical-align: -3px; margin-right: 3px; }
.welcome-greeting { font-size: 29px; font-weight: 800; letter-spacing: -0.6px; margin: 18px 0 4px; }
.welcome-greeting span { color: #ffd66b; }
.welcome-sub { font-size: 14.5px; opacity: 0.92; margin-bottom: 22px; }
.welcome-quote { border-top: 1px solid rgba(255,255,255,0.2); padding-top: 18px; margin-bottom: 24px; }
.wq-zh { font-size: 17.5px; font-weight: 600; line-height: 1.6; margin-bottom: 7px; }
.wq-en { font-size: 13px; opacity: 0.85; font-style: italic; line-height: 1.55; }
.welcome-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: #fff; color: var(--accent); font-weight: 700; font-size: 15px;
  padding: 13px 30px; border-radius: 99px; cursor: pointer; border: none; font-family: inherit;
  transition: transform 0.2s, box-shadow 0.2s; box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.welcome-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(0,0,0,0.3); }
.welcome-btn .material-symbols-outlined { font-size: 19px; }

/* ── Tokens ── */
:root {
  --bg:            #ffffff;
  --bg-2:          #f5f5f7;
  --bg-3:          #e8e8ed;
  --bg-card:       #ffffff;
  --surface:       rgba(255,255,255,0.85);
  --border:        rgba(0,0,0,0.08);
  --border-strong: rgba(0,0,0,0.14);
  --text-primary:  #1d1d1f;
  --text-secondary:#6e6e73;
  --text-tertiary: #aeaeb2;
  --accent:        #0071e3;
  --accent-hover:  #0077ed;
  --accent-light:  rgba(0,113,227,0.10);
  --accent-light2: rgba(0,113,227,0.06);
  --green:         #34c759;
  --green-light:   rgba(52,199,89,0.12);
  --orange:        #ff9500;
  --orange-light:  rgba(255,149,0,0.12);
  --red:           #ff3b30;
  --red-light:     rgba(255,59,48,0.10);
  --purple:        #af52de;
  --purple-light:  rgba(175,82,222,0.10);
  --sidebar-w:     280px;
  --topbar-h:      56px;
  --radius:        14px;
  --radius-sm:     10px;
  --radius-xs:     7px;
  --shadow-sm:     0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow:        0 4px 16px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.06);
  --shadow-lg:     0 20px 40px rgba(0,0,0,0.12), 0 4px 12px rgba(0,0,0,0.08);
  --transition:    0.2s cubic-bezier(0.4,0,0.2,1);
  --font-mono:     'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
}

[data-dark="1"] {
  --bg:            #000000;
  --bg-2:          #1c1c1e;
  --bg-3:          #2c2c2e;
  --bg-card:       #1c1c1e;
  --surface:       rgba(28,28,30,0.92);
  --border:        rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.14);
  --text-primary:  #f5f5f7;
  --text-secondary:#98989d;
  --text-tertiary: #636366;
  --accent:        #2997ff;
  --accent-hover:  #409cff;
  --accent-light:  rgba(41,151,255,0.14);
  --accent-light2: rgba(41,151,255,0.07);
  --green:         #30d158;
  --green-light:   rgba(48,209,88,0.14);
  --orange:        #ff9f0a;
  --orange-light:  rgba(255,159,10,0.14);
  --red:           #ff453a;
  --red-light:     rgba(255,69,58,0.14);
  --purple:        #bf5af2;
  --purple-light:  rgba(191,90,242,0.14);
  --shadow-sm:     0 1px 3px rgba(0,0,0,0.3);
  --shadow:        0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg:     0 20px 40px rgba(0,0,0,0.5);
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  overflow: hidden;
  height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }

/* ── Layout ── */
#app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  flex-shrink: 0;
  overflow: hidden;
  transition: transform var(--transition);
  z-index: 200;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-mark {
  width: 38px; height: 38px;
  background: var(--accent);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,113,227,0.35);
}

.logo-name {
  font-size: 15px; font-weight: 700;
  color: var(--text-primary); line-height: 1.2;
  letter-spacing: -0.3px;
}

.logo-sub {
  font-size: 10px; font-weight: 500;
  color: var(--text-tertiary); text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sidebar-close-btn { display: none; }

/* Overall progress */
.sidebar-progress {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.progress-row {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 6px;
}

.progress-label { font-size: 11px; font-weight: 500; color: var(--text-secondary); }
.progress-pct   { font-size: 11px; font-weight: 600; color: var(--accent); }

.progress-track {
  height: 4px; background: var(--bg-3); border-radius: 99px; overflow: hidden;
}

.progress-bar {
  height: 100%; background: var(--accent); border-radius: 99px;
  transition: width 0.5s cubic-bezier(0.4,0,0.2,1);
}

/* Search */
.search-wrap {
  position: relative;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.search-ico {
  position: absolute; left: 22px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; color: var(--text-tertiary);
}

#searchInput {
  width: 100%; padding: 7px 10px 7px 32px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font-size: 13px; color: var(--text-primary);
  outline: none; transition: border-color var(--transition), box-shadow var(--transition);
}

#searchInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

#searchInput::placeholder { color: var(--text-tertiary); }

/* Chapter nav */
.chap-nav {
  flex: 1; overflow-y: auto; padding: 8px 0 20px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}

.chap-nav::-webkit-scrollbar { width: 4px; }
.chap-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

.chap-group { margin-bottom: 4px; }

.chap-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px 6px;
  cursor: pointer; user-select: none;
  transition: background var(--transition);
  border-radius: 0;
}

.chap-header:hover { background: var(--border); }

.chap-header-left { display: flex; align-items: center; gap: 9px; }

.chap-icon {
  width: 26px; height: 26px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; flex-shrink: 0;
}

.chap-title-text {
  font-size: 12px; font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.4px;
  line-height: 1.3;
}

.chap-chevron {
  width: 14px; height: 14px; color: var(--text-tertiary);
  transition: transform var(--transition); flex-shrink: 0;
}

.chap-group.open .chap-chevron { transform: rotate(90deg); }

.chap-lessons {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s cubic-bezier(0.4,0,0.2,1);
}

.chap-group.open .chap-lessons { max-height: 800px; }

.lesson-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 16px 7px 24px;
  cursor: pointer; border-radius: 0;
  transition: background var(--transition);
  position: relative;
}

.lesson-item:hover { background: var(--border); }

.lesson-item.active {
  background: var(--accent-light);
}

.lesson-item.active::before {
  content: '';
  position: absolute; left: 0; top: 20%; bottom: 20%;
  width: 3px; background: var(--accent); border-radius: 0 3px 3px 0;
}

.lesson-dot {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border-strong); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}

.lesson-item.done .lesson-dot {
  background: var(--green); border-color: var(--green);
}

.lesson-item.done .lesson-dot::after {
  content: '';
  width: 6px; height: 4px;
  border-left: 1.5px solid #fff; border-bottom: 1.5px solid #fff;
  transform: rotate(-45deg) translateY(-1px);
  display: block;
}

.lesson-item.active .lesson-dot { border-color: var(--accent); background: var(--accent-light); }

.lesson-item-text { flex: 1; min-width: 0; }

.lesson-item-title {
  font-size: 13px; font-weight: 500;
  color: var(--text-primary); line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.lesson-item.active .lesson-item-title { color: var(--accent); font-weight: 600; }

.lesson-item-dur {
  font-size: 10px; color: var(--text-tertiary); margin-top: 1px;
}

/* ── Sidebar overlay (mobile) ── */
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.4); z-index: 150;
  backdrop-filter: blur(2px);
}

/* ── Main ── */
.main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  height: 100%;
  background: var(--bg);
}

/* ── Topbar ── */
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  flex-shrink: 0;
  position: sticky; top: 0; z-index: 100;
}

.icon-btn {
  width: 34px; height: 34px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}

.icon-btn:hover { background: var(--bg-3); color: var(--text-primary); }
.icon-btn svg { width: 18px; height: 18px; }

#menuBtn { display: none; }

.breadcrumb {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 6px;
  list-style: none; overflow: hidden;
}

.breadcrumb li {
  font-size: 14px; color: var(--text-secondary); white-space: nowrap;
}

.breadcrumb li:first-child { font-weight: 600; color: var(--text-primary); }

.breadcrumb li + li::before {
  content: '/';
  margin-right: 6px; color: var(--text-tertiary);
}

.topbar-end { margin-left: auto; }

/* ── Content scroll ── */
.content-scroll {
  flex: 1; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}

.content-scroll::-webkit-scrollbar { width: 6px; }
.content-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

.content-area {
  max-width: 820px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

/* ── HOME PAGE ── */
.home-hero {
  text-align: center;
  padding: 48px 24px 40px;
}

.home-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-light);
  color: var(--accent);
  padding: 5px 14px; border-radius: 99px;
  font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 20px;
}

.home-title {
  font-size: clamp(32px, 5vw, 52px);
  font-weight: 800; letter-spacing: -1.5px;
  line-height: 1.1;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.home-title span { color: var(--accent); }

.home-sub {
  font-size: 17px; color: var(--text-secondary);
  max-width: 520px; margin: 0 auto 32px;
  line-height: 1.65;
}

.home-stats {
  display: flex; justify-content: center; gap: 40px;
  margin-bottom: 48px; flex-wrap: wrap;
}

.home-stat { text-align: center; }
.home-stat-num { font-size: 28px; font-weight: 700; color: var(--text-primary); letter-spacing: -0.5px; }
.home-stat-lbl { font-size: 12px; color: var(--text-secondary); font-weight: 500; margin-top: 2px; }

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 40px;
}

.chapter-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  box-shadow: var(--shadow-sm);
}

.chapter-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--accent);
}

.chapter-card-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; margin-bottom: 14px;
}

.chapter-card-title {
  font-size: 15px; font-weight: 700; color: var(--text-primary);
  margin-bottom: 6px; letter-spacing: -0.2px;
}

.chapter-card-desc {
  font-size: 13px; color: var(--text-secondary); line-height: 1.5;
  margin-bottom: 14px;
}

.chapter-card-meta {
  display: flex; align-items: center; justify-content: space-between;
}

.chapter-card-count {
  font-size: 11px; color: var(--text-tertiary); font-weight: 500;
}

.chapter-card-progress {
  height: 3px; background: var(--bg-3); border-radius: 99px;
  overflow: hidden; margin-top: 10px;
}

.chapter-card-bar { height: 100%; border-radius: 99px; transition: width 0.5s; }

/* ── LESSON PAGE ── */
.lesson-header {
  margin-bottom: 32px;
}

.lesson-meta-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 12px;
}

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 99px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px;
}

.badge-chapter { background: var(--accent-light); color: var(--accent); }
.badge-beginner { background: var(--green-light); color: var(--green); }
.badge-intermediate { background: var(--orange-light); color: var(--orange); }
.badge-advanced { background: var(--red-light); color: var(--red); }
.badge-duration { background: var(--bg-3); color: var(--text-secondary); }

.lesson-title {
  font-size: clamp(24px, 4vw, 36px);
  font-weight: 800; letter-spacing: -0.8px;
  color: var(--text-primary); line-height: 1.15;
  margin-bottom: 12px;
}

.lesson-intro {
  font-size: 17px; color: var(--text-secondary);
  line-height: 1.7; border-left: 3px solid var(--accent);
  padding-left: 16px;
}

/* ── Lesson content typography ── */
.lesson-body h2 {
  font-size: 22px; font-weight: 700; letter-spacing: -0.4px;
  color: var(--text-primary); margin: 36px 0 14px;
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
}

.lesson-body h3 {
  font-size: 18px; font-weight: 700; letter-spacing: -0.3px;
  color: var(--text-primary); margin: 28px 0 10px;
}

.lesson-body h4 {
  font-size: 15px; font-weight: 600; color: var(--text-primary);
  margin: 20px 0 8px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.lesson-body p {
  font-size: 16px; line-height: 1.75; color: var(--text-primary);
  margin-bottom: 16px;
}

.lesson-body ul, .lesson-body ol {
  padding-left: 20px; margin-bottom: 16px;
}

.lesson-body li {
  font-size: 16px; line-height: 1.75; color: var(--text-primary);
  margin-bottom: 6px;
}

.lesson-body strong { font-weight: 700; }
.lesson-body em { font-style: italic; }

.lesson-body code:not(.hljs *) {
  font-family: var(--font-mono);
  font-size: 13.5px;
  background: var(--bg-3);
  color: var(--accent);
  padding: 2px 6px; border-radius: 5px;
}

/* ── Info boxes ── */
.box {
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  margin: 20px 0;
  border-left: 4px solid;
}

.box-info    { background: var(--accent-light2); border-color: var(--accent); }
.box-tip     { background: var(--green-light); border-color: var(--green); }
.box-warning { background: var(--orange-light); border-color: var(--orange); }
.box-key     { background: var(--purple-light); border-color: var(--purple); }

.box-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.6px; margin-bottom: 6px;
}

.box-info .box-title    { color: var(--accent); }
.box-tip .box-title     { color: var(--green); }
.box-warning .box-title { color: var(--orange); }
.box-key .box-title     { color: var(--purple); }

.box p { margin: 0; font-size: 15px; line-height: 1.65; }

/* ── Math display ── */
.math-block {
  overflow-x: auto;
  padding: 16px 20px;
  background: var(--bg-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin: 20px 0;
  text-align: center;
}

/* ── Code section ── */
.code-section {
  margin: 28px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.code-section-header {
  padding: 12px 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}

.code-section-title {
  font-size: 13px; font-weight: 700; color: var(--text-primary);
  display: flex; align-items: center; gap: 8px;
}

.code-section-title::before {
  content: '</>'; font-family: var(--font-mono);
  font-size: 11px; color: var(--text-tertiary);
}

/* Code tabs */
.code-tabs {
  display: flex; gap: 4px;
}

.code-tab {
  padding: 5px 14px; border-radius: var(--radius-xs);
  font-size: 12px; font-weight: 600;
  color: var(--text-secondary); cursor: pointer;
  transition: all var(--transition); border: 1px solid transparent;
  font-family: var(--font-mono);
}

.code-tab:hover { background: var(--bg-3); }

.code-tab[data-lang="r"]      { }
.code-tab[data-lang="python"] { }
.code-tab[data-lang="sas"]    { }

.code-tab.active[data-lang="r"]      { background: #2161a7; color: #fff; border-color: #2161a7; }
.code-tab.active[data-lang="python"] { background: #3472a3; color: #fff; border-color: #3472a3; }
.code-tab.active[data-lang="sas"]    { background: #0071b9; color: #fff; border-color: #0071b9; }

.code-pane { display: none; position: relative; }
.code-pane.active { display: block; }

.code-pane pre {
  margin: 0 !important;
  border-radius: 0 !important;
  font-size: 13.5px !important;
  line-height: 1.6 !important;
  padding: 20px !important;
  overflow-x: auto;
  background: var(--bg-card) !important;
}

.copy-btn {
  position: absolute; top: 10px; right: 10px;
  background: var(--bg-3); border: 1px solid var(--border);
  padding: 5px 10px; border-radius: 6px;
  font-size: 11px; font-weight: 600; color: var(--text-secondary);
  cursor: pointer; transition: all var(--transition);
  font-family: inherit;
  opacity: 0; pointer-events: none;
}

.code-pane:hover .copy-btn { opacity: 1; pointer-events: auto; }
.copy-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.copy-btn.copied { background: var(--green); color: #fff; border-color: var(--green); }

/* ── Exercises section ── */
.exercises-section {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 2px solid var(--border);
}

.exercises-title {
  font-size: 22px; font-weight: 800; letter-spacing: -0.4px;
  color: var(--text-primary); margin-bottom: 6px;
  display: flex; align-items: center; gap: 10px;
}

.exercises-subtitle {
  font-size: 14px; color: var(--text-secondary); margin-bottom: 28px;
}

.question-card {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 20px;
  transition: border-color var(--transition);
  box-shadow: var(--shadow-sm);
}

.question-num {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.6px; color: var(--accent); margin-bottom: 8px;
}

.question-text {
  font-size: 16px; font-weight: 600; color: var(--text-primary);
  line-height: 1.5; margin-bottom: 18px;
}

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

.option-btn {
  width: 100%; text-align: left;
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 16px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--bg);
  cursor: pointer; transition: all var(--transition);
  font-size: 15px; color: var(--text-primary); line-height: 1.5;
  font-family: inherit;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-light2);
}

.option-letter {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--bg-3); border: 1.5px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
  transition: all var(--transition);
}

.option-btn.correct {
  border-color: var(--green); background: var(--green-light);
}
.option-btn.correct .option-letter { background: var(--green); border-color: var(--green); color: #fff; }

.option-btn.wrong {
  border-color: var(--red); background: var(--red-light);
}
.option-btn.wrong .option-letter { background: var(--red); border-color: var(--red); color: #fff; }

.option-btn:disabled { cursor: default; }

.feedback-box {
  margin-top: 14px; padding: 14px 16px;
  border-radius: var(--radius-sm); display: none;
  font-size: 14px; line-height: 1.6;
}

.feedback-box.show { display: block; }
.feedback-box.correct-fb { background: var(--green-light); color: var(--text-primary); border-left: 3px solid var(--green); }
.feedback-box.wrong-fb  { background: var(--red-light);   color: var(--text-primary); border-left: 3px solid var(--red); }

.feedback-title { font-weight: 700; margin-bottom: 4px; }
.feedback-box.correct-fb .feedback-title { color: var(--green); }
.feedback-box.wrong-fb  .feedback-title { color: var(--red); }

.show-answer-btn {
  margin-top: 12px;
  font-size: 13px; font-weight: 600; color: var(--accent);
  background: var(--accent-light); border: none;
  padding: 7px 14px; border-radius: var(--radius-xs);
  cursor: pointer; transition: all var(--transition);
  font-family: inherit; display: none;
}

.show-answer-btn.visible { display: inline-flex; align-items: center; gap: 6px; }
.show-answer-btn:hover { background: var(--accent); color: #fff; }

/* ── Lesson nav ── */
.lesson-nav {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 48px; padding-top: 24px;
  border-top: 1px solid var(--border);
  gap: 12px; flex-wrap: wrap;
}

.nav-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 20px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: all var(--transition); font-family: inherit;
  border: 1.5px solid var(--border); background: var(--bg-card);
  color: var(--text-primary);
}

.nav-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light2); }

.nav-btn-primary {
  background: var(--accent); color: #fff; border-color: var(--accent);
}

.nav-btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }

.nav-btn svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ── Complete banner ── */
.complete-banner {
  background: linear-gradient(135deg, var(--green) 0%, #30a64a 100%);
  color: #fff; padding: 20px 24px; border-radius: var(--radius);
  display: flex; align-items: center; gap: 16px;
  margin: 20px 0;
}

.complete-icon { font-size: 32px; flex-shrink: 0; }
.complete-text h3 { font-size: 17px; font-weight: 700; margin-bottom: 2px; }
.complete-text p { font-size: 14px; opacity: 0.9; }

/* ── Modal ── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 20px;
}

@media (min-width: 600px) {
  .modal-backdrop { align-items: center; }
}

.modal-box {
  background: var(--bg-card);
  border-radius: var(--radius);
  max-width: 560px; width: 100%;
  max-height: 80vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 20px 16px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-card);
  z-index: 1;
}

.modal-head h2 { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }

.modal-body { padding: 20px; }

/* ── Utility ── */
.text-center { text-align: center; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }

/* highlight.js override */
.hljs { background: transparent !important; padding: 0 !important; }
pre code.hljs { display: block; }

/* ── Mobile ── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.visible { display: block; }
  .sidebar-close-btn { display: flex; }
  #menuBtn { display: flex; }

  .content-area { padding: 20px 16px 60px; }

  .chapter-grid { grid-template-columns: 1fr; }

  .home-stats { gap: 24px; }
}

/* ── Transitions / animations ── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.content-area > * { animation: fadeIn 0.3s ease both; }

/* katex override */
.katex-display { overflow-x: auto; overflow-y: hidden; }

/* Formula table */
.formula-table {
  width: 100%; border-collapse: collapse;
  margin: 16px 0; font-size: 14px;
}
.formula-table th, .formula-table td {
  padding: 10px 14px;
  border: 1px solid var(--border);
  text-align: left;
}
.formula-table th {
  background: var(--bg-2); font-weight: 600;
  color: var(--text-secondary); font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.4px;
}
.formula-table tr:nth-child(even) td { background: var(--bg-2); }

/* ═══ Dashboard design system ═══ */
.material-symbols-outlined {
  font-family: 'Material Symbols Outlined';
  font-weight: normal; font-style: normal;
  font-size: 22px; line-height: 1;
  display: inline-block; vertical-align: middle;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  -webkit-font-feature-settings: 'liga'; -webkit-font-smoothing: antialiased;
}

/* score chip in topbar */
.score-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-light); color: var(--accent);
  padding: 5px 12px; border-radius: 99px;
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
  cursor: pointer; transition: background var(--transition);
}
.score-chip:hover { background: var(--accent); color: #fff; }
.score-chip .material-symbols-outlined { font-size: 17px; }
.streak-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--orange-light); color: var(--orange);
  padding: 5px 11px; border-radius: 99px; font-size: 13px; font-weight: 700;
}
.streak-chip .material-symbols-outlined { font-size: 17px; }

/* ── Bottom navigation ── */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 300;
  display: flex; justify-content: space-around; align-items: center;
  height: 60px; padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(1.6); -webkit-backdrop-filter: blur(18px) saturate(1.6);
  border-top: 1px solid var(--border);
}
.bn-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--text-tertiary); cursor: pointer; padding: 6px 0;
  transition: color var(--transition); background: none; border: none; font-family: inherit;
}
.bn-item .material-symbols-outlined { font-size: 23px; }
.bn-item span:last-child { font-size: 10px; font-weight: 600; letter-spacing: 0.2px; }
.bn-item.active { color: var(--accent); }
.bn-item.active .material-symbols-outlined { font-variation-settings: 'FILL' 1, 'wght' 500; }

/* room for bottom nav */
.content-scroll { padding-bottom: 68px; }

/* ── Practice quiz ── */
.practice-quiz { padding-top: 6px; }
.practice-scorebar { display: inline-flex; align-items: baseline; gap: 4px; background: var(--purple-light); color: var(--purple); padding: 8px 16px; border-radius: 99px; font-size: 14px; font-weight: 600; margin: 4px 0 20px; }
.practice-scorebar b { font-size: 18px; font-weight: 800; }
.practice-scorebar .ps-total { color: var(--text-tertiary); }
.practice-q .question-num { color: var(--purple); }
.options-tf { flex-direction: row; gap: 10px; }
.options-tf li { flex: 1; }
.fill-row { display: flex; gap: 8px; flex-wrap: wrap; }
.fill-input { flex: 1; min-width: 180px; padding: 11px 14px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); color: var(--text-primary); font-size: 15px; font-family: inherit; outline: none; transition: border-color var(--transition); }
.fill-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.fill-check { white-space: nowrap; }

/* ── Cloud sync card ── */
.cloud-row { display: flex; gap: 8px; flex-wrap: wrap; }
.cloud-row input {
  flex: 1; min-width: 160px; padding: 11px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text-primary); font-size: 15px; font-family: inherit; outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.cloud-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.cloud-code { letter-spacing: 4px; font-variant-numeric: tabular-nums; text-align: center; }
.cloud-card .nav-btn { white-space: nowrap; }

/* ── Bento dashboard ── */
.dash { max-width: 980px; margin: 0 auto; padding: 24px 20px 40px; }
.dash-greeting { margin-bottom: 20px; }
.dash-hello { font-size: 26px; font-weight: 800; letter-spacing: -0.6px; color: var(--text-primary); }
.dash-hello span { color: var(--accent); }
.dash-sub { font-size: 14px; color: var(--text-secondary); margin-top: 3px; }

.bento {
  display: grid; gap: 16px;
  grid-template-columns: repeat(12, 1fr);
}
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm);
  position: relative; overflow: hidden;
}
.card-glass {
  background: var(--surface);
  backdrop-filter: blur(12px) saturate(1.4); -webkit-backdrop-filter: blur(12px) saturate(1.4);
}
.card-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-secondary); margin-bottom: 12px; display: flex; align-items: center; gap: 7px; }
.card-title .material-symbols-outlined { font-size: 18px; color: var(--accent); }

/* span helpers */
.col-3 { grid-column: span 3; } .col-4 { grid-column: span 4; }
.col-5 { grid-column: span 5; } .col-6 { grid-column: span 6; }
.col-7 { grid-column: span 7; } .col-8 { grid-column: span 8; } .col-12 { grid-column: span 12; }

/* KPI cards */
.kpi { display: flex; flex-direction: column; gap: 2px; }
.kpi-icon { width: 38px; height: 38px; border-radius: 11px; display: flex; align-items: center; justify-content: center; margin-bottom: 10px; }
.kpi-icon .material-symbols-outlined { font-size: 21px; }
.kpi-num { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.kpi-lbl { font-size: 12px; color: var(--text-secondary); font-weight: 500; }

/* Score / level card */
.score-hero { display: flex; align-items: center; gap: 18px; }
.score-big { font-size: 40px; font-weight: 800; letter-spacing: -1.5px; color: var(--accent); font-variant-numeric: tabular-nums; line-height: 1; }
.score-meta { flex: 1; }
.level-badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; color: var(--purple); background: var(--purple-light); padding: 3px 10px; border-radius: 99px; margin-bottom: 8px; }
.level-track { height: 7px; background: var(--bg-3); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.level-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--purple)); border-radius: 99px; transition: width 0.6s; }
.level-hint { font-size: 11px; color: var(--text-tertiary); margin-top: 6px; }

/* progress ring (SVG) */
.ring-wrap { display: flex; align-items: center; justify-content: center; position: relative; }
.ring-bg { stroke: var(--bg-3); }
.ring-fg { stroke: var(--accent); stroke-linecap: round; transform: rotate(-90deg); transform-origin: center; transition: stroke-dashoffset 0.7s cubic-bezier(0.4,0,0.2,1); }
.ring-label { position: absolute; text-align: center; }
.ring-pct { font-size: 22px; font-weight: 800; color: var(--text-primary); }
.ring-sub { font-size: 10px; color: var(--text-tertiary); }

/* badges */
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 12px; }
.badge {
  display: flex; flex-direction: column; align-items: center; gap: 5px; text-align: center;
  opacity: 0.4; filter: grayscale(1); transition: all var(--transition);
}
.badge.earned { opacity: 1; filter: none; }
.badge-ico { width: 44px; height: 44px; border-radius: 13px; display: flex; align-items: center; justify-content: center; }
.badge-ico .material-symbols-outlined { font-size: 24px; color: #fff; }
.badge-name { font-size: 10px; font-weight: 600; color: var(--text-secondary); line-height: 1.2; }

/* continue learning */
.continue-row { display: flex; align-items: center; gap: 14px; cursor: pointer; }
.continue-thumb { width: 46px; height: 46px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0; }
.continue-info { flex: 1; min-width: 0; }
.continue-ch { font-size: 11px; color: var(--text-tertiary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.continue-title { font-size: 15px; font-weight: 700; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.continue-go { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

/* recommended horizontal scroll */
.reco-row { display: flex; gap: 14px; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: thin; }
.reco-row::-webkit-scrollbar { height: 5px; }
.reco-row::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
.reco-card { flex: 0 0 200px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; cursor: pointer; transition: transform var(--transition), border-color var(--transition); }
.reco-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.reco-ico { width: 40px; height: 40px; border-radius: 11px; display: flex; align-items: center; justify-content: center; font-size: 20px; margin-bottom: 10px; }
.reco-title { font-size: 14px; font-weight: 700; color: var(--text-primary); line-height: 1.3; margin-bottom: 4px; }
.reco-desc { font-size: 12px; color: var(--text-secondary); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* recommended reading cards (external links) */
.reco-read { display: flex; flex-direction: column; text-decoration: none; }
.reco-read:hover { text-decoration: none; }
.reco-read-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.reco-tag { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: var(--accent); background: var(--accent-light); padding: 3px 9px; border-radius: 99px; }
.reco-ext { font-size: 17px; color: var(--text-tertiary); }
.reco-read .reco-desc { -webkit-line-clamp: 3; margin-bottom: 10px; }
.reco-src { font-size: 11px; color: var(--text-tertiary); font-weight: 600; display: flex; align-items: center; gap: 4px; margin-top: auto; }
.reco-src .material-symbols-outlined { font-size: 14px; }

/* Daily Paper card */
.paper-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.paper-pick { font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.6px; color: #fff; background: linear-gradient(135deg, var(--accent), var(--purple)); padding: 4px 10px; border-radius: 99px; }
.paper-actions { display: flex; gap: 6px; }
.paper-btn { width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--border); background: var(--bg-2); color: var(--text-secondary); display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all var(--transition); }
.paper-btn:hover { color: var(--accent); border-color: var(--accent); }
.paper-btn.active { color: var(--orange); }
.paper-btn.active .material-symbols-outlined { font-variation-settings: 'FILL' 1; }
.paper-title { font-size: 17px; font-weight: 700; color: var(--text-primary); line-height: 1.35; margin-bottom: 8px; }
.paper-meta { font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.paper-meta b { color: var(--text-primary); font-weight: 600; }
.paper-journal { font-size: 12px; color: var(--accent); font-weight: 600; font-style: italic; margin-bottom: 10px; }
.paper-abstract { font-size: 13.5px; color: var(--text-primary); line-height: 1.6; margin-bottom: 12px; }
.paper-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.paper-tag { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: var(--bg-3); color: var(--text-secondary); }
.paper-link { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--accent); }
.paper-link .material-symbols-outlined { font-size: 17px; }

/* Music card */
.music-src { display: flex; gap: 6px; margin-bottom: 8px; }
.music-srcbtn { flex: 1; padding: 7px; border-radius: var(--radius-xs); border: 1px solid var(--border); background: var(--bg-2); font-size: 12px; font-weight: 600; color: var(--text-secondary); cursor: pointer; transition: all var(--transition); font-family: inherit; display: flex; align-items: center; justify-content: center; gap: 4px; }
.music-srcbtn .material-symbols-outlined { font-size: 15px; }
.music-srcbtn.active { background: var(--purple); color: #fff; border-color: var(--purple); }
.music-note { font-size: 11px; color: var(--text-tertiary); margin-top: 10px; display: flex; align-items: flex-start; gap: 5px; line-height: 1.4; }
.music-note .material-symbols-outlined { font-size: 14px; flex-shrink: 0; }
.music-modes { display: flex; gap: 6px; margin-bottom: 12px; }
.music-mode { flex: 1; padding: 8px; border-radius: var(--radius-xs); border: 1px solid var(--border); background: var(--bg-2); font-size: 12px; font-weight: 600; color: var(--text-secondary); cursor: pointer; transition: all var(--transition); font-family: inherit; display: flex; align-items: center; justify-content: center; gap: 5px; }
.music-mode .material-symbols-outlined { font-size: 16px; }
.music-mode.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.music-now { font-size: 13px; color: var(--text-secondary); margin-bottom: 10px; }
.music-now b { color: var(--text-primary); font-weight: 600; }
.music-embed { border-radius: 12px; overflow: hidden; border: 1px solid var(--border); }
.music-embed iframe { display: block; width: 100%; border: 0; }
.music-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.music-shuffle { font-size: 12px; font-weight: 600; color: var(--accent); cursor: pointer; display: inline-flex; align-items: center; gap: 5px; background: none; border: none; font-family: inherit; }
.music-shuffle .material-symbols-outlined { font-size: 16px; }

/* section header in dash */
.dash-sec-head { display: flex; align-items: center; justify-content: space-between; margin: 26px 0 12px; }
.dash-sec-title { font-size: 17px; font-weight: 800; letter-spacing: -0.3px; color: var(--text-primary); }
.dash-sec-link { font-size: 13px; font-weight: 600; color: var(--accent); cursor: pointer; }

/* glossary */
.glossary-search { margin-bottom: 16px; }
.glossary-item { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 16px; margin-bottom: 10px; }
.glossary-term { font-size: 15px; font-weight: 700; color: var(--text-primary); margin-bottom: 4px; }
.glossary-def { font-size: 14px; color: var(--text-secondary); line-height: 1.55; }
.glossary-src { font-size: 11px; color: var(--text-tertiary); margin-top: 6px; cursor: pointer; }

@media (max-width: 760px) {
  .col-3,.col-4,.col-5,.col-6,.col-7,.col-8 { grid-column: span 12; }
  .col-6.kpi-pair { grid-column: span 6; }
  .dash { padding: 18px 14px 40px; }
}

/* ── Flashcards (flip) ── */
.flashdeck {
  margin: 28px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-2);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.flashdeck-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; font-size: 13px; font-weight: 700; color: var(--text-primary);
  border-bottom: 1px solid var(--border);
}
.flashdeck-counter { font-size: 12px; font-weight: 600; color: var(--purple); font-variant-numeric: tabular-nums; }
.flashdeck-stage { position: relative; padding: 22px 18px; min-height: 200px; display: flex; align-items: center; justify-content: center; }
.flashcard { display: none; width: 100%; max-width: 440px; height: 190px; perspective: 1200px; cursor: pointer; }
.flashcard.active { display: block; animation: fadeIn 0.25s ease; }
.flashcard-inner {
  position: relative; width: 100%; height: 100%;
  transition: transform 0.55s cubic-bezier(0.4,0,0.2,1);
  transform-style: preserve-3d;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute; inset: 0;
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
  border-radius: var(--radius); padding: 22px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; box-shadow: var(--shadow);
}
.flashcard-front { background: var(--bg-card); border: 1.5px solid var(--border); }
.flashcard-back {
  background: linear-gradient(135deg, var(--accent) 0%, var(--purple) 130%);
  color: #fff; transform: rotateY(180deg);
}
.flashcard-tag {
  position: absolute; top: 12px; left: 14px;
  width: 24px; height: 24px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800;
}
.flashcard-front .flashcard-tag { background: var(--accent-light); color: var(--accent); }
.flashcard-back .flashcard-tag { background: rgba(255,255,255,0.25); color: #fff; }
.flashcard-text { font-size: 16px; line-height: 1.5; font-weight: 500; }
.flashcard-front .flashcard-text { color: var(--text-primary); font-weight: 600; }
.flashcard-hint { position: absolute; bottom: 12px; font-size: 11px; color: var(--text-tertiary); }
.flashdeck-nav { display: flex; gap: 8px; padding: 0 16px 16px; flex-wrap: wrap; }
.fd-btn {
  flex: 1; min-width: 70px; padding: 9px 12px; border-radius: var(--radius-xs);
  background: var(--bg-card); border: 1px solid var(--border);
  font-size: 13px; font-weight: 600; color: var(--text-primary);
  cursor: pointer; transition: all var(--transition); font-family: inherit;
}
.fd-btn:hover { border-color: var(--accent); color: var(--accent); }
.fd-flip { background: var(--accent); color: #fff; border-color: var(--accent); }
.fd-flip:hover { background: var(--accent-hover); color: #fff; }

/* ── Mnemonic card ── */
.mnemonic-card {
  margin: 24px 0; border-radius: var(--radius);
  background: var(--purple-light); border: 1px solid var(--purple);
  border-left: 4px solid var(--purple); padding: 16px 18px;
}
.mnem-head { font-size: 13px; font-weight: 700; color: var(--purple); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.4px; }
.mnem-phrase { font-size: 18px; font-weight: 800; color: var(--text-primary); margin-bottom: 12px; letter-spacing: -0.2px; }
.mnem-items { display: flex; flex-direction: column; gap: 7px; }
.mnem-row { display: flex; align-items: baseline; gap: 12px; }
.mnem-key {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 7px;
  background: var(--purple); color: #fff; font-weight: 800; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.mnem-val { font-size: 15px; color: var(--text-primary); line-height: 1.5; }
.mnem-note { margin-top: 12px; font-size: 13px; color: var(--text-secondary); font-style: italic; }

/* ── Progressive reveal ── */
.reveal-box {
  margin: 24px 0; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-card); padding: 16px 18px; box-shadow: var(--shadow-sm);
}
.reveal-head { font-size: 13px; font-weight: 700; color: var(--text-primary); margin-bottom: 12px; }
.reveal-steps { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.reveal-step {
  padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--bg-2); border-left: 3px solid var(--accent);
  animation: fadeIn 0.3s ease;
}
.reveal-step-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--accent); margin-bottom: 4px; }
.reveal-step-body { font-size: 15px; line-height: 1.6; color: var(--text-primary); }
.reveal-btn {
  padding: 9px 16px; border-radius: var(--radius-xs);
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: background var(--transition);
}
.reveal-btn:hover { background: var(--accent-hover); }
.reveal-btn:disabled { background: var(--green); cursor: default; opacity: 0.9; }

/* checkpoint reuses .question-card; tint the border */
.checkpoint-card { border-color: var(--orange) !important; border-left: 4px solid var(--orange) !important; }

/* ── Static figures ── */
.fig-block {
  margin: 26px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
  padding: 14px 14px 4px;
}
.fig-title {
  font-size: 13px; font-weight: 700; color: var(--text-primary);
  margin-bottom: 6px; text-align: center;
}
.fig-canvas { display: block; width: 100%; }
.fig-caption {
  font-size: 12px; color: var(--text-secondary);
  text-align: center; padding: 8px 6px 6px; line-height: 1.5;
  font-style: italic;
}

/* ── Interactive viz widgets ── */
.viz-widget {
  margin: 28px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.viz-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}
.viz-title { font-size: 13px; font-weight: 700; color: var(--text-primary); }
.viz-tag {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--accent); background: var(--accent-light);
  padding: 3px 8px; border-radius: 99px;
}
.viz-controls {
  display: flex; flex-wrap: wrap; gap: 14px 20px;
  padding: 16px; border-bottom: 1px solid var(--border);
  align-items: flex-end;
}
.viz-ctl { display: flex; flex-direction: column; gap: 5px; min-width: 150px; flex: 1; }
.viz-ctl-lab { font-size: 12px; font-weight: 500; color: var(--text-secondary); }
.viz-ctl-lab b { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.viz-ctl input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; border-radius: 99px;
  background: var(--bg-3); outline: none; cursor: pointer;
}
.viz-ctl input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25); border: 2px solid var(--bg-card);
}
.viz-ctl input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 2px solid var(--bg-card);
}
.viz-ctl select {
  padding: 7px 10px; border-radius: var(--radius-xs);
  border: 1px solid var(--border); background: var(--bg);
  color: var(--text-primary); font-size: 13px; font-family: inherit; outline: none;
}
.viz-btn {
  padding: 8px 14px; border-radius: var(--radius-xs);
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 600;
  font-family: inherit; cursor: pointer; transition: background var(--transition);
  align-self: flex-end; white-space: nowrap;
}
.viz-btn:hover { background: var(--accent-hover); }
.viz-canvas { display: block; width: 100%; padding: 8px 6px 0; }
.viz-readout {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 12px 16px 16px;
}
.viz-readout:empty { display: none; }
.viz-chip {
  font-size: 12px; color: var(--text-secondary);
  background: var(--bg-2); border: 1px solid var(--border);
  padding: 5px 11px; border-radius: 99px; font-weight: 500;
}
.viz-chip b { font-weight: 700; font-variant-numeric: tabular-nums; }

/* Difficulty pills on home */
.pill {
  display: inline-block;
  padding: 2px 8px; border-radius: 99px;
  font-size: 11px; font-weight: 600;
}
.pill-green { background: var(--green-light); color: var(--green); }
.pill-orange { background: var(--orange-light); color: var(--orange); }
.pill-red { background: var(--red-light); color: var(--red); }

/* ═══ iOS PWA safe areas + mobile polish (priority: iOS standalone) ═══ */
* { -webkit-tap-highlight-color: transparent; }
html, body { -webkit-text-size-adjust: 100%; }

/* Notch / status bar: push the sticky topbar below the safe area */
.topbar {
  padding-top: env(safe-area-inset-top);
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
}

/* Home indicator: keep content clear of the fixed bottom nav + safe area */
.content-scroll {
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
.chap-nav { -webkit-overflow-scrolling: touch; }
.bottom-nav {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  height: calc(60px + env(safe-area-inset-bottom));
}

/* Side notches (landscape) */
.dash, .content-area {
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
}
.welcome {
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

/* Sidebar drawer clears the notch */
.sidebar-header { padding-top: calc(20px + env(safe-area-inset-top)); }

/* Phone layout tightening */
@media (max-width: 760px) {
  .dash, .content-area {
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }
  .dash-hello { font-size: 23px; }
  .score-big { font-size: 34px; }
  .reco-card { flex-basis: 78vw; max-width: 280px; }
  .badge-grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); }
  .welcome-card { padding: 30px 22px 26px; border-radius: 24px; }
  .welcome-greeting { font-size: 25px; }
  .topbar { gap: 8px; }
  .topbar-end { gap: 6px !important; }
  .score-chip, .streak-chip { padding: 5px 9px; font-size: 12px; }
}

/* Very small phones: let the score/streak chips shrink gracefully */
@media (max-width: 380px) {
  .breadcrumb li:not(:first-child) { display: none; }
}
