/* Hallmark, macrostructure: Workbench (app shell: rail + document column + side tutor), tone: utilitarian-warm
 * theme: studied-DNA (source: Felt.app, docs/brand/palette/ui-colours.json), paper oklch(98.4% 0.004 12), ink oklch(20% 0.02 12)
 * fonts: Schibsted Grotesk + Atkinson Hyperlegible Next, system fallback for Cyrillic (as in Felt.app)
 * Space Read: app UI, balanced, STEP 8, DENSITY 5, RIGOR 8; rows 56px on hairlines, label to list 8, section gap 48 */
@import url("/tokens.css");

*, *::before, *::after { box-sizing: border-box; }
html, body { overflow-x: clip; }
html { -webkit-text-size-adjust: 100%; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body {
  margin: 0;
  background: var(--color-paper);
  color: var(--color-ink);
  font: 400 var(--text-base)/1.5 var(--font-ui);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p, ol, ul, figure { margin: 0; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
img, svg { display: block; }
.hidden { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
::selection { background: var(--color-neutral); }

.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 16px; height: 16px; }
/* Stroke tracks the label weight: 2px beside 600, 2.4px beside 700 (16px icons scale the 20-unit box by 0.8). */
.nav .icon, .row-title + .icon, .h3 .icon { stroke-width: 2; }
.btn .icon.icon-sm { stroke-width: 3.2; }
.link-btn .icon-sm { stroke-width: 2; }
.btn .icon { stroke-width: 2.4; }

/* ── Shell ─────────────────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); min-height: 100dvh; }
.rail {
  position: sticky; top: 0; height: 100dvh;
  display: flex; flex-direction: column; gap: var(--space-lg);
  padding: var(--space-lg) var(--space-md);
  background: var(--color-desk);
  border-inline-end: var(--rule-hair) solid var(--color-rule);
}
.brand { display: flex; align-items: center; gap: var(--space-sm); padding-inline: var(--space-xs); min-height: 40px; }
.brand-mark { width: 32px; height: 32px; flex: none; color: var(--color-ink); }
.brand-name { font: 800 var(--text-lead)/1 var(--font-display); letter-spacing: -0.01em; }
.nav { display: flex; flex-direction: column; gap: var(--space-2xs); }
.nav a {
  display: flex; align-items: center; gap: var(--space-sm);
  min-height: 40px; padding: 0 var(--space-sm); border-radius: var(--radius);
  text-decoration: none; font-weight: 600; color: var(--color-ink);
  transition: background-color var(--dur-fast) var(--ease-out);
}
.nav a[aria-current="page"] { background: var(--color-neutral); }
.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: var(--space-2xs); }
.who { display: flex; align-items: center; gap: var(--space-sm); padding: var(--space-xs) var(--space-sm); min-width: 0; }
.who-name { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-foot .link-btn { justify-content: flex-start; padding-inline: var(--space-sm); }

.main { min-width: 0; }
.page { max-width: calc(var(--content-max) + 2 * var(--page-gutter)); margin: 0 auto; padding: var(--space-2xl) var(--page-gutter) var(--space-3xl); }

/* ── Type ──────────────────────────────────────────────────────────── */
.h1 { font: 800 var(--text-head)/1.125 var(--font-display); letter-spacing: -0.02em; text-wrap: balance; overflow-wrap: anywhere; }
.h2 { font: 800 var(--text-title)/1.17 var(--font-display); letter-spacing: -0.01em; text-wrap: balance; }
.h3 { font: 700 var(--text-base)/1.5 var(--font-ui); }
.meta { color: var(--color-ink-2); }
.small { font-size: var(--text-sm); line-height: 1.54; }
.label { font: 700 var(--text-sm)/1.54 var(--font-ui); color: var(--color-ink-2); }
.num { font-variant-numeric: tabular-nums; }

/* ── Buttons ───────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-xs);
  min-height: var(--control-h); padding: 0 var(--space-lg);
  border: var(--rule-edge) solid transparent; border-radius: var(--radius);
  font-weight: 700; line-height: 1.2; white-space: nowrap; text-decoration: none;
  transition-property: background-color, border-color, color, scale, opacity;
  transition-duration: var(--dur-fast); transition-timing-function: var(--ease-out);
}
.btn-primary { background: var(--color-ink); color: var(--color-on-ink); }
.btn-quiet { background: transparent; border-color: var(--color-edge); color: var(--color-ink); }
.btn-block { display: flex; width: 100%; white-space: normal; text-align: center; padding-block: var(--space-xs); }
.btn-sm { min-height: 40px; padding: 0 var(--space-md); font-size: var(--text-sm); }
.btn:not(:disabled):active { scale: 0.96; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn[data-state="loading"] { opacity: 0.7; cursor: progress; }
.link-btn {
  display: inline-flex; align-items: center; gap: var(--space-xs);
  min-height: 40px; padding: 0; border: 0; background: none;
  color: var(--color-ink-2); font-size: var(--text-sm);
  text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: from-font;
}
.link-btn.danger { color: var(--color-wrong); }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none;
  border: 0; border-radius: var(--radius); background: transparent; color: inherit;
  transition: background-color var(--dur-fast) var(--ease-out);
}
@media (hover: hover) {
  .nav a:hover:not([aria-current="page"]) { background: var(--color-hover); }
  .btn-primary:not(:disabled):hover { background: var(--color-ink-hover); }
  .btn-quiet:not(:disabled):hover { background: var(--color-hover); }
  .link-btn:hover { color: var(--color-ink); }
  .link-btn.danger:hover { color: var(--color-wrong); }
  .icon-btn:hover { background: var(--color-band-rule); }
  .row-link:hover { background: var(--color-hover); }
  .option:not(:disabled):hover { background: var(--color-hover); }
  .flash:hover { border-color: var(--color-edge); }
}

/* ── Fields ────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: var(--space-xs); }
.field label { font-weight: 700; font-size: var(--text-sm); }
.input, .textarea, .select {
  width: 100%; min-height: var(--control-h); padding: 0 var(--space-sm);
  border: var(--rule-hair) solid var(--color-edge); border-radius: var(--radius);
  background: var(--color-paper); color: var(--color-ink); font-size: var(--text-base);
}
.textarea { padding: var(--space-sm); min-height: 96px; resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--color-ink-2); }
.input[aria-invalid="true"] { border-color: var(--color-wrong); }
.input:disabled { background: var(--color-desk); color: var(--color-ink-2); }
.input-row { display: flex; gap: var(--space-sm); align-items: stretch; }
.input-row .input { flex: 1 1 160px; min-width: 0; }
.input-row .btn { flex: none; }

/* ── Gate & login ──────────────────────────────────────────────────── */
.solo { min-height: 100dvh; display: grid; place-items: center; padding: var(--space-xl) var(--space-md); background: var(--color-desk); }
.solo-card {
  width: min(420px, 100%); display: flex; flex-direction: column; gap: var(--space-lg);
  padding: var(--space-xl); border-radius: var(--radius-panel); background: var(--color-paper);
  border: var(--rule-hair) solid transparent;
  box-shadow: 0 1px 2px var(--color-shadow), 0 12px 32px var(--color-shadow);
}
.solo-head { display: flex; flex-direction: column; gap: var(--space-xs); }
.solo-card form { display: flex; flex-direction: column; gap: var(--space-md); }
.solo-card .brand { padding: 0; }
.form-error { color: var(--color-wrong); font-size: var(--text-sm); }

/* ── Page heads ────────────────────────────────────────────────────── */
.head { display: flex; flex-direction: column; gap: var(--space-md); margin-bottom: var(--space-2xl); }
.head-top { display: flex; flex-direction: column; gap: var(--space-2xs); }
.course-line { display: flex; align-items: center; gap: var(--space-xs); font-weight: 700; min-width: 0; }
.chip { width: 12px; height: 12px; border-radius: 3px; background: var(--course, var(--color-course-default)); flex: none; }
.big-count { font: 800 var(--text-head)/1.125 var(--font-display); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 4px; background: var(--color-neutral); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--color-ink); border-radius: inherit; transition: width var(--dur) var(--ease-out); }
.bar-thin { height: 4px; }

/* ── Lists ─────────────────────────────────────────────────────────── */
.section { display: flex; flex-direction: column; gap: var(--space-2xs); }
.section > .h2 + * { margin-top: var(--space-xs); }
.section + .section { margin-top: var(--space-2xl); }
.list { list-style: none; padding: 0; border-top: var(--rule-hair) solid var(--color-rule); }
.list > li { border-bottom: var(--rule-hair) solid var(--color-rule); }
.row-link {
  display: flex; align-items: center; gap: var(--space-sm);
  min-height: 56px; padding: var(--space-sm) var(--space-sm); margin-inline: calc(-1 * var(--space-sm));
  border-radius: var(--radius); text-decoration: none; color: inherit;
  transition: background-color var(--dur-fast) var(--ease-out);
}
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-title { font-weight: 600; overflow-wrap: anywhere; text-wrap: pretty; }
.row-sub { color: var(--color-ink-2); font-size: var(--text-sm); }
.row-end { flex: none; display: flex; align-items: center; gap: var(--space-xs); color: var(--color-ink-2); font-size: var(--text-sm); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cover { width: 40px; height: 40px; flex: none; border-radius: var(--radius); background: var(--course, var(--color-course-default)); }
.status { width: 20px; height: 20px; flex: none; color: var(--color-ink-2); }
.status.done { color: var(--color-ink); }
.next-tile { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: var(--radius); background: var(--color-neutral); }
.next { display: flex; flex-direction: column; gap: var(--space-md); margin-bottom: var(--space-2xl); }
.next .row-link { min-height: 64px; }
.empty { padding: var(--space-xl) 0; color: var(--color-ink-2); }

/* ── Band (topic / exam header in the course colour) ──────────────── */
.band { background: var(--course, var(--color-course-default)); color: var(--color-on-band); }
.band-inner { max-width: calc(var(--content-max) + 2 * var(--page-gutter)); margin: 0 auto; padding: var(--space-md) var(--page-gutter) var(--space-xl); display: flex; flex-direction: column; gap: var(--space-lg); }
.band-bar { display: flex; align-items: center; gap: var(--space-sm); }
.band-bar .bar { flex: 1; background: var(--color-band-track); }
.band-bar .bar > i { background: var(--color-on-band); }
.band-count { font-size: var(--text-sm); font-variant-numeric: tabular-nums; white-space: nowrap; }
.band-title { display: flex; flex-direction: column; gap: var(--space-2xs); }
.band .icon-btn:focus-visible { outline-color: var(--color-on-band); }
.timer { margin-inline-start: auto; padding: var(--space-2xs) var(--space-sm); border-radius: var(--radius); background: var(--color-on-band); color: var(--course, var(--color-course-default)); font-weight: 700; font-variant-numeric: tabular-nums; }
.timer.low { background: var(--color-wrong); color: var(--color-paper); }

/* ── Theory ────────────────────────────────────────────────────────── */
.theory { max-width: var(--read-max); font-size: var(--text-read); line-height: 1.6; display: flex; flex-direction: column; gap: var(--space-md); }
.theory h3 { font: 800 var(--text-lead)/1.3 var(--font-display); margin-top: var(--space-lg); }
.theory ul, .theory ol { padding-inline-start: 1.25em; display: flex; flex-direction: column; gap: var(--space-2xs); }
.theory code, .q code, .explain code, .hint code, .option code {
  font-family: var(--font-mono); font-size: 0.9em; padding: 1px 5px; border-radius: 4px; background: var(--color-neutral);
}
.theory .formula { font: 700 var(--text-lead)/1.4 var(--font-ui); text-align: center; padding: var(--space-md); border-radius: var(--radius); background: var(--color-desk); }
.theory .tip, .tip { padding: var(--space-sm) var(--space-md); border-inline-start: 3px solid var(--course, var(--color-course-default)); background: var(--color-desk); border-radius: 0 var(--radius) var(--radius) 0; }
.table-wrap { overflow-x: auto; overscroll-behavior-x: contain; }
.cheat { width: 100%; border-collapse: collapse; font-size: var(--text-base); }
.cheat td, .cheat th { border-bottom: var(--rule-hair) solid var(--color-rule); padding: var(--space-xs) var(--space-xs) var(--space-xs) 0; text-align: start; vertical-align: top; }
.cheat th { padding-top: var(--space-lg); font: 700 var(--text-sm)/1.54 var(--font-ui); color: var(--color-ink-2); }
.cheat td:first-child { white-space: nowrap; font-weight: 600; }
.fig { width: 100%; max-width: 440px; height: auto; margin: var(--space-xs) auto; }
.fig text { fill: var(--color-ink); font-size: 12px; text-anchor: middle; font-family: var(--font-ui); }
.fig .cap text { text-anchor: start; fill: var(--color-ink-2); }
.fig line, .fig path { stroke: var(--color-ink-2); stroke-width: 1.5; fill: none; }
.fig .grid line { stroke: var(--color-rule); stroke-width: 1; }
.fig .wave { stroke: var(--color-ink); stroke-width: 2; }
.fig .smp { stroke: var(--color-mark); }
.fig .dot { fill: var(--color-mark); }
.fig .node, .fig .nd { fill: var(--color-ink-2); }
.fig .leaf circle, .fig .leafc { fill: var(--color-ink); }
.fig .free, .fig .freec { fill: none; stroke: var(--color-mark); stroke-width: 2; stroke-dasharray: 4 3; }
.fig .lt text, .fig .lt2 { fill: var(--color-paper); font-weight: 700; }
.fig .bad { fill: var(--color-wrong); }
.fig .ft { fill: var(--color-mark); font-size: 11px; }
.fig .bl { fill: var(--color-ink-2); font-size: 11px; }
.fig .fe { stroke: var(--color-mark); stroke-dasharray: 4 3; }
.fig .px { stroke: var(--color-paper); stroke-width: 0.5; }
.ladder, .ladder2 { display: flex; flex-wrap: wrap; gap: var(--space-xs); align-items: center; }
.ladder span, .ladder2 span { padding: var(--space-2xs) var(--space-sm); border-radius: var(--radius-sm); background: var(--color-neutral); font-weight: 600; font-variant-numeric: tabular-nums; }
.ladder i { color: var(--color-ink-2); font-style: normal; }
.ladder2 span { font-weight: 400; }
.ladder2 .lo { opacity: 0.5; }
.ladder2 .hit { background: var(--color-ink); color: var(--color-on-ink); }

/* Interactive schemes inside the theory */
.wid { display: flex; flex-direction: column; gap: var(--space-sm); padding: var(--space-md); border-radius: var(--radius-panel); background: var(--color-desk); font-size: var(--text-base); }
.wid-row { display: flex; flex-wrap: wrap; gap: var(--space-xs) var(--space-sm); align-items: center; }
.wid-row label { display: inline-flex; align-items: center; gap: var(--space-xs); }
.wid .input, .wid .select { width: auto; min-width: 0; flex: 0 1 120px; }
.wid .textarea { min-height: 120px; font-family: var(--font-mono); }
.wout { display: flex; flex-direction: column; gap: var(--space-2xs); font-variant-numeric: tabular-nums; }
.pix { image-rendering: pixelated; border-radius: var(--radius-sm); }

/* Flash cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); gap: var(--space-sm); }
.flash {
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-xs); text-align: start;
  min-height: 96px; padding: var(--space-md); border-radius: var(--radius); border: var(--rule-hair) solid var(--color-rule);
  background: var(--color-paper); color: var(--color-ink); transition: border-color var(--dur-fast) var(--ease-out);
}
.flash .back { display: none; font-weight: 700; }
.flash[aria-expanded="true"] { background: var(--color-desk); }
.flash[aria-expanded="true"] .back { display: block; }
.flash .turn { margin-top: auto; color: var(--color-ink-2); font-size: var(--text-sm); }

/* ── Tasks ─────────────────────────────────────────────────────────── */
.tasks { list-style: none; padding: 0; display: flex; flex-direction: column; }
.task { display: flex; flex-direction: column; gap: var(--space-md); padding: var(--space-xl) 0; border-top: var(--rule-hair) solid var(--color-rule); }
.section > .tasks .task:first-child { border-top: 0; padding-top: var(--space-sm); }
.task-head { display: flex; align-items: center; gap: var(--space-md); font-size: var(--text-sm); color: var(--color-ink-2); font-weight: 700; }
.task-head .done { color: var(--color-ink); display: inline-flex; align-items: center; gap: var(--space-2xs); }
.q { font-size: var(--text-read); line-height: 1.6; max-width: var(--read-max); overflow-wrap: anywhere; text-wrap: pretty; }
.theory p, .meta, .explain { text-wrap: pretty; }
.options { display: flex; flex-direction: column; gap: var(--space-sm); }
.option {
  display: flex; align-items: center; gap: var(--space-sm); width: 100%; min-height: var(--control-h);
  padding: var(--space-sm) var(--space-md); text-align: start;
  border: var(--rule-hair) solid var(--color-rule); border-radius: var(--radius); background: var(--color-paper); color: var(--color-ink);
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.option .opt-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.option .opt-note { flex: none; font-size: var(--text-sm); }
.option.right { background: var(--color-ink); border-color: var(--color-ink); color: var(--color-on-ink); font-weight: 700; }
.option.right code { background: transparent; }
.option.wrong { border-color: var(--color-wrong); color: var(--color-wrong); }
.option.wrong .opt-text { text-decoration: line-through; }
.option.dim { color: var(--color-ink-2); }
.option:disabled { cursor: default; }
.task .input-row, .task .steps { max-width: var(--read-max); }
.task-tools { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-sm) var(--space-lg); }
.hint { padding: var(--space-sm) var(--space-md); border-radius: var(--radius); background: var(--color-desk); max-width: var(--read-max); }
.steps { display: flex; flex-direction: column; gap: var(--space-sm); }
.step-done { display: flex; align-items: center; gap: var(--space-xs); color: var(--color-ink-2); }
.step-done b { color: var(--color-ink); }
.step-form { display: flex; flex-direction: column; gap: var(--space-xs); }

.feedback { display: flex; flex-direction: column; gap: var(--space-xs); padding: var(--space-md) var(--space-lg); border-radius: var(--radius); background: var(--color-desk); max-width: var(--read-max); }
.feedback.no { background: var(--color-wrong-soft); }
.feedback-title { font: 800 var(--text-title)/1.17 var(--font-display); letter-spacing: -0.01em; }
.feedback.no .feedback-title { color: var(--color-wrong); }
.feedback .actions { display: flex; flex-wrap: wrap; gap: var(--space-sm); margin-top: var(--space-xs); }
.explain { line-height: 1.6; overflow-wrap: anywhere; }
.explain details summary { cursor: pointer; color: var(--color-ink-2); }

.next-topic { margin-top: var(--space-xl); }
.result { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-xs); padding: var(--space-xl) 0; border-top: var(--rule-hair) solid var(--color-rule); }
.result-big { font: 800 var(--text-grade)/1 var(--font-display); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.result .btn { margin-top: var(--space-md); }

/* ── Tutor panel ───────────────────────────────────────────────────── */
.tutor {
  position: fixed; inset-block: 0; inset-inline-end: 0; z-index: 20; width: min(var(--tutor-w), 100%);
  display: flex; flex-direction: column; background: var(--color-paper);
  border-inline-start: var(--rule-hair) solid var(--color-rule);
  box-shadow: -8px 0 32px var(--color-shadow);
  translate: 100% 0; visibility: hidden;
  transition: translate var(--dur) var(--ease-out), visibility 0s linear var(--dur);
}
.tutor.open { translate: 0 0; visibility: visible; transition: translate var(--dur) var(--ease-out), visibility 0s; }
.tutor-head { display: flex; align-items: center; gap: var(--space-xs); min-height: 56px; padding: var(--space-xs) var(--space-xs) var(--space-xs) var(--space-md); border-bottom: var(--rule-hair) solid var(--color-rule); }
.tutor-head .h3 { flex: 1; }
.tutor-head .icon-btn:hover { background: var(--color-hover); }
.msgs { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: var(--space-md); display: flex; flex-direction: column; gap: var(--space-md); }
.msgs .intro { display: flex; flex-direction: column; gap: var(--space-xs); }
.msg { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; }
.msg.user { align-self: flex-end; max-width: 88%; padding: var(--space-xs) var(--space-sm); border-radius: var(--radius-chip); background: var(--color-neutral); }
.msg.wait { color: var(--color-ink-2); }
.tutor-form { display: flex; align-items: flex-end; gap: var(--space-xs); padding: var(--space-sm) var(--space-md) var(--space-md); border-top: var(--rule-hair) solid var(--color-rule); }
.tutor-form .textarea { min-height: 48px; max-height: 160px; resize: none; }
.send { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border: 0; border-radius: var(--radius); background: var(--color-ink); color: var(--color-on-ink); transition: scale var(--dur-fast) var(--ease-out), opacity var(--dur-fast) var(--ease-out); }
.send:not(:disabled):active { scale: 0.96; }
.send:disabled { opacity: 0.45; cursor: default; }
.scrim { position: fixed; inset: 0; z-index: 19; background: var(--color-scrim); opacity: 0; pointer-events: none; transition: opacity var(--dur) var(--ease-out); }
.scrim.open { opacity: 1; pointer-events: auto; }
@media (min-width: 1200px) { .scrim { display: none; } body.tutor-open .main { padding-inline-end: var(--tutor-w); } }

/* ── Admin ─────────────────────────────────────────────────────────── */
.drop {
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-sm);
  padding: var(--space-lg); border: var(--rule-edge) dashed var(--color-edge); border-radius: var(--radius-panel);
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.drop.over { background: var(--color-desk); border-color: var(--color-ink); }
.notice { padding: var(--space-sm) var(--space-md); border-radius: var(--radius); background: var(--color-desk); }
.notice.no { background: var(--color-wrong-soft); }
.notice ul { margin-top: var(--space-xs); padding-inline-start: 1.25em; }
.row-static { display: flex; align-items: center; gap: var(--space-sm); min-height: 64px; padding-block: var(--space-sm); flex-wrap: wrap; }
.row-static > .row-main { flex: 1 1 220px; }
.row-actions { display: flex; align-items: center; gap: var(--space-md); flex-wrap: wrap; }
.cover-btn { padding: 0; border: 0; cursor: pointer; }
.swatches { display: flex; flex-wrap: wrap; gap: var(--space-xs); padding-bottom: var(--space-md); }
.swatch { width: 28px; height: 28px; border-radius: var(--radius-sm); border: var(--rule-edge) solid transparent; background: var(--sw); padding: 0; }
.swatch[aria-pressed="true"] { border-color: var(--color-ink); box-shadow: inset 0 0 0 2px var(--color-paper); }
.grid-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); font-variant-numeric: tabular-nums; }
.grid-table th, .grid-table td { padding: var(--space-xs) var(--space-sm) var(--space-xs) 0; border-bottom: var(--rule-hair) solid var(--color-rule); text-align: start; vertical-align: top; white-space: nowrap; }
.grid-table th { color: var(--color-ink-2); font-weight: 700; }
.grid-table .bar { width: 80px; margin-top: var(--space-2xs); }
.grid-table td.full { font-weight: 700; }
.grid-table td.stuck { color: var(--color-wrong); }
.person-name { font-weight: 700; font-size: var(--text-base); }
.person.blocked .person-name { text-decoration: line-through; color: var(--color-ink-2); }
details.more > summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: var(--space-2xs); color: var(--color-ink-2); font-size: var(--text-sm); text-decoration: underline; text-underline-offset: 3px; min-height: 32px; }
details.more > summary::-webkit-details-marker { display: none; }
details:not([open]) > :not(summary) { display: none; }
details.more[open] > summary { margin-bottom: var(--space-xs); }
.logq { padding: var(--space-xs) 0; border-bottom: var(--rule-hair) solid var(--color-rule); }
.toast { position: fixed; inset-inline: 0; bottom: var(--space-lg); margin: 0 auto; width: max-content; max-width: calc(100% - 32px); z-index: 30; padding: var(--space-sm) var(--space-md); border-radius: var(--radius); background: var(--color-ink); color: var(--color-on-ink); font-weight: 600; box-shadow: 0 8px 24px var(--color-shadow-lift); opacity: 0; translate: 0 8px; transition: opacity var(--dur-fast) var(--ease-out), translate var(--dur-fast) var(--ease-out); pointer-events: none; }
.toast.show { opacity: 1; translate: 0 0; }

