/* OOP Trainer – screen styles.
 *
 * Direction: "squared exam paper and graphite". The app is a study notebook, not a dashboard:
 * cool paper surfaces, graphite ink, Torata's eye blue for actions, his pale aqua disc for
 * selection, and the amber of his collar used sparingly for marks (active tab, readiness).
 * The one bold device is the answer area: Karopapier (5 mm squared paper, as in Swiss school
 * notebooks) behind typed and handwritten answers. Grading reads like a correction in the margin.
 *
 * Order: fonts → tokens (light, then dark) → base → layout → components → views → line art →
 * layout modes → utilities. Exam sheet: exam.css. Print: print.css.
 * The first :root block holds every token (ui-exam.js copies it into downloaded exams), so keep it
 * a single flat block without nested braces.
 * Layout keys off <html data-layout-effective="phone|tablet|desktop" data-orientation="…">
 * and input off data-input-effective="touch|mouse" (set by layout.js).
 */

/* ---------- Fonts (self-hosted, SIL OFL 1.1: assets/fonts/OFL-*.txt) ----------
 * Atkinson Hyperlegible Next / Mono (Braille Institute): built so that l/1/I, 0/O and
 * rn/m cannot be confused, which is exactly what "predict the output" questions need.
 * The printed exam sheet uses a sober Arial stack instead (like the real paper; slashed zeros
 * in "30 Punkte" would look technical there). */
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("assets/fonts/atkinson-hyperlegible-next.woff2") format("woff2");
  font-weight: 200 800; font-style: normal; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Atkinson Hyperlegible Mono";
  src: url("assets/fonts/atkinson-hyperlegible-mono.woff2") format("woff2");
  font-weight: 200 800; font-style: normal; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  /* colour – light: paper, graphite, eye blue, aqua disc, collar amber */
  --color-bg: #edf1f1;
  --color-surface: #ffffff;
  --color-surface-2: #e4eaeb;
  --color-sunken: #f5f8f8;
  --color-text: #1d262b;
  --color-muted: #4f5c64;
  --color-border: #d0d9db;
  --color-border-strong: #7c8a92;
  --color-accent: #1d5c77;
  --color-accent-hover: #164a61;
  --color-accent-text: #ffffff;
  --color-accent-soft: #dcf3f2;
  --color-accent-ink: #174d63;
  --color-tiger: #9c5520;
  --color-tiger-soft: #f6e8db;
  --color-blush: #e8a4a4;
  --color-ok: #236c47;
  --color-ok-soft: #e1f0e6;
  --color-bad: #a83232;
  --color-bad-soft: #f8e4e2;
  --color-warn: #7d5408;
  --color-warn-soft: #f7ecd6;
  --color-code-bg: #f4f7f7;
  --color-code-gutter: #e8eeee;
  --color-code-num: #5f6d74;
  --color-grid: #d5e6e6;
  --color-grid-margin: #e7b8b0;
  --color-lineart: #66747c;
  --color-paper: #ffffff;
  --color-paper-text: #111111;
  --color-paper-line: #b9bec8;
  --color-shadow: rgba(29, 52, 62, .12);
  --color-focus: #1d5c77;
  /* type: Atkinson Hyperlegible; minor-third scale (×1.2) on a 16px base */
  --font-sans: "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "Atkinson Hyperlegible Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --font-sheet: Arial, "Helvetica Neue", Helvetica, "Liberation Sans", sans-serif;
  --font-serif: Georgia, "Times New Roman", serif;
  --text-base: 16px;
  --step--2: .694rem;
  --step--1: .833rem;
  --step-0: 1rem;
  --step-1: 1.2rem;
  --step-2: 1.44rem;
  --step-3: 1.728rem;
  --step-4: 2.488rem;
  --text-xs: var(--step--2);
  --text-sm: var(--step--1);
  --text-lg: var(--step-1);
  --line: 1.55;
  --line-tight: 1.25;
  --line-code: 1.6;
  /* spacing: 4px base */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --gutter: 16px;
  /* shape: radius grows with the size of the thing */
  --radius-xs: 3px;
  --radius-sm: 5px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-pill: 999px;
  /* squared paper: one square per text line */
  --grid: 24px;
  /* sizes */
  --tap: 36px;
  --content-max: 1200px;
  --measure: 68ch;
  --topbar-h: 104px;
  --peek-w: 6rem;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  /* aliases read by the self-contained modules mascot.css / offline.css */
  --surface: var(--color-surface);
  --surface-2: var(--color-surface-2);
  --text: var(--color-text);
  --muted: var(--color-muted);
  --border: var(--color-border);
  --accent: var(--color-accent);
  --accent-text: var(--color-accent-text);
  --ok: var(--color-ok);
  --ok-soft: var(--color-ok-soft);
  --bad: var(--color-bad);
  --bad-soft: var(--color-bad-soft);
  --warn: var(--color-warn);
  --code-bg: var(--color-code-bg);
  --sans: var(--font-sans);
  --mono: var(--font-mono);
  --radius-module: var(--radius);
  /* mascot.css tokens */
  --mascot-disc: #dff7f6;
  --mascot-ring: var(--color-surface);
  --mascot-accent: var(--color-accent);
  --mascot-accent-fg: var(--color-accent-text);
  --mascot-focus: var(--color-focus);
  --mascot-bubble-bg: var(--color-surface);
  --mascot-bubble-fg: var(--color-text);
  --mascot-bubble-border: var(--color-border-strong);
  --mascot-good: var(--color-ok);
  --mascot-bad: var(--color-tiger);
  --mascot-radius: var(--radius-lg);
  --mascot-ink-color: var(--color-lineart);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  /* dark: the same desk at night – slate fur shadows, lit paper stays paper */
  :root {
    --color-bg: #13181b;
    --color-surface: #1a2125;
    --color-surface-2: #232b30;
    --color-sunken: #161c20;
    --color-text: #e1e8ea;
    --color-muted: #a0aeb5;
    --color-border: #2e393f;
    --color-border-strong: #6e7d85;
    --color-accent: #8ccbe0;
    --color-accent-hover: #a7d9ea;
    --color-accent-text: #0b2230;
    --color-accent-soft: #19343a;
    --color-accent-ink: #a9deec;
    --color-tiger: #e3a66c;
    --color-tiger-soft: #36281b;
    --color-ok: #72cd9a;
    --color-ok-soft: #16301f;
    --color-bad: #f2918a;
    --color-bad-soft: #3a1e1d;
    --color-warn: #e6b862;
    --color-warn-soft: #342915;
    --color-code-bg: #11171a;
    --color-code-gutter: #161d21;
    --color-code-num: #85959d;
    --color-grid: #25323a;
    --color-grid-margin: #5a3a38;
    --color-lineart: #9eacb3;
    --color-shadow: rgba(0, 0, 0, .45);
    --color-focus: #8ccbe0;
    --mascot-disc: #cfeceb;
    color-scheme: dark;
  }
}

