:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #5c6672;
  --line: #d9e1ea;
  --panel: #ffffff;
  --soft: #f5f7fb;
  --field: #ffffff;
  --accent: #0b6bcb;
  --accent-strong: #074f9f;
  --signal: #148f86;
  --signal-soft: #e3f5f2;
  --warning: #9a5b00;
  --warning-soft: #fff5df;
  --error: #a52b2b;
  --error-soft: #fff0f0;
  --header-bg: rgba(255, 255, 255, 0.94);
  --rail-bg: #eef3f8;
  --shadow: 0 16px 38px rgba(24, 35, 51, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e8eef6;
  --muted: #a7b2c2;
  --line: #2a3b4d;
  --panel: #111923;
  --soft: #0b1118;
  --field: #0f1721;
  --accent: #69afff;
  --accent-strong: #9dccff;
  --signal: #36d0c2;
  --signal-soft: #102c2d;
  --warning: #ffc267;
  --warning-soft: #352812;
  --error: #ff9a9a;
  --error-soft: #35191c;
  --header-bg: rgba(11, 17, 24, 0.95);
  --rail-bg: #0e1721;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
}

/* Diagram colour scheme (semantic, theme-aware). Shared by all topic SVGs:
   resultant/hypotenuse = blue, horizontal/adjacent/x = teal, vertical/opposite/y
   = amber, angle = violet, with a faint fill and a text halo for legibility. */
:root {
  --fig-resultant: var(--accent);
  --fig-x: var(--signal);
  --fig-y: #c2710c;
  --fig-angle: #7c5cff;
  --fig-fill: color-mix(in srgb, var(--accent) 9%, transparent);
  --fig-halo: var(--soft);
}
:root[data-theme="dark"] {
  --fig-y: #f5b454;
  --fig-angle: #b69bff;
  --fig-fill: color-mix(in srgb, var(--accent) 16%, transparent);
}
.hook-figure svg text, .example-figure svg text, .exam-figure svg text {
  paint-order: stroke; stroke: var(--fig-halo); stroke-width: 3.5px; stroke-linejoin: round;
}

* { box-sizing: border-box; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--soft); color: var(--ink); line-height: 1.55; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 230px 1fr auto;
  align-items: center;
  gap: 24px;
  min-height: 68px;
  padding: 10px 22px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand { font-weight: 800; text-decoration: none; }
.course-title { display: flex; align-items: baseline; gap: 12px; }
.course-title span { color: var(--accent-strong); font-weight: 800; }
.course-title strong { font-size: 14px; color: var(--muted); }
.header-actions { display: flex; align-items: center; gap: 10px; }
.learner-badge { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--signal); color: #fff; font-size: 13px; font-weight: 850; }
.theme-toggle { display: inline-flex; align-items: center; min-height: 36px; padding: 0 13px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--ink); font-weight: 750; text-decoration: none; cursor: pointer; }

