/* =====================================================================
   MATH1851 Visual Mastery — Calm Editorial Design System
   Dark & Light themes + Anim-Core tokens + 17 Lesson Block Styles
   ===================================================================== */

:root,
[data-theme="dark"] {
  --bg: #070b14;
  --surface: #0e1424;
  --surface-2: #151d33;
  --surface-hover: #1b2540;
  --subtle: rgba(255, 255, 255, 0.035);
  --border: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(91, 140, 255, 0.36);

  --text: #eef2fb;
  --text-2: #c9d3e8;
  --text-muted: #8f9bb8;

  /* Exact tokens read by anim-core.js */
  --canvas-bg: #090e1c;
  --canvas-grid: rgba(148, 163, 184, 0.11);
  --canvas-axis: rgba(203, 213, 225, 0.52);

  --c-blue: #5b8cff;
  --c-violet: #a78bfa;
  --c-emerald: #34d399;
  --c-amber: #fbbf24;
  --c-rose: #fb7185;
  --c-cyan: #22d3ee;
  --c-pink: #f472b6;
  --c-orange: #fb923c;

  --soft-blue: rgba(91, 140, 255, 0.13);
  --soft-violet: rgba(167, 139, 250, 0.13);
  --soft-emerald: rgba(52, 211, 153, 0.12);
  --soft-amber: rgba(251, 191, 36, 0.13);
  --soft-rose: rgba(251, 113, 133, 0.13);
  --soft-cyan: rgba(34, 211, 238, 0.12);
  --soft-pink: rgba(244, 114, 182, 0.12);
  --soft-orange: rgba(251, 146, 60, 0.13);

  --grad-hero: linear-gradient(135deg, rgba(91, 140, 255, 0.14) 0%, rgba(167, 139, 250, 0.11) 50%, rgba(52, 211, 153, 0.08) 100%);
  --grad-accent: linear-gradient(135deg, #4f7cff 0%, #8b5cf6 100%);
  --shadow-card: 0 8px 30px -12px rgba(0, 0, 0, 0.45);
  --shadow-float: 0 24px 60px -18px rgba(0, 0, 0, 0.65);
}

[data-theme="light"] {
  --bg: #f6f8fc;
  --surface: #ffffff;
  --surface-2: #f0f4fb;
  --surface-hover: #e9effa;
  --subtle: rgba(15, 23, 42, 0.032);
  --border: rgba(15, 23, 42, 0.095);
  --border-strong: rgba(37, 99, 235, 0.34);

  --text: #0f172a;
  --text-2: #334155;
  --text-muted: #64748b;

  --canvas-bg: #fafcff;
  --canvas-grid: rgba(15, 23, 42, 0.075);
  --canvas-axis: rgba(15, 23, 42, 0.42);

  --c-blue: #2563eb;
  --c-violet: #7c3aed;
  --c-emerald: #059669;
  --c-amber: #d97706;
  --c-rose: #e11d48;
  --c-cyan: #0891b2;
  --c-pink: #db2777;
  --c-orange: #ea580c;

  --soft-blue: rgba(37, 99, 235, 0.085);
  --soft-violet: rgba(124, 58, 237, 0.085);
  --soft-emerald: rgba(5, 150, 105, 0.085);
  --soft-amber: rgba(217, 119, 6, 0.1);
  --soft-rose: rgba(225, 29, 72, 0.085);
  --soft-cyan: rgba(8, 145, 178, 0.085);
  --soft-pink: rgba(219, 39, 119, 0.085);
  --soft-orange: rgba(234, 88, 12, 0.085);

  --grad-hero: linear-gradient(135deg, rgba(37, 99, 235, 0.08) 0%, rgba(124, 58, 237, 0.06) 55%, rgba(5, 150, 105, 0.05) 100%);
  --grad-accent: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
  --shadow-card: 0 6px 24px -10px rgba(15, 23, 42, 0.09);
  --shadow-float: 0 24px 50px -15px rgba(15, 23, 42, 0.16);
}

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

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15.5px;
  line-height: 1.68;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, .display {
  font-family: "Plus Jakarta Sans", "Inter", sans-serif;
  letter-spacing: -0.025em;
  line-height: 1.24;
  overflow-wrap: break-word;
  max-width: 100%;
}

code, pre, .mono {
  font-family: "JetBrains Mono", ui-monospace, monospace;
}

a {
  color: var(--c-blue);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

button {
  font-family: inherit;
  cursor: pointer;
}

.hidden { display: none !important; }

body.hide-zh .blk-zh { display: none !important; }

/* Custom Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.24); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, 0.42); }

/* =====================================================================
   SHELL & NAVIGATION
   ===================================================================== */
.shell {
  display: flex;
  min-height: 100vh;
}

.topbar {
  display: none;
  position: fixed;
  inset: 0 0 auto 0;
  height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 14px;
  align-items: center;
  justify-content: space-between;
  z-index: 50;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 9px;
}
.topbar-brand strong { font-size: 0.95rem; display: block; line-height: 1.1; }
.topbar-brand small { font-size: 0.72rem; color: var(--text-muted); }

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--grad-accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
}

.sidebar {
  width: 256px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 18px 14px 16px;
  overflow-y: auto;
  z-index: 60;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 2px 4px 14px;
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--grad-accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  font-weight: 800;
  box-shadow: 0 8px 20px -6px rgba(91, 140, 255, 0.55);
}

.brand-name {
  font-family: "Plus Jakarta Sans", sans-serif;
  font-size: 1.08rem;
  font-weight: 800;
}

.brand-sub {
  font-size: 0.74rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Compact Countdown Pill */
.cd-pill {
  background: var(--grad-hero);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 11px 12px;
  margin-bottom: 14px;
}

.cd-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--c-amber);
  margin-bottom: 8px;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--c-amber);
  box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.7);
  animation: pulse 2.2s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.65); }
  70% { box-shadow: 0 0 0 7px rgba(251, 191, 36, 0); }
  100% { box-shadow: 0 0 0 0 rgba(251, 191, 36, 0); }
}

