/* App shell for the notes reader. Tokens live in lib/notes.css; rules in DESIGN.md. */
:root {
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --scrim: rgb(0 0 0 / .6);
  --edge: rgb(255 255 255 / .09);
  --sh-2: 0 0 0 1px var(--edge), 0 1px 1px rgb(0 0 0 / .3), 0 6px 12px -4px rgb(0 0 0 / .45), inset 0 1px 0 rgb(255 255 255 / .04);
  --sh-3: 0 0 0 1px var(--edge), 0 1px 1px rgb(0 0 0 / .3), 0 12px 24px -6px rgb(0 0 0 / .55), 0 32px 48px -12px rgb(0 0 0 / .45), inset 0 1px 0 rgb(255 255 255 / .05);
  --bar-h: 56px;
  --tab-h: 64px;
  --rail-w: 272px;
  --toc-w: 264px;
  --gutter: max(20px, env(safe-area-inset-left));
  /* the page re-inks itself when the subject changes */
  transition: --accent 600ms var(--ease-in-out), --accent-subtle 600ms var(--ease-in-out), --accent-line 600ms var(--ease-in-out), --accent-hover 600ms var(--ease-in-out), --accent-ring 600ms var(--ease-in-out);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); scroll-padding-top: calc(var(--bar-h) + 16px); }
html, body { overflow-x: clip; }
body {
  margin: 0; min-height: 100svh; background: var(--bg); color: var(--fg);
  font-family: var(--font); font-size: 16px; line-height: 1.5; font-weight: 400;
  font-optical-sizing: auto; font-synthesis: none;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
}
h1, h2, h3, h4, h5, h6, b, strong, th { font-weight: 550; }
em, i, cite { font-style: oblique 10deg; }
code, pre, kbd, samp { font-family: var(--mono); }
::selection { background: var(--accent); color: var(--on-accent); }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
a { color: inherit; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
input { font: inherit; }
svg.i { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.skip { position: fixed; left: 12px; top: -60px; z-index: 100; background: var(--fg); color: var(--bg); padding: 10px 14px; border-radius: var(--r-sm); text-decoration: none; }
.skip:focus { top: 12px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- app bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 30; background: var(--bg);
  padding-top: env(safe-area-inset-top); view-transition-name: appbar;
  transition: box-shadow 200ms ease;
}
.appbar[data-scrolled] { box-shadow: 0 1px 0 var(--line-subtle); }
.appbar-in { height: var(--bar-h); display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 4px; padding: 0 max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left)); max-width: 840px; margin: 0 auto; }
.appbar-lead, .appbar-actions { display: flex; align-items: center; gap: 2px; min-width: 44px; }
.appbar-actions { justify-content: flex-end; }
.appbar-title {
  font-size: 16px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 4px;
  opacity: 0; transform: translateY(8px); filter: blur(2px);
  transition: opacity 250ms var(--ease-out), transform 250ms var(--ease-out), filter 250ms var(--ease-out);
}
.appbar[data-titled] .appbar-title { opacity: 1; transform: none; filter: none; }
.readbar { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; pointer-events: none; opacity: 0; transition: opacity 200ms ease; }
.readbar span { display: block; height: 100%; background: var(--accent); transform-origin: 0 50%; transform: scaleX(0); }
.appbar[data-reading] .readbar { opacity: 1; }

.icon-btn {
  position: relative; width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: var(--r-md); color: var(--fg-secondary);
  transition: background-color 150ms ease, color 150ms ease, transform 140ms var(--ease-out);
}
.icon-btn:active { transform: scale(0.92); background: var(--fill-active); }
.logo { display: block; height: 22px; width: auto; aspect-ratio: 471.5 / 715; color: var(--fg); flex: none; }
.brand-mark { color: var(--fg); }
@media (min-width: 1024px) { .brand-mark { display: none; } }
@media (hover: hover) and (pointer: fine) { .icon-btn:hover { background: var(--fill); color: var(--fg); } }