.learning-shell { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: calc(100vh - 68px); }
.topic-rail { position: sticky; top: 68px; height: calc(100vh - 68px); overflow-y: auto; padding: 24px 16px 40px; background: var(--rail-bg); border-right: 1px solid var(--line); }
.rail-heading { padding: 0 10px 18px; }
.rail-heading h2 { margin: 0 0 14px; font-size: 23px; }
.eyebrow { margin: 0 0 8px; color: var(--accent-strong); font-size: 11px; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }
/* sticky in-page lesson navigation (built by lesson.js buildLessonNav) */
.lesson-nav { position: sticky; top: 68px; z-index: 15; display: flex; gap: 4px; overflow-x: auto; padding: 8px 10px; margin: 0 0 20px; border: 1px solid var(--line); border-radius: 999px; background: color-mix(in srgb, var(--panel) 90%, transparent); backdrop-filter: blur(8px); box-shadow: var(--shadow); scrollbar-width: none; }
.lesson-nav::-webkit-scrollbar { display: none; }
.lesson-nav a { flex: 0 0 auto; padding: 6px 13px; border-radius: 999px; color: var(--muted); font-size: 13px; font-weight: 750; text-decoration: none; white-space: nowrap; }
.lesson-nav a:hover { color: var(--ink); background: var(--soft); }
.lesson-nav a.is-active { color: #fff; background: var(--accent); }
.lesson-nav .nav-tick { margin-left: 4px; color: var(--signal); }
.lesson-nav a.is-active .nav-tick { color: #fff; }
[data-lesson-anchor] { scroll-margin-top: 132px; }
.course-progress { font-size: 13px; color: var(--muted); }
.course-progress strong { color: var(--ink); }
.progress-track { height: 7px; margin-top: 7px; overflow: hidden; border-radius: 999px; background: var(--line); }
.progress-track span { display: block; width: 0; height: 100%; background: var(--signal); transition: width .35s ease; }

.topic-nav section + section { margin-top: 24px; }
.topic-nav h3 { margin: 0 10px 7px; color: var(--muted); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
.topic-nav a { display: flex; align-items: center; gap: 9px; min-height: 39px; padding: 7px 9px; border-radius: 7px; color: var(--muted); font-size: 14px; text-decoration: none; }
.topic-nav a:hover { background: color-mix(in srgb, var(--panel) 70%, transparent); color: var(--ink); }
.topic-nav a.is-current { background: var(--panel); color: var(--ink); box-shadow: 0 4px 14px rgba(24, 35, 51, .08); font-weight: 800; }
.topic-nav a.is-future { opacity: .68; }
.status-dot { display: grid; flex: 0 0 auto; place-items: center; width: 23px; height: 23px; border: 1px solid var(--line); border-radius: 50%; background: var(--field); font-size: 11px; font-weight: 850; }
.status-dot.is-done { border-color: var(--signal); background: var(--signal); color: #fff; }

.lesson { width: min(1040px, calc(100% - 48px)); margin: 0 auto; padding: 42px 0 70px; }
.lesson > section { scroll-margin-top: 88px; }
.lesson-topline { display: flex; align-items: end; justify-content: space-between; gap: 30px; margin-bottom: 30px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(36px, 5vw, 64px); line-height: 1.02; letter-spacing: -.035em; }
h2 { margin-bottom: 10px; font-size: clamp(25px, 3vw, 36px); line-height: 1.15; letter-spacing: -.02em; }
h3 { line-height: 1.25; }
.lede { max-width: 760px; margin-bottom: 0; color: var(--muted); font-size: 18px; }
.math { display: inline-block; }
.math .katex { font-size: 1em; }
.lesson-score { min-width: 120px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); text-align: right; box-shadow: var(--shadow); }
.lesson-score span { display: block; color: var(--muted); font-size: 12px; }
.lesson-score strong { font-size: 25px; }

.engineering-hook, .theory-card, .animation-card, .try-card, .practice-card, .exam-bridge, .mock-test, .topic-card, .future-note { margin-bottom: 24px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); box-shadow: var(--shadow); }
.topic-card { padding: 28px 32px; }
.outcomes { margin: 8px 0 0; padding-left: 20px; }
.outcomes li { margin: 5px 0; }
.draft-note { margin: 14px 0 0; padding: 10px 12px; border: 1px dashed var(--line); border-radius: 7px; background: var(--soft); color: var(--muted); font-size: 13px; font-style: italic; }
.spec-list { margin: 12px 0 0; padding-left: 18px; }
.spec-list li { margin: 9px 0; }
.spec-list--exam { padding-left: 0; }
.spec-list--exam li { list-style: none; padding: 12px 14px; border: 1px solid var(--line); border-radius: 7px; background: var(--soft); }
.spec-tier { display: inline-block; margin-right: 6px; padding: 2px 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--soft); color: var(--accent-strong); font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.spec-type { color: var(--muted); font-size: 12px; }
.exam-item .answer-row { align-items: center; }
.exam-q { margin: 0 0 10px; }
/* MathLive themes itself from the OS color scheme; we drive its colours from our
   theme tokens instead (these custom properties pierce its shadow DOM), so the
   editor matches our light/dark toggle regardless of the OS setting. This fixes
   the white fraction placeholders seen when OS=light but the app is in dark mode. */
.ml-field {
  display: block; width: 100%; margin: 8px 0; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 7px;
  background: var(--field); color: var(--ink); font-size: 20px;
  --caret-color: var(--accent);
  --primary-color: var(--accent);
  --selection-background-color: color-mix(in srgb, var(--accent) 30%, var(--field));
  --selection-color: var(--ink);
  --contains-highlight-background-color: color-mix(in srgb, var(--accent) 16%, var(--field));
  --placeholder-color: var(--muted);
  --placeholder-opacity: 1;
  --box-placeholder-color: var(--muted);
  --smart-fence-color: var(--muted);
}
.ml-field:focus-within { outline: 3px solid color-mix(in srgb, var(--accent) 22%, transparent); border-color: var(--accent); }
.li-actions { margin-top: 12px; }
.exam-mark-row { display: flex; justify-content: flex-end; margin-top: 8px; min-height: 36px; }
.exam-solution { margin-top: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); font-size: 14px; }
.exam-solution p { margin: 0 0 6px; }
.exam-solution p:last-child { margin-bottom: 0; }
.engineering-hook { display: grid; grid-template-columns: 1.5fr .7fr; gap: 36px; align-items: center; padding: 32px; background: linear-gradient(135deg, var(--panel), var(--signal-soft)); }
.engineering-hook p:last-child { margin-bottom: 0; }
.hook-aside { display: grid; gap: 14px; }
.hook-figure { margin: 0; display: grid; gap: 8px; justify-items: center; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.hook-figure svg { width: 100%; max-width: 300px; height: auto; }
.hook-figure figcaption { color: var(--muted); font-size: 13px; text-align: center; }
.circuit-figure { margin: 0; padding: 16px; border: 1px solid color-mix(in srgb, var(--signal) 30%, var(--line)); border-radius: 8px; background: var(--panel); }
.circuit-figure svg { display: block; width: 100%; height: auto; color: var(--ink); }
.circuit-figure .wire, .circuit-figure .terminal { fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.circuit-figure .terminal { stroke-width: 3; }
.circuit-figure .resistor { fill: none; stroke: var(--accent); stroke-width: 2.6; }
.circuit-figure .current { fill: var(--signal); stroke: none; }
.circuit-figure text { font: italic 700 16px Georgia, "Times New Roman", serif; fill: currentColor; }
.circuit-figure .lbl-r { fill: var(--accent); }
.circuit-figure .lbl-i { fill: var(--signal); }
.circuit-figure figcaption { margin-top: 10px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.circuit-figure figcaption .math { color: var(--ink); }
.circuit-card { display: grid; grid-template-columns: 1fr auto; gap: 8px 18px; padding: 20px; border: 1px solid color-mix(in srgb, var(--signal) 42%, var(--line)); border-radius: 8px; background: var(--panel); }
.circuit-card span { color: var(--muted); }
.circuit-card strong { color: var(--signal); }
.symbol-legend { display: grid; gap: 7px; margin: 20px 0 0; padding: 14px 16px; border: 1px solid color-mix(in srgb, var(--signal) 30%, var(--line)); border-radius: 7px; background: color-mix(in srgb, var(--panel) 74%, transparent); }
.symbol-legend div { display: grid; grid-template-columns: 34px 1fr; gap: 10px; align-items: baseline; }
.symbol-legend dt { color: var(--signal); font-size: 19px; font-weight: 800; }
.symbol-legend dd { margin: 0; color: var(--muted); font-size: 13px; }

.theory-card { padding: 30px 32px; }
.visual-lab { margin-bottom: 24px; padding: 28px 32px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); box-shadow: var(--shadow); }
.visual-lab__body { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(220px, .7fr); gap: 22px; align-items: stretch; }
.visual-lab canvas { display: block; width: 100%; min-height: 260px; aspect-ratio: 900 / 420; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); }
.visual-controls { display: grid; align-content: center; gap: 14px; padding: 18px; border: 1px solid var(--line); border-radius: 9px; background: var(--soft); }
.visual-control { margin: 0; }
.visual-control span { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 5px; color: var(--muted); font-size: 12px; }
.visual-control strong { color: var(--signal); }
.visual-control input[type="range"] { width: 100%; min-height: 26px; padding: 0; accent-color: var(--signal); }
.visual-controls output { min-height: 54px; padding: 10px 12px; border: 1px solid color-mix(in srgb, var(--signal) 35%, var(--line)); border-radius: 7px; background: var(--panel); color: var(--ink); font-size: 13px; font-weight: 750; }
.balance-rule { display: grid; grid-template-columns: 1fr 1fr auto 1fr; align-items: center; gap: 12px; margin-top: 20px; padding: 18px; border-radius: 8px; background: var(--soft); text-align: center; }
.balance-rule span:first-child { color: var(--muted); font-size: 13px; text-align: left; }
.balance-rule strong { padding: 10px; border-bottom: 3px solid var(--signal); }

.examples-section { padding: 22px 0 4px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 22px; margin-bottom: 16px; }
.section-heading p:last-child { max-width: 380px; margin-bottom: 4px; color: var(--muted); }
.scaffold-note { margin: 0 0 16px; padding: 12px 14px; border: 1px solid color-mix(in srgb, var(--signal) 36%, var(--line)); border-radius: 7px; background: var(--signal-soft); color: var(--muted); font-size: 13px; }
.scaffold-note strong { color: var(--signal); }

.steps-mode { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 0 0 16px; }
.steps-mode__label { font-size: 13px; font-weight: 800; color: var(--ink); }
.steps-mode__help { flex-basis: 100%; color: var(--muted); font-size: 12px; }
.steps-toggle { display: inline-flex; align-items: center; min-height: 36px; padding: 5px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--ink); font-size: 13px; font-weight: 800; cursor: pointer; }
.steps-toggle:hover { border-color: var(--accent); }
.steps-toggle:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 22%, transparent); outline-offset: 2px; border-color: var(--accent); }
.steps-toggle__state { position: relative; display: inline-flex; align-items: center; min-height: 18px; padding-left: 42px; }
.steps-toggle__state::before { content: ""; position: absolute; left: 0; top: calc(50% - 9px); width: 32px; height: 18px; border-radius: 999px; background: var(--line); transition: background .2s ease; }
.steps-toggle__state::after { content: ""; position: absolute; left: 2px; top: calc(50% - 7px); width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: left .2s ease; }
.steps-toggle[aria-checked="true"] .steps-toggle__state::before { background: var(--signal); }
.steps-toggle[aria-checked="true"] .steps-toggle__state::after { left: 16px; }