.cd-digits {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  margin-bottom: 10px;
}
.cd-digits > div {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 2px;
  text-align: center;
}
.cd-digits span {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.98rem;
  font-weight: 700;
  display: block;
  line-height: 1.15;
}
.cd-digits small {
  font-size: 0.58rem;
  font-weight: 700;
  color: var(--text-muted);
}

.cd-progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-2);
  margin-bottom: 5px;
}

.progress-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.18);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--c-blue), var(--c-emerald));
  transition: width 0.35s ease;
}

.nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-label {
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 11px 10px 4px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-2);
  font-size: 0.87rem;
  font-weight: 600;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.nav-btn:hover {
  background: var(--subtle);
  color: var(--text);
}
.nav-btn.active {
  background: var(--soft-blue);
  border-color: var(--border-strong);
  color: var(--c-blue);
  font-weight: 700;
}

.nav-ico { width: 20px; text-align: center; font-size: 1rem; }
.nav-txt { flex: 1; }
.nav-tag {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--subtle);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.tag-rose {
  background: var(--soft-rose);
  color: var(--c-rose);
  border-color: rgba(251, 113, 133, 0.3);
}

.sidebar-bottom {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pref-row {
  display: flex;
  gap: 7px;
}
.pref-chip {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--subtle);
  color: var(--text-2);
  font-size: 0.78rem;
  font-weight: 600;
}
.pref-chip strong { color: var(--c-emerald); }

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--subtle);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  transition: all 0.15s ease;
}
.icon-btn:hover {
  border-color: var(--c-blue);
  background: var(--soft-blue);
}

.formula-cta {
  width: 100%;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--soft-blue);
  color: var(--c-blue);
  font-size: 0.8rem;
  font-weight: 700;
  transition: all 0.15s ease;
}
.formula-cta:hover {
  background: var(--c-blue);
  color: #fff;
}

.sidebar-backdrop { display: none; }

.main {
  flex: 1;
  min-width: 0;
  padding: 30px 38px 72px;
  max-width: 1220px;
  margin: 0 auto;
}

/* =====================================================================
   SHARED PRIMITIVES (Buttons, Badges, Cards, Grids)
   ===================================================================== */
.page-head {
  margin-bottom: 24px;
  min-width: 0;
}
.eyebrow {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-blue);
  margin-bottom: 6px;
}
.page-title {
  font-size: 1.9rem;
  font-weight: 800;
  margin-bottom: 6px;
}
.page-sub {
  color: var(--text-muted);
  max-width: 780px;
  font-size: 0.97rem;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 17px;
  border-radius: 11px;
  font-size: 0.88rem;
  font-weight: 700;
  border: 1px solid transparent;
  transition: transform 0.15s ease, filter 0.15s ease, border-color 0.15s ease;
  text-decoration: none !important;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--grad-accent); color: #fff; box-shadow: 0 8px 20px -6px rgba(91, 140, 255, 0.5); }