/* ---------- tab bar (phones) / rail (desktop) ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--n2);
  box-shadow: 0 -1px 0 var(--line-subtle); padding-bottom: env(safe-area-inset-bottom);
  view-transition-name: tabbar;
  transition: transform 350ms var(--ease-drawer);
}
.tabbar[data-hidden] { transform: translateY(calc(100% + 2px)); }
.tabbar[data-gone] { transform: translateY(calc(100% + 2px)); visibility: hidden; transition: transform 350ms var(--ease-drawer), visibility 0s 350ms; }
.rail-brand, .rail-subjects, .toc-rail, .crumbs { display: none; }
@media (max-width: 1023px) { .desk-only { display: none !important; } }
@media (min-width: 1024px) { .mob-only { display: none !important; } }
.appbar-mid { display: grid; min-width: 0; }
.appbar-mid > * { grid-area: 1 / 1; min-width: 0; }
.kbd-hint { margin: 10px 0 0; font-size: 13px; color: var(--fg-muted); text-align: center; }
.pill[aria-current="page"] { background: var(--accent-subtle); color: var(--accent); }
.tabs { position: relative; display: grid; grid-template-columns: repeat(4, 1fr); height: var(--tab-h); max-width: 560px; margin: 0 auto; isolation: isolate; }
.tab {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  text-decoration: none; color: var(--fg-muted); font-size: 12px; font-weight: 500; user-select: none;
  transition: color 200ms ease;
}
.tab .i { width: 24px; height: 24px; transition: transform 300ms var(--ease-out); }
.tab:active .i { transform: scale(0.88); }
.tab[aria-current="page"] { color: var(--fg); }
.tab-pill {
  position: absolute; z-index: -1; top: 8px; left: 0; width: 60px; height: 32px; border-radius: var(--r-full);
  background: var(--fill-active); pointer-events: none; transform-origin: 50% 50%;
}
.tab-pill[hidden] { display: none; }

/* ---------- screens ---------- */
.view { display: block; outline: none; }
.screen { max-width: 720px; margin: 0 auto; padding: 8px var(--gutter) 64px; }
.screen-title { font-size: 34px; line-height: 1.1; font-weight: 550; letter-spacing: -0.025em; margin: 4px 0 0; text-wrap: balance; }
.screen-sub { margin: 10px 0 0; color: var(--fg-secondary); font-size: 16px; max-width: 52ch; text-wrap: pretty; }
.group { margin-top: 40px; }
.group-h { font-size: 19px; font-weight: 550; letter-spacing: -0.01em; margin: 0 0 12px; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.group-h .aside { font-size: 14px; font-weight: 400; color: var(--fg-muted); }
.muted { color: var(--fg-muted); }
.num { font-variant-numeric: tabular-nums; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 16px; border-radius: var(--r-sm);
  font-size: 15px; font-weight: 510; white-space: nowrap; text-decoration: none; user-select: none;
  background: var(--fill); color: var(--fg);
  transition: background-color 150ms ease, color 150ms ease, transform 140ms var(--ease-out);
}
.btn .i { width: 18px; height: 18px; }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger-subtle); color: var(--danger); }
.btn-block { width: 100%; }
.btn-lg { height: 52px; font-size: 16px; padding: 0 20px; }
.btn:disabled { background: var(--fill); color: var(--fg-disabled); cursor: not-allowed; transform: none; }
@media (hover: hover) and (pointer: fine) {
  .btn:hover { background: var(--fill-hover); }
  .btn-primary:hover { background: var(--accent-hover); }
  .btn-ghost:hover { background: var(--fill); }
  .btn-danger:hover { background: var(--danger-line); }
}
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* chips */
.chip { display: inline-flex; align-items: center; height: 24px; padding: 0 8px; border-radius: var(--r-xs); font-size: 12.5px; font-weight: 510; background: var(--fill); color: var(--fg-secondary); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chip-accent { background: var(--accent-subtle); color: var(--accent); }
.chip-warn { background: var(--warn-subtle); color: var(--warn); }

/* progress ring and bar */
.ring { --p: 0; width: 44px; height: 44px; flex: none; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 5; }
.ring .track { stroke: var(--fill-active); }
.ring .val { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset 1100ms var(--ease-expo) 120ms; }
.bar { height: 4px; border-radius: var(--r-full); background: var(--fill-active); overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: inherit; background: var(--accent); transform-origin: 0 50%; transform: scaleX(0); transition: transform 1000ms var(--ease-expo) 150ms; }

/* ---------- home ---------- */
.continue {
  display: block; text-decoration: none; padding: 16px; border-radius: var(--r-md); background: var(--accent-subtle);
  transition: transform 140ms var(--ease-out);
}
.continue:active { transform: scale(0.98); }
.continue-t { font-size: 18px; font-weight: 550; letter-spacing: -0.01em; line-height: 1.3; }
.continue-m { margin-top: 4px; font-size: 14px; color: var(--fg-secondary); }
.continue .bar { margin-top: 14px; background: var(--accent-line); }
.continue-go { margin-top: 14px; display: flex; align-items: center; justify-content: space-between; font-size: 14px; font-weight: 510; color: var(--accent); }
.continue-go .i { width: 18px; height: 18px; transition: transform 200ms var(--ease-out); }
@media (hover: hover) and (pointer: fine) { .continue:hover .continue-go .i { transform: translateX(3px); } }

.subjects { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.subj {
  position: relative; display: flex; flex-direction: column; justify-content: space-between; gap: 20px; min-height: 152px; padding: 16px;
  border-radius: var(--r-md); background: var(--surface); text-decoration: none;
  transition: background-color 150ms ease, transform 140ms var(--ease-out);
}
.subj:active { transform: scale(0.97); }
@media (hover: hover) and (pointer: fine) { .subj:hover { background: var(--surface-hover); } }
.subj-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.subj-pct { font-size: 13px; font-variant-numeric: tabular-nums; }
.subj-name { font-size: 18px; font-weight: 550; letter-spacing: -0.01em; line-height: 1.2; width: fit-content; }
.subj-meta { margin-top: 4px; font-size: 13px; color: var(--fg-muted); line-height: 1.4; }
.subj .ring .track { stroke: var(--accent-ring); }
.subj-pct { color: var(--accent); }

.totals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; margin-top: 12px; }
.total { padding: 12px 0; }
.total-v { font-size: 24px; font-weight: 550; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.total-l { font-size: 13px; color: var(--fg-muted); }

/* ---------- rows ---------- */
.rows { list-style: none; margin: 0; padding: 0; }
.rows > li + li { border-top: 1px solid var(--line-subtle); }
.row {
  display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 12px; margin: 0 -12px; border-radius: var(--r-sm);
  text-decoration: none; color: var(--fg); transition: background-color 150ms ease, transform 140ms var(--ease-out);
}
.row:active { background: var(--fill); }
@media (hover: hover) and (pointer: fine) { .row:hover { background: var(--fill); transition-duration: 0ms; } }
.row-main { flex: 1; min-width: 0; }
.row-t { font-size: 16px; font-weight: 500; line-height: 1.35; text-wrap: pretty; width: fit-content; max-width: 100%; }
.row-m { margin-top: 2px; font-size: 13px; color: var(--fg-muted); line-height: 1.4; }
.row-end { display: flex; align-items: center; gap: 6px; color: var(--fg-muted); flex: none; }
.row-end .i { width: 18px; height: 18px; color: var(--fg-disabled); }
.row .katex { font-size: 1em; }

/* ---------- subject screen ---------- */
a.pill { display: inline-flex; align-items: center; text-decoration: none; }
.subj-switch { margin: 4px calc(-1 * var(--gutter)) 12px; }
.cover { margin-top: 8px; padding: 20px; border-radius: var(--r-lg); background: var(--accent-subtle); }
.cover-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.cover .ring { width: 64px; height: 64px; }
.cover .ring .track { stroke: var(--accent-ring); }
.cover .ring circle { stroke-width: 6; }
.cover h1 { font-size: 32px; line-height: 1.1; font-weight: 550; letter-spacing: -0.025em; margin: 0; width: fit-content; }
.cover-meta { margin-top: 8px; color: var(--fg-secondary); font-size: 15px; }
.cover-pct { font-size: 14px; color: var(--accent); margin-top: 2px; font-variant-numeric: tabular-nums; }
.cover .btn-row { margin-top: 18px; }
.cover .btn { background: var(--accent-line); color: var(--fg); }
@media (hover: hover) and (pointer: fine) { .cover .btn:hover { background: color-mix(in oklab, var(--accent-line) 80%, white); } }

/* ---------- reader ---------- */
.reader { max-width: 720px; margin: 0 auto; padding: 8px var(--gutter) 48px; }
.unit-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.unit-actions:empty { display: none; }
.sec > h2 .bm, .q-head .bm { margin-left: auto; }
.sec > h2 .sec-exam + .bm { margin-left: auto; }
.q-head .q-marks + .bm { margin-left: 4px; }
.bm { width: 36px; height: 36px; margin: -6px -8px -6px 0; display: inline-grid; place-items: center; border-radius: var(--r-sm); color: var(--fg-disabled); position: relative; flex: none; transition: color 150ms ease, transform 140ms var(--ease-out); }
.bm::after { content: ""; position: absolute; inset: -4px; }
.bm .i { width: 18px; height: 18px; transition: fill 200ms ease, transform 350ms var(--ease-out); }
.bm[aria-pressed="true"] { color: var(--accent); }
.bm[aria-pressed="true"] .i { fill: currentColor; }
.bm.pop .i { animation: pop 420ms var(--ease-out); }
.bm:active { transform: scale(0.88); }
@media (hover: hover) and (pointer: fine) { .bm:hover { color: var(--fg-secondary); background: var(--fill); } }
@keyframes pop { 0% { transform: scale(0.6); } 55% { transform: scale(1.18); } 100% { transform: scale(1); } }

.skel { border-radius: var(--r-sm); background: var(--fill); animation: skel 1.4s ease-in-out infinite; }
@keyframes skel { 50% { background: var(--fill-hover); } }
.skel-line { height: 14px; margin-top: 12px; }
.skel-block { height: 120px; margin-top: 24px; border-radius: var(--r-md); }
.loading-note { margin-top: 16px; font-size: 14px; color: var(--fg-muted); }
.chunking .reader-end { visibility: hidden; }

/* off-screen questions and topics are not painted until they come near the viewport */
.notes[data-reader] .q { content-visibility: auto; contain-intrinsic-size: auto 420px; }

/* hide answers until tapped */
.hide-sol .sol, .hide-sol .book-answer, .hide-sol .part-sol, .hide-sol .opt-mark, .hide-sol .part-answer { display: none; }
.hide-sol .opt.correct .opt-key { background: var(--fill); color: var(--fg-secondary); }
.hide-sol .opt.correct .opt-text { font-weight: inherit; }
.hide-sol .q.revealed .sol, .hide-sol .q.revealed .part-sol, .hide-sol .q.revealed .book-answer, .hide-sol .q.revealed .part-answer { display: block; animation: reveal 420ms var(--ease-out); }
.hide-sol .q.revealed .opt.correct .opt-key { background: var(--accent); color: var(--on-accent); }
.hide-sol .q.revealed .opt-mark { display: inline; }
.reveal { display: none; }
.hide-sol .reveal { display: inline-flex; margin-top: 12px; height: 36px; font-size: 14px; padding: 0 12px; }
.hide-sol .q.revealed .reveal { display: none; }
.hide-sol .opts:not(.answered) .opt { cursor: pointer; }
.hide-sol .opt { padding: 8px 10px; margin: 0 -10px; border-radius: var(--r-sm); transition: background-color 150ms ease; }
@media (hover: hover) and (pointer: fine) { .hide-sol .opts:not(.answered) .opt:hover { background: var(--fill); } }
.opt.picked-ok { background: var(--ok-subtle); }
.opt.picked-ok .opt-key { background: var(--ok) !important; color: var(--on-accent) !important; }
.opt.picked-bad { background: var(--danger-subtle); animation: nudge 360ms var(--ease-out); }
.opt.picked-bad .opt-key { background: var(--danger) !important; color: var(--on-accent) !important; }
@keyframes reveal { from { opacity: 0; transform: translateY(8px); filter: blur(3px); } }
@keyframes nudge { 20% { transform: translateX(-5px); } 45% { transform: translateX(4px); } 70% { transform: translateX(-2px); } }

.flash { animation: flash 1800ms var(--ease-out); border-radius: var(--r-sm); }
@keyframes flash { 0%, 30% { background-color: var(--accent-subtle); box-shadow: 0 0 0 10px var(--accent-subtle); } 100% { background-color: transparent; box-shadow: 0 0 0 10px transparent; } }

.reader-end { margin-top: 64px; display: grid; gap: 10px; }
.done-card { padding: 20px; border-radius: var(--r-md); background: var(--surface); }
.done-card p { margin: 0 0 14px; color: var(--fg-secondary); font-size: 15px; }
.done-btn .i { width: 18px; height: 18px; }
.done-btn[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.done-btn .check { stroke-dasharray: 24; stroke-dashoffset: 24; transition: stroke-dashoffset 400ms var(--ease-out) 80ms; }
.done-btn[aria-pressed="true"] .check { stroke-dashoffset: 0; }
.next-card { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-radius: var(--r-md); background: var(--surface); text-decoration: none; transition: background-color 150ms ease, transform 140ms var(--ease-out); }
.next-card:active { transform: scale(0.98); }
@media (hover: hover) and (pointer: fine) { .next-card:hover { background: var(--surface-hover); } }
.next-card .row-m { margin: 0 0 2px; }

.to-top {
  position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px); z-index: 35;
  width: 48px; height: 48px; border-radius: var(--r-full); display: grid; place-items: center;
  background: var(--raised); color: var(--fg); box-shadow: var(--sh-2);
  opacity: 0; transform: translateY(12px) scale(0.9); pointer-events: none;
  transition: opacity 250ms var(--ease-out), transform 250ms var(--ease-out), bottom 350ms var(--ease-drawer);
}
.to-top.show { opacity: 1; transform: none; pointer-events: auto; }
.to-top:active { transform: scale(0.92); }
body[data-tabs-hidden] .to-top { bottom: calc(env(safe-area-inset-bottom) + 16px); }

/* paper view */
.paper-group { margin-top: 48px; }
.paper-group > h2 { font-size: 21px; font-weight: 550; margin: 0 0 2px; }
.paper-meta { color: var(--fg-muted); font-size: 14px; margin: 0; }
.unit-tag { font-size: 13px; color: var(--accent); text-decoration: underline; text-decoration-color: var(--accent-line); text-underline-offset: 3px; padding: 4px 0; }

/* ---------- sheet ---------- */
.sheet-layer { position: fixed; inset: 0; z-index: 60; }
.sheet-layer[hidden] { display: none; }
.scrim { position: absolute; inset: 0; background: var(--scrim); opacity: 0; transition: opacity 500ms var(--ease-drawer); }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 600px; max-height: min(86svh, 760px);
  display: flex; flex-direction: column; border-radius: var(--r-lg) var(--r-lg) 0 0; box-shadow: var(--sh-3);
  transform: translate3d(0, 100%, 0); transition: transform 500ms var(--ease-drawer); will-change: transform; outline: none;
}
.raised { background: var(--raised); --fill: var(--n5); --fill-hover: var(--n6); --fill-active: var(--n7); --line-subtle: var(--n5); --line: var(--n6); }
.sheet-layer.open .scrim { opacity: 1; }
.sheet-layer.open .sheet { transform: translate3d(0, 0, 0); }
.sheet-grab { flex: none; height: 28px; display: grid; place-items: center; cursor: grab; touch-action: none; }
.sheet-grab span { width: 36px; height: 5px; border-radius: var(--r-full); background: var(--n7); }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 0 20px max(24px, env(safe-area-inset-bottom)); }
.sheet-h { font-size: 19px; font-weight: 550; margin: 4px 0 4px; letter-spacing: -0.01em; }
.sheet-sub { margin: 0 0 12px; font-size: 14px; color: var(--fg-muted); }
.sheet .rows > li + li { border-top-color: var(--line-subtle); }
.toc-row { min-height: 48px; padding: 10px 12px; }
.toc-row .row-t { font-size: 15px; font-weight: 400; color: var(--fg-secondary); }
.toc-row.sub .row-t { padding-left: 14px; }
.toc-row[aria-current="true"] { background: var(--accent-subtle); }
.toc-row[aria-current="true"] .row-t { color: var(--accent); font-weight: 500; }