.example-stack { display: grid; gap: 14px; }
.worked-lines div[hidden] { display: none; }
.example-card { padding: 25px 28px; border: 1px solid var(--line); border-left: 5px solid var(--accent); border-radius: 8px; background: var(--panel); box-shadow: 0 8px 24px rgba(24, 35, 51, .06); }
.example-card--exam { border-left-color: var(--signal); }
.example-label, .difficulty-label { display: inline-block; margin-bottom: 12px; padding: 4px 9px; border-radius: 999px; background: var(--soft); color: var(--accent-strong); font-size: 11px; font-weight: 850; text-transform: uppercase; letter-spacing: .05em; }
.equation-purpose { margin: -2px 0 8px; color: var(--ink); font-size: 14px; }
.term-definitions { margin: -2px 0 16px; color: var(--muted); font-size: 13px; line-height: 1.65; }
.term-definitions .math { color: var(--ink); }
.example-body { display: grid; gap: 18px; }
.example-card--figured .example-body { grid-template-columns: 290px minmax(0, 1fr); align-items: start; }
.example-figure { margin: 0; display: grid; gap: 8px; justify-items: center; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--soft); position: sticky; top: 84px; }
.example-figure svg { width: 100%; max-width: 280px; height: auto; }
.example-figure figcaption { color: var(--muted); font-size: 12.5px; text-align: center; line-height: 1.45; }
.worked-lines { display: grid; gap: 1px; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.worked-lines div { display: grid; grid-template-columns: minmax(180px, .8fr) 1.2fr; gap: 22px; align-items: center; padding: 11px 15px; background: var(--soft); }
.worked-lines div.cancellation-step { background: color-mix(in srgb, var(--signal-soft) 76%, var(--panel)); }
.worked-lines .math { font-size: 27px; }
.worked-lines small { color: var(--muted); }

.animation-card { display: grid; grid-template-columns: 1fr; overflow: hidden; }
.animation-copy { padding: 32px 32px 0; }
.video-transcript { margin-top: 22px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 7px; background: var(--soft); }
.video-transcript summary { color: var(--accent-strong); font-weight: 800; cursor: pointer; }
.video-transcript ol { margin: 12px 0 2px; padding-left: 22px; }
.video-transcript li + li { margin-top: 8px; }
.manim-video-frame { align-self: stretch; display: grid; align-content: center; padding: 18px; background: #10151f; }
.manim-video-frame video { display: block; width: 100%; aspect-ratio: 16 / 9; border: 1px solid #344054; border-radius: 7px; background: #10151f; }
.manim-video-frame p { margin: 10px 4px 0; color: #aab4c3; font-size: 12px; text-align: center; }

.video-section { margin-bottom: 24px; padding: 28px 32px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); box-shadow: var(--shadow); }
.video-tiers { display: grid; grid-template-columns: 1fr; gap: 22px; }
.video-card { display: grid; grid-template-columns: 1fr; overflow: hidden; border: 1px solid var(--line); border-radius: 9px; background: var(--soft); }
.video-card__media { width: 100%; aspect-ratio: 16 / 9; display: grid; place-items: center; background: #10151f; }
.video-card__media video { display: block; width: 100%; height: 100%; object-fit: contain; background: #10151f; }
.video-pending { padding: 16px; text-align: center; color: #aab4c3; }
.video-pending__tag { display: inline-block; margin-bottom: 8px; padding: 3px 10px; border-radius: 999px; background: rgba(255, 255, 255, .08); color: #e8eef6; font-size: 11px; font-weight: 850; letter-spacing: .05em; text-transform: uppercase; }
.video-pending p { margin: 0 0 10px; font-size: 13px; }
.video-card__body { padding: 16px 18px 18px; }
.video-tier-label { display: inline-block; margin-bottom: 4px; padding: 2px 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--soft); color: var(--accent-strong); font-size: 11px; font-weight: 850; letter-spacing: .05em; text-transform: uppercase; }
.video-card__body h3 { margin: 4px 0 6px; font-size: 20px; line-height: 1.25; }
.video-card__body p { margin: 0; max-width: 760px; color: var(--muted); font-size: 14px; }

.button, button { border: 1px solid var(--line); }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 0 15px; border-radius: 7px; background: var(--panel); color: var(--ink); font-weight: 800; text-decoration: none; cursor: pointer; }
.button:hover:not(:disabled) { border-color: var(--accent); }
.button--primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.button--disabled { cursor: not-allowed; opacity: .62; }
.text-button { padding: 0; border: 0; background: transparent; color: var(--accent-strong); font-weight: 800; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

.try-card { display: grid; grid-template-columns: minmax(0, 1fr) 260px; overflow: hidden; }
.try-copy { padding: 32px; }
.prompt { display: block; margin: 18px 0; padding: 18px; border-radius: 8px; background: var(--soft); font-size: 42px; text-align: center; }
label { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 800; }
.answer-row, .numeric-row { display: flex; gap: 10px; }
input { width: 100%; min-height: 46px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--field); color: var(--ink); font-size: 17px; }
input:focus { outline: 3px solid color-mix(in srgb, var(--accent) 22%, transparent); border-color: var(--accent); }
#symbolic-help { display: block; margin-top: 7px; color: var(--muted); }
.symbol-palette { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.numeric-row .symbol-palette { flex: 1 0 100%; grid-column: 1 / -1; margin-bottom: 8px; }
.symbol-palette button { min-width: 38px; min-height: 36px; padding: 0 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--soft); color: var(--ink); font-size: 16px; font-weight: 700; line-height: 1; cursor: pointer; }
.symbol-palette button:hover { border-color: var(--accent); }
.symbol-palette button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 22%, transparent); outline-offset: 2px; }
.symbol-palette sup { font-size: .7em; }
.symbol-palette .frac-key { letter-spacing: .02em; }
.symbol-palette .frac-key sup, .symbol-palette .frac-key sub { font-size: .8em; }
.answer-preview { min-height: 46px; margin: 10px 0 4px; padding: 8px 14px; border: 1px dashed var(--line); border-radius: 7px; background: var(--soft); }
.answer-preview__label { display: block; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.answer-preview__math { min-height: 24px; margin-top: 2px; }
.answer-preview__math .katex-display { margin: 4px 0 0; text-align: left; }
.answer-preview.is-stale .answer-preview__math { opacity: .4; }
.attempt-panel { padding: 30px 24px; background: var(--soft); border-left: 1px solid var(--line); }
.attempt-panel span { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; }
.attempt-panel strong { display: block; margin: 7px 0 18px; font-size: 21px; }
.attempt-panel p { color: var(--muted); font-size: 13px; }
.feedback { min-height: 28px; margin-top: 12px; padding: 0; font-weight: 750; }
.feedback.is-success, .feedback.is-error, .feedback.is-hint { padding: 10px 12px; border-radius: 7px; }
.feedback.is-success { background: var(--signal-soft); color: var(--signal); }
.feedback.is-error { background: var(--error-soft); color: var(--error); }
.feedback.is-hint { background: var(--warning-soft); color: var(--warning); }
.support-actions { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 11px; }
.practice-next { margin-top: 14px; }

.practice-card { padding: 32px; }
.practice-stats { display: flex; gap: 18px; color: var(--muted); font-size: 13px; }
.practice-stats strong { color: var(--ink); font-size: 18px; }
.practice-tier { margin: 0; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.practice-prompt { margin: 6px 0 4px; font-size: 20px; font-weight: 750; }
.numeric-row { align-items: center; flex-wrap: wrap; }
.numeric-row input { flex: 1; width: auto; }
.numeric-suffix { flex: 0 0 auto; color: var(--muted); font-weight: 750; white-space: nowrap; }
.exam-source { margin: 0 0 4px; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.exam-q { font-size: 18px; font-weight: 750; margin: 4px 0 12px; }
.exam-figure { margin: 4px 0 14px; }
.exam-figure img { display: block; max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 8px; }
.exam-figure svg { display: block; width: 100%; max-width: 300px; height: auto; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--soft); }
.exam-figure figcaption { margin-top: 6px; color: var(--muted); font-size: 12.5px; line-height: 1.45; max-width: 260px; }
.exam-solution { margin-top: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--soft); }
.exam-solution p { margin: 4px 0; }
.calc-result { display: inline-block; margin-top: 6px; color: var(--accent); font-weight: 800; white-space: nowrap; }

/* Glossary widget */
.gloss-fab { position: fixed; right: 18px; bottom: 18px; z-index: 60; display: inline-flex; align-items: center; gap: 7px; padding: 11px 16px; border: 1px solid var(--line); border-radius: 999px; background: var(--accent); color: #fff; font-size: 14px; font-weight: 800; cursor: pointer; box-shadow: var(--shadow); }
.gloss-fab:hover { filter: brightness(1.05); }
.gloss-fab:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 30%, transparent); outline-offset: 2px; }
.gloss-panel { position: fixed; right: 18px; bottom: 70px; z-index: 60; width: min(380px, calc(100vw - 36px)); max-height: min(560px, calc(100vh - 110px)); display: flex; flex-direction: column; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); }
.gloss-panel[hidden] { display: none; }
.gloss-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.gloss-head strong { font-size: 16px; }
.gloss-close { border: none; background: none; color: var(--muted); font-size: 16px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.gloss-close:hover { background: var(--soft); color: var(--ink); }
.gloss-langs { display: flex; gap: 6px; margin-bottom: 10px; }
.gloss-lang { padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--soft); color: var(--ink); font-size: 13px; font-weight: 800; cursor: pointer; }
.gloss-lang[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.gloss-en { color: var(--muted); font-size: 11px; font-weight: 700; }
.gloss-term { border: none; background: none; padding: 0 1px; margin: 0; font: inherit; color: var(--accent-strong); cursor: help; border-bottom: 1px dashed color-mix(in srgb, var(--accent) 60%, transparent); }
.gloss-term::after { content: "\00a0?"; font-size: .72em; font-weight: 800; vertical-align: super; line-height: 0; }
.gloss-term:hover, .gloss-term:focus-visible { background: var(--signal-soft); border-bottom-style: solid; outline: none; }
.gloss-term[aria-expanded="true"] { background: var(--signal-soft); border-bottom-style: solid; }
/* inline definition popover (tap-to-define) */
.gloss-pop[hidden] { display: none; }
.gloss-pop { position: absolute; z-index: 70; width: min(320px, calc(100vw - 24px)); padding: 12px 30px 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); box-shadow: var(--shadow); }
.gloss-pop h4 { margin: 0 0 5px; font-size: 14px; }
.gloss-pop p { margin: 0; font-size: 13px; line-height: 1.5; color: var(--ink); }
.gloss-pop-foot { margin-top: 9px; }
.gloss-pop-more { border: none; background: none; padding: 0; color: var(--accent); font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; text-decoration: underline; }
.gloss-pop-close { position: absolute; top: 6px; right: 6px; border: none; background: none; color: var(--muted); font-size: 14px; line-height: 1; cursor: pointer; padding: 4px 7px; border-radius: 6px; }
.gloss-pop-close:hover { background: var(--soft); color: var(--ink); }
.gloss-search { width: 100%; min-height: 42px; }
.gloss-results { margin-top: 10px; overflow-y: auto; }
.gloss-item { padding: 10px 0; border-top: 1px solid var(--line); }
.gloss-item:first-child { border-top: none; }
.gloss-item h4 { margin: 0 0 4px; font-size: 15px; }
.gloss-item p { margin: 0; font-size: 14px; line-height: 1.5; color: var(--ink); }
.gloss-see { margin-top: 6px !important; color: var(--muted); font-size: 12px !important; }
.gloss-link { border: none; background: none; padding: 0; color: var(--accent); font: inherit; font-size: 12px; cursor: pointer; text-decoration: underline; }
.gloss-empty, .gloss-note { color: var(--muted); font-size: 12px; }
.gloss-note { margin: 10px 0 0; padding-top: 8px; border-top: 1px solid var(--line); }
.numeric-row .calc-result { flex: 1 0 100%; margin-top: 4px; }
.practice-workspace { display: grid; grid-template-columns: minmax(0, 1fr) 270px; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.problem-panel { padding: 28px; }
.practice-step + .practice-step { margin-top: 18px; padding-top: 18px; border-top: 1px dashed var(--line); }
.step-label { display: flex; align-items: center; gap: 9px; margin: 0 0 10px; font-weight: 800; }
.step-label span { padding: 3px 9px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 850; letter-spacing: .05em; text-transform: uppercase; }
.problem-context { color: var(--muted); }
.problem-context + .equation-purpose { margin-top: -8px; }
.problem-equation { display: block; margin: 18px 0; padding: 19px; border-radius: 8px; background: var(--soft); font-size: 44px; text-align: center; }
.problem-equation + .term-definitions { margin-top: -7px; }
.problem-question { font-weight: 750; }
.numeric-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; }
.unit-box { display: grid; min-width: 52px; place-items: center; padding: 0 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--soft); font-weight: 850; }
.mastery-panel { padding: 27px 22px; background: var(--soft); border-left: 1px solid var(--line); text-align: center; }
.mastery-ring { display: grid; place-items: center; width: 118px; height: 118px; margin: 8px auto 18px; border-radius: 50%; background: conic-gradient(var(--signal) var(--mastery, 0%), var(--line) 0); position: relative; }
.mastery-ring::after { content: ""; position: absolute; inset: 10px; border-radius: 50%; background: var(--soft); }
.mastery-ring strong { position: relative; z-index: 1; font-size: 23px; }
.mastery-panel p { color: var(--muted); font-size: 13px; }
.mastery-steps { display: flex; justify-content: center; gap: 7px; margin-top: 18px; }
.mastery-steps span { width: 17px; height: 17px; border: 1px solid var(--line); border-radius: 50%; background: var(--field); }
.mastery-steps span.is-complete { border-color: var(--signal); background: var(--signal); }

.exam-bridge { display: flex; align-items: center; justify-content: space-between; gap: 28px; padding: 30px 32px; background: linear-gradient(135deg, var(--panel), var(--warning-soft)); }
.mock-test { padding: 32px; }
.mock-list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 14px; }
.mock-item { padding: 20px 22px; border: 1px solid var(--line); border-left: 5px solid var(--accent); border-radius: 8px; background: var(--soft); }
.mock-q { margin: 0 0 12px; font-weight: 750; }
.mock-item .answer-row { align-items: center; }
.mock-mark { display: inline-grid; place-items: center; min-width: 36px; min-height: 36px; padding: 0 8px; border-radius: 7px; font-size: 18px; font-weight: 850; }
.mock-mark.is-correct { background: var(--signal-soft); color: var(--signal); }
.mock-mark.is-wrong { background: var(--error-soft); color: var(--error); }
.mock-solution { margin-top: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); font-size: 14px; }
.mock-solution p { margin: 0 0 6px; }
.mock-solution p:last-child { margin-bottom: 0; }
.mock-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 18px; margin-top: 18px; }
.exam-bridge p { max-width: 680px; margin-bottom: 0; }
.lesson-navigation { display: flex; justify-content: space-between; gap: 16px; margin: 34px 0; }
.future-note { padding: 20px 24px; color: var(--muted); }
.future-note p { margin: 5px 0 0; }

