:root {
  --bg: #f4f3ff;
  --surface: #ffffff;
  --surface-2: #ecebfb;
  --text: #15123a;
  --muted: #55527a;
  --border: #d6d3f0;
  --accent: #5b2ee6;
  --accent-text: #ffffff;
  --accent-soft: #ebe6ff;
  --neon-2: #c4208f;
  --cta: #a6f03c;
  --cta-text: #12240a;
  --cta-edge: #5f9a12;
  --glow-ring: #7a4dff;
  --grp-stem: #0e8fb0;
  --grp-lang: #c026a3;
  --grp-soc: #d9730d;
  --grp-arts: #2f9e44;
  --grid-line: #e9e7fa;
  --good: #11763a;
  --good-soft: #dff5e6;
  --bad: #b83a0a;
  --bad-soft: #fdece4;
  --warn-soft: #fff4d6;
  --extra: #8a2fb5;
  --extra-soft: #f3e8fa;
  --tier-foundations: #26803a;
  --tier-application: #1c6fc4;
  --tier-challenge: #c2255c;
  --grid: #e4e2f6;
  --axis: #6b6890;
  --line: #5b2ee6;
  --user-line: #e8590c;
  --wire: #2b2a4a;
  --glow: #ffc53d;
  --radius: 18px;
  --shadow: 0 1px 2px rgb(21 18 58 / 6%), 0 8px 24px rgb(21 18 58 / 7%);
  color-scheme: light;
}

/* The dark tokens, twice: for a device that prefers dark (unless the student chose light with the toggle), and for the
   student's own choice of dark (data-theme="dark" on <html>, set by the theme toggle). Keep the two blocks identical. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0d1f;
    --surface: #15183a;
    --surface-2: #1f2350;
    --text: #eef0ff;
    --muted: #a7add6;
    --border: #2c3170;
    --accent: #3ee6ff;
    --accent-text: #06121f;
    --accent-soft: #17295e;
    --neon-2: #ff5ce1;
    --cta: #b6ff3d;
    --cta-text: #0f1a06;
    --cta-edge: #5c9a10;
    --glow-ring: #3ee6ff;
    --grp-stem: #3ee6ff;
    --grp-lang: #ff5ce1;
    --grp-soc: #ffb02e;
    --grp-arts: #8bff5a;
    --grid-line: #14183d;
    --good: #7dffa0;
    --good-soft: #12372b;
    --bad: #ff9c66;
    --bad-soft: #3d2128;
    --warn-soft: #3a3414;
    --extra: #e3a8ff;
    --extra-soft: #2f2250;
    --tier-foundations: #7dff9a;
    --tier-application: #6fd0ff;
    --tier-challenge: #ff7fb0;
    --grid: #262b5c;
    --axis: #8f96c8;
    --line: #5ad7ff;
    --user-line: #ffa63d;
    --wire: #c9cee8;
    --glow: #ffd666;
    --shadow: 0 0 0 1px rgb(62 230 255 / 16%), 0 10px 30px -14px rgb(62 230 255 / 45%);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0b0d1f;
  --surface: #15183a;
  --surface-2: #1f2350;
  --text: #eef0ff;
  --muted: #a7add6;
  --border: #2c3170;
  --accent: #3ee6ff;
  --accent-text: #06121f;
  --accent-soft: #17295e;
  --neon-2: #ff5ce1;
  --cta: #b6ff3d;
  --cta-text: #0f1a06;
  --cta-edge: #5c9a10;
  --glow-ring: #3ee6ff;
  --grp-stem: #3ee6ff;
  --grp-lang: #ff5ce1;
  --grp-soc: #ffb02e;
  --grp-arts: #8bff5a;
  --grid-line: #14183d;
  --good: #7dffa0;
  --good-soft: #12372b;
  --bad: #ff9c66;
  --bad-soft: #3d2128;
  --warn-soft: #3a3414;
  --extra: #e3a8ff;
  --extra-soft: #2f2250;
  --tier-foundations: #7dff9a;
  --tier-application: #6fd0ff;
  --tier-challenge: #ff7fb0;
  --grid: #262b5c;
  --axis: #8f96c8;
  --line: #5ad7ff;
  --user-line: #ffa63d;
  --wire: #c9cee8;
  --glow: #ffd666;
  --shadow: 0 0 0 1px rgb(62 230 255 / 16%), 0 10px 30px -14px rgb(62 230 255 / 45%);
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* The hidden attribute always wins. An author rule such as `.btn { display: inline-flex }` beats the
   browser's own `[hidden] { display: none }`, so without this a hidden button is still shown and focusable.
   (This also overrides hidden="until-found", which nothing here uses.) */