.btn-emerald { background: linear-gradient(135deg, #059669, #0d9488); color: #fff; }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { border-color: var(--c-blue); color: var(--c-blue); }

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  border: 1px solid var(--border);
  background: var(--subtle);
  color: var(--text-2);
  text-decoration: none !important;
  transition: all 0.15s ease;
}
.pill-btn:hover { border-color: var(--c-blue); color: var(--c-blue); }
.accent-pill {
  background: var(--soft-blue);
  border-color: var(--border-strong);
  color: var(--c-blue);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}
.badge-blue { background: var(--soft-blue); color: var(--c-blue); }
.badge-violet { background: var(--soft-violet); color: var(--c-violet); }
.badge-emerald { background: var(--soft-emerald); color: var(--c-emerald); }
.badge-amber { background: var(--soft-amber); color: var(--c-amber); }
.badge-rose { background: var(--soft-rose); color: var(--c-rose); }
.badge-cyan { background: var(--soft-cyan); color: var(--c-cyan); }
.badge-pink { background: var(--soft-pink); color: var(--c-pink); }
.badge-orange { background: var(--soft-orange); color: var(--c-orange); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px 22px;
  box-shadow: var(--shadow-card);
}
.card-hover { transition: border-color 0.16s ease, transform 0.16s ease; }
.card-hover:hover { border-color: var(--border-strong); transform: translateY(-2px); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 18px;
}

.tab-btn {
  padding: 8px 15px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 0.85rem;
  font-weight: 700;
  transition: all 0.15s ease;
}
.tab-btn:hover { border-color: var(--c-blue); color: var(--text); }
.tab-btn.active { background: var(--c-blue); border-color: var(--c-blue); color: #fff; }

.input-ctrl {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.87rem;
  font-family: inherit;
  outline: none;
}
.input-ctrl:focus { border-color: var(--c-blue); }

/* =====================================================================
   COURSE MAP (DASHBOARD)
   ===================================================================== */
.hero {
  background: var(--grad-hero);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 26px 28px;
  margin-bottom: 24px;
  display: grid;
  grid-template-columns: 1.55fr 1fr;
  gap: 24px;
  align-items: center;
}
.hero h1 { font-size: 1.95rem; margin: 10px 0; }
.hero p { color: var(--text-2); margin-bottom: 18px; max-width: 620px; }

.hero-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 13px 15px;
}
.stat-tile strong {
  font-family: "JetBrains Mono", monospace;
  font-size: 1.35rem;
  display: block;
}
.stat-tile span {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

.part-section { margin-top: 26px; }
.part-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.part-head h2 { font-size: 1.22rem; }
.part-head span { font-size: 0.82rem; color: var(--text-muted); }

.mod-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.mod-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  transition: border-color 0.16s ease, transform 0.16s ease, background 0.16s ease;
}
.mod-card:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
  transform: translateY(-2px);
}
.mod-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.mod-ico {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  font-weight: 800;
  background: var(--soft-blue);
  color: var(--c-blue);
}
.mod-card h3 { font-size: 1rem; font-weight: 700; }
.mod-card p { font-size: 0.84rem; color: var(--text-muted); flex: 1; line-height: 1.48; }
.mod-card-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.info-panel { margin-top: 26px; }
.plan-day-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 20px;
  margin-bottom: 14px;
}
.task-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 11px;
  background: var(--subtle);
  border: 1px solid var(--border);
  margin-top: 8px;
  cursor: pointer;
}
.task-row:hover { border-color: var(--c-blue); }
.task-row.done { opacity: 0.64; border-color: rgba(52, 211, 153, 0.35); }
.task-row.done .task-title { text-decoration: line-through; }
.task-check {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 2px solid var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 800;
  flex-shrink: 0;
}
.task-row.done .task-check {
  background: var(--c-emerald);
  border-color: var(--c-emerald);
  color: #fff;
}

/* =====================================================================
   CALM EDITORIAL LESSON READER
   ===================================================================== */
.learn-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 16px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--border);
}

.learn-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}

.learn-outline {
  position: sticky;
  top: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

.outline-title {
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  padding: 4px 8px 8px;
}

.outline-item {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-2);
  text-align: left;
  font-size: 0.84rem;
  line-height: 1.38;
  margin-bottom: 3px;
}
.outline-item:hover { background: var(--subtle); color: var(--text); }
.outline-item.active {
  background: var(--soft-blue);
  border-color: var(--border-strong);
  color: var(--text);
  font-weight: 600;
}