.course-map { width: min(900px, calc(100% - 48px)); margin: 0 auto; padding: 42px 0 70px; }
.course-intro { margin-bottom: 28px; }
.course-intro h1 { margin-bottom: 10px; font-size: clamp(30px, 4vw, 48px); letter-spacing: -.03em; }
.course-note { margin-top: 10px; color: var(--muted); font-size: 14px; }
.map-section { margin-bottom: 22px; padding: 22px 24px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); box-shadow: var(--shadow); }
.map-section__head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.map-section__head h2 { margin: 0; font-size: 20px; }
.map-marks { color: var(--muted); font-size: 13px; font-weight: 800; white-space: nowrap; }
.map-topics { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.map-topic a, .map-topic--disabled { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--soft); color: inherit; text-decoration: none; }
.map-topic a:hover { border-color: var(--accent); }
.map-topic--disabled { opacity: .7; }
.map-topic__n { display: grid; place-items: center; flex: 0 0 auto; min-width: 34px; height: 30px; padding: 0 6px; border-radius: 7px; background: var(--field); border: 1px solid var(--line); font-size: 12px; font-weight: 850; }
.map-topic__title { flex: 1; font-weight: 750; }
.map-tag { flex: 0 0 auto; padding: 3px 8px; border-radius: 6px; background: var(--soft); border: 1px solid var(--line); color: var(--muted); font-size: 11px; font-weight: 850; letter-spacing: .03em; }
.map-ring { position: relative; display: inline-flex; align-items: center; flex: 0 0 auto; color: var(--accent); }
.map-ring.is-full { color: var(--signal); }
.map-ring__tick { position: absolute; inset: 0; display: grid; place-items: center; font-size: 10px; font-weight: 900; color: var(--signal); }
.map-badge { padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 850; text-transform: uppercase; letter-spacing: .04em; }
.map-badge.is-prototype { background: var(--signal-soft); color: var(--signal); }
.map-badge.is-draft { background: var(--warning-soft); color: var(--warning); }
.map-badge.is-planned { background: var(--soft); color: var(--muted); border: 1px solid var(--line); }