:root[data-input-effective="touch"] { --tap: 44px; }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  background: var(--color-bg);
  color: var(--color-text);
  font: var(--text-base)/var(--line) var(--font-sans);
  font-optical-sizing: auto;
  min-height: 100dvh;
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { line-height: var(--line-tight); font-weight: 700; text-wrap: balance; }
p { text-wrap: pretty; }
code, pre, kbd, textarea.is-code { font-family: var(--font-mono); }
a { color: var(--color-accent); text-underline-offset: .15em; }
.muted, .field__hint { color: var(--color-muted); }
.field__hint { font-size: var(--text-sm); line-height: 1.45; }
.field__hint code { font-size: .95em; overflow-wrap: anywhere; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
button, select, input, textarea, .btn { touch-action: manipulation; }
img { max-width: 100%; }
::selection { background: var(--color-accent-soft); color: var(--color-text); }
:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }

/* ---------- Top bar & tabs ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: calc(var(--space-2) + var(--safe-top)) calc(var(--gutter) + var(--safe-right)) 0 calc(var(--gutter) + var(--safe-left));
}
.topbar__row { display: flex; align-items: center; gap: var(--space-3); flex-wrap: nowrap; max-width: var(--content-max); margin: 0 auto; }
.topbar__row > * { flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: var(--space-3); }
.brand__mascot { display: inline-flex; flex: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.brand__avatar { --mascot-size: 38px; }
.brand__name { display: flex; flex-direction: column; font-weight: 700; font-size: var(--step-0); line-height: 1.1; letter-spacing: -.005em; }
.brand__by { font-weight: 500; font-size: var(--step--2); color: var(--color-tiger); letter-spacing: .01em; }
.subject-picker { flex: 0 1 18rem !important; min-width: 7rem; margin-left: var(--space-2); }
.subject-picker__select { width: 100%; font-weight: 700; }
.layout-quick { margin-left: auto; }
.layout-quick__select { min-height: var(--tap); }

.readiness-badge {
  display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: var(--tap); padding: 0 var(--space-3);
  border-radius: var(--radius); border: 1px solid var(--color-border);
  background: var(--color-sunken); color: var(--color-text); font: inherit; cursor: pointer;
}
.readiness-badge__value { font-weight: 700; font-variant-numeric: tabular-nums; }
.readiness-badge__label { font-size: var(--text-sm); color: var(--color-muted); }
.readiness-badge[data-level="ready"] { border-color: var(--color-ok); }
.readiness-badge[data-level="ready"] .readiness-badge__value { color: var(--color-ok); }
.readiness-badge[data-level="progress"] .readiness-badge__value { color: var(--color-warn); }
.readiness-badge[data-level="low"] .readiness-badge__value { color: var(--color-text); }
:root[data-input-effective="mouse"] .readiness-badge:hover { border-color: var(--color-border-strong); }

.tabs { display: flex; gap: var(--space-1); max-width: var(--content-max); margin: var(--space-2) auto 0; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs__tab {
  position: relative;
  font: inherit; font-weight: 600; white-space: nowrap;
  min-height: var(--tap); padding: 0 var(--space-3);
  background: transparent; color: var(--color-muted);
  border: 0; cursor: pointer;
}
.tabs__tab::after {
  /* the selected tab carries a short collar-amber mark */
  content: ""; position: absolute; left: var(--space-3); right: var(--space-3); bottom: 0; height: 3px;
  border-radius: 3px 3px 0 0; background: transparent;
}
.tabs__tab[aria-selected="true"] { color: var(--color-text); }
.tabs__tab[aria-selected="true"]::after { background: var(--color-tiger); }
:root[data-input-effective="mouse"] .tabs__tab:hover { color: var(--color-text); }
.tabs__tab:focus-visible { outline-offset: -2px; }

/* ---------- Main layout ---------- */
.app {
  display: flex; flex-direction: column; gap: var(--space-5);
  max-width: var(--content-max); margin: 0 auto;
  padding: var(--space-5) calc(var(--gutter) + var(--safe-right)) calc(var(--space-7) + var(--safe-bottom)) calc(var(--gutter) + var(--safe-left));
}
.view { display: flex; flex-direction: column; gap: var(--space-5); min-width: 0; }

/* Cards come in two weights: .card is a sheet of paper (white, hairline), .panel-like cards
 * (settings, focus) sit lower on the desk. */
.card {
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  padding: var(--space-5); min-width: 0;
}
.settings, .focus { background: var(--color-sunken); }
.card__title { font-size: var(--step-1); margin: 0 0 var(--space-4); letter-spacing: -.01em; }
.card__title-sub { color: var(--color-muted); font-weight: 500; margin-left: .2em; }
.card__subtitle { font-size: var(--step-0); margin: var(--space-5) 0 var(--space-2); }
.card__head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-2); }
.card__head .card__title { margin-bottom: var(--space-3); }
details.card > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; min-height: var(--tap); }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary .card__title { margin: 0; }
details.card > summary::before {
  content: ""; width: 8px; height: 8px; flex: none; margin-inline: 2px;
  border-right: 2px solid var(--color-muted); border-bottom: 2px solid var(--color-muted);
  transform: rotate(-45deg); transition: transform .15s;
}
details.card[open] > summary::before { transform: rotate(45deg); }
details.card[open] > summary { margin-bottom: var(--space-4); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-4); min-width: 0; }
.field--inline { flex-direction: row; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.field__compact, .field.field__compact { display: inline-flex; flex-direction: row; align-items: center; gap: var(--space-2); }
.field__label { font-weight: 700; font-size: var(--step--1); }
.field__label .field__hint { font-weight: 400; }
.input-row { display: flex; gap: var(--space-2); min-width: 0; flex-wrap: wrap; }
.input-row > input, .input-row > select { flex: 1 1 8rem; min-width: 0; }
/* :where() keeps these defaults at zero specificity so component rules (offline.css etc.) win */
:where(input:not([type="checkbox"], [type="radio"], [type="file"]), select, textarea) {
  width: 100%; min-height: var(--tap);
  font: inherit; font-size: max(16px, 1rem);
  color: var(--color-text); background: var(--color-surface);
  border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm); padding: 6px 10px;
}
:where(select) {
  appearance: none; padding-right: 32px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--color-muted) 50%), linear-gradient(-45deg, transparent 50%, var(--color-muted) 50%);
  background-position: right 16px center, right 11px center;
  background-size: 5px 5px; background-repeat: no-repeat;
}
::placeholder { color: var(--color-muted); opacity: .85; }
.field__compact select, .field__compact input { width: auto; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 1px; border-color: var(--color-focus); }
input:disabled, textarea:disabled, select:disabled { opacity: .65; }
textarea { resize: vertical; min-height: 7rem; line-height: 1.5; }
textarea.is-code { font-size: max(16px, .95rem); tab-size: 4; white-space: pre; overflow-wrap: normal; overflow-x: auto; }
input[type="checkbox"], input[type="radio"], progress { accent-color: var(--color-accent); }
.check { display: flex; gap: var(--space-2); align-items: center; min-height: var(--tap); cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 0; flex: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--tap); padding: 0 var(--space-4);
  font: inherit; font-weight: 700; white-space: nowrap; text-decoration: none;
  border-radius: var(--radius-sm); border: 1px solid var(--color-border-strong);
  background: var(--color-surface); color: var(--color-text); cursor: pointer;
  transition: background-color .12s, border-color .12s;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn--primary { background: var(--color-accent); color: var(--color-accent-text); border-color: var(--color-accent); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--color-accent); }