[hidden] { display: none !important; }

body {
  margin: 0;
  background-color: var(--bg);
  /* A subtle backdrop made of gradients only: two soft glows at the top corners and a faint grid. No images. */
  background-image:
    radial-gradient(640px 300px at 100% -40px, color-mix(in srgb, var(--neon-2) 16%, transparent), transparent 70%),
    radial-gradient(600px 280px at 0% -40px, color-mix(in srgb, var(--accent) 14%, transparent), transparent 70%),
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: auto, auto, 36px 36px, 36px 36px;
  background-repeat: no-repeat, no-repeat, repeat, repeat;
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  /* A word longer than its box (a long German compound in a title or a task prompt, at large text) breaks inside the box
     instead of pushing the page sideways. `break-word`, not `anywhere`: it leaves the minimum width of a box alone, so
     nothing breaks a word that already fits. */
  overflow-wrap: break-word;
}

a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.6rem, 4vw, 2.1rem); }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; margin-bottom: 0.5rem; }
p { margin: 0; }
code { font: 0.85em ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 5px; }

/* The app bar (.topbar, .brand and the nav) is in styles/shell.css. */

.page { max-width: 760px; margin: 0 auto; padding: 1.5rem 16px 4rem; outline: none; }
.stack { display: flex; flex-direction: column; gap: 1.1rem; }
.stack-sm { display: flex; flex-direction: column; gap: 0.6rem; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.kicker { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); margin-bottom: 0.35rem; }
.lede { font-size: 1.05rem; color: var(--muted); }

.hero { padding: 0.5rem 0 0.5rem; }
.hero .lede { margin-top: 0.6rem; max-width: 60ch; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); }
.callout { background: var(--accent-soft); border-color: transparent; }
.callout--good { background: var(--good-soft); }
.callout h2 { margin-bottom: 0.4rem; }
.callout .btn { margin-top: 0.8rem; }

/* Buttons are chunky: a border, a "3D" bottom edge, and a press that moves the button down onto its edge. No transition on them
   (or on the bar): the widget browser tests assert that nothing on a widget's page animates. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  font: inherit; font-weight: 700; font-size: 0.95rem;
  padding: 0.55rem 1rem; min-height: 44px;
  border-radius: 14px; border: 2px solid var(--border);
  background: var(--surface); color: var(--text);
  box-shadow: 0 3px 0 var(--border);
  cursor: pointer; text-decoration: none;
  /* A long label (or a large text size) wraps inside the button instead of making it wider than the page. */
  max-width: 100%; text-align: center; overflow-wrap: anywhere;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--border); }
.btn:disabled { opacity: 0.55; cursor: default; box-shadow: none; }
.btn-primary { background: var(--cta); color: var(--cta-text); border-color: var(--cta); box-shadow: 0 4px 0 var(--cta-edge), 0 10px 22px -10px color-mix(in srgb, var(--cta) 75%, transparent); }
.btn-primary:hover:not(:disabled) { border-color: var(--cta); filter: brightness(1.06); }
.btn-primary:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--cta-edge); }
.btn-quiet { background: transparent; box-shadow: none; }
.btn-quiet:active:not(:disabled) { transform: translateY(1px); box-shadow: none; }
.btn-small { min-height: 34px; padding: 0.3rem 0.7rem; font-size: 0.85rem; }
/* A neon ring that glows (an outline for the keyboard user, and a soft halo around it). */
:focus-visible { outline: 3px solid var(--glow-ring); outline-offset: 2px; }
.btn:focus-visible, .card:focus-visible, .subject-chip:focus-visible { box-shadow: 0 0 0 6px color-mix(in srgb, var(--glow-ring) 28%, transparent); }
.page:focus, .page:focus-visible { outline: none; }

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip { font-size: 0.75rem; font-weight: 700; padding: 0.15rem 0.6rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.chip--topic { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); max-width: 100%; overflow-wrap: anywhere; }
.chip--extra { background: var(--extra-soft); color: var(--extra); border-color: color-mix(in srgb, var(--extra) 35%, transparent); }

