/* Interactive lesson components. Loaded only on lesson pages (extraCss).
   Uses the site tokens from site.css, so light and dark themes both work. */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.lesson-hero { padding-block: 8px 40px; border-bottom: 1px solid var(--line); }
.hero-grid { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 48px; align-items: start; }
.hero-grid > div:first-child { padding-top: 24px; }
.lesson-hero .lede { color: var(--ink); max-width: 36ch; }
.hero-note { font-size: 15px; color: var(--muted); margin: 0; }

/* hundred-grid explorer */
.explorer { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.readout { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.readout div { background: var(--accent-soft); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.readout small { display: block; font-size: 12.5px; color: var(--muted); }
.readout output { font: 700 24px/1.2 var(--f); font-variant-numeric: tabular-nums; color: var(--ink); }
#grid100 { width: 100%; height: auto; display: block; }
#grid100 .cell { fill: var(--surface-2); }
#grid100 .fill { fill: var(--accent); }
.slider-row { display: flex; align-items: center; gap: 12px; margin: 14px 0 10px; }
.slider-row label { font-size: 14px; color: var(--muted); white-space: nowrap; }
.slider-row input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); height: 28px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.presets button { font: 600 14px var(--f); background: transparent; color: var(--ink); border: 1px solid var(--line); border-radius: 20px; padding: 5px 12px; cursor: pointer; }
.presets button:hover { border-color: var(--accent); }
.presets button[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.explain-line { font-size: 14.5px; color: var(--muted); margin: 12px 0 0; min-height: 2.6em; }

/* body */
.lesson-body { max-width: 760px; }
.lesson-body section { padding: 36px 0 4px; }
.lesson-body h3 { margin: 26px 0 8px; font-size: 19px; }
.lesson-body p { margin: 0 0 14px; }
.toc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; margin-top: 32px; }
.toc p { font-weight: 600; margin: 0 0 6px; }
.toc ol { margin: 0; padding-left: 22px; columns: 2; column-gap: 28px; font-size: 15.5px; }
.toc li { margin: 3px 0; break-inside: avoid; }
.lesson-body figure { margin: 18px 0 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.lesson-body figure svg { width: 100%; height: auto; display: block; }
.lesson-body figcaption { font-size: 14.5px; color: var(--muted); margin-top: 8px; }
svg .t { fill: var(--ink); font-family: var(--f); }
svg .tm { fill: var(--muted); font-family: var(--f); }
svg .axis { stroke: var(--ink); }
svg .mark { stroke: var(--accent); }
svg .grid { stroke: var(--line); }
svg .bar { fill: var(--surface-2); }
svg .bar.top { fill: var(--accent); }

/* method cards: real sequences, so numbered */
.methods { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 16px 0; }
.methods.one { grid-template-columns: minmax(0, 1fr); }
.method { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px; padding: 14px 16px; }
.method h3 { margin: 0 0 6px; font-size: 17px; }
.method ol { margin: 0; padding-left: 20px; font-size: 15.5px; }
.method .eg { margin: 8px 0 0; font-size: 14.5px; background: var(--accent-soft); border-radius: 6px; padding: 6px 9px; font-variant-numeric: tabular-nums; }

/* tool panels */
.tool { background: var(--surface); border: 1.5px solid var(--accent); border-radius: var(--radius); padding: 18px; margin: 18px 0; }
.tool-title { font-weight: 600; font-size: 18px; margin: 0 0 4px; }
.tool-hint { font-size: 14.5px; color: var(--muted); margin: 0 0 12px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.lesson-body input[type=text], .lesson-body input[type=number] { font: 16px var(--f); padding: 9px 12px; border: 1.5px solid var(--line); border-radius: 8px; min-width: 0; background: var(--bg); color: var(--ink); }
.lesson-body input[type=text]:focus, .lesson-body input[type=number]:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.lbtn { font: 600 15px var(--f); background: var(--accent); color: var(--accent-ink); border: 1.5px solid var(--accent); border-radius: 8px; padding: 9px 16px; cursor: pointer; }
.lbtn:hover { filter: brightness(1.08); }
.lbtn.ghost { background: transparent; color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 6px; }
.chip { background: var(--accent-soft); border-radius: 8px; padding: 6px 12px; font-variant-numeric: tabular-nums; }
.chip b { font-size: 19px; margin-left: 4px; }
ol.steps { margin: 8px 0 0; padding-left: 22px; }
ol.steps li { margin: 5px 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.err { color: var(--bad); font-weight: 600; }

/* benchmark table */
.tbl-tools { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 10px; }
.tbl-wrap { overflow-x: auto; }
table.bench { width: 100%; border-collapse: collapse; background: var(--surface); font-variant-numeric: tabular-nums; font-size: 15.5px; }
table.bench th { background: var(--surface-2); text-align: left; padding: 9px 12px; font-weight: 600; }
table.bench td { border-bottom: 1px solid var(--line); padding: 8px 12px; }
table.bench td.hidden-cell { color: transparent; background: repeating-linear-gradient(45deg, var(--accent-soft), var(--accent-soft) 6px, var(--surface) 6px, var(--surface) 12px); cursor: pointer; }
.note { font-size: 14.5px; color: var(--muted); margin-top: 8px; }

/* compare game */
.cards4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 12px 0; }
.cards4 button { font: 700 23px var(--f); color: var(--ink); background: var(--accent-soft); border: 2px solid transparent; border-radius: 8px; padding: 16px 6px; cursor: pointer; font-variant-numeric: tabular-nums; }
.cards4 button:hover { border-color: var(--accent); }
.cards4 button.is-right { background: var(--ok-soft); border-color: var(--ok); }
.cards4 button.is-wrong { background: var(--bad-soft); border-color: var(--bad); }
.feedback { margin: 8px 0 0; font-size: 15.5px; min-height: 1.6em; }
.feedback.good { color: var(--ok); font-weight: 600; }
.feedback.bad { color: var(--bad); font-weight: 600; }

/* score bar */
.bar-track { height: 22px; background: var(--accent-soft); border-radius: 11px; overflow: hidden; margin: 12px 0 4px; }
.bar-fill { height: 100%; background: var(--accent); width: 0; transition: width .45s ease; }

/* traps */
.traps { list-style: none; padding: 0; margin: 12px 0; }
.traps li { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin: 0 0 10px; }
.traps li strong { color: var(--bad); }

/* practice questions */
.q { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin: 0 0 14px; }
.q-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; margin-bottom: 6px; }
.q-head strong { font-size: 17px; }
.tag { font-size: 13px; border-radius: 12px; padding: 2px 10px; background: var(--accent-soft); color: var(--ink); white-space: nowrap; }
.tag.nocalc { background: var(--surface-2); }
.qopts { display: grid; gap: 6px; margin: 10px 0; }
.qopts label { display: flex; gap: 10px; align-items: center; border: 1.5px solid var(--line); border-radius: 8px; padding: 8px 12px; cursor: pointer; }
.qopts label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
table.tf { width: 100%; margin: 10px 0; border-collapse: collapse; }
table.tf td, table.tf th { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; }
table.tf th { font-size: 14px; background: var(--surface-2); }
table.tf .c { text-align: center; width: 64px; }
.answer-row { display: flex; gap: 10px; align-items: center; margin: 10px 0; }
.qresult { display: none; margin-top: 10px; border-radius: 8px; padding: 10px 12px; font-size: 15.5px; }
.qresult.show { display: block; }
.qresult.ok { background: var(--ok-soft); border-left: 4px solid var(--ok); }
.qresult.no { background: var(--bad-soft); border-left: 4px solid var(--bad); }
.scoreline { position: sticky; bottom: 12px; background: var(--ink); color: var(--bg); border-radius: 30px; padding: 10px 18px; display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 16px 0; }
.scoreline .lbtn { padding: 6px 14px; }

/* summary */
.summary { background: var(--accent-soft); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 24px; margin: 36px 0 8px; }
.summary ul { margin: 0; padding-left: 20px; }
.summary li { margin: 6px 0; }
.summary code { font-family: var(--f); background: var(--surface); padding: 1px 6px; border-radius: 4px; }
.lesson-note { font-size: 14px; color: var(--muted); margin: 18px 0 0; }
.lesson-foot { padding-top: 8px; }
.lesson-foot .callout, .lesson-foot .pager { max-width: 760px; }

@media (max-width: 820px) {
  .hero-grid { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .methods { grid-template-columns: minmax(0, 1fr); }
  .toc ol { columns: 1; }
  .cards4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 420px) { .readout output { font-size: 20px; } }
@media (prefers-reduced-motion: reduce) { .bar-fill { transition: none; } }

/* lesson meta line and completion box */
.lesson-meta-line { font-size: 14.5px; color: var(--muted); margin: -8px 0 16px; }
.lesson-complete { max-width: 760px; background: var(--surface); border: 1.5px solid var(--ok); border-radius: var(--radius); padding: 20px 22px; margin: 18px 0 8px; }
.lesson-complete[hidden] { display: none; }
.lesson-complete h2 { display: flex; align-items: center; gap: 10px; font-size: 22px; margin: 0 0 12px; }
.lesson-complete h2 svg { width: 26px; height: 26px; color: var(--ok); }
.lc-row { display: flex; justify-content: space-between; gap: 10px; font-size: 15px; color: var(--muted); }
.lc-row b { color: var(--ink); }
.lc-track { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; margin: 8px 0 12px; }
.lc-fill { height: 100%; width: 0; background: var(--ok); border-radius: 5px; transition: width .4s ease; }
.lc-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0 0; }
.lc-actions .btn, .lc-actions .btn-outline { font-size: 15px; padding: 11px 18px; }
@media (prefers-reduced-motion: reduce) { .lc-fill { transition: none; } }

/* ===== Shared lesson palette (added with lessons 2–4) =====
   Lesson markup and scripts use these names (navy, gold, sheet …). They map onto the site tokens,
   so lessons follow the light/dark theme. Two areas keep a fixed look in both themes:
   the hero explorer (a navy "instrument panel") and figures (diagrams on a white card). */
:root {
  --navy: var(--accent); --navy-soft: var(--accent-soft); --sheet: var(--surface); --paper: var(--bg);
  --right: var(--ok); --right-soft: var(--ok-soft); --wrong: var(--bad); --wrong-soft: var(--bad-soft);
  --gold: #b58900; --gold-soft: #fbf1d3; --gold-ink: #6d5300;
  --radius-s: 8px; --radius-l: var(--radius); --body: var(--f); --display: var(--f);
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --gold: #f2b155; --gold-soft: #3a2f14; --gold-ink: #f6cf8a; } }
:root[data-theme="dark"] { --gold: #f2b155; --gold-soft: #3a2f14; --gold-ink: #f6cf8a; }

/* explorer: fixed navy panel in both themes */
.explorer {
  --surface: #14365d; --surface-2: #1d4170; --accent: #e3b23c; --accent-ink: #14365d; --accent-soft: rgba(255,255,255,.08);
  --ink: #ffffff; --muted: #b9c8dc; --line: #5b7aa0; --navy: #14365d; --gold: #b58900; --bad: #f3b8b2;
  background: #14365d; color: #fff; border: 0; color-scheme: dark;
}
.explorer .row { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.explorer input[type=text], .base-row input { flex: 1; min-width: 120px; font: 16px var(--f); padding: 8px 10px; border: 1.5px solid #5b7aa0; border-radius: 8px; background: #0e2948; color: #fff; }
.explorer input[type=text]:focus, .base-row input:focus { outline: 2px solid #e3b23c; outline-offset: 1px; }
.readout output.bad { color: #f3b8b2; }
.readout output { white-space: nowrap; }
#bars, #dialSvg { width: 100%; height: auto; display: block; background: #0e2948; border-radius: 8px; }
.base-row { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; font-size: 14px; color: #cbd7e6; }
.base-row input { flex: 0 0 120px; width: 120px; }
.explain-line .err { color: #ffb4ad; }
/* fraction controls (lesson 3) */
.fr-ctl { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 14px 0 8px; }
.frac { display: grid; grid-template-columns: 28px 36px 28px; gap: 2px; align-items: center; justify-items: center; }
.frac button { width: 28px; height: 28px; border-radius: 14px; border: 1px solid #5b7aa0; background: transparent; color: #fff; font: 700 16px/1 var(--f); cursor: pointer; padding: 0; }
.frac button:hover { background: #e3b23c; border-color: #e3b23c; color: #14365d; }
.frac output { font: 700 22px/1.1 var(--f); font-variant-numeric: tabular-nums; text-align: center; }
.frac .vinc { grid-column: 1 / -1; width: 100%; height: 2px; background: #fff; margin: 1px 0; }
.frac-name { grid-column: 1 / -1; font-size: 12px; color: #b9c8dc; }
.opsym { font: 700 30px/1 var(--f); color: #e3b23c; width: 28px; text-align: center; }
.ops { display: flex; justify-content: center; gap: 6px; margin: 6px 0 10px; }
.ops button { font: 700 18px/1 var(--f); width: 44px; height: 34px; background: transparent; color: #fff; border: 1px solid #5b7aa0; border-radius: 8px; cursor: pointer; }
.ops button:hover, .ops button[aria-pressed=true] { background: #e3b23c; border-color: #e3b23c; color: #14365d; }
/* expression stepper (lesson 2) */
.expr { background: #0e2948; border-radius: 8px; padding: 14px; margin: 12px 0 10px; font: 700 clamp(22px,3.2vw,32px)/1.3 var(--f); font-variant-numeric: tabular-nums; letter-spacing: .02em; min-height: 2.4em; display: flex; align-items: center; flex-wrap: wrap; gap: 0 .18em; overflow-wrap: anywhere; }
.expr .hot { color: #ffd45c; border-bottom: 3px solid #e3b23c; }
.expr .new { color: #ffd45c; }
.expr .done { color: #8fe3bd; }
.trace { list-style: none; margin: 10px 0 0; padding: 0; font-size: 14px; color: #b9c8dc; font-variant-numeric: tabular-nums; }
.trace li { padding: 2px 0; border-top: 1px dashed #37557b; }
.trace li b { color: #fff; font-weight: 700; }
.lbtn.gold { background: #e3b23c; border-color: #e3b23c; color: #14365d; }
.lbtn.light { background: transparent; color: #fff; border-color: #7f9bbf; }
.lbtn.light:hover { background: rgba(255,255,255,.1); filter: none; }
.lbtn.ghost[aria-pressed=true] { background: var(--accent); color: var(--accent-ink); }

/* figures: diagrams on a white card in both themes (their drawings use fixed light-background colours) */
.lesson-body figure {
  --surface: #ffffff; --surface-2: #e9eef4; --ink: #18233a; --muted: #56627a; --line: #d5dde8; --accent: #2f78b7; --accent-soft: #e4f0fa;
  background: #ffffff; color: #18233a; color-scheme: light;
}
.lesson-body figure figcaption { color: #56627a; }

/* tables in lessons (generic, plus the benchmark self-test) */
.tbl-wrap, .tbl-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.lesson-body table { width: 100%; border-collapse: collapse; background: var(--surface); font-variant-numeric: tabular-nums; font-size: 15.5px; }
.lesson-body table th { background: var(--surface-2); text-align: left; padding: 9px 12px; font-weight: 600; }
.lesson-body table td { border-bottom: 1px solid var(--line); padding: 8px 12px; }
.lesson-body table td.hidden-cell { color: transparent; background: repeating-linear-gradient(45deg, var(--accent-soft), var(--accent-soft) 6px, var(--surface) 6px, var(--surface) 12px); cursor: pointer; }
tbody tr.sep td, tbody tr.group td { background: var(--accent-soft); font-weight: 600; font-size: 14px; }

/* tools: fields, game, till, drill */
.field { display: flex; flex-direction: column; gap: 3px; font-size: 14px; color: var(--muted); min-width: 0; max-width: 100%; }
.lesson-body select { font: 16px var(--f); padding: 9px 12px; border: 1.5px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); max-width: 100%; width: 100%; }
.check { display: flex; gap: 8px; align-items: center; font-size: 15px; }
.game-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; align-items: center; margin: 0 0 10px; font-size: 15px; color: var(--muted); }
.game-head output { font: 700 20px var(--f); color: var(--ink); font-variant-numeric: tabular-nums; }
.game-q, .drill-q { font: 700 clamp(24px,4vw,34px)/1.2 var(--f); color: var(--ink); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.game-q { background: var(--accent-soft); border-radius: 8px; padding: 16px 18px; margin: 10px 0; min-height: 2.2em; }
.drill-q { margin: 10px 0 4px; }
.till { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 12px 0; }
.till div { background: var(--accent-soft); border-radius: 8px; padding: 12px 14px; }
.till small { display: block; font-size: 13px; color: var(--muted); }
.till b { font: 700 24px/1.2 var(--f); color: var(--ink); font-variant-numeric: tabular-nums; }
.feedback .how { display: block; color: var(--ink); font-weight: 400; margin-top: 4px; }
.method.gold { border-left-color: var(--gold); }
.lesson-body code { font-family: var(--f); background: var(--accent-soft); padding: 1px 6px; border-radius: 4px; font-variant-numeric: tabular-nums; }
.chip { background: var(--gold-soft); }
.tag.nocalc { background: var(--gold-soft); color: var(--gold-ink); }
@media (max-width: 420px) { .fr-ctl { gap: 8px; } .expr { font-size: 22px; } }