.btn--small { padding: 0 var(--space-3); font-size: var(--text-sm); }
.btn--link { background: none; border: 0; color: var(--color-accent); padding: 0; min-height: auto; text-decoration: underline; font-weight: 500; }
:root[data-input-effective="mouse"] .btn:hover:not(:disabled) { border-color: var(--color-text); }
:root[data-input-effective="mouse"] .btn--primary:hover:not(:disabled) { background: var(--color-accent-hover); border-color: var(--color-accent-hover); }
:root[data-input-effective="mouse"] .btn--ghost:hover:not(:disabled) { background: var(--color-accent-soft); border-color: transparent; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.file-btn { position: relative; overflow: hidden; }
.file-btn__input { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }
.file-btn:focus-within { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.actions { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.input-row .btn--small { padding: 0 var(--space-2); }

.segmented {
  display: inline-flex; flex-wrap: wrap; gap: 2px; align-self: flex-start; max-width: 100%;
  padding: 2px; border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm); background: var(--color-surface);
}
.segmented__item {
  font: inherit; font-size: var(--step--1); font-weight: 700; min-height: calc(var(--tap) - 6px);
  background: transparent; color: var(--color-muted); border: 0; border-radius: var(--radius-xs); padding: 0 var(--space-3); cursor: pointer;
}
.segmented__item[aria-checked="true"] { background: var(--color-accent); color: var(--color-accent-text); }
:root[data-input-effective="mouse"] .segmented__item:not([aria-checked="true"]):hover { color: var(--color-text); background: var(--color-surface-2); }

.banner { border-radius: var(--radius-sm); padding: 10px 12px; margin: var(--space-2) 0; font-size: var(--step--1); white-space: pre-line; overflow-wrap: anywhere; border-left: 4px solid currentColor; }
.banner--error { background: var(--color-bad-soft); color: var(--color-bad); }
.banner--warn { background: var(--color-warn-soft); color: var(--color-warn); }
#fatal, #storage-warning { margin: var(--space-4) auto; max-width: var(--content-max); }

/* ---------- Settings ---------- */
.settings__more { border-top: 1px solid var(--color-border); padding: var(--space-1) 0; }
.settings__more > summary {
  cursor: pointer; font-weight: 700; min-height: var(--tap); display: flex; align-items: center; gap: var(--space-2);
  list-style: none;
}
.settings__more > summary::-webkit-details-marker { display: none; }
.settings__more > summary::after {
  content: ""; width: 7px; height: 7px; margin-left: auto; margin-right: 4px; flex: none;
  border-right: 2px solid var(--color-muted); border-bottom: 2px solid var(--color-muted); transform: rotate(45deg);
}
.settings__more[open] > summary::after { transform: rotate(-135deg); }
.settings__more[open] > summary { margin-bottom: var(--space-2); }
.settings .actions:last-child { margin-top: var(--space-4); }
.key-actions { margin: calc(-1 * var(--space-3)) 0 var(--space-3); }
.lock-state { font-weight: 700; }
.lock-state[data-state="locked"] { color: var(--color-warn); }
.lock-state[data-state="unlocked"] { color: var(--color-ok); }

/* ---------- Lists ---------- */
.list-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-1); }
.list-head__quick { display: flex; gap: var(--space-1); }
.choice-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); gap: 0 var(--space-3);
  max-height: 300px; overflow-y: auto; padding: var(--space-1) var(--space-2);
  border: 1px solid var(--color-border); border-radius: var(--radius); background: var(--color-surface);
}
.choice-list--compact { max-height: none; }
.choice-list__item { display: flex; gap: var(--space-2); align-items: center; font-size: var(--step--1); min-height: var(--tap); padding: 2px var(--space-1); cursor: pointer; border-radius: var(--radius-xs); line-height: 1.3; }
.choice-list__input { width: 18px; height: 18px; flex: none; }
.choice-list__item:has(.choice-list__input:not(:checked)) { color: var(--color-muted); }
:root[data-input-effective="mouse"] .choice-list__item:hover { background: var(--color-surface-2); }