/* The cards of the start page's More row (review, Power-ups, browse) share this look; the row itself is in styles/views/home.css. */
.review-card { display: flex; align-items: center; gap: 1rem; text-decoration: none; color: inherit; flex-wrap: wrap; }
.review-card p { color: var(--muted); font-size: 0.92rem; }
.review-card > div { flex: 1 1 220px; }
.review-card--due { border-color: var(--accent); }
.review-count { display: grid; place-items: center; min-width: 2.6rem; height: 2.6rem; padding: 0 0.4rem; border-radius: 999px; font-size: 1.3rem; font-weight: 800; background: var(--accent); color: var(--accent-text); box-shadow: 0 0 18px -4px color-mix(in srgb, var(--accent) 70%, transparent); }

/* The subject grid (the Lessons page draws it, ui-home.test.js loads only this file): tiles with an accent stripe in their
   group's colour. */
.subject-grid { display: flex; flex-direction: column; gap: 1rem; }
.subject-group { --grp: var(--accent); }
.subject-group[data-group="stem"] { --grp: var(--grp-stem); }
.subject-group[data-group="languages"] { --grp: var(--grp-lang); }
.subject-group[data-group="gesellschaft"] { --grp: var(--grp-soc); }
.subject-group[data-group="arts-sport"] { --grp: var(--grp-arts); }
.subject-group-label { margin: 0 0 0.4rem; font-size: 0.75rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.subject-chips { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 9.5rem), 1fr)); gap: 0.6rem; }
.subject-chip { display: flex; flex-direction: column; justify-content: center; min-height: 48px; height: 100%; padding: 0.55rem 0.8rem 0.5rem; border: 1px solid var(--border); border-top: 4px solid var(--grp); border-radius: var(--radius); background: var(--surface); text-decoration: none; color: var(--text); font-weight: 700; overflow-wrap: anywhere; transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s; }
.subject-chip:hover { border-color: var(--grp); transform: translateY(-1px); }
.subject-chip--current { border-color: var(--grp); background: color-mix(in srgb, var(--grp) 12%, var(--surface)); box-shadow: 0 0 0 1px var(--grp), 0 8px 22px -12px var(--grp); }
.subject-chip-count { font-size: 0.75rem; font-weight: 600; color: var(--muted); }

.meter { height: 8px; border-radius: 99px; background: var(--surface-2); margin-top: 0.6rem; overflow: hidden; border: 1px solid var(--border); }
.meter span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--neon-2)); border-radius: inherit; }
.meter-label { font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem; }
.about { margin-top: 1.5rem; color: var(--muted); font-size: 0.9rem; }
.about summary { cursor: pointer; font-weight: 600; margin-bottom: 0.6rem; }

/* Lesson */
.back { font-weight: 600; text-decoration: none; font-size: 0.92rem; }
.lesson-header h1 { margin: 0.5rem 0 0.4rem; }
.source-line { font-size: 0.85rem; color: var(--muted); }
.source-line--extra { color: var(--extra); }

/* The five steps share one row while they fit. When the text is large they wrap onto more rows, so the steps
   never push the page sideways (an equal-columns grid could not shrink below its widest label times five). */
.stepper ol { list-style: none; margin: 0; padding: 0.35rem; display: flex; flex-wrap: wrap; gap: 0.35rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.stepper li { flex: 1 1 0; display: flex; }
.step { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0.25rem; padding: 0.5rem 0.2rem; border-radius: 12px; text-decoration: none; color: var(--muted); font-size: 0.8rem; font-weight: 700; text-align: center; }
.step:hover { background: var(--surface-2); }
.step-num { width: 1.7rem; height: 1.7rem; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); border: 2px solid var(--border); font-size: 0.85rem; }
/* A level-progress track: the steps behind you are filled, the current one glows. */
.step--past .step-num { background: var(--good); border-color: var(--good); color: var(--surface); }
.step--current { color: var(--accent); background: var(--accent-soft); }
.step--current .step-num { background: var(--accent); border-color: var(--accent); color: var(--accent-text); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent), 0 0 16px 2px color-mix(in srgb, var(--accent) 55%, transparent); }
@media (max-width: 480px) { .step-label { font-size: 0.68rem; } }