.calc-panel { position: fixed; right: 18px; bottom: 18px; z-index: 50; width: 264px; max-height: calc(100vh - 96px); overflow: auto; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); box-shadow: var(--shadow); }
.calc-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; cursor: move; touch-action: none; user-select: none; }
.calc-tools { display: flex; align-items: center; gap: 6px; }
.calc-mini { min-height: 28px; padding: 0 9px; border: 1px solid var(--line); border-radius: 999px; background: var(--soft); color: var(--ink); font-size: 11px; font-weight: 850; cursor: pointer; }
.calc-mini:hover { border-color: var(--accent); }
.calc-mini:focus-visible, .calc-close:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 22%, transparent); outline-offset: 2px; }
.calc-close { cursor: pointer; }
.calc-panel.is-dragging { opacity: .96; }
.calc-panel.is-sci { width: 300px; }
.calc-panel .calc-sci-keys { display: none; margin-bottom: 6px; }
.calc-panel.is-sci .calc-sci-keys { display: grid; }
.calc-sci-keys button { font-size: 13px; }
.calc-close { border: 0; background: transparent; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; }
.calc-input { font-size: 16px; }
.calc-result { min-height: 30px; margin: 8px 0; padding: 6px 10px; border-radius: 7px; background: var(--soft); font-size: 21px; font-weight: 850; text-align: right; overflow-x: auto; }
.calc-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.calc-keys button { min-height: 42px; border: 1px solid var(--line); border-radius: 7px; background: var(--soft); color: var(--ink); font-size: 15px; font-weight: 750; cursor: pointer; }
.calc-keys button:hover { border-color: var(--accent); }
.calc-keys .calc-equals { background: var(--accent); border-color: var(--accent); color: #fff; }
.calc-keys button:focus-visible, .calc-close:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 22%, transparent); outline-offset: 2px; }