.item-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.item-list__item {
  display: flex; gap: var(--space-3); align-items: center; justify-content: space-between; flex-wrap: wrap;
  padding: var(--space-3) var(--space-1); border-top: 1px solid var(--color-border);
}
.item-list__item:last-child { border-bottom: 1px solid var(--color-border); }
.item-list__item.is-active { background: var(--color-accent-soft); box-shadow: inset 3px 0 var(--color-accent); padding-left: var(--space-3); }
.item-list__item.is-primary .item-list__title { font-weight: 800; }
.item-list__main { display: flex; flex-direction: column; min-width: 0; flex: 1 1 14rem; }
.item-list__title { font-weight: 700; overflow-wrap: anywhere; }
.item-list__meta { font-size: var(--text-sm); color: var(--color-muted); }
.item-list__actions { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.doc-list__kind { width: auto; }
.empty { color: var(--color-muted); font-size: var(--step--1); list-style: none; }

.progress-list { margin: var(--space-4) 0 0; padding-left: 0; list-style: none; display: flex; flex-direction: column; border-top: 1px solid var(--color-border); }
.progress-list__item { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; padding: var(--space-2) 0; border-bottom: 1px solid var(--color-border); font-size: var(--step--1); }
.progress-list__title { flex: 1 1 12rem; }
.progress-list__status { font-weight: 700; }
.progress-list__item[data-state="ok"] .progress-list__status { color: var(--color-ok); }
.progress-list__item[data-state="failed"] .progress-list__status { color: var(--color-bad); }
.progress-list__item[data-state="running"] .progress-list__status { color: var(--color-accent); }
.progress-list__error { flex-basis: 100%; font-size: var(--text-sm); color: var(--color-bad); white-space: pre-line; }

/* ---------- Focus ---------- */
.focus__summary .muted { font-size: var(--step--1); }
.focus__grid { display: flex; gap: var(--space-3) var(--space-6); flex-wrap: wrap; align-items: flex-end; margin-bottom: var(--space-2); }
.focus__grid .field { min-width: 10rem; margin-bottom: 0; }
.focus__grid .check { min-height: calc(var(--tap) + 4px); }

/* ---------- Quiz ---------- */
.quiz { position: relative; padding: var(--space-5) var(--space-5) var(--space-4); }
.quiz__panes { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-5); }
.quiz__meta { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; margin-bottom: var(--space-4); font-size: var(--step--1); line-height: 1.35; }
.quiz__score { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--color-text); }
.pill {
  display: inline-flex; align-items: center; min-height: 24px;
  border: 1px solid var(--color-border-strong); border-radius: var(--radius-xs);
  padding: 0 8px; font-weight: 700; color: var(--color-text); background: var(--color-surface);
}
#q-type { background: var(--color-accent-soft); color: var(--color-accent-ink); border-color: transparent; }
.pill--offline { background: var(--color-warn-soft); color: var(--color-warn); border-color: transparent; }
#q-topic { flex-basis: 100%; order: 5; }
.loading { display: flex; align-items: center; gap: 10px; color: var(--color-muted); padding: var(--space-5) 0; }
#q-loading { flex-direction: column; align-items: stretch; padding: var(--space-2) 0; }
.loading__plain { display: flex; align-items: center; gap: 10px; padding: var(--space-3) 0; }
.loading__mascot:empty, .mascot-off .loading__mascot { display: none; }
:root:not(.mascot-off) .loading__mascot:not(:empty) + .loading__plain { display: none; }
#q-free[data-offline="true"] .answer__modes { display: none; }
.result__selfcheck { margin-top: var(--space-3); }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--color-border); border-top-color: var(--color-accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.quiz__text { font-size: var(--step-1); line-height: 1.5; max-width: var(--measure); }
.quiz__text p { margin: 0 0 var(--space-3); }

/* Rich text and code */
.rich p { margin: 0 0 .6rem; overflow-wrap: anywhere; }
.rich > :last-child { margin-bottom: 0; }
.rich code, .option code {
  font-size: .9em; padding: .05em .3em; border-radius: var(--radius-xs);
  background: var(--color-code-bg); box-shadow: inset 0 0 0 1px var(--color-border);
  overflow-wrap: anywhere; -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
pre.code {
  position: relative;
  background: var(--color-code-bg); color: var(--color-text);
  border: 1px solid var(--color-border); border-radius: var(--radius);
  padding: var(--space-3) var(--space-4); margin: 0 0 var(--space-4);
  overflow-x: auto; max-width: 100%;
  font-size: .9rem; line-height: var(--line-code); white-space: pre; tab-size: 4;
  font-variant-ligatures: none;
  -webkit-overflow-scrolling: touch;
}
pre.code code { background: none; border: 0; padding: 0; font-size: inherit; box-shadow: none; }
/* numbered: a fixed gutter that stays put while long lines scroll */
pre.code--numbered { padding: 0; }
.code--numbered code { counter-reset: line; display: block; min-width: max-content; }
.code--numbered .code__line { counter-increment: line; }
.code--numbered .code__line::before {
  content: counter(line); position: sticky; left: 0; display: inline-block;
  width: 3.4em; margin-right: 1em; padding-right: .75em;
  text-align: right; color: var(--color-code-num); background: var(--color-code-gutter);
  box-shadow: 1px 0 var(--color-border);
  font-variant-numeric: tabular-nums; user-select: none; -webkit-user-select: none;
}
.code--numbered code::before, .code--numbered code::after {
  /* gutter continues through the top/bottom padding */
  content: ""; display: block; height: var(--space-3); width: 3.4em; background: var(--color-code-gutter); box-shadow: 1px 0 var(--color-border);
  position: sticky; left: 0;
}

/* Multiple choice */
.options { display: flex; flex-direction: column; gap: var(--space-2); margin: 0 0 var(--space-4); counter-reset: none; }
.option {
  display: flex; gap: var(--space-3); align-items: flex-start; text-align: left; min-height: calc(var(--tap) + 8px);
  font: inherit; color: var(--color-text); background: var(--color-surface);
  border: 1px solid var(--color-border-strong); border-radius: var(--radius); padding: var(--space-3) var(--space-4) var(--space-3) var(--space-3); cursor: pointer;
  line-height: 1.45;
}
.option:disabled { cursor: default; }
:root[data-input-effective="mouse"] .option:hover:not(:disabled) { border-color: var(--color-accent); background: var(--color-accent-soft); }
.option__key {
  display: inline-grid; place-items: center; flex: none;
  width: 26px; height: 26px; margin-top: -1px;
  font-family: var(--font-mono); font-size: var(--step--1); font-weight: 700; color: var(--color-muted);
  border: 1px solid var(--color-border-strong); border-radius: var(--radius-xs);
}
.option__text { white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; padding-top: 1px; }
.option.is-correct { border-color: var(--color-ok); background: var(--color-ok-soft); box-shadow: inset 4px 0 var(--color-ok); }
.option.is-correct .option__key { background: var(--color-ok); border-color: var(--color-ok); color: var(--color-surface); }
.option.is-wrong { border-color: var(--color-bad); background: var(--color-bad-soft); box-shadow: inset 4px 0 var(--color-bad); }
.option.is-wrong .option__key { background: var(--color-bad); border-color: var(--color-bad); color: var(--color-surface); }
.options:has(.is-correct) .option:not(.is-correct):not(.is-wrong) { color: var(--color-muted); border-color: var(--color-border); }

/* Free answer: squared paper (Karopapier). One square per text line. */
.answer { display: flex; flex-direction: column; gap: var(--space-3); }
.answer__textarea, .transcription textarea {
  width: 100%;
  line-height: var(--grid); padding: calc(var(--grid) / 2) var(--space-3);
  min-height: calc(var(--grid) * 9);
  background-color: var(--color-surface);
  background-image:
    linear-gradient(var(--color-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--color-grid) 1px, transparent 1px);
  background-size: var(--grid) var(--grid);
  background-position: -1px calc(var(--grid) / 2 - 1px);
  background-attachment: local;
  border-radius: var(--radius-sm);
}
.answer__hint { display: block; margin-top: calc(-1 * var(--space-2)); }
:root[data-input-effective="touch"] .answer__hint { display: none; }
.transcription { border-top: 1px dashed var(--color-border-strong); padding-top: var(--space-3); }
.transcription .field { margin-bottom: var(--space-2); }

/* Grading result: a correction in the margin – verdict in correction ink, then feedback,
 * model answer and explanation as short sections. */
.result {
  position: relative;
  margin: 0 0 var(--space-4); padding: var(--space-4) var(--space-4) var(--space-4) calc(var(--space-4) + 4px);
  border-radius: var(--radius); background: var(--color-sunken); border: 1px solid var(--color-border);
  overflow-wrap: anywhere;
}
.result::before { content: ""; position: absolute; left: -1px; top: -1px; bottom: -1px; width: 4px; border-radius: var(--radius) 0 0 var(--radius); background: var(--color-border-strong); }
.result[data-verdict="ok"]::before { background: var(--color-ok); }
.result[data-verdict="bad"]::before { background: var(--color-bad); }
.result[data-verdict="partial"]::before { background: var(--color-warn); }
.result__verdict { font-size: var(--step-1); font-weight: 700; line-height: var(--line-tight); margin-bottom: var(--space-2); font-variant-numeric: tabular-nums; }
.result[data-verdict="ok"] .result__verdict { color: var(--color-ok); }
.result[data-verdict="bad"] .result__verdict { color: var(--color-bad); }
.result[data-verdict="partial"] .result__verdict { color: var(--color-warn); }
.result__title { font-size: var(--step--1); font-weight: 700; margin: var(--space-4) 0 var(--space-1); color: var(--color-muted); }
.result pre.code { background: var(--color-surface); margin-bottom: var(--space-2); }

.action-bar { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; margin-top: var(--space-4); }
.quiz__actions #btn-next, .quiz__actions #btn-submit, .quiz__actions #btn-retry { order: -1; min-width: 8rem; }

.thumbs { list-style: none; margin: var(--space-2) 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-2); }
.thumbs__item { display: flex; flex-direction: column; gap: var(--space-1); align-items: center; }
.thumbs__img { width: 96px; height: 96px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--color-border); }