.prose p + p { margin-top: 0.7rem; }
.math { font-family: "Cambria Math", "STIX Two Math", Georgia, serif; font-size: 1.06em; white-space: nowrap; background: var(--surface-2); padding: 0 0.3em; border-radius: 5px; }
/* A formula in the lesson's own text (a worked step, a prompt) stays one line, as `nowrap` keeps it, except where it is longer
   than a whole line: then it may start a new line after a binary operator or a relation outside every bracket. `rich()` cuts
   such a formula into `.math-part`s there (`mathParts` in ui/dom.js) and only a formula with parts may wrap; a part never wraps,
   so a line never ends inside a number ("10 800"), between a number and its unit ("5 A") or inside a bracket. It stays an
   inline box, so no line break appears around it: the full stop after a formula never starts a line. A scroll box in running
   text would hide the end of a step and need a keyboard stop of its own. An answer (the "Answer:" line, the wrap-up key's
   summary) is not cut into parts and keeps the one-line `.math`: tests hold that, and a long answer is `.math--prose`. */
.math:has(> .math-part) { white-space: normal; }
.math-part { white-space: nowrap; }
/* Long free-text answer (an `open` task's model answer) in the answer row: wraps, keeps its line breaks. */
.math.math--prose { font-family: inherit; font-size: 1em; font-weight: 400; white-space: pre-line; overflow-wrap: anywhere; }
.solution-answer .math--prose { display: block; margin-top: 0.25rem; }
/* In the wrap-up row's summary a long answer is a two-line preview; the open row shows it in full below. */
.key-row summary .math--prose { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
.key-row details[open] > summary .math--prose { display: none; }
.analogy { background: var(--warn-soft); border-color: transparent; }
.key-ideas { margin: 0; padding-left: 1.2rem; display: flex; flex-direction: column; gap: 0.35rem; }
.glossary { display: grid; grid-template-columns: fit-content(50%) minmax(0, 1fr); gap: 0.3rem 1rem; margin: 0; }
.glossary dt { font-weight: 600; overflow-wrap: break-word; }
.glossary dd { margin: 0; color: var(--muted); hyphens: auto; overflow-wrap: anywhere; }
/* An entry is a div around its dt and dd(s). With two languages it adds no box: the grid above lays out the dt and dd as before.
   With three (`.glossary--rows`, learn.js) the entry is the unit that is read together, in the order es, de, en: on a card
   of 26rem or more (a tablet or desktop) one row of three columns; on a phone the term on its line with the two translations
   side by side under it (about 120 px each at 320 px); on a card under 14rem (large text) all three stacked. Three columns
   on a phone card are only 75 to 88 px wide, and cut common words in two (cumpleaño|s, pantalone|s). */
.glossary-entry { display: contents; }
.glossary--rows { grid-template-columns: minmax(0, 1fr); gap: 0.6rem; }
.glossary--rows .glossary-entry { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.2rem 0.75rem; }
.glossary--rows dt { grid-column: 1 / -1; }
/* A column is narrow on a phone: automatic hyphenation would split a word that fits on the next line (drü-ben). */
.glossary--rows dd { hyphens: manual; }
/* On a narrow card the term goes above its translation(s), full width, so neither is squeezed into half a card: always
   when the text is large (a card under 14rem, as at 320 px with a 200% root size), and for a glossary with a very long
   term (`.glossary--long`, learn.js) when the card is under 36rem. The card is the container, in rem like the root size.
   A term only breaks inside a word when the word is wider than its line (`overflow-wrap: break-word` does not change the
   column's width, so a column keeps the width of its longest word as before). Hyphenation is on only at large sizes:
   at the default size `hyphens: auto` would split a word that fits on the next line (curr-ent). */
.glossary-card { container-type: inline-size; }
@container (width >= 26rem) { .glossary--rows .glossary-entry { grid-template-columns: repeat(3, minmax(0, 1fr)); } .glossary--rows dt { grid-column: auto; } }
@container (width < 14rem) { .glossary { grid-template-columns: minmax(0, 1fr); } .glossary--rows .glossary-entry { grid-template-columns: minmax(0, 1fr); } .glossary dt, .glossary--rows dd { hyphens: auto; } .glossary-entry:not(:first-child) dt { margin-top: 0.4rem; } }
@container (width < 36rem) { .glossary--long, .glossary--long .glossary-entry { grid-template-columns: minmax(0, 1fr); } .glossary--long .glossary-entry:not(:first-child) dt { margin-top: 0.4rem; } }
.worked-problem { font-weight: 600; margin-bottom: 0.2rem; }
.worked-steps { margin: 0.7rem 0; padding-left: 1.3rem; display: flex; flex-direction: column; gap: 0.45rem; }
.worked-steps li { animation: fade-in 0.25s ease; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } }
.next-row { display: flex; justify-content: flex-end; padding-top: 0.5rem; border-top: 1px solid var(--border); }