.toc-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.toc-head > div { display: flex; gap: 4px; }
.toc-head .icon-btn { width: 40px; height: 40px; background: var(--fill); color: var(--fg); }
.toc-head .icon-btn[aria-disabled="true"] { color: var(--fg-disabled); background: none; pointer-events: none; }
.toc-tabs { margin: 8px 0 8px; }
.toc-row .chip { margin-left: 8px; }
.toc-n { color: var(--fg-muted); font-variant-numeric: tabular-nums; min-width: 1.8em; display: inline-block; }
[data-pane][hidden] { display: none; }
.toc-row[aria-current="true"] .toc-n { color: var(--accent); }
.kbd-list { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; align-items: baseline; font-size: 14px; color: var(--fg-secondary); margin: 0; }
.kbd-list dt { white-space: nowrap; }
kbd { display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 6px; border-radius: var(--r-xs); background: var(--fill); color: var(--fg); font-size: 12.5px; }

/* settings rows, switch, segmented */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; padding: 10px 0; }
.set-row + .set-row { border-top: 1px solid var(--line-subtle); }
.set-l { font-size: 16px; }
.set-d { font-size: 13px; color: var(--fg-muted); margin-top: 2px; text-wrap: pretty; }
.switch { position: relative; width: 52px; height: 32px; flex: none; border-radius: var(--r-full); background: var(--fill-active); transition: background-color 250ms ease; }
.switch::after { content: ""; position: absolute; inset: -6px; }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: var(--r-full); background: var(--fg); box-shadow: 0 1px 3px rgb(0 0 0 / .4); transition: transform 350ms var(--ease-drawer), width 200ms var(--ease-out), background-color 250ms ease; }
.switch:active .knob { width: 32px; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"] .knob { transform: translateX(20px); background: var(--on-accent); }
.switch[aria-checked="true"]:active .knob { transform: translateX(14px); }
.seg { position: relative; display: inline-flex; padding: 4px; border-radius: var(--r-full); background: var(--fill); isolation: isolate; }
.seg button { position: relative; height: 36px; min-width: 44px; padding: 0 12px; border-radius: var(--r-full); font-size: 14px; font-weight: 510; color: var(--fg-muted); transition: color 200ms ease; font-variant-numeric: tabular-nums; }
.seg button[aria-checked="true"] { color: var(--fg); }
.seg-pill { position: absolute; z-index: -1; top: 4px; left: 0; height: 36px; border-radius: var(--r-full); background: var(--fill-active); transition: transform 400ms var(--ease-drawer), width 400ms var(--ease-drawer); }
.preview { margin-top: 12px; padding: 14px 16px; border-radius: var(--r-md); background: var(--surface); font-size: var(--read-size); line-height: 1.65; color: var(--fg-secondary); transition: font-size 250ms var(--ease-out); }

/* ---------- toasts ---------- */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 12px); z-index: 70; display: grid; justify-items: center; gap: 8px; padding: 0 16px; pointer-events: none; transition: bottom 350ms var(--ease-drawer); }
body[data-tabs-hidden] .toasts { bottom: calc(env(safe-area-inset-bottom) + 16px); }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 12px; min-height: 48px; max-width: 440px; width: 100%; padding: 8px 8px 8px 16px;
  border-radius: var(--r-md); font-size: 14px; box-shadow: var(--sh-3);
  transition: transform 400ms var(--ease-drawer), opacity 300ms ease;
}
.toast-t { flex: 1; }
.toast .btn { height: 36px; padding: 0 12px; font-size: 14px; color: var(--accent); background: transparent; }
.toast.out { opacity: 0; transform: translateY(16px) scale(0.98); }