.ink-host, .practice__ink { width: 100%; }
.ink-pad { width: 100%; border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm); overflow: hidden; background: #fff; }
.ink-pad__canvas { display: block; width: 100%; height: auto; touch-action: none; cursor: crosshair; }
.ink-pad.is-pen .ink-pad__canvas { touch-action: pan-y; }

/* ---------- Mascot slots (speech bubbles stay in the flow: never over answers or the action bar) ---------- */
.mascot-slot:empty { display: none; }
.mascot-slot .mascot-say { margin: var(--space-2) 0 0; }
.quiz__mascot { margin-top: var(--space-2); }
li.empty-state { list-style: none; }
.empty-state .mascot-empty { padding: var(--space-4) var(--space-2); }
.settings__mascot { margin: var(--space-2) 0; }
.mascot-lines__list { display: grid; gap: var(--space-2); grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr)); margin-top: var(--space-3); }
.mascot-lines__text { width: 100%; resize: vertical; }
.mascot-lines .segmented { margin-top: var(--space-2); }
.mascot-bubble { box-shadow: 0 1px 0 var(--color-border); }
.mascot-empty-title { font-size: var(--step-0); }
.mascot-empty-text { font-size: var(--step--1); }
.mascot-empty-action { border-radius: var(--radius-sm); }

/* ---------- Mock exam ---------- */
.exam-setup__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 10rem), 1fr)); gap: 0 var(--space-4); max-width: 40rem; }
.exam-setup > .field__hint { max-width: var(--measure); margin: calc(-1 * var(--space-2)) 0 var(--space-4); }
.exam-viewer { padding: 0; overflow: clip; }
.exam-viewer__toolbar {
  display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center;
  padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border); background: var(--color-surface);
}
.exam-viewer__toolbar .actions { margin-left: auto; }
.exam-viewer > .banner, .exam-viewer > .exam-photo { margin: var(--space-3) var(--space-4); }
.exam-photo { border: 1px solid var(--color-border); border-radius: var(--radius); padding: var(--space-4); }
.exam-photo__title { margin: 0 0 var(--space-2); font-size: var(--step-0); }
.photo-results { display: flex; flex-direction: column; gap: var(--space-3); }
.photo-results__total { font-weight: 700; font-size: var(--step-1); font-variant-numeric: tabular-nums; }
.photo-result { border-top: 1px solid var(--color-border); padding-top: var(--space-2); }
.photo-result__title { margin: 0 0 var(--space-2); display: flex; flex-wrap: wrap; gap: var(--space-2); justify-content: space-between; font-size: var(--step-0); }
.photo-result__score { color: var(--color-accent); font-variant-numeric: tabular-nums; }
.photo-result[data-found="false"] .photo-result__score { color: var(--color-muted); }

