/* =========================================================
   LearnLab — monochrome design system (black / white)
   ========================================================= */
:root {
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --serif: 'Instrument Serif', 'Iowan Old Style', Georgia, serif;
  --mono: 'JetBrains Mono', ui-monospace, 'Cascadia Code', Consolas, monospace;
  --sidebar-w: 284px;
  --topbar-h: 58px;
  --radius: 14px;
  --ease: cubic-bezier(.22, .9, .3, 1);
  --spring: cubic-bezier(.34, 1.56, .64, 1);
}

:root, :root[data-theme="dark"] {
  --bg: #000;
  --bg-2: #070707;
  --surface: #0d0d0d;
  --surface-2: #141414;
  --surface-3: #1f1f1f;
  --border: #222;
  --border-2: #333;
  --text: #f5f5f5;
  --text-2: #a8a8a8;
  --text-3: #6e6e6e;
  --accent: #f5f5f5;
  --accent-2: #9a9a9a;
  --accent-3: #d6d6d6;
  --accent-ink: #000;
  --ok: #4caf7d;
  --warn: #d4a73a;
  --bad: #e5604d;
  --accent-soft: rgba(255, 255, 255, .055);
  --violet-soft: rgba(255, 255, 255, .03);
  --shadow: 0 12px 40px -16px rgba(0, 0, 0, .9);
  --glow: 0 0 0 1px rgba(255, 255, 255, .5);
  --code-bg: #0a0a0a;
  --code-border: #222;
  --grid-line: rgba(255, 255, 255, .035);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #fff;
  --bg-2: #fafafa;
  --surface: #fff;
  --surface-2: #f6f6f6;
  --surface-3: #ebebeb;
  --border: #e6e6e6;
  --border-2: #d0d0d0;
  --text: #0a0a0a;
  --text-2: #4d4d4d;
  --text-3: #8c8c8c;
  --accent: #0a0a0a;
  --accent-2: #6b6b6b;
  --accent-3: #2b2b2b;
  --accent-ink: #fff;
  --ok: #2f8a5b;
  --warn: #a8801c;
  --bad: #c2412f;
  --accent-soft: rgba(0, 0, 0, .04);
  --violet-soft: rgba(0, 0, 0, .025);
  --shadow: 0 14px 34px -18px rgba(0, 0, 0, .25);
  --glow: 0 0 0 1px rgba(0, 0, 0, .7);
  --code-bg: #0a0a0a;
  --code-border: #0a0a0a;
  --grid-line: rgba(0, 0, 0, .04);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--topbar-h) + 20px); }
body {
  margin: 0; font-family: var(--font); font-size: 16px; line-height: 1.7;
  color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
  transition: background .3s, color .3s;
}
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px), linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at 70% 0%, #000 0%, transparent 65%);
}
a { color: var(--text); text-decoration: underline; text-decoration-color: var(--border-2); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--text); }
::selection { background: var(--text); color: var(--bg); }
button { font-family: inherit; }
kbd { font-family: var(--mono); font-size: 11px; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--border-2); border-bottom-width: 2px; background: var(--surface-2); color: var(--text-2); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

.muted { color: var(--text-3); }
.small { font-size: 12.5px; }
.muted-link { color: var(--text-2); text-decoration: none; font-size: 14px; }
.muted-link:hover { color: var(--text); }
.boot { padding: 120px 40px; text-align: center; color: var(--text-3); }

/* ---------- reading progress ---------- */
.progress-bar { position: fixed; top: 0; left: 0; height: 2px; width: 0; background: var(--text); z-index: 100; transition: width .1s linear; }