/* ---------- search ---------- */
.search-box { position: sticky; top: calc(var(--bar-h) + env(safe-area-inset-top)); z-index: 5; background: var(--bg); padding: 4px 0 12px; margin-top: 4px; }
.field { position: relative; display: flex; align-items: center; }
.field > .i { position: absolute; left: 14px; width: 20px; height: 20px; color: var(--fg-muted); pointer-events: none; }
.field input {
  width: 100%; height: 50px; padding: 0 48px 0 44px; border: 0; border-radius: var(--r-md); background: var(--fill); color: var(--fg); font-size: 16px;
  transition: background-color 150ms ease;
}
.field input::placeholder { color: var(--fg-muted); }
.field input:focus { background: var(--fill-hover); }
.field input::-webkit-search-cancel-button { display: none; }
.field .icon-btn { position: absolute; right: 3px; transform: scale(0.9); opacity: 0; pointer-events: none; transition: opacity 150ms ease, transform 200ms var(--ease-out); }
.field.has .icon-btn { opacity: 1; transform: none; pointer-events: auto; }
.pills { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 12px calc(-1 * var(--gutter)) 0; padding: 0 var(--gutter); scroll-padding: 0 var(--gutter); }
.pills::-webkit-scrollbar { display: none; }
.pill { flex: none; height: 36px; padding: 0 14px; border-radius: var(--r-full); background: var(--fill); color: var(--fg-secondary); font-size: 14px; font-weight: 510; transition: background-color 200ms ease, color 200ms ease, transform 140ms var(--ease-out); }
.pill:active { transform: scale(0.95); }
.pill[aria-pressed="true"] { background: var(--accent-subtle); color: var(--accent); }
@media (hover: hover) and (pointer: fine) { .pill:hover { background: var(--fill-hover); } .pill[aria-pressed="true"]:hover { background: var(--accent-subtle); } }
.result-count { font-size: 13px; color: var(--fg-muted); margin: 8px 0 4px; }
.empty { padding: 32px 0; color: var(--fg-muted); font-size: 15px; }
.empty-t { color: var(--fg); font-size: 17px; font-weight: 550; margin: 0 0 4px; }
.empty p { margin: 0; max-width: 44ch; text-wrap: pretty; }
.empty .btn-row { margin-top: 16px; }
.suggest { display: flex; flex-wrap: wrap; gap: 8px; }