.practice__head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-3); flex-wrap: wrap; }
.practice__timer {
  font-family: var(--font-mono); font-size: var(--step-2); font-weight: 700; font-variant-numeric: tabular-nums;
  padding: 0 var(--space-3); border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm);
}
.practice__timer[data-state="warning"] { color: var(--color-warn); border-color: currentColor; }
.practice__timer[data-state="expired"] { color: var(--color-bad); border-color: currentColor; }
.practice__start { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: center; }
.practice__nav { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-4) 0; }
.practice__nav-item {
  position: relative;
  min-width: var(--tap); min-height: var(--tap); font: inherit; font-weight: 700; font-variant-numeric: tabular-nums;
  border-radius: var(--radius-sm); border: 1px solid var(--color-border-strong); background: var(--color-surface); color: var(--color-text); cursor: pointer;
}
.practice__nav-item.is-answered { background: var(--color-ok-soft); border-color: var(--color-ok); }
.practice__nav-item.is-answered::after {
  /* a paw print marks answered tasks */
  content: ""; position: absolute; right: -5px; top: -6px; width: 13px; height: 12px;
  background: var(--color-ok);
  -webkit-mask: url("assets/lineart/paw-print.svg") center / contain no-repeat;
          mask: url("assets/lineart/paw-print.svg") center / contain no-repeat;
}
.practice__nav-item.is-current { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.practice__panes { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-5); }
.practice__task-title { margin: 0 0 var(--space-3); font-size: var(--step-1); }
.practice__answers { display: flex; flex-direction: column; gap: var(--space-2); }
.practice__part { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--space-2); align-items: baseline; }
.practice__typed textarea { line-height: var(--grid); background-color: var(--color-surface); background-image: linear-gradient(var(--color-grid) 1px, transparent 1px), linear-gradient(90deg, var(--color-grid) 1px, transparent 1px); background-size: var(--grid) var(--grid); background-position: -1px calc(6px - 1px); background-attachment: local; }
.practice__result { position: relative; margin-top: var(--space-4); }
.practice__total { font-size: var(--step-2); font-weight: 700; font-variant-numeric: tabular-nums; margin: 0 0 var(--space-3); line-height: var(--line-tight); }
.practice__task-result { border: 1px solid var(--color-border); border-radius: var(--radius); padding: var(--space-2) var(--space-3); margin-bottom: var(--space-2); background: var(--color-surface); }
.practice__task-result > summary { cursor: pointer; font-weight: 700; min-height: var(--tap); display: flex; align-items: center; gap: var(--space-3); list-style: none; font-variant-numeric: tabular-nums; }
.practice__task-result > summary::-webkit-details-marker { display: none; }
.practice__task-result > summary::after { content: ""; width: 7px; height: 7px; margin-left: auto; margin-right: 4px; flex: none; border-right: 2px solid var(--color-muted); border-bottom: 2px solid var(--color-muted); transform: rotate(45deg); }
.practice__task-result[open] > summary::after { transform: rotate(-135deg); }
.practice__task-result h4 { font-size: var(--step--1); color: var(--color-muted); margin: var(--space-3) 0 var(--space-1); }
.practice__part-feedback { margin: var(--space-1) 0; }