/* ── Small screens: the rail becomes a top bar ─────────────────────── */
@media (max-width: 899px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { position: sticky; z-index: 10; height: auto; flex-direction: row; align-items: center; gap: var(--space-xs); padding: var(--space-xs) var(--space-md); border-inline-end: 0; border-bottom: var(--rule-hair) solid var(--color-rule); }
  .brand { padding: 0; margin-inline-end: auto; }
  .brand-name { font-size: var(--text-base); }
  .brand-mark { width: 28px; height: 28px; }
  .nav { flex-direction: row; }
  .nav a { padding: 0 var(--space-sm); }
  .nav .nav-text { display: none; }
  .nav a { width: 40px; justify-content: center; padding: 0; }
  .rail-foot { margin: 0; flex-direction: row; }
  .who { display: none; }
  .rail-foot .link-btn { width: 40px; justify-content: center; padding: 0; }
  .rail-foot .link-text { display: none; }
  .page { padding-top: var(--space-xl); }
}
/* Touch: every control gets a 44px target. */
@media (max-width: 899px), (pointer: coarse) {
  .nav a, .rail-foot .link-btn, .icon-btn { min-width: 44px; min-height: 44px; }
  .link-btn, .btn-sm, .btn, details.more > summary { min-height: 44px; }
  .cover-btn { width: 44px; height: 44px; }
}
@media (max-width: 479px) {
  .input-row { flex-wrap: wrap; }
  .input-row .btn { flex: 1 1 100%; }
  .solo-card { padding: var(--space-lg); }
  .feedback { padding: var(--space-md); }
}