/* ---------- topbar ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px; padding: 0 18px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border-bottom: 1px solid var(--border); z-index: 50;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-size: 17px; font-weight: 600; letter-spacing: -.02em; }
.brand b { font-family: var(--serif); font-style: italic; font-weight: 400; font-size: 21px; }
.brand-logo { width: 26px; height: 26px; border-radius: 8px; background: var(--text); position: relative; display: grid; place-items: center; }
.brand-logo::after { content: ""; width: 11px; height: 11px; border-radius: 50%; border: 2.5px solid var(--bg); animation: breathe 3.2s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(.65); } }
.search-trigger {
  flex: 1; max-width: 440px; margin-left: 22px; display: flex; align-items: center; gap: 10px;
  height: 36px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-3); font-size: 14px; cursor: pointer; text-align: left; transition: border-color .2s;
}
.search-trigger span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-trigger:hover { border-color: var(--border-2); color: var(--text-2); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.chip { display: flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); color: var(--text); font-weight: 600; font-size: 13px; font-variant-numeric: tabular-nums; text-decoration: none; background: var(--surface); }
.chip svg { color: var(--text-2); }
.chip.bump { animation: bump .6s var(--spring); }
@keyframes bump { 40% { transform: scale(1.2); } }
.icon-btn { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); cursor: pointer; transition: all .2s; }
.icon-btn:hover { color: var(--text); border-color: var(--border-2); }
[data-theme="dark"] .icon-btn .sun { display: none; }
[data-theme="light"] .icon-btn .moon { display: none; }
.menu-btn { display: none; }

/* ---------- sidebar ---------- */
.sidebar {
  position: fixed; top: var(--topbar-h); left: 0; bottom: 0; width: var(--sidebar-w);
  overflow-y: auto; padding: 14px 12px 40px; border-right: 1px solid var(--border);
  background: var(--bg-2); z-index: 40; transition: transform .35s var(--ease);
}
.nav-group { display: flex; flex-direction: column; gap: 2px; margin-bottom: 16px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; color: var(--text-2); font-size: 14px; font-weight: 500; text-decoration: none; transition: background .15s, color .15s; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--surface-3); color: var(--text); }
.nav-item .badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; background: var(--text); color: var(--bg); font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.nav-label { font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--text-3); padding: 0 10px 8px; }
.nav-course { margin-bottom: 4px; border-radius: 12px; }
.nav-course.open { background: var(--surface); border: 1px solid var(--border); padding-bottom: 6px; }
.nav-course-head { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: var(--text); text-decoration: none; }
.nav-course-head:hover { background: var(--surface-2); }
.nav-course-head.active { background: var(--surface-2); }
.glyph { flex: none; width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--text); color: var(--bg); font-family: var(--serif); font-size: 15px; letter-spacing: .02em; }
.nc-t { display: flex; flex-direction: column; font-weight: 600; font-size: 14px; line-height: 1.25; }
.nc-t small { font-weight: 500; font-size: 11.5px; color: var(--text-3); }
.nav-part { margin: 4px 0; }
.nav-part-title { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 12px 4px; border: 0; background: none; color: var(--text-3); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; cursor: pointer; text-align: left; }
.nav-part-title .chev { margin-left: auto; transition: transform .25s; flex: none; }
.nav-part.collapsed .chev { transform: rotate(-90deg); }
.nav-part.collapsed .nav-list { display: none; }
.nav-list { list-style: none; margin: 0; padding: 0 4px; }
.nav-link { display: flex; align-items: flex-start; gap: 10px; padding: 6px 8px; border-radius: 8px; color: var(--text-2); font-size: 13.5px; line-height: 1.35; text-decoration: none; position: relative; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--surface-3); color: var(--text); font-weight: 600; }
.nav-num { flex: none; width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font-size: 11px; font-weight: 600; font-family: var(--mono); background: var(--surface-2); color: var(--text-3); border: 1px solid var(--border); }
.nav-link.done .nav-num { background: var(--text); color: var(--bg); border-color: var(--text); }
.nav-link.active .nav-num { border-color: var(--text); color: var(--text); }
.nav-link.done.active .nav-num { color: var(--bg); }
.scrim { display: none; }