/* ---------- Subjects ---------- */
.subject-form { border-top: 1px solid var(--color-border); margin-top: var(--space-5); padding-top: var(--space-4); display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 14rem), 1fr)); gap: 0 var(--space-4); align-items: end; }
.subject-form__title { grid-column: 1 / -1; margin: 0 0 var(--space-3); font-size: var(--step-0); }
.subject-form .btn { margin-bottom: var(--space-4); }
.uploads > .field__hint { max-width: var(--measure); margin: calc(-1 * var(--space-2)) 0 var(--space-4); }
.uploads__controls { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.uploads__controls .field { margin-bottom: 0; }
.dropzone { margin-top: var(--space-3); padding: var(--space-5); text-align: center; color: var(--color-muted); border: 1.5px dashed var(--color-border-strong); border-radius: var(--radius); font-size: var(--step--1); }
.dropzone.is-over { border-color: var(--color-accent); color: var(--color-accent-ink); background: var(--color-accent-soft); }
:root[data-input-effective="touch"] .dropzone { display: none; }
.topic-editor { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; }
.topic-editor__item { display: flex; flex-direction: column; gap: 2px; padding: var(--space-2) 0; border-bottom: 1px solid var(--color-border); }
.topic-editor__title { font-weight: 700; }
.topic-editor__subs { font-size: var(--step--1); color: var(--color-muted); }
.topic-add { margin-top: var(--space-3); }
.profile-view__meta { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--space-1) var(--space-4); margin: 0 0 var(--space-4); }
.profile-view__meta dt { font-weight: 700; color: var(--color-muted); }
.profile-view__meta dd { margin: 0; overflow-wrap: anywhere; }
.profile-view__styles { color: var(--color-muted); font-size: var(--step--1); }
.table-scroll { overflow-x: auto; max-width: 100%; }
.profile-view__sections { border-collapse: collapse; width: 100%; font-size: var(--step--1); }
.profile-view__sections th, .profile-view__sections td { border-bottom: 1px solid var(--color-border); padding: 6px 8px; text-align: left; vertical-align: top; }
.profile-view__sections th { border-bottom-color: var(--color-border-strong); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Stats ---------- */
.readiness__summary { display: flex; align-items: center; gap: var(--space-3) var(--space-5); flex-wrap: wrap; margin-bottom: var(--space-2); }
.readiness__value { font-size: var(--step-4); font-weight: 700; line-height: 1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.readiness__label { font-weight: 700; padding: 2px 10px; border-radius: var(--radius-xs); background: var(--color-surface-2); }
.readiness__label[data-level="ready"] { color: var(--color-ok); background: var(--color-ok-soft); }
.readiness__label[data-level="progress"] { color: var(--color-warn); background: var(--color-warn-soft); }
.readiness__label[data-level="low"] { color: var(--color-text); background: var(--color-surface-2); }
.readiness > .field__hint { max-width: var(--measure); }
.sparkline { max-width: 100%; height: auto; }
.sparkline__line { stroke: var(--color-accent); stroke-width: 2; }
.sparkline__ref { stroke: var(--color-ok); stroke-width: 1; stroke-dasharray: 3 3; }

/* Per topic: one row each – title and meta, bar, value, action. Two columns on wide screens. */
.readiness-list {
  list-style: none; margin: var(--space-4) 0 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 30rem), 1fr)); gap: 0 var(--space-6);
}
.readiness-list__item {
  display: grid; align-items: center; gap: 2px var(--space-3);
  grid-template-columns: minmax(0, 1fr) 3.2rem auto;
  grid-template-areas: "title value btn" "meter meter btn" "meta meta btn";
  padding: var(--space-3) 0; border-top: 1px solid var(--color-border);
}
.readiness-list__head, .readiness-list__foot { display: contents; }
.readiness-list__title { grid-area: title; font-weight: 700; min-width: 0; overflow-wrap: anywhere; line-height: 1.3; }
.readiness-list__value { grid-area: value; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.readiness-list__meter { grid-area: meter; margin: 4px 0; }
.readiness-list__meta { grid-area: meta; font-size: var(--step--2); color: var(--color-muted); line-height: 1.35; }
.readiness-list__foot .btn { grid-area: btn; background: transparent; border-color: transparent; color: var(--color-accent); }
:root[data-input-effective="mouse"] .readiness-list__foot .btn:hover:not(:disabled) { background: var(--color-accent-soft); border-color: transparent; }
.readiness-list__item[data-level="unseen"] .readiness-list__title,
.readiness-list__item[data-level="unseen"] .readiness-list__value { color: var(--color-muted); font-weight: 500; }

/* meters: thin, honest bars; colour only once a topic is solidly known */
meter {
  -webkit-appearance: none; appearance: none;
  display: block; width: 100%; height: 6px; border: 0; border-radius: 3px;
  background: var(--color-surface-2);
}
meter::-webkit-meter-bar { background: var(--color-surface-2); border: 0; border-radius: 3px; height: 6px; }
meter::-webkit-meter-optimum-value { background: var(--color-ok); border-radius: 3px; }
meter::-webkit-meter-suboptimum-value { background: var(--color-accent); border-radius: 3px; }
meter::-webkit-meter-even-less-good-value { background: var(--color-accent); border-radius: 3px; }
meter::-moz-meter-bar { background: var(--color-accent); border-radius: 3px; }
meter:-moz-meter-optimum::-moz-meter-bar { background: var(--color-ok); }

.stats-total { font-size: var(--step-2); font-weight: 700; margin: 0 0 var(--space-3); font-variant-numeric: tabular-nums; }
.stats-total small { font-size: var(--step--1); font-weight: 400; color: var(--color-muted); }
.stats-list { display: flex; flex-direction: column; gap: var(--space-2); max-width: 44rem; }
.stats-list__row { font-size: var(--step--1); }
.stats-list__label { display: flex; justify-content: space-between; gap: var(--space-2); margin-bottom: 2px; }
.stats-list__label span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats-list__label span:last-child { font-variant-numeric: tabular-nums; }
.stats-list__group { font-size: var(--step--1); font-weight: 700; color: var(--color-muted); margin-top: var(--space-2); }
.mistake-list { display: flex; flex-direction: column; }
.mistake-list__item { border-top: 1px solid var(--color-border); padding: var(--space-1) 0; font-size: var(--step--1); }
.mistake-list__item:last-child { border-bottom: 1px solid var(--color-border); }
.mistake-list__item > summary { cursor: pointer; min-height: var(--tap); padding: var(--space-2) 0; }
.mistake-list__body { margin: var(--space-2) 0 var(--space-3); }
.mistake-list h4 { margin: var(--space-3) 0 var(--space-1); font-size: var(--step--1); color: var(--color-muted); }

/* ---------- Line art (assets/lineart, ink via currentColor + mask) ----------
 * One character moment per screen: Torata peeks over the question sheet, sleeps in empty lists,
 * swims while something loads, celebrates a passed mock exam and sinks (gently) on a failed one. */
.ta-art {
  display: block; pointer-events: none; user-select: none;
  color: var(--color-lineart); background-color: currentColor;
  -webkit-mask-position: center; mask-position: center;
  -webkit-mask-size: contain; mask-size: contain;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
}
.quiz__peek {
  position: absolute; bottom: 100%; right: var(--space-6); margin-bottom: -3px;
  width: var(--peek-w); aspect-ratio: 93 / 69.6;
  -webkit-mask-image: url("assets/lineart/peek-ears.svg"); mask-image: url("assets/lineart/peek-ears.svg");
}
.mascot-off .quiz__peek { display: none; }
/* while a question loads Torata is busy swimming (loader below), so he is not peeking */
.quiz:has(> .quiz__panes #q-loading:not([hidden])) .quiz__peek { visibility: hidden; }

/* empty lists: Torata asleep instead of the swim sketch */
.mascot-empty:not([aria-busy="true"]) .mascot-swim {
  width: 5.5rem; aspect-ratio: 100.4 / 102.9; animation: none;
  background: var(--color-lineart);
  -webkit-mask-image: url("assets/lineart/sleeping.svg"); mask-image: url("assets/lineart/sleeping.svg");
}
/* loading: the traced swim sketch, two frames (tail flick) */
.mascot-empty[aria-busy="true"] .mascot-swim {
  position: relative; aspect-ratio: 117.1 / 63.4; width: min(100%, 11rem);
  background: none; -webkit-mask: none; mask: none; color: var(--color-lineart);
}
.mascot-empty[aria-busy="true"] .mascot-swim::before,
.mascot-empty[aria-busy="true"] .mascot-swim::after {
  content: ""; position: absolute; inset: 0; background: currentColor;
  -webkit-mask: url("assets/lineart/swim-loader.svg") center / contain no-repeat;
          mask: url("assets/lineart/swim-loader.svg") center / contain no-repeat;
}
.mascot-empty[aria-busy="true"] .mascot-swim::after {
  -webkit-mask-image: url("assets/lineart/swim-loader-2.svg"); mask-image: url("assets/lineart/swim-loader-2.svg");
  opacity: 0;
}
@media (prefers-reduced-motion: no-preference) {
  .mascot-empty[aria-busy="true"] .mascot-swim::before { animation: ta-frame-a .9s steps(1, end) infinite; }
  .mascot-empty[aria-busy="true"] .mascot-swim::after { animation: ta-frame-b .9s steps(1, end) infinite; }
}
@keyframes ta-frame-a { 0% { opacity: 1; } 50% { opacity: 0; } }
@keyframes ta-frame-b { 0% { opacity: 0; } 50% { opacity: 1; } }

/* mock exam practice result: pass (Swiss grade ≥ 4) celebrates, fail sinks */
.practice__result[data-outcome]::before {
  content: ""; display: block; width: 5.5rem; aspect-ratio: 107.8 / 103.6; margin: 0 0 var(--space-2);
  background: var(--color-lineart);
  -webkit-mask: url("assets/lineart/celebrating.svg") center / contain no-repeat;
          mask: url("assets/lineart/celebrating.svg") center / contain no-repeat;
}
.practice__result[data-outcome="fail"]::before {
  width: 6.5rem; aspect-ratio: 104 / 58;
  -webkit-mask-image: url("assets/lineart/sinking.svg"); mask-image: url("assets/lineart/sinking.svg");
}
.mascot-off .practice__result[data-outcome]::before { content: none; }

/* exam-ready: celebrate next to the readiness number (only when ready) */
.readiness__art { display: none; }
.readiness:has(.readiness__label[data-level="ready"]) .readiness__art {
  display: block; width: 4.5rem; aspect-ratio: 107.8 / 103.6; margin-left: auto;
  -webkit-mask-image: url("assets/lineart/celebrating.svg"); mask-image: url("assets/lineart/celebrating.svg");
}
.mascot-off .readiness__art { display: none !important; }

/* =====================================================================
 * Layouts (data-layout-effective). Forced layouts never widen the page:
 * multi-column grids use auto-fit with min(100%, …) so they wrap.
 * ===================================================================== */

/* Phone */
:root[data-layout-effective="phone"] { --gutter: 12px; --topbar-h: 96px; }
:root[data-layout-effective="phone"] .brand__name,
:root[data-layout-effective="phone"] .readiness-badge__label,
:root[data-layout-effective="phone"] .tabs__more { display: none; }
/* Hide the quick switch only on a genuinely small screen; a forced layout must stay escapable. */
:root[data-layout-effective="phone"][data-layout="auto"] .layout-quick { display: none; }
:root[data-layout-effective="phone"]:not([data-layout="auto"]) .layout-quick__select { max-width: 7.5rem; }
/* A forced layout wider than the device must not push Settings/the switch off-screen: let the row wrap. */
:root:not([data-layout="auto"]) .topbar__row,
:root[data-layout-effective="phone"]:not([data-layout="auto"]) .topbar__row { flex-wrap: wrap; row-gap: var(--space-1); }
:root[data-layout-effective="phone"] .topbar__row { gap: var(--space-2); flex-wrap: nowrap; }
:root[data-layout-effective="phone"] .subject-picker { flex: 1 1 auto; margin-left: 0; }
:root[data-layout-effective="phone"] #btn-settings { margin-left: auto; }
:root[data-layout-effective="phone"] .tabs { display: grid; grid-template-columns: repeat(4, auto); justify-content: space-between; gap: 0; }
:root[data-layout-effective="phone"] .tabs__tab { padding: 0 var(--space-2); }
:root[data-layout-effective="phone"] .tabs__tab::after { left: var(--space-2); right: var(--space-2); }
:root[data-layout-effective="phone"] .app { gap: var(--space-4); padding-top: var(--space-4); }
:root[data-layout-effective="phone"] .view { gap: var(--space-4); }
:root[data-layout-effective="phone"] .card { padding: var(--space-4) var(--space-3); border-radius: var(--radius); }
:root[data-layout-effective="phone"] .quiz { padding-bottom: var(--space-3); }
:root[data-layout-effective="phone"] .quiz__text { font-size: 1.1rem; }
:root[data-layout-effective="phone"] .quiz__peek { display: none; }
:root[data-layout-effective="phone"] pre.code { font-size: .85rem; }
/* question code bleeds to the card edges on phones: more room for long lines */
:root[data-layout-effective="phone"] .quiz__question pre.code { margin-left: calc(-1 * var(--space-3)); margin-right: calc(-1 * var(--space-3)); max-width: none; border-radius: 0; border-left: 0; border-right: 0; }
:root[data-layout-effective="phone"] .code--numbered .code__line::before,
:root[data-layout-effective="phone"] .code--numbered code::before,
:root[data-layout-effective="phone"] .code--numbered code::after { width: 2.6em; }
:root[data-layout-effective="phone"] .code--numbered .code__line::before { margin-right: .75em; padding-right: .5em; }
:root[data-layout-effective="phone"] .action-bar {
  position: sticky; bottom: 0; z-index: 10;
  margin: var(--space-3) calc(-1 * var(--space-3)) calc(-1 * var(--space-3));
  padding: var(--space-2) var(--space-3) calc(var(--space-2) + var(--safe-bottom));
  background: var(--color-surface); border-top: 1px solid var(--color-border);
  border-radius: 0 0 var(--radius) var(--radius);
}
:root[data-layout-effective="phone"] .action-bar .btn { flex: 1 1 auto; }
:root[data-layout-effective="phone"] .exam-viewer { padding: 0; }
:root[data-layout-effective="phone"] .exam-viewer__toolbar .actions { margin-left: 0; width: 100%; }
:root[data-layout-effective="phone"] .exam-viewer__toolbar .actions .btn { flex: 1 1 45%; }
:root[data-layout-effective="phone"] .readiness__value { font-size: var(--step-3); }
:root[data-layout-effective="phone"] .readiness-list__item {
  grid-template-columns: minmax(0, 1fr) 3rem;
  grid-template-areas: "title value" "meter meter" "meta btn";
}
:root[data-layout-effective="phone"] .result { margin-left: calc(-1 * var(--space-1)); margin-right: calc(-1 * var(--space-1)); padding-right: var(--space-3); }

/* Tablet (portrait: single column, wider measure; landscape: two panes) */
:root[data-layout-effective="tablet"] { --gutter: 24px; --measure: 76ch; }
:root[data-layout-effective="tablet"] .action-bar {
  position: sticky; bottom: var(--safe-bottom); z-index: 10; background: var(--color-surface);
  padding: var(--space-3) 0; margin-bottom: calc(-1 * var(--space-4)); border-top: 1px solid var(--color-border);
}
:root[data-layout-effective="tablet"][data-orientation="landscape"] .quiz__panes,
:root[data-layout-effective="tablet"][data-orientation="landscape"] .practice__panes {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr));
  align-items: start;
}
:root[data-layout-effective="tablet"][data-orientation="landscape"] .quiz__question,
:root[data-layout-effective="tablet"][data-orientation="landscape"] .quiz__answer,
:root[data-layout-effective="tablet"][data-orientation="landscape"] .practice__task,
:root[data-layout-effective="tablet"][data-orientation="landscape"] .practice__answers {
  max-height: calc(100dvh - var(--topbar-h) - 140px); overflow-y: auto; overscroll-behavior: contain; min-width: 0;
}