/* Tasks */
.task { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 0.85rem; }
.task-header { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.task-number { font-size: 0.8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-right: auto; }
.tier { font-size: 0.72rem; font-weight: 800; padding: 0.15rem 0.6rem; border-radius: 999px; border: 1.5px solid currentColor; background: color-mix(in srgb, currentColor 12%, transparent); }
.tier--foundations { color: var(--tier-foundations); }
.tier--application { color: var(--tier-application); }
.tier--challenge { color: var(--tier-challenge); }
.task-prompt { font-size: 1.08rem; font-weight: 500; }

.answer-input { font: inherit; font-size: 1.05rem; padding: 0.6rem 0.8rem; min-height: 46px; width: 100%; max-width: 320px; border: 1.5px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); }
.answer-input:focus { border-color: var(--accent); outline: none; }
.answer-input.is-good { border-color: var(--good); background: var(--good-soft); }
.answer-input.is-bad { border-color: var(--bad); background: var(--bad-soft); }

.task-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.feedback:empty { display: none; }
.feedback { padding: 0.6rem 0.85rem; border-radius: 10px; font-weight: 500; }
.feedback--good { background: var(--good-soft); color: var(--good); }
.feedback--bad { background: var(--bad-soft); color: var(--bad); }
.feedback--info { background: var(--surface-2); color: var(--muted); }
.hints { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.hints:empty { display: none; }
.hints li { background: var(--warn-soft); padding: 0.55rem 0.8rem; border-radius: 10px; }
.hint-label { font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.solution-box summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.solution { margin-top: 0.6rem; padding: 0.8rem 1rem; border-left: 3px solid var(--good); background: var(--surface-2); border-radius: 0 10px 10px 0; }
.solution ol { margin: 0.5rem 0 0; padding-left: 1.2rem; display: flex; flex-direction: column; gap: 0.3rem; }

.value-table { border-collapse: collapse; font-variant-numeric: tabular-nums; }
.value-table th, .value-table td { border: 1px solid var(--border); padding: 0.4rem 0.9rem; text-align: center; }
.value-table th { background: var(--surface-2); font-style: italic; }

/* Graphs */
.graph-wrap { width: 100%; max-width: 340px; }
.graph { width: 100%; height: auto; display: block; background: var(--bg); border-radius: 10px; border: 1px solid var(--border); touch-action: manipulation; }
.graph--interactive { cursor: crosshair; }
.graph--locked { cursor: default; }
.graph-grid line { stroke: var(--grid); stroke-width: 1; }
.graph-grid line.axis { stroke: var(--axis); stroke-width: 1.5; }
.graph .tick { font-size: 8px; fill: var(--muted); }
.graph .axis-label { font-size: 11px; font-style: italic; font-weight: 700; fill: var(--axis); }
.graph-line { stroke: var(--line); stroke-width: 2.5; }
.graph-line--user { stroke: var(--user-line); }
.graph-point { fill: var(--line); }
.graph-point--user { fill: var(--user-line); stroke: var(--surface); stroke-width: 2; }
.graph-ghost { fill: var(--user-line); opacity: 0.3; pointer-events: none; }
.graph-triangle path { fill: none; stroke: var(--tier-challenge); stroke-width: 2; stroke-dasharray: 5 3; }
.graph-triangle text { font-size: 11px; font-weight: 700; fill: var(--tier-challenge); }
.plot { display: flex; flex-direction: column; gap: 0.5rem; }
.plot-bar { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; font-size: 0.9rem; color: var(--muted); }

.explorer { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: min(1.1rem, 17.6px) min(1.2rem, 19.2px); box-shadow: var(--shadow); }
.explorer figcaption { font-weight: 700; margin-bottom: 0.4rem; overflow-wrap: anywhere; } /* a long word in a caption breaks inside the card instead of pushing the page sideways */
.explorer-equation { display: inline-block; max-width: calc(100% + 4px); margin-inline-end: -4px; /* a fraction of a pixel of rounding must not wrap an equation that fits */ font-size: 1.4rem; margin-bottom: 0.8rem; white-space: normal; overflow-wrap: anywhere; } /* a long equation wraps at its spaces (.math is nowrap) */
.explorer-body { display: flex; flex-wrap: wrap; gap: 1.2rem; align-items: flex-start; }
.explorer-body .graph { flex: 1 1 260px; max-width: 340px; }
.explorer-controls { flex: 1 1 200px; min-width: 0; display: flex; flex-direction: column; gap: 1rem; }
.explorer-slider { display: grid; grid-template-columns: minmax(0, 1fr) auto; overflow-wrap: anywhere; gap: 0.2rem 0.6rem; font-weight: 600; font-size: 0.9rem; }
.explorer-slider input { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); height: 28px; }
.explorer-slider output { font-variant-numeric: tabular-nums; color: var(--accent); }
.explorer-description { color: var(--muted); font-size: 0.95rem; }

/* A box inside a widget (or a task: its table of values, `.vt-box`) that scrolls sideways (a table, the keys, the staff). Its caption stays as wide as the box, so the heading is
   never cut off. A new scrolling box in a widget is added to the lists below; the large-text sweep fails for one that is not. */
:is(.explorer, .task) :is(.ps-table-box, .cg-table-box, .dc-table-box, .mk-scroll, .sr-scroll, .vt-box) { container-type: inline-size; }
.explorer :is(.ps-table-box, .cg-table-box, .dc-table-box) caption { width: 100cqw; box-sizing: border-box; }

/* The box shows it can scroll: a shadow at an edge that has more content beyond it, painted over the content. The shadows follow the
   box's own scroll position (a scroll-driven animation) and do nothing when nothing overflows, so a box that fits looks as before.
   The content shares one grid row with the two shadows, which span the box's full width, so they are as tall as the box and sit at its edges. A browser without scroll-driven animations
   gets none of this: it still scrolls, with its own scrollbar. */
@supports (animation-timeline: scroll()) {
  :is(.explorer, .task) :is(.ps-table-box, .cg-table-box, .dc-table-box, .mk-scroll, .sr-scroll, .vt-box) {
    display: grid; overflow-x: auto; padding-inline: 0;
    grid-template-columns: minmax(0, var(--box-padding, 0px)) minmax(min-content, 1fr) minmax(0, var(--box-padding, 0px)); /* a box's side padding becomes two empty columns, so the shadows can reach the box's edges; they give way before the box would overflow (a table that just fits the card must not start to scroll) */
  }
  :is(.explorer, .task) :is(.ps-table-box, .cg-table-box, .dc-table-box, .mk-scroll, .sr-scroll, .vt-box) > * { grid-area: 1 / 2; }
  .explorer :is(.ps-table-box, .cg-table-box, .dc-table-box) caption { width: calc(100cqw - 2 * var(--box-padding, 0px)); }
  :is(.explorer, .task) :is(.ps-table-box, .cg-table-box, .dc-table-box, .mk-scroll, .sr-scroll, .vt-box)::before,
  :is(.explorer, .task) :is(.ps-table-box, .cg-table-box, .dc-table-box, .mk-scroll, .sr-scroll, .vt-box)::after {
    content: ''; grid-area: 1 / 1 / 2 / -1; position: sticky; z-index: 2; width: 20px; pointer-events: none; opacity: 0;
    animation-duration: 1ms; animation-timing-function: linear; animation-fill-mode: both; animation-timeline: scroll(nearest inline);
  }
  :is(.explorer, .task) :is(.ps-table-box, .cg-table-box, .dc-table-box, .mk-scroll, .sr-scroll, .vt-box)::before {
    justify-self: start; left: 0; background: linear-gradient(to right, color-mix(in srgb, var(--text) 45%, transparent), transparent); animation-name: scroll-edge-start;
  }
  :is(.explorer, .task) :is(.ps-table-box, .cg-table-box, .dc-table-box, .mk-scroll, .sr-scroll, .vt-box)::after {
    justify-self: end; right: 0; background: linear-gradient(to left, color-mix(in srgb, var(--text) 45%, transparent), transparent); animation-name: scroll-edge-end;
  }
  @keyframes scroll-edge-start { 0% { opacity: 0; } 3% { opacity: 1; } 100% { opacity: 1; } }
  @keyframes scroll-edge-end { 0% { opacity: 1; } 97% { opacity: 1; } 100% { opacity: 0; } }
}

/* Circuits */
.cx { display: block; width: 100%; height: auto; }
.cx-wire { fill: none; stroke: var(--wire); stroke-width: 2; stroke-linejoin: round; }
.cx-stroke { fill: none; stroke: var(--wire); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.cx-fill { fill: var(--surface); }
.cx-thick { stroke-width: 4.5; }
.cx-mask { fill: var(--surface); stroke: none; }
.cx-removed { stroke-dasharray: 3 3; opacity: 0.55; }
.cx-glow { fill: var(--glow); }
.cx-junction { fill: var(--wire); }
.cx-letter { font-size: 13px; font-weight: 700; fill: var(--wire); font-family: inherit; }
.cx-label { font-size: 12px; font-weight: 700; fill: var(--accent); font-variant-numeric: tabular-nums; }
.cx-label--muted { fill: var(--muted); font-weight: 600; }
.cx-axis { fill: none; stroke: var(--axis); stroke-width: 1.5; }
.cx-trace-line { fill: none; stroke: var(--user-line); stroke-width: 2.5; }
.cx-clickable { cursor: pointer; }
.cx-hit { fill: transparent; }
.cx-wrap { flex: 1 1 280px; max-width: 420px; background: var(--surface); }
.cx-figure { margin: 0; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.5rem; }
.cx-figure--symbol { max-width: 160px; }
.cx-figure--trace { max-width: 300px; }
.cx-figure figcaption { font-size: 0.85rem; color: var(--muted); text-align: center; margin-top: 0.3rem; overflow-wrap: anywhere; }
.cx-figures { display: flex; flex-wrap: wrap; gap: 0.8rem; }
.cx-figures .cx-figure { flex: 1 1 200px; }
.answer-row { display: flex; flex-direction: column; gap: 0.3rem; align-items: flex-start; }

/* Practice */
.practice-bar { display: flex; flex-direction: column; gap: 0.3rem; }
.dots { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.dot { width: 2.3rem; height: 2.3rem; border-radius: 50%; font: inherit; font-size: 0.85rem; font-weight: 800; cursor: pointer; border: 2px solid var(--border); background: var(--surface); color: var(--muted); border-bottom-width: 4px; }
.dot:active { transform: translateY(2px); }
.dot--foundations { border-bottom-color: var(--tier-foundations); }
.dot--application { border-bottom-color: var(--tier-application); }
.dot--challenge { border-bottom-color: var(--tier-challenge); }
.dot--tried { background: var(--warn-soft); }
.dot--revealed { background: var(--surface-2); color: var(--text); }
.dot--solved { background: var(--good-soft); color: var(--good); border-color: var(--good); }
.dot--current { outline: 2.5px solid var(--accent); outline-offset: 2px; box-shadow: 0 0 14px -2px color-mix(in srgb, var(--accent) 70%, transparent); }
.pager { display: flex; justify-content: space-between; gap: 0.5rem; }
.pager .btn-primary { margin-left: auto; }

/* Watch-outs & wrap-up */
.misconception { display: flex; flex-direction: column; gap: 0.45rem; }
.mis-wrong, .mis-fix { display: flex; gap: 0.6rem; align-items: baseline; font-weight: 600; }
.mis-wrong .mis-icon { color: var(--bad); }
.mis-fix .mis-icon { color: var(--good); }
.mis-why { color: var(--muted); font-size: 0.95rem; padding-left: 1.4rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.7rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem 1rem; display: flex; flex-direction: column; }
.stat-value { font-size: 1.8rem; font-weight: 800; color: var(--accent); }
.stat-label { color: var(--muted); font-size: 0.88rem; }
.answer-key { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }
.key-row { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.7rem 0.9rem; }
.key-row summary { cursor: pointer; font-weight: 600; }
/* The task and its "Try it first" link share a row while they fit; at large text the link drops below the task (the link
   keeps its width, the task text takes the rest and may break a long word) instead of pushing the page sideways. */
.key-row--locked { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.3rem 1rem; color: var(--muted); font-size: 0.9rem; align-items: baseline; }
.key-row--locked > span { flex: 1 1 6rem; min-width: 0; }
.key-row--locked a { flex: none; max-width: 100%; font-weight: 600; text-decoration: none; }
/* "Further practice" in the wrap-up: a list of cards that look like answer-key rows but are not (no collapse, no lock). */
.resource-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }
.resource-row { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.7rem 0.9rem; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  .btn:active:not(:disabled), .dot:active, .subject-chip:hover { transform: none; }
}