/* saved: rows collapse on remove */
.saved-li { display: grid; grid-template-rows: 1fr; transition: grid-template-rows 300ms var(--ease-out), opacity 200ms ease; }
.saved-li > div { min-height: 0; overflow: hidden; }
.saved-li.gone { grid-template-rows: 0fr; opacity: 0; }
.saved-row { display: flex; align-items: center; gap: 4px; }
.saved-row .row { flex: 1; min-width: 0; margin-right: 0; }

/* ---------- practice (quiz) ---------- */
.practice { max-width: 640px; margin: 0 auto; padding: 0 var(--gutter); min-height: calc(100svh - var(--bar-h) - env(safe-area-inset-top)); display: flex; flex-direction: column; }
.p-progress { display: flex; align-items: center; gap: 12px; padding: 4px 0 8px; }
.p-progress .bar { flex: 1; height: 6px; }
.p-progress .bar span { transition: transform 600ms var(--ease-drawer); }
.p-count { font-size: 13px; color: var(--fg-muted); font-variant-numeric: tabular-nums; min-width: 4.5em; text-align: right; }
.p-score { font-size: 13px; color: var(--fg-muted); }
.qstage { position: relative; flex: 1; padding-top: 16px; }
.qcard { padding-bottom: 24px; }
.qcard .q-prompt { font-size: 19px; font-weight: 500; line-height: 1.45; margin: 0; letter-spacing: -0.005em; }
.qsrc { font-size: 13px; color: var(--fg-muted); margin-bottom: 8px; }
.qopts { list-style: none; margin: 20px 0 0; padding: 0; display: grid; gap: 8px; }
.qopt {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 12px 14px; text-align: left; border-radius: var(--r-md);
  background: var(--fill); font-size: 16px; line-height: 1.4;
  transition: background-color 200ms ease, color 200ms ease, transform 140ms var(--ease-out);
}
.qopt:active:not(:disabled) { transform: scale(0.98); }
@media (hover: hover) and (pointer: fine) { .qopt:hover:not(:disabled) { background: var(--fill-hover); } }
.qopt-k { flex: none; width: 30px; height: 30px; border-radius: var(--r-sm); display: grid; place-items: center; background: var(--fill-active); font-size: 14px; font-weight: 550; transition: background-color 200ms ease, color 200ms ease; }
.qopt-k .i { width: 18px; height: 18px; stroke-width: 2.25; }
.qopt-t { flex: 1; min-width: 0; }
.qopt:disabled { cursor: default; color: var(--fg-muted); }
.qopt.ok { background: var(--ok-subtle); color: var(--fg); }
.qopt.ok .qopt-k { background: var(--ok); color: var(--on-accent); }
.qopt.bad { background: var(--danger-subtle); color: var(--fg); animation: nudge 360ms var(--ease-out); }
.qopt.bad .qopt-k { background: var(--danger); color: var(--on-accent); }
.qwhy { margin-top: 16px; padding: 14px 16px; border-radius: var(--r-md); background: var(--surface); animation: reveal 450ms var(--ease-out); }
.qwhy-h { font-size: 14px; font-weight: 550; margin-bottom: 2px; }
.qwhy-h.ok { color: var(--ok); } .qwhy-h.bad { color: var(--danger); }
.qwhy .notes p:first-child { margin-top: 0; }
.p-foot { position: sticky; bottom: 0; padding: 12px 0 max(16px, env(safe-area-inset-bottom)); background: var(--bg); box-shadow: 0 -12px 12px -4px var(--bg); }
.result { text-align: center; padding: 32px 0 24px; }
.result .ring { width: 168px; height: 168px; }
.result .ring circle { stroke-width: 10; }
.result-ring { position: relative; width: 168px; height: 168px; margin: 0 auto; }
.result-v { position: absolute; inset: 0; display: grid; place-content: center; }
.result-v b { font-size: 44px; font-weight: 550; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; line-height: 1; }
.result-v span { font-size: 14px; color: var(--fg-muted); margin-top: 4px; }
.result h2 { font-size: 24px; font-weight: 550; letter-spacing: -0.02em; margin: 24px 0 4px; }
.result p { margin: 0 auto; color: var(--fg-secondary); max-width: 36ch; }
.result-actions { display: grid; gap: 8px; margin-top: 24px; text-align: left; }