/* ---------- main ---------- */
.main { position: relative; z-index: 1; margin-left: var(--sidebar-w); padding-top: var(--topbar-h); min-height: 100vh; }
.page { animation: pageIn .5s var(--ease); }
@keyframes pageIn { from { opacity: 0; transform: translateY(12px); } }
.wrap { padding: 44px 52px; max-width: 1240px; }
.wrap.narrow { max-width: 860px; }
.display { font-family: var(--serif); font-weight: 400; font-size: clamp(42px, 5.6vw, 76px); line-height: 1; letter-spacing: -.02em; margin: 10px 0 16px; }
.lead { font-size: 18px; color: var(--text-2); max-width: 640px; margin: 0 0 26px; }
.lead b { color: var(--text); }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--text-3); margin: 0; }
.serif-sub { font-family: var(--serif); font-style: italic; font-size: 26px; color: var(--text-2); margin: -6px 0 14px; }
.crumbs { font-size: 13px; color: var(--text-3); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.crumbs a { color: var(--text-2); text-decoration: none; }
.crumbs a:hover { color: var(--text); }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.sec-head h2 { font-family: var(--serif); font-weight: 400; font-size: 34px; margin: 0; letter-spacing: -.01em; }
.sec-head h3 { margin: 0; font-size: 15px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; max-width: 680px; background: var(--border); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.stat { padding: 14px 16px; background: var(--surface); }
.stat b { display: block; font-family: var(--serif); font-weight: 400; font-size: 34px; line-height: 1.05; font-variant-numeric: tabular-nums; }
.stat b small { font-size: 16px; color: var(--text-3); }
.stat span { font-size: 12px; color: var(--text-3); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 42px; padding: 0 18px; border-radius: 10px;
  font-weight: 600; font-size: 14.5px; cursor: pointer; text-decoration: none;
  border: 1px solid var(--border-2); background: var(--surface); color: var(--text);
  transition: transform .2s var(--spring), border-color .2s, background .2s, opacity .2s;
}
.btn:hover { transform: translateY(-1px); border-color: var(--text); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.btn-primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn-primary:hover { opacity: .88; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; margin: 16px 0 6px; }
.btn small { font-family: var(--mono); font-size: 10px; color: var(--text-3); margin-left: 4px; }
.btn-primary small { color: inherit; opacity: .6; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 30px; }
.row-btns { display: flex; gap: 6px; flex-wrap: wrap; }

.pbar { height: 4px; border-radius: 9px; background: var(--surface-3); overflow: hidden; }
.pbar i { display: block; height: 100%; width: 0; background: var(--text); border-radius: 9px; transition: width .8s var(--ease); }

/* ---------- dashboard ---------- */
.dash-hero, .course-hero { position: relative; overflow: hidden; padding: 64px 52px 52px; border-bottom: 1px solid var(--border); }
.field { position: absolute; inset: 0; width: 100%; height: 100%; }
.dash-hero-in, .course-hero-in { position: relative; max-width: 760px; }
.course-hero { display: flex; gap: 40px; align-items: flex-start; }
.course-ring { position: relative; margin-left: auto; padding-top: 40px; }

.continue {
  display: flex; align-items: center; gap: 18px; padding: 18px 20px; border-radius: 16px; text-decoration: none; color: var(--text);
  border: 1px solid var(--border); background: var(--surface); transition: border-color .25s, transform .25s var(--ease);
}
.continue:hover { border-color: var(--text); transform: translateY(-2px); }
.cont-glyph { flex: none; width: 54px; height: 54px; border-radius: 14px; display: grid; place-items: center; background: var(--text); color: var(--bg); font-family: var(--serif); font-size: 22px; }
.cont-body { flex: 1; min-width: 0; }
.cont-body small { color: var(--text-3); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
.cont-body h3 { margin: 2px 0 10px; font-size: 18px; }

.cat-label { display: flex; align-items: baseline; gap: 12px; margin: 30px 0 14px; font-size: 12px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--text-2); }
.cat-label:first-of-type { margin-top: 4px; }
.cat-label span { font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--text-3); }
.cat-label::after { content: ""; flex: 1; height: 1px; background: var(--border); transform: translateY(-4px); }
.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.course-card {
  position: relative; display: flex; flex-direction: column; gap: 10px; padding: 22px; border-radius: 18px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); transition: border-color .25s, transform .3s var(--ease), box-shadow .3s;
}
.course-card:hover { border-color: var(--border-2); transform: translateY(-3px); box-shadow: var(--shadow); }
.cc-top { display: flex; justify-content: space-between; align-items: flex-start; text-decoration: none; }
.cc-glyph { width: 64px; height: 64px; border-radius: 16px; display: grid; place-items: center; background: var(--text); color: var(--bg); font-family: var(--serif); font-size: 28px; }
.cc-title { text-decoration: none; color: var(--text); }
.cc-title h3 { margin: 6px 0 0; font-family: var(--serif); font-weight: 400; font-size: 30px; line-height: 1.05; }
.cc-sub { margin: 2px 0 0; color: var(--text-2); font-style: italic; font-family: var(--serif); font-size: 18px; }
.cc-desc { margin: 0; color: var(--text-2); font-size: 14px; line-height: 1.55; }
.cc-meta { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-3); padding-top: 4px; border-top: 1px solid var(--border); margin-top: auto; padding-top: 12px; }
.cc-actions { display: flex; gap: 8px; }
.ring text { font-family: var(--font); }

.two-col { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; padding-top: 0; }
.panel { padding: 20px 22px; border-radius: 18px; border: 1px solid var(--border); background: var(--surface); }
.heat { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 6px; }
.hm-col { display: flex; flex-direction: column; gap: 4px; }
.hm { display: block; width: 13px; height: 13px; border-radius: 3px; background: var(--surface-3); }
.hm.l1 { background: color-mix(in srgb, var(--text) 28%, var(--surface-3)); }
.hm.l2 { background: color-mix(in srgb, var(--text) 50%, var(--surface-3)); }
.hm.l3 { background: color-mix(in srgb, var(--text) 75%, var(--surface-3)); }
.hm.l4 { background: var(--text); }
.hm.f { opacity: .3; }
.hm-legend { display: flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--text-3); margin-top: 10px; }
.hm-legend .hm { width: 11px; height: 11px; }
.big-num { font-family: var(--serif); font-size: 64px; line-height: 1; margin: 6px 0 2px; }
.boxes { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; height: 70px; margin-top: 16px; align-items: end; }
.boxes div { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 4px; }
.boxes i { display: block; width: 100%; min-height: 3px; border-radius: 4px; background: var(--text); opacity: .85; transition: height .8s var(--ease); }
.boxes span { font-size: 11px; color: var(--text-3); font-family: var(--mono); }