/* Two panes (tablet landscape, desktop): the answer sits on its own sheet edge */
:root[data-layout-effective="desktop"] .quiz__panes,
:root[data-layout-effective="desktop"] .practice__panes {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
  align-items: start;
}
:root[data-layout-effective="desktop"] .quiz__panes:has(> .quiz__answer:not([hidden])),
:root[data-layout-effective="tablet"][data-orientation="landscape"] .quiz__panes:has(> .quiz__answer:not([hidden])) { column-gap: var(--space-6); }
:root[data-layout-effective="desktop"] .settings__form { display: block; max-width: 760px; }
:root[data-layout-effective="desktop"] .quiz,
:root[data-layout-effective="tablet"] .quiz { margin-top: calc(var(--peek-w) * 69.6 / 93 - var(--space-5) - 3px); }
:root[data-layout-effective="desktop"] .quiz { padding: var(--space-6) var(--space-6) var(--space-5); }

/* Touch: full-size segmented controls */
:root[data-input-effective="touch"] .segmented__item { min-height: var(--tap); }
.card, .view, .exam-sheet { scroll-margin-top: calc(var(--topbar-h) + var(--space-2)); }

/* ---------- Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 3s; }
  details.card > summary::before, .btn { transition: none; }
  .btn:active:not(:disabled) { transform: none; }
}