@media (prefers-reduced-motion: reduce) {
  .tutor { transition: opacity var(--dur-fast) linear, visibility 0s linear var(--dur-fast); translate: 0 0; opacity: 0; }
  .tutor.open { opacity: 1; transition: opacity var(--dur-fast) linear, visibility 0s; }
  .btn:not(:disabled):active, .send:not(:disabled):active { scale: 1; }
  .toast { translate: 0 0; }
  .bar > i { transition: none; }
}

/* Quiet buttons that sit on the course band keep the band's ink in both themes. */
.band .btn-quiet { border-color: var(--color-band-track); color: var(--color-on-band); }
@media (hover: hover) { .band .btn-quiet:hover { background: var(--color-band-rule); } }

/* ── Felt lesson player: one step per screen, verdict panel at the bottom (as in Felt.app) ── */
.felt-prompt { font-size: var(--text-title); line-height: 1.25; overflow-wrap: anywhere; }
.felt-step { padding-bottom: var(--space-2xl); }
.felt-body { display: flex; flex-direction: column; gap: var(--space-lg); max-width: 40em; }
.felt-theory .katex-display, .explain .katex-display { margin: var(--space-xs) 0; overflow-x: auto; overflow-y: hidden; }
.felt-figure { margin: 0; display: flex; flex-direction: column; gap: var(--space-xs); }
.felt-table caption { text-align: start; padding-bottom: var(--space-xs); }
.felt-foot { position: sticky; bottom: 0; z-index: 5; background: var(--color-paper); border-top: var(--rule-hair) solid var(--color-rule); }
.felt-foot.ok { background: var(--color-desk); }
.felt-foot.no { background: var(--color-wrong-soft); border-top-color: var(--color-wrong); }
.felt-foot-inner { max-width: calc(var(--content-max) + 2 * var(--page-gutter)); margin: 0 auto; padding: var(--space-md) var(--page-gutter) calc(var(--space-md) + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: var(--space-sm); }
.felt-foot-inner .form-error:empty { display: none; }
.felt-foot-hint { text-align: center; }
.felt-verdict { display: flex; flex-direction: column; gap: var(--space-xs); max-height: 40dvh; overflow-y: auto; overscroll-behavior: contain; }
.felt-foot.no .feedback-title { color: var(--color-wrong); }
.felt-actions { display: flex; flex-wrap: wrap; gap: var(--space-sm); justify-content: flex-end; }
.felt-actions .btn-primary { min-width: 160px; }
.unit-title { margin-top: var(--space-xs); }

.option.check .tick { width: 18px; height: 18px; flex: none; border: var(--rule-edge) solid var(--color-edge); border-radius: 4px; display: grid; place-items: center; }
.option.check[aria-pressed="true"] { border-color: var(--color-ink); }
.option.check[aria-pressed="true"] .tick { background: var(--color-ink); border-color: var(--color-ink); }
.option.check[aria-pressed="true"] .tick::after { content: ""; width: 8px; height: 4px; border: solid var(--color-paper); border-width: 0 0 2px 2px; rotate: -45deg; translate: 0 -1px; }
.option.missed { border-color: var(--color-ink); border-style: dashed; }
.option.right .tick { border-color: var(--color-on-ink); }

.match { display: flex; flex-direction: column; border-top: var(--rule-hair) solid var(--color-rule); }
.match-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-xs) var(--space-md); align-items: center; padding: var(--space-sm) 0; border-bottom: var(--rule-hair) solid var(--color-rule); }
.match-note { grid-column: 2; color: var(--color-ink-2); }
.match-note:empty { display: none; }
.match-row.wrong .match-note { color: var(--color-wrong); }
.match-row.wrong .select { border-color: var(--color-wrong); }
@media (max-width: 599px) { .match-row { grid-template-columns: minmax(0, 1fr); } .match-note { grid-column: 1; } }