/* ---------- course page ---------- */
.part { margin-bottom: 44px; }
.part-head { display: flex; align-items: flex-start; gap: 18px; padding-bottom: 14px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.part-no { flex: none; width: 70px; font-size: 12px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--text-3); padding-top: 12px; }
.part-head h2 { margin: 0; font-family: var(--serif); font-weight: 400; font-size: 32px; }
.part-head p { margin: 2px 0 0; font-size: 14px; }
.part-pct { margin-left: auto; font-family: var(--mono); font-size: 13px; color: var(--text-2); padding-top: 12px; }
.lesson-list { display: flex; flex-direction: column; }
.lesson-row {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) auto 70px 24px; align-items: center; gap: 16px; padding: 14px 10px 14px 0;
  border-bottom: 1px solid var(--border); color: var(--text); text-decoration: none; transition: background .2s, padding .25s var(--ease);
}
.lesson-row:hover { background: var(--accent-soft); padding-left: 10px; }
.lr-num { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; font-family: var(--mono); font-size: 12px; color: var(--text-2); border: 1px solid var(--border-2); }
.lesson-row.done .lr-num { background: var(--text); color: var(--bg); border-color: var(--text); }
.lr-main { display: flex; flex-direction: column; min-width: 0; }
.lesson-list { padding-left: 88px; }
.lr-main b { font-size: 15.5px; font-weight: 600; }
.lr-main small { color: var(--text-3); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lr-meta { font-size: 12.5px; color: var(--text-3); white-space: nowrap; }
.lr-go { color: var(--text-3); transition: transform .25s var(--ease), color .2s; }
.lesson-row:hover .lr-go { transform: translateX(4px); color: var(--text); }
.mini-bar { display: block; height: 3px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.mini-bar i { display: block; height: 100%; background: var(--text); }

/* ---------- lesson page ---------- */
.ch-layout { display: grid; grid-template-columns: minmax(0, 1fr) 236px; gap: 44px; max-width: 1220px; padding: 0 52px; }
.ch-hero { position: relative; overflow: hidden; padding: 52px 52px 38px; border-bottom: 1px solid var(--border); margin-bottom: 44px; }
.ch-hero canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.ch-hero-inner { position: relative; max-width: 820px; }
.ch-kicker { margin-top: 18px; font-size: 12px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--text-3); }
.ch-hero h1.display { font-size: clamp(38px, 5vw, 64px); margin: 6px 0 12px; }
.ch-hero .sub { font-size: 18px; color: var(--text-2); max-width: 700px; margin: 0; }
.ch-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 20px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 500; background: var(--surface); border: 1px solid var(--border); color: var(--text-2); text-decoration: none; }
.pill.solid { background: var(--text); color: var(--bg); border-color: var(--text); }

.content { min-width: 0; padding-bottom: 80px; }
.content > section { margin-bottom: 60px; position: relative; }
.content h2 { font-family: var(--serif); font-weight: 400; font-size: 36px; letter-spacing: -.01em; line-height: 1.1; margin: 0 0 18px; display: flex; align-items: baseline; gap: 14px; }
.content h2 .h-num { font-family: var(--mono); font-size: 12px; font-weight: 500; color: var(--text-3); letter-spacing: 0; transform: translateY(-6px); }
.content h3 { font-size: 18px; margin: 30px 0 10px; letter-spacing: -.01em; }
.content h4 { font-size: 15px; margin: 22px 0 8px; }
.content p, .content li { color: color-mix(in srgb, var(--text) 86%, var(--text-2)); }
.content p { margin: 0 0 14px; }
.content ul, .content ol { padding-left: 22px; margin: 0 0 16px; }
.content li { margin: 6px 0; }
.content li::marker { color: var(--text-3); }
.content strong { color: var(--text); font-weight: 600; }
.content a { color: var(--text); }
.content code:not(pre code) { font-family: var(--mono); font-size: .85em; padding: 1px 6px; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--border); }
.term { font-weight: 600; color: var(--text); background: linear-gradient(transparent 62%, color-mix(in srgb, var(--text) 16%, transparent) 62%); }
.sec-end { height: 1px; }
.kbd-hint { text-align: center; color: var(--text-3); font-size: 12.5px; margin-top: 26px; }

.reveal { opacity: 0; transform: translateY(18px); transition: opacity .7s var(--ease), transform .7s var(--ease); }
.reveal.in { opacity: 1; transform: none; }