/* ---------- flashcards ---------- */
.deck { position: relative; height: min(56svh, 460px); margin-top: 16px; perspective: 1400px; }
.fc { position: absolute; inset: 0; transition: transform 450ms var(--ease-drawer), opacity 300ms ease; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.fc[data-pos="1"] { transform: translateY(14px) scale(0.95); }
.fc[data-pos="2"] { transform: translateY(28px) scale(0.9); }
.fc[data-pos="3"] { transform: translateY(28px) scale(0.9); opacity: 0; }
.fc[data-pos="0"] { cursor: grab; z-index: 3; }
.fc[data-pos="1"] { z-index: 2; } .fc[data-pos="2"] { z-index: 1; }
.fc.dragging { transition: none; cursor: grabbing; }
.fc-inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform 650ms var(--ease-in-out); }
.fc.flipped .fc-inner { transform: rotateY(180deg); }
.fc-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: flex; flex-direction: column; padding: 24px; border-radius: var(--r-lg); background: var(--surface); overflow: hidden;
}
.fc[data-pos="1"] .fc-face, .fc[data-pos="2"] .fc-face { background: var(--n4); }
.fc[data-pos="2"] .fc-face { background: var(--n5); }
.fc-back { transform: rotateY(180deg); background: var(--accent-subtle) !important; }
.fc-kind { font-size: 13px; color: var(--fg-muted); }
.fc-back .fc-kind { color: var(--accent); }
.fc-main { flex: 1; display: flex; flex-direction: column; justify-content: center; min-height: 0; overflow-y: auto; }
.fc-front .fc-main { font-size: 26px; font-weight: 550; letter-spacing: -0.02em; line-height: 1.2; text-wrap: balance; }
.fc-back .fc-main { font-size: 17px; line-height: 1.55; }
.fc-back .fc-main .katex-display { margin: 4px 0; overflow-x: auto; overflow-y: hidden; }
.fc-hint { font-size: 13px; color: var(--fg-muted); text-align: center; }
.fc-stamp { position: absolute; top: 20px; padding: 6px 12px; border-radius: var(--r-sm); font-size: 15px; font-weight: 550; opacity: 0; pointer-events: none; z-index: 2; }
.fc-stamp.know { right: 20px; background: var(--ok); color: var(--on-accent); }
.fc-stamp.learn { left: 20px; background: var(--fg); color: var(--bg); }
.deck-actions { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; margin-top: 44px; }
.deck-actions .icon-btn { width: 52px; height: 52px; background: var(--fill); color: var(--fg); border-radius: var(--r-full); }
.deck-actions .btn { height: 52px; }

/* ---------- footer ---------- */
.site-foot { max-width: 720px; margin: 16px auto 0; padding: 0 var(--gutter) 32px; color: var(--fg-muted); font-size: 14px; }
.site-foot.wide { max-width: 1040px; }
.chunking ~ .site-foot, .view:has(.chunking) .site-foot { visibility: hidden; }
.foot-main { display: grid; grid-template-columns: 1fr 1fr; gap: 32px 24px; padding-top: 32px; border-top: 1px solid var(--line-subtle); }
.foot-brand { grid-column: 1 / -1; }
.foot-name { display: inline-flex; align-items: center; gap: 10px; color: var(--fg); font-size: 16px; font-weight: 550; letter-spacing: -0.01em; text-decoration: none; }
.foot-name .logo { height: 24px; }
.foot-brand p { margin: 12px 0 0; max-width: 36ch; line-height: 1.55; text-wrap: pretty; }
.foot-col h2 { margin: 0 0 10px; font-size: 13px; font-weight: 500; color: var(--fg); }
.foot-col ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.foot-col a, .foot-col button { display: inline-flex; align-items: center; min-height: 32px; color: var(--fg-muted); text-decoration: none; font-size: 14px; transition: color 150ms ease; }
/* subject links take their own ink on hover; the app links go to full ink */
@media (hover: hover) and (pointer: fine) {
  .foot-col a:hover { color: var(--accent); }
  .foot-col[aria-label="App"] a:hover, .foot-col button:hover { color: var(--fg); }
}
.foot-base { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 24px; margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--line-subtle); font-size: 12.5px; line-height: 1.5; }
.foot-base span:last-child { max-width: 52ch; }
@media (min-width: 720px) {
  .foot-main { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr); }
  .foot-brand { grid-column: auto; }
}

/* ---------- staged entrance ---------- */
.enter { animation: enter 560ms var(--ease-expo) both; animation-delay: calc(var(--i, 0) * 45ms); }
@keyframes enter { from { opacity: 0; transform: translateY(14px); filter: blur(4px); } }