.outline-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--subtle);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
}
.outline-item.done .outline-num {
  background: var(--soft-emerald);
  border-color: var(--c-emerald);
  color: var(--c-emerald);
}

.outline-tabs {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.learn-shell > * {
  min-width: 0;
}

.learn-article {
  max-width: 780px;
  width: 100%;
  min-width: 0;
  margin: 0 auto;
}

.lesson-head {
  margin-bottom: 24px;
  min-width: 0;
}
.lesson-head h1 {
  font-size: 1.85rem;
  font-weight: 800;
  margin: 8px 0 8px;
}
.lesson-summary {
  color: var(--text-muted);
  font-size: 1rem;
}

.lesson-blocks {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.lesson-footer {
  margin-top: 32px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

/* =====================================================================
   17 LESSON BLOCK TYPES
   ===================================================================== */
.blk-p {
  color: var(--text-2);
  font-size: 1rem;
  line-height: 1.75;
}
.blk-p strong { color: var(--text); }

.blk-h {
  font-size: 1.24rem;
  font-weight: 800;
  color: var(--text);
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.blk-big {
  background: var(--grad-hero);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 20px 22px;
}
.blk-big-label {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-blue);
  margin-bottom: 6px;
}
.blk-big h3 { font-size: 1.18rem; margin-bottom: 8px; }
.blk-big p, .blk-big div { color: var(--text-2); }

.blk-analogy {
  background: var(--soft-amber);
  border: 1px solid rgba(251, 191, 36, 0.28);
  border-left: 4px solid var(--c-amber);
  border-radius: 14px;
  padding: 16px 18px;
}
.blk-title-sm {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.blk-anim {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px 20px;
  box-shadow: var(--shadow-card);
}
.anim-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.anim-head h4 { font-size: 1.04rem; font-weight: 700; }
.anim-cap {
  font-size: 0.9rem;
  color: var(--text-2);
  margin-top: 12px;
}
.anim-notice {
  margin-top: 10px;
  padding: 11px 14px;
  border-radius: 11px;
  background: var(--subtle);
  border: 1px solid var(--border);
  font-size: 0.86rem;
  color: var(--text-2);
}
.anim-notice strong { color: var(--text); }
.anim-notice ul { padding-left: 18px; margin-top: 4px; }
.anim-notice li { margin: 3px 0; }

.blk-formula {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 18px 20px;
}
.formula-label {
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--c-blue);
  margin-bottom: 6px;
}
.formula-tex {
  overflow-x: auto;
  padding: 4px 0;
  font-size: 1.05rem;
}
.formula-where {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--text-2);
}
.where-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.where-sym { min-width: 56px; font-weight: 700; color: var(--text); }
.formula-note {
  margin-top: 10px;
  font-size: 0.84rem;
  color: var(--text-muted);
}

/* Derive (line-by-line) */
.blk-derive {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 20px;
}
.derive-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.derive-lines { display: flex; flex-direction: column; gap: 8px; }
.derive-line {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 10px 14px;
  transition: opacity 0.2s ease;
}
.derive-line.locked { display: none; }
.derive-note { font-size: 0.84rem; color: var(--text-muted); margin-top: 4px; }

/* Worked Example (do + why) */
.blk-example {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px 22px;
  box-shadow: var(--shadow-card);
}
.ex-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.ex-problem {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 14px;
  overflow-x: auto;
  font-weight: 500;
}
.ex-steps { display: flex; flex-direction: column; gap: 10px; }
.ex-step {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 15px;
  background: var(--subtle);
}
.ex-step.locked { display: none; }
.ex-step-num {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--c-emerald);
  text-transform: uppercase;
  margin-bottom: 5px;
}
.ex-do { font-size: 0.96rem; overflow-x: auto; color: var(--text); }
.ex-why {
  margin-top: 7px;
  padding-top: 7px;
  border-top: 1px dashed var(--border);
  font-size: 0.86rem;
  color: var(--text-muted);
}
.ex-why::before {
  content: "Why: ";
  font-weight: 700;
  color: var(--c-cyan);
}
.ex-answer {
  margin-top: 12px;
  padding: 13px 16px;
  border-radius: 12px;
  border: 1.5px solid var(--c-emerald);
  background: var(--soft-emerald);
  font-weight: 600;
  overflow-x: auto;
}
.ex-answer.locked { display: none; }

/* Recipe */
.blk-recipe {
  background: var(--surface);
  border: 1px solid rgba(52, 211, 153, 0.3);
  border-radius: 16px;
  padding: 18px 20px;
}
.recipe-list {
  list-style: none;
  counter-reset: rec;
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-top: 10px;
}
.recipe-list li {
  counter-increment: rec;
  display: flex;
  gap: 11px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: 11px;
  background: var(--subtle);
}
.recipe-list li::before {
  content: counter(rec);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--c-emerald);
  color: #062118;
  font-size: 0.75rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

/* Check MCQ */
.blk-check {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 18px 20px;
}
.mcq-options { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.mcq-opt {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 11px 14px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  text-align: left;
  font-size: 0.93rem;
  transition: all 0.14s ease;
}
.mcq-opt:hover { border-color: var(--c-blue); background: var(--soft-blue); }
.mcq-opt.selected { border-color: var(--c-blue); background: var(--soft-blue); }
.mcq-opt.correct { border-color: var(--c-emerald); background: var(--soft-emerald); }
.mcq-opt.wrong { border-color: var(--c-rose); background: var(--soft-rose); }
.opt-letter {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  font-weight: 800;
  flex-shrink: 0;
}

.blk-warn, .blk-tip, .blk-zh, .blk-keys {
  border-radius: 14px;
  padding: 15px 18px;
}
.blk-warn { background: var(--soft-rose); border: 1px solid rgba(251, 113, 133, 0.28); border-left: 4px solid var(--c-rose); }
.blk-tip { background: var(--soft-amber); border: 1px solid rgba(251, 191, 36, 0.28); border-left: 4px solid var(--c-amber); }
.blk-zh { background: var(--soft-cyan); border: 1px solid rgba(34, 211, 238, 0.25); }
.blk-zh summary { cursor: pointer; font-weight: 700; font-size: 0.88rem; color: var(--c-cyan); list-style: none; }
.blk-zh-body { margin-top: 8px; color: var(--text-2); font-size: 0.93rem; }
.blk-keys { background: var(--surface-2); border: 1px solid var(--border); }
.blk-keys ul { padding-left: 19px; margin-top: 8px; color: var(--text-2); }
.blk-keys li { margin: 5px 0; }

/* Table, Compare, SVG */
.blk-table {
  border-radius: 14px;
  border: 1px solid var(--border);
  overflow-x: auto;
  background: var(--surface);
}
.blk-table table, .data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.blk-table th, .blk-table td, .data-table th, .data-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.blk-table th, .data-table th {
  background: var(--surface-2);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.blk-table tr:last-child td, .data-table tr:last-child td { border-bottom: none; }
.table-cap { padding: 8px 14px; font-size: 0.8rem; color: var(--text-muted); background: var(--surface-2); border-top: 1px solid var(--border); }

.blk-compare {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.compare-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--c-blue);
  border-radius: 14px;
  padding: 15px 16px;
}
.compare-col h4 { font-size: 0.96rem; margin-bottom: 8px; }
.compare-col.cc-violet { border-top-color: var(--c-violet); }
.compare-col.cc-emerald { border-top-color: var(--c-emerald); }
.compare-col.cc-amber { border-top-color: var(--c-amber); }
.compare-col.cc-rose { border-top-color: var(--c-rose); }
.compare-col.cc-cyan { border-top-color: var(--c-cyan); }

.blk-svg {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  text-align: center;
  overflow-x: auto;
}
.blk-svg svg { max-width: 100%; height: auto; display: inline-block; }

/* =====================================================================
   ANIM-CORE STYLES (required by js/core/anim-core.js)
   ===================================================================== */
.anim {
  display: flex;
  flex-direction: column;
  gap: 11px;
}
.anim-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-2);
}
.anim-legend .lg {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.anim-legend .lg i {
  display: inline-block;
  width: 14px;
  height: 4px;
  border-radius: 2px;
}
.anim-stage {
  display: block;
}
.anim-stage.anim-cols {
  display: grid;
  grid-template-columns: var(--cols, repeat(2, minmax(0, 1fr)));
  gap: 12px;
}
.anim-surface {
  background: var(--canvas-bg);
  border: 1px solid var(--border);
  border-radius: 13px;
  overflow: hidden;
}
.anim-surface-title {
  padding: 7px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.anim-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.ctl {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
}
.ctl-slider {
  flex: 1 1 200px;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
}
.ctl-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.ctl-label { font-weight: 600; color: var(--text-2); font-size: 0.8rem; }
.ctl-val { font-family: "JetBrains Mono", monospace; font-size: 0.8rem; color: var(--c-blue); }

.ctl-slider input[type="range"],
.player-bar {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--c-blue) var(--pct, 50%), rgba(148, 163, 184, 0.25) var(--pct, 50%));
  outline: none;
  cursor: pointer;
}
.ctl-slider input[type="range"]::-webkit-slider-thumb,
.player-bar::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--c-blue);
  border: 2px solid var(--surface);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.ctl-choice {
  flex-wrap: wrap;
}
.seg {
  display: inline-flex;
  flex-wrap: wrap;
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
  background: var(--surface);
}
.seg button {
  padding: 5px 10px;
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 0.78rem;
  font-weight: 600;
  border-right: 1px solid var(--border);
}
.seg button:last-child { border-right: none; }
.seg button.on {
  background: var(--c-blue);
  color: #fff;
}
.ctl-choice select {
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.8rem;
  font-family: inherit;
}