/* formula */
.formula {
  position: relative; margin: 18px 0 22px; padding: 22px 24px 18px; border-radius: 12px; text-align: center;
  font-family: 'Cambria Math', 'STIX Two Math', 'Latin Modern Math', Georgia, serif; font-size: 20px; line-height: 1.6;
  background: var(--surface); border: 1px solid var(--border); overflow-x: auto;
}
.formula .lbl { position: absolute; top: 7px; left: 12px; font-family: var(--font); font-size: 10.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--text-3); }
.formula .frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; margin: 0 3px; }
.formula .frac > span:first-child { border-bottom: 1.4px solid currentColor; padding: 0 4px; }
.formula .frac > span:last-child { padding: 0 4px; }

/* callouts */
.callout { position: relative; display: flex; gap: 14px; margin: 20px 0; padding: 16px 18px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); }
.callout::before { content: ""; position: absolute; left: -1px; top: 12px; bottom: 12px; width: 3px; border-radius: 3px; background: var(--c); }
.callout .ci { flex: none; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; color: var(--c); border: 1px solid var(--border); }
.callout b.ct { display: block; color: var(--text); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 2px; }
.callout p:last-child { margin-bottom: 0; }
.callout.key { --c: var(--text); }
.callout.note { --c: var(--text-3); }
.callout.tip { --c: var(--ok); }
.callout.warn { --c: var(--bad); }

/* tables */
.tbl-wrap { overflow-x: auto; margin: 18px 0 22px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; padding: 11px 14px; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .15s; }
tbody tr:hover { background: var(--accent-soft); }
td:first-child { font-weight: 600; color: var(--text); }