/* ---------- view transitions ---------- */
::view-transition-group(*) { animation-duration: 480ms; animation-timing-function: var(--ease-drawer); }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 380ms; animation-timing-function: var(--ease-out); }
html[data-nav="fwd"]::view-transition-old(root) { animation-name: vt-out-l; }
html[data-nav="fwd"]::view-transition-new(root) { animation-name: vt-in-r; }
html[data-nav="back"]::view-transition-old(root) { animation-name: vt-out-r; }
html[data-nav="back"]::view-transition-new(root) { animation-name: vt-in-l; }
html[data-nav="tab"]::view-transition-old(root) { animation: vt-fade-out 180ms ease both; }
html[data-nav="tab"]::view-transition-new(root) { animation: vt-rise 420ms var(--ease-out) both; }
html[data-nav="up"]::view-transition-old(root) { animation: vt-fade-out 200ms ease both; }
html[data-nav="up"]::view-transition-new(root) { animation: vt-up 480ms var(--ease-drawer) both; }
html[data-nav="down"]::view-transition-old(root) { animation: vt-down 320ms var(--ease-out) both; }
html[data-nav="down"]::view-transition-new(root) { animation: vt-fade-in 300ms ease both; }
::view-transition-old(appbar), ::view-transition-new(appbar) { animation-duration: 260ms; }
/* the tab bar and rail stay live during a route change, so their own motion (the sliding highlight) is what shows */
::view-transition-group(tabbar) { animation: none; }
::view-transition-old(tabbar) { display: none; }
::view-transition-new(tabbar) { animation: none; }
@keyframes vt-out-l { to { opacity: 0; transform: translateX(-48px); } }
@keyframes vt-in-r { from { opacity: 0; transform: translateX(64px); } }
@keyframes vt-out-r { to { opacity: 0; transform: translateX(64px); } }
@keyframes vt-in-l { from { opacity: 0; transform: translateX(-48px); } }
@keyframes vt-fade-out { to { opacity: 0; } }
@keyframes vt-fade-in { from { opacity: 0; } }
@keyframes vt-rise { from { opacity: 0; transform: translateY(10px); filter: blur(3px); } }
@keyframes vt-up { from { opacity: 0; transform: translateY(48px) scale(0.98); } }
@keyframes vt-down { to { opacity: 0; transform: translateY(48px) scale(0.98); } }
/* fallback push when the View Transitions API is missing */
.nav-fwd { animation: vt-in-r 380ms var(--ease-out) both; }
.nav-back { animation: vt-in-l 380ms var(--ease-out) both; }
.nav-tab { animation: vt-rise 420ms var(--ease-out) both; }
.nav-up { animation: vt-up 480ms var(--ease-drawer) both; }
.nav-down { animation: vt-fade-in 300ms ease both; }