.template { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-xs); font-size: var(--text-lead); line-height: 1.6; }
.tpl-box { width: 5.5em; min-width: 0; text-align: center; font-size: var(--text-base); }
.tpl-box.raised { width: 3.5em; align-self: flex-start; }
.tpl-box.right { border-color: var(--color-ink); border-width: var(--rule-edge); }
.tpl-box.wrong, .felt-num .input[aria-invalid="true"] { border-color: var(--color-wrong); color: var(--color-wrong); }
.unit { align-self: center; color: var(--color-ink-2); }
.felt-num .input { flex: 0 1 240px; }

.rungs { list-style: none; padding: 0; display: flex; flex-direction: column; border-top: var(--rule-hair) solid var(--color-rule); counter-reset: rung; }
.rung { display: flex; flex-direction: column; gap: var(--space-xs); padding: var(--space-md) 0; border-bottom: var(--rule-hair) solid var(--color-rule); counter-increment: rung; }
.rung-label { font-weight: 600; }
.rung-label::before { content: counter(rung) ". "; color: var(--color-ink-2); }
.rung .input-row .input { flex: 0 1 240px; }
.rung-note:empty { display: none; }
.rung.right .rung-note { color: var(--color-ink); font-weight: 700; }
.rung.follow .rung-note { color: var(--color-fading); }
.rung.wrong .rung-note { color: var(--color-wrong); }
.rung.wrong .input { border-color: var(--color-wrong); }
.felt-passage .theory { margin-top: var(--space-xs); }
/* The verdict panel sits at the bottom of the window even on short steps. */
.main:has(.felt-foot) { display: flex; flex-direction: column; min-height: 100dvh; }
.felt-foot { margin-top: auto; }
.main:has(.felt-foot) > * { width: 100%; }
@media (max-width: 899px) { .main:has(.felt-foot) { min-height: calc(100dvh - 61px); } }
@media (max-width: 599px) {
  .band-ask { width: 44px; padding: 0; }
  .band-ask .ask-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
@media (max-width: 599px) {
  .felt-prompt { font-size: var(--text-lead); line-height: 1.3; }
  .felt-verdict { max-height: 30dvh; }
  .felt-actions { flex-wrap: nowrap; }
  .felt-actions .btn { flex: 1 1 0; min-width: 0; padding-inline: var(--space-sm); }
  .felt-actions .btn-primary { min-width: 0; }
}