/* code (always dark, like a terminal) */
.code { position: relative; margin: 18px 0 22px; border-radius: 12px; overflow: hidden; background: var(--code-bg); border: 1px solid var(--code-border); }
.code-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid #1d1d1d; font-size: 12px; color: #7a7a7a; font-family: var(--mono); }
.code-head .dots { display: flex; gap: 6px; margin-right: 6px; }
.code-head .dots i { width: 10px; height: 10px; border-radius: 50%; background: #2c2c2c; }
.copy-btn { margin-left: auto; padding: 3px 10px; border-radius: 6px; cursor: pointer; border: 1px solid #2c2c2c; background: transparent; color: #8a8a8a; font-size: 11px; font-family: var(--mono); }
.copy-btn:hover { color: #fff; border-color: #555; }
.code pre { margin: 0; padding: 16px 18px; overflow-x: auto; font-family: var(--mono); font-size: 13px; line-height: 1.65; color: #e8e8e8; }
.tok-k { color: #ffffff; font-weight: 600; }
.tok-s { color: #b5b5b5; }
.tok-c { color: #6a6a6a; font-style: italic; }
.tok-n { color: #d9d9d9; }
.tok-f { color: #ffffff; text-decoration: underline; text-decoration-color: #444; text-underline-offset: 3px; }
.tok-b { color: #c9c9c9; font-style: italic; }

/* widgets */
.widget { margin: 26px 0 30px; border-radius: 16px; overflow: hidden; border: 1px solid var(--border); background: var(--surface); }
.widget-head { display: flex; align-items: center; gap: 12px; padding: 13px 18px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.widget-head .wi { flex: none; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--text); color: var(--bg); }
.widget-head h4 { margin: 0; font-size: 14.5px; }
.widget-head p { margin: 0; font-size: 12.5px; color: var(--text-3); line-height: 1.4; }
.widget-head .tag { margin-left: auto; font-size: 10px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--text-2); border: 1px solid var(--border-2); padding: 3px 8px; border-radius: 99px; white-space: nowrap; }
.widget-body { padding: 18px; }
.widget canvas { display: block; max-width: 100%; border-radius: 10px; }
.w-row { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-start; }
.w-col { flex: 1 1 260px; min-width: 0; }
.w-stage { flex: 2 1 340px; min-width: 0; }
.w-controls { display: flex; flex-direction: column; gap: 14px; }
.w-note { font-size: 13px; color: var(--text-2); margin-top: 10px; line-height: 1.55; }
.w-out { font-family: var(--mono); font-size: 12.5px; padding: 12px 14px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); white-space: pre-wrap; line-height: 1.6; }
.w-out b { color: var(--text); font-weight: 700; }
.canvas-box { position: relative; background: var(--surface-2); border-radius: 12px; border: 1px solid var(--border); padding: 8px; }
.canvas-label { font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); margin: 0 0 6px 2px; }

.ctl { display: flex; flex-direction: column; gap: 6px; }
.ctl-top { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-2); font-weight: 500; }
.ctl-top output { font-family: var(--mono); color: var(--text); font-weight: 600; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 4px; border-radius: 99px; background: linear-gradient(90deg, var(--text) var(--p, 50%), var(--surface-3) var(--p, 50%)); outline: none; cursor: pointer; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--bg); border: 2px solid var(--text); transition: transform .15s; }
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.25); }
input[type=range]::-moz-range-thumb { width: 13px; height: 13px; border-radius: 50%; background: var(--bg); border: 2px solid var(--text); }
.seg { display: inline-flex; flex-wrap: wrap; gap: 3px; padding: 3px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.seg button { border: 0; background: transparent; color: var(--text-2); padding: 5px 10px; border-radius: 7px; font-size: 12.5px; font-weight: 600; cursor: pointer; transition: all .2s; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--text); color: var(--bg); }
.w-btns { display: flex; gap: 8px; flex-wrap: wrap; }
select, .w-input { height: 34px; padding: 0 10px; border-radius: 8px; font-size: 14px; font-family: inherit; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.w-input { width: 80px; font-family: var(--mono); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text-2); cursor: pointer; }
.check input { accent-color: var(--text); width: 15px; height: 15px; }

.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 90px 1fr 60px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .track { height: 10px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.bar-row .fill { height: 100%; border-radius: 99px; background: var(--text); transition: width .45s var(--ease); }
.bar-row .v { font-family: var(--mono); text-align: right; color: var(--text-2); }

.mgrid { display: inline-grid; gap: 3px; font-family: var(--mono); font-size: 12px; }
.mgrid div { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 6px; background: var(--surface-3); color: var(--text); transition: background .25s, transform .25s, box-shadow .25s; }
.mgrid div.hl { box-shadow: 0 0 0 2px var(--text); transform: scale(1.06); }
.mgrid input { width: 40px; height: 34px; text-align: center; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-family: var(--mono); font-size: 12px; }

/* flip cards */
.check-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.check-head p { margin: 0; color: var(--text-2); }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.flip { perspective: 1200px; cursor: pointer; min-height: 170px; }
.flip-inner { position: relative; height: 100%; min-height: 170px; transition: transform .7s var(--ease); transform-style: preserve-3d; }
.flip.on .flip-inner { transform: rotateY(180deg); }
.flip-face { position: absolute; inset: 0; padding: 18px; border-radius: 14px; backface-visibility: hidden; -webkit-backface-visibility: hidden; border: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; }
.flip-face .q-n { font-size: 10.5px; font-weight: 600; color: var(--text-3); letter-spacing: .1em; text-transform: uppercase; }
.flip-face .q-t { font-weight: 600; margin-top: 6px; line-height: 1.45; font-size: 15px; }
.flip-face .hint { margin-top: auto; font-size: 12px; color: var(--text-3); }
.flip-back { transform: rotateY(180deg); background: var(--text); color: var(--bg); border-color: var(--text); }
.flip-back .q-n { color: color-mix(in srgb, var(--bg) 60%, var(--text)); }
.flip-back .q-a { margin-top: 6px; font-size: 14.5px; line-height: 1.55; }
.flip-back a { color: var(--bg); }

/* quiz */
.quiz { border-radius: 16px; border: 1px solid var(--border); background: var(--surface); overflow: hidden; }
.quiz-head { display: flex; align-items: center; gap: 14px; padding: 16px 22px; border-bottom: 1px solid var(--border); }
.quiz-head h3 { margin: 0; font-size: 16px; }
.quiz-head .qprog { margin-left: auto; font-family: var(--mono); font-size: 12.5px; color: var(--text-2); }
.quiz-track { height: 2px; background: var(--surface-3); }
.quiz-track i { display: block; height: 100%; width: 0; background: var(--text); transition: width .5s var(--ease); }
.quiz-body { padding: 24px 22px; min-height: 250px; }
.quiz-q { font-size: 17px; font-weight: 600; margin-bottom: 16px; line-height: 1.5; }
.opts { display: grid; gap: 8px; }
.opt { display: flex; align-items: center; gap: 12px; text-align: left; padding: 12px 14px; border-radius: 11px; cursor: pointer; font-size: 15px; border: 1px solid var(--border); background: var(--surface); color: var(--text); transition: transform .2s var(--spring), border-color .2s, background .2s; }
.opt:hover:not(:disabled) { border-color: var(--text); transform: translateX(3px); }
.opt .ol { flex: none; width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; font-weight: 600; font-size: 12px; border: 1px solid var(--border-2); color: var(--text-2); }
.opt.right { border-color: var(--text); background: var(--surface-2); animation: pop .45s var(--spring); }
.opt.right .ol { background: var(--text); color: var(--bg); border-color: var(--text); }
.opt.wrong { border-color: var(--bad); animation: shake .4s; }
.opt.wrong .ol { background: var(--bad); border-color: var(--bad); color: #fff; }
.opt:disabled { cursor: default; }
@keyframes pop { 50% { transform: scale(1.02); } }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
.explain { margin-top: 14px; padding: 14px 16px; border-radius: 11px; font-size: 14.5px; background: var(--surface-2); border: 1px solid var(--border); animation: pageIn .4s var(--ease); }
.quiz-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.quiz-result { text-align: center; padding: 20px 0; }
.quiz-result .score { font-family: var(--serif); font-size: 84px; line-height: 1; }
.quiz-result p { color: var(--text-2); }

.ch-complete { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; padding: 24px; border-radius: 16px; margin: 40px 0 24px; border: 1px solid var(--border); background: var(--surface); }
.ch-complete h3 { margin: 0 0 4px; font-family: var(--serif); font-weight: 400; font-size: 28px; }
.ch-complete p { margin: 0; color: var(--text-2); font-size: 14px; max-width: 480px; }
.ch-complete .btn { margin-left: auto; }
.ch-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ch-nav a { display: block; padding: 16px 18px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none; transition: all .25s var(--ease); }
.ch-nav a:hover { border-color: var(--text); transform: translateY(-2px); }
.ch-nav small { display: block; color: var(--text-3); font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
.ch-nav .next { text-align: right; }
.ch-nav span { font-weight: 600; }

/* TOC */
.toc { position: sticky; top: calc(var(--topbar-h) + 24px); align-self: start; font-size: 13px; padding-bottom: 40px; max-height: calc(100vh - var(--topbar-h) - 40px); overflow-y: auto; }
.toc h5 { margin: 20px 0 10px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em; color: var(--text-3); font-weight: 600; }
.toc ol { list-style: none; padding: 0; margin: 0; }
.toc a { display: flex; gap: 8px; align-items: flex-start; padding: 5px 0; color: var(--text-3); line-height: 1.4; text-decoration: none; transition: color .2s; }
.toc a:hover { color: var(--text); }
.toc a.on { color: var(--text); font-weight: 600; }
.toc .tick { flex: none; width: 12px; height: 12px; margin-top: 3px; border-radius: 50%; border: 1.5px solid var(--border-2); transition: all .3s; }
.toc a.read .tick { background: var(--text); border-color: var(--text); }
.toc a.on .tick { border-color: var(--text); }
.toc-card { margin-top: 14px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); }
.toc-card b { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.toc-prog { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-3); margin-bottom: 8px; }
.toc-prog b { margin: 0; font-family: var(--mono); color: var(--text); }

/* notes drawer */
.notes-drawer {
  position: fixed; top: var(--topbar-h); right: 0; bottom: 0; width: min(420px, 100vw); z-index: 60;
  display: flex; flex-direction: column; background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  transform: translateX(100%); transition: transform .4s var(--ease);
}
.notes-drawer.open { transform: none; }
.nd-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.nd-head .muted { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notes-drawer textarea { flex: 1; resize: none; border: 0; outline: 0; padding: 18px; background: transparent; color: var(--text); font: 15px/1.7 var(--font); }
.nd-foot { display: flex; justify-content: space-between; padding: 10px 16px; border-top: 1px solid var(--border); }

/* review + notes pages */
.rv { margin-top: 30px; }
.rv-meta { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--text-3); margin-bottom: 10px; }
.rv-card, .rv-card .flip-inner, .rv-card .flip-face { min-height: 280px; }
.rv-card .flip-face { padding: 30px; justify-content: center; text-align: center; align-items: center; }
.rv-card .q-t { font-size: 22px; font-family: var(--serif); font-weight: 400; line-height: 1.3; }
.rv-card .q-a { font-size: 17px; }
.rv-card .flip-back { align-items: center; }
.rv-btns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; animation: pageIn .35s var(--ease); }
.empty { text-align: center; padding: 50px 20px; border: 1px dashed var(--border-2); border-radius: 18px; }
.empty h3 { margin: 0 0 6px; font-family: var(--serif); font-weight: 400; font-size: 30px; }
.note-card { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); margin-bottom: 12px; overflow: hidden; }
.nc-h { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.nc-h a { text-decoration: none; color: var(--text); display: flex; flex-direction: column; }
.nc-h small { color: var(--text-3); font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; }
.note-card textarea { width: 100%; border: 0; outline: 0; padding: 14px 16px; background: transparent; color: var(--text); font: 14.5px/1.65 var(--font); resize: vertical; }

/* search */
.search-modal { position: fixed; inset: 0; z-index: 200; background: rgba(0, 0, 0, .55); backdrop-filter: blur(5px); display: flex; justify-content: center; padding-top: 12vh; animation: fade .2s; }
.search-modal[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.search-box { width: min(640px, calc(100% - 32px)); max-height: 70vh; display: flex; flex-direction: column; border-radius: 16px; background: var(--surface); border: 1px solid var(--border-2); box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .6); overflow: hidden; animation: pageIn .3s var(--ease); }
.search-input-row { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); color: var(--text-3); }
.search-input-row input { flex: 1; border: 0; outline: 0; background: none; color: var(--text); font-size: 17px; font-family: inherit; }
.search-results { overflow-y: auto; padding: 8px; }
.sr { display: block; padding: 10px 14px; border-radius: 10px; color: var(--text); text-decoration: none; }
.sr:hover, .sr.sel { background: var(--surface-2); }
.sr small { display: block; color: var(--text-3); font-size: 12px; }
.sr .ctx { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.sr mark { background: var(--text); color: var(--bg); border-radius: 3px; padding: 0 2px; }
.sr-empty { padding: 30px; text-align: center; color: var(--text-3); }

/* toasts */
.toast-wrap { position: fixed; right: 20px; bottom: 20px; z-index: 300; display: flex; flex-direction: column; gap: 10px; }
.toast { display: flex; align-items: center; gap: 12px; padding: 11px 15px; border-radius: 12px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); font-size: 14px; animation: toastIn .5s var(--spring); }
.toast .ti { min-width: 30px; height: 30px; padding: 0 6px; border-radius: 8px; display: grid; place-items: center; background: var(--bg); color: var(--text); font-weight: 700; font-size: 12.5px; }
.toast.out { animation: toastOut .35s forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(20px) scale(.92); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(40px); } }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 250; width: 100%; height: 100%; }

/* glossary / flashcards / roadmap (course widgets) */
.filter-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.filter-row input { flex: 1; min-width: 200px; height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 15px; font-family: inherit; }
.filter-row input:focus { outline: none; border-color: var(--text); }
.gloss-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 10px; }
.gloss { padding: 15px 17px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); transition: transform .25s var(--spring), border-color .2s; }
.gloss:hover { transform: translateY(-2px); border-color: var(--border-2); }
.gloss b { display: block; font-size: 15px; margin-bottom: 4px; }
.gloss span { font-size: 14px; color: var(--text-2); }
.flash-stage { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.flash-stage .flip { width: min(620px, 100%); min-height: 260px; }
.flash-stage .flip-inner, .flash-stage .flip-face { min-height: 260px; }
.flash-stage .flip-face { justify-content: center; align-items: center; text-align: center; padding: 30px; }
.flash-stage .q-t { font-size: 20px; }
.flash-stage .q-a { font-size: 17px; }
.overall { padding: 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); }
.overall-top { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.overall-bar { height: 5px; border-radius: 99px; background: var(--surface-3); margin-top: 8px; overflow: hidden; }
.overall-bar i { display: block; height: 100%; width: 0; border-radius: 99px; background: var(--text); transition: width .8s var(--ease); }
.roadmap { position: relative; margin: 20px 0; padding-left: 34px; }
.roadmap::before { content: ""; position: absolute; left: 12px; top: 6px; bottom: 6px; width: 1px; background: var(--border-2); }
.rm-item { position: relative; margin-bottom: 12px; padding: 14px 46px 14px 16px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); transition: border-color .2s; }
.rm-item::before { content: ""; position: absolute; left: -28px; top: 19px; width: 11px; height: 11px; border-radius: 50%; background: var(--bg); border: 2px solid var(--text-3); transition: all .3s; }
.rm-item.done { border-color: var(--border-2); }
.rm-item.done::before { background: var(--text); border-color: var(--text); }
.rm-item .wk { font-family: var(--mono); font-size: 11.5px; color: var(--text-3); font-weight: 600; }
.rm-item h4 { margin: 2px 0 4px; font-size: 16px; }
.rm-item p { margin: 0; font-size: 14px; color: var(--text-2); }
.rm-item label { position: absolute; top: 14px; right: 14px; }

/* responsive */
@media (max-width: 1180px) {
  .ch-layout { grid-template-columns: minmax(0, 1fr); }
  .toc { display: none; }
  .two-col { grid-template-columns: 1fr; }
  .lesson-list { padding-left: 0; }
  .part-no { display: none; }
}
@media (max-width: 960px) {
  .menu-btn { display: grid; }
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, .45); }
  .main { margin-left: 0; }
  .search-trigger { margin-left: 6px; }
  .search-trigger kbd { display: none; }
  .course-ring { display: none; }
}
@media (max-width: 640px) {
  .wrap, .dash-hero, .course-hero, .ch-hero { padding-left: 16px; padding-right: 16px; }
  .ch-layout { padding: 0 16px; }
  .brand-text, #xpChip { display: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .ch-nav { grid-template-columns: 1fr; }
  .widget-body { padding: 12px; }
  .bar-row { grid-template-columns: 70px 1fr 50px; }
  .content h2 { font-size: 28px; }
  .lesson-row { grid-template-columns: 34px minmax(0, 1fr) 20px; }
  .lr-meta, .lr-read { display: none; }
  .rv-btns { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .reveal { opacity: 1; transform: none; }
}