/* ---------- desktop: the tab bar becomes a rail ---------- */
@media (min-width: 1024px) {
  body { padding-bottom: 0; padding-left: var(--rail-w); }
  .tabbar { top: 0; right: auto; width: var(--rail-w); padding: 20px 12px; background: var(--bg); box-shadow: 1px 0 0 var(--line-subtle); display: flex; flex-direction: column; overflow-y: auto; }
  .tabbar[data-hidden], .tabbar[data-gone] { transform: none; visibility: visible; }
  .rail-brand { display: flex; align-items: center; gap: 10px; padding: 4px 12px 20px; font-size: 16px; font-weight: 550; letter-spacing: -0.01em; text-decoration: none; }
  .rail-brand .logo { height: 24px; }
  .tabs { display: flex; flex-direction: column; height: auto; gap: 2px; margin: 0; max-width: none; }
  .tab { flex-direction: row; justify-content: flex-start; gap: 12px; height: 40px; padding: 0 12px; font-size: 14px; border-radius: var(--r-sm); }
  .tab .i { width: 20px; height: 20px; }
  .tab-pill { top: 0; height: 40px; border-radius: var(--r-sm); background: var(--fill); }
  @media (hover: hover) { .tab:hover { color: var(--fg); } }
  .subj-switch { display: none; }
  /* subject tree: each subject expands to its units */
  .rail-subjects { display: grid; gap: 2px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line-subtle); }
  .rail-h { padding: 0 12px 6px; font-size: 13px; color: var(--fg-muted); }
  .rail-row { display: flex; align-items: center; gap: 2px; }
  .rail-subj { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 36px; padding: 0 10px 0 12px; border-radius: var(--r-sm); text-decoration: none; font-size: 14px; color: var(--fg-secondary); transition: background-color 150ms ease, color 150ms ease; }
  .rail-subj .rail-count { font-size: 12px; color: var(--accent); font-variant-numeric: tabular-nums; }
  .rail-subj:hover { background: var(--fill); color: var(--fg); }
  .rail-subj[data-in="true"] { color: var(--fg); }
  .rail-subj[aria-current="true"] { background: var(--accent-subtle); color: var(--accent); }
  .rail-tog { width: 32px; height: 32px; flex: none; display: grid; place-items: center; border-radius: var(--r-sm); color: var(--fg-muted); transition: background-color 150ms ease, color 150ms ease; }
  .rail-tog:hover { background: var(--fill); color: var(--fg); }
  .rail-tog .i { width: 16px; height: 16px; transition: transform 300ms var(--ease-out); }
  .rail-group.open .rail-tog .i { transform: rotate(90deg); }
  .rail-units { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 300ms var(--ease-out); }
  .rail-units > div { min-height: 0; overflow: hidden; }
  .rail-group.open .rail-units { grid-template-rows: 1fr; }
  .rail-units ul { list-style: none; margin: 2px 0 8px; padding: 0 0 0 8px; opacity: 0; transform: translateY(-4px); transition: opacity 250ms ease, transform 300ms var(--ease-out); }
  .rail-group.open .rail-units ul { opacity: 1; transform: none; }
  .rail-unit { display: flex; align-items: baseline; gap: 8px; padding: 6px 10px; border-radius: var(--r-sm); text-decoration: none; font-size: 13.5px; line-height: 1.35; color: var(--fg-muted); transition: background-color 150ms ease, color 150ms ease; }
  .rail-unit:hover { background: var(--fill); color: var(--fg); }
  .rail-unit .ru-n { flex: none; min-width: 1.5em; font-variant-numeric: tabular-nums; color: var(--fg-disabled); }
  .rail-unit .ru-t { flex: 1; min-width: 0; }
  .rail-unit .ru-done { flex: none; font-size: 12px; color: var(--accent); }
  .rail-unit[aria-current="true"] { background: var(--accent-subtle); color: var(--fg); }
  .rail-unit[aria-current="true"] .ru-n { color: var(--accent); }
  .rail-unit .katex { font-size: 1em; }
  .to-top, body[data-tabs-hidden] .to-top { bottom: 24px; }
  .tabbar { scrollbar-width: thin; scrollbar-color: var(--n6) transparent; }
  .toasts, body[data-tabs-hidden] .toasts { bottom: 24px; padding-left: var(--rail-w); }
  .subjects { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  /* breadcrumbs replace the scrolling title */
  .appbar[data-crumbs] .appbar-title { display: none; }
  .crumbs { display: flex; align-items: center; gap: 4px; min-width: 0; padding: 0 4px; font-size: 14px; white-space: nowrap; }
  .crumbs a { color: var(--fg-muted); text-decoration: none; padding: 6px 6px; border-radius: var(--r-xs); transition: color 150ms ease, background-color 150ms ease; flex: none; }
  .crumbs a:hover { color: var(--fg); background: var(--fill); }
  .crumbs span { color: var(--fg); font-weight: 500; padding: 6px; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .crumbs .i { width: 14px; height: 14px; color: var(--fg-disabled); }
  .appbar-in { max-width: none; padding: 0 16px; }
  /* home: two columns */
  .screen.wide { max-width: 1040px; }
  .home { display: grid; grid-template-columns: minmax(0, 1fr) 340px; column-gap: 40px; grid-template-areas: "title title" "sub sub" "cont prog" "subj subj" "pap pap"; align-items: start; }
  .home.no-cont { grid-template-areas: "title title" "sub sub" "prog prog" "subj subj" "pap pap"; }
  .home > .screen-title { grid-area: title; }
  .home > .screen-sub { grid-area: sub; }
  .home .g-cont { grid-area: cont; } .home .g-prog { grid-area: prog; } .home .g-subj { grid-area: subj; } .home .g-pap { grid-area: pap; }
  .home .g-prog .totals { margin-top: 0; }
  .home .g-prog .total { padding: 8px 0; }
  .rows.cols2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 32px; }
  .rows.cols2 > li { border-top: 1px solid var(--line-subtle); }
  .sheet { bottom: 24px; border-radius: var(--r-lg); max-height: min(80svh, 720px); }
  .screen-title { font-size: 40px; }
  .appbar-in { max-width: 760px; }
}
/* topics of the open unit, on screens wide enough for a third column */
@media (min-width: 1200px) {
  body[data-toc] { padding-right: var(--toc-w); }
  body[data-toc] .to-top { right: calc(var(--toc-w) + 16px); }
  body[data-toc] .appbar [data-act="toc"] { display: none; }
  .toc-rail:not([hidden]) {
    display: flex; flex-direction: column; position: fixed; top: 0; right: 0; bottom: 0; width: var(--toc-w); z-index: 20;
    padding: 72px 16px 24px 12px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--n6) transparent;
  }
  .toc-h { font-size: 13px; font-weight: 500; color: var(--fg-muted); margin: 0 0 2px 10px; }
  .toc-pct { font-size: 12px; color: var(--fg-muted); margin: 0 0 10px 10px; font-variant-numeric: tabular-nums; }
  .toc-list { list-style: none; margin: 0; padding: 0; }
  .toc-ind { position: absolute; z-index: -1; left: 0; right: 0; top: 0; height: 0; border-radius: var(--r-sm); background: var(--accent-subtle); transition: transform 350ms var(--ease-drawer), height 350ms var(--ease-drawer), opacity 200ms ease; pointer-events: none; }
  .toc-a { display: block; padding: 5px 10px; border-radius: var(--r-sm); font-size: 13.5px; line-height: 1.4; color: var(--fg-muted); text-decoration: none; transition: color 200ms ease; }
  .toc-a.sub { padding-left: 20px; }
  .toc-a:hover { color: var(--fg); }
  .toc-a[aria-current="true"] { color: var(--accent); }
  .toc-a .katex { font-size: 1em; }
  .toc-more { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line-subtle); display: grid; gap: 6px; }
  .toc-more .btn { justify-content: flex-start; height: 38px; font-size: 14px; }
  .toc-nav { display: grid; gap: 2px; margin-top: 8px; }
  .toc-nav a { display: block; padding: 8px 10px; border-radius: var(--r-sm); text-decoration: none; font-size: 13.5px; line-height: 1.35; transition: background-color 150ms ease; }
  .toc-nav a:hover { background: var(--fill); }
  .toc-nav small { display: block; font-size: 12px; color: var(--fg-muted); }
}
@media (min-width: 640px) and (max-width: 1023px) {
  .subjects { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 359px) {
  .subj { min-height: 136px; padding: 14px; }
  .subj-name { font-size: 16px; }
  .screen-title { font-size: 30px; }
}

/* ---------- reduced motion: keep fades, drop travel ---------- */
@media (prefers-reduced-motion: reduce) {
  :root { transition: none; }
  .enter { animation-name: vt-fade-in; animation-duration: 200ms; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation-duration: 150ms !important; }
  html[data-nav]::view-transition-old(root) { animation: vt-fade-out 150ms ease both !important; }
  html[data-nav]::view-transition-new(root) { animation: vt-fade-in 150ms ease both !important; }
  .fc-inner { transition-duration: 1ms; }
  .opt.picked-bad, .qopt.bad { animation: none; }
}
:root[data-reduce] { transition: none; }
:root[data-reduce] .enter { animation-name: vt-fade-in; animation-duration: 200ms; }
:root[data-reduce] .fc-inner { transition-duration: 1ms; }
:root[data-reduce] .opt.picked-bad, :root[data-reduce] .qopt.bad { animation: none; }
:root[data-reduce]::view-transition-group(*) { animation-duration: 1ms !important; }
:root[data-reduce][data-nav]::view-transition-old(root) { animation: vt-fade-out 150ms ease both !important; }
:root[data-reduce][data-nav]::view-transition-new(root) { animation: vt-fade-in 150ms ease both !important; }