.ctl-toggle {
  cursor: pointer;
  user-select: none;
}
.ctl-toggle input { display: none; }
.ctl-toggle .switch {
  width: 34px;
  height: 19px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.35);
  position: relative;
  transition: background 0.16s ease;
}
.ctl-toggle .switch::after {
  content: "";
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  position: absolute;
  top: 3px;
  left: 3px;
  transition: transform 0.16s ease;
}
.ctl-toggle input:checked + .switch { background: var(--c-emerald); }
.ctl-toggle input:checked + .switch::after { transform: translateX(15px); }

.ctl-btn {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 700;
}
.ctl-btn:hover { border-color: var(--c-blue); color: var(--c-blue); }
.ctl-btn.primary { background: var(--c-blue); border-color: var(--c-blue); color: #fff; }
.ctl-btn.primary:hover { filter: brightness(1.08); color: #fff; }
.ctl-btn.icon { width: 30px; padding: 6px 0; text-align: center; }

.ctl-player {
  flex: 1 1 260px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.player-bar { flex: 1; }

.anim-readouts {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.anim-readout {
  padding: 9px 13px;
  border-radius: 10px;
  background: var(--subtle);
  border: 1px solid var(--border);
  font-size: 0.87rem;
  color: var(--text-2);
}
.anim-readout b { color: var(--text); }
.anim-note { font-size: 0.78rem; color: var(--text-muted); }
.anim-error, .anim-missing {
  padding: 12px;
  border-radius: 10px;
  background: var(--soft-rose);
  color: var(--c-rose);
  font-size: 0.84rem;
}

/* =====================================================================
   PRACTICE, MOCK EXAM, FLASHCARDS & MODAL
   ===================================================================== */
.exam-bar {
  position: sticky;
  top: 12px;
  z-index: 30;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 15px;
  padding: 13px 18px;
  margin-bottom: 18px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-float);
}
.timer-readout {
  font-family: "JetBrains Mono", monospace;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--c-amber);
}

.flashcard-stage {
  perspective: 1200px;
  max-width: 660px;
  margin: 18px auto;
}
.flashcard-inner {
  position: relative;
  width: 100%;
  min-height: 270px;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
  cursor: pointer;
}
.flashcard-inner.flipped { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: 20px;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-card);
  overflow-y: auto;
}
.flashcard-back { transform: rotateY(180deg); border-color: var(--c-emerald); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 9, 20, 0.72);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  width: 100%;
  max-width: 920px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-float);
}
.modal-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.modal-header h2 { font-size: 1.15rem; margin-top: 4px; }
.modal-actions { display: flex; align-items: center; gap: 8px; }
.modal-body { padding: 20px 22px; overflow-y: auto; }

/* KaTeX Polish */
.katex-display { margin: 0.65em 0 !important; overflow-x: auto; overflow-y: hidden; }

/* =====================================================================
   RESPONSIVE
   ===================================================================== */
@media (max-width: 1060px) {
  .hero, .learn-shell, .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .learn-outline { position: static; max-height: none; }
}

@media (max-width: 820px) {
  .topbar { display: flex; }
  .sidebar {
    position: fixed;
    left: -272px;
    top: 0;
    bottom: 0;
    transition: left 0.24s ease;
  }
  .sidebar.open { left: 0; }
  .sidebar-backdrop.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 55;
  }
  .main { padding: 76px 16px 56px; }
  .hero { padding: 20px 18px; }
  .hero h1, .page-title, .lesson-head h1 { font-size: 1.38rem; }
}

@media (max-width: 680px) {
  .anim-stage.anim-cols { grid-template-columns: 1fr; }
}