@media (max-width: 900px) {
  .site-header { grid-template-columns: 1fr auto; }
  .course-title { display: none; }
  .learning-shell { grid-template-columns: 1fr; }
  .topic-rail { position: static; height: auto; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .rail-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding-bottom: 8px; }
  .rail-heading .eyebrow, .rail-heading h2 { display: none; }
  .course-progress { width: 100%; }
  .topic-nav { display: flex; overflow-x: auto; gap: 8px; padding-bottom: 4px; }
  .topic-nav section { display: contents; }
  .topic-nav section + section { margin-top: 0; }
  .topic-nav h3 { display: none; }
  .topic-nav a { flex: 0 0 auto; background: var(--panel); }
  .lesson { width: min(100% - 28px, 780px); padding-top: 28px; }
  .engineering-hook, .animation-card, .try-card, .practice-workspace { grid-template-columns: 1fr; }
  .visual-lab__body { grid-template-columns: 1fr; }
  .attempt-panel, .mastery-panel { border-top: 1px solid var(--line); border-left: 0; }
  .mastery-panel { text-align: left; }
  .mastery-ring { margin-left: 0; }
}

@media (max-width: 620px) {
  .site-header { padding: 9px 14px; }
  .lesson-topline, .section-heading, .exam-bridge { align-items: stretch; flex-direction: column; }
  .lesson-score { align-self: flex-start; text-align: left; }
  .engineering-hook, .theory-card, .animation-copy, .try-copy, .practice-card, .exam-bridge { padding: 23px 20px; }
  .visual-lab { padding: 23px 20px; }
  .visual-lab canvas { min-height: 190px; }
  .balance-rule { grid-template-columns: 1fr; }
  .balance-rule span:first-child { text-align: center; }
  .worked-lines div { grid-template-columns: 1fr; gap: 2px; }
  .example-card--figured .example-body { grid-template-columns: 1fr; }
  .example-figure { position: static; }
  .answer-row, .numeric-row { grid-template-columns: 1fr; flex-direction: column; }
  .unit-box { min-height: 42px; }
  .practice-stats { flex-wrap: wrap; }
  .lesson-navigation { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
