/* A-level Coach — design system (subject-neutral)
 * Ported from Cube Coach. Calm paper-like surfaces, one confident accent (ink blue), and a fixed
 * rating scale used everywhere: none (grey) · taught (outline) · learning (red) · building (amber)
 * · secure (teal) · exam-ready (green). Green means earned: only Exam-ready is green, so Secure is
 * teal, and nothing else uses green fills.
 * Light by default; dark via prefers-color-scheme, overridable with <html data-theme="light|dark">.
 * Phone first: 360–430px is the primary target, tap targets are at least 44px.
 */

/* ================================================================ tokens */
:root {
  color-scheme: light;

  /* surfaces & text */
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f1efea;
  --surface-3: #e6e3dc;
  --border: #e3e0d8;
  --border-strong: #cbc7bc;
  --text: #1b1e26;
  --text-2: #4b5060;
  --text-3: #5d6270;

  /* accent: ink blue */
  --accent: #3347b8;
  --accent-hover: #2a3c9f;
  --accent-active: #233285;
  --accent-soft: #eaedfb;
  --accent-soft-2: #d4daf6;
  --accent-text: #2c3ea6;
  --on-accent: #ffffff;

  /* status */
  --success: #1d7f45;  --success-soft: #e3f3e9;  --success-border: #b2dbc0;  --success-text: #156535;
  --warn: #a35f00;     --warn-soft: #fff3dc;     --warn-border: #f0d199;     --warn-text: #7f4a00;
  --danger: #c0262d;   --danger-soft: #fdecec;   --danger-border: #f1bfbd;   --danger-text: #a01f25;
  --info: #1d6a86;     --info-soft: #e7f2f6;     --info-border: #bcdbe6;     --info-text: #155873;
  --on-danger: #ffffff;

  /* the rating scale (pills, map tiles, strand bars, meters) */
  --r-none: #c9c6bd;     --r-none-bg: #f1efea;     --r-none-text: #5c6170;     --r-none-border: #dedad1;
  --r-taught: #7a7f8d;   --r-taught-bg: transparent; --r-taught-text: #4b5060; --r-taught-border: #9a9eaa;
  --r-learning: #d2463c; --r-learning-bg: #fcebe8; --r-learning-text: #a3302a; --r-learning-border: #f2c3bd;
  --r-building: #e19a1b; --r-building-bg: #fdf2dc; --r-building-text: #85520a; --r-building-border: #f1d49b;
  --r-secure: #2a9fb0;   --r-secure-bg: #e3f3f6;   --r-secure-text: #17697a;   --r-secure-border: #afdbe4;
  --r-ready: #1b7f45;    --r-ready-bg: #1b7f45;    --r-ready-text: #ffffff;    --r-ready-border: #1b7f45;
  --r-ready-soft: #e3f3e9; --r-ready-soft-border: #b2dbc0;   /* a light green tint for green (Exam-ready) surfaces */

  --toast-bg: #1b1e26;
  --toast-fg: #f2f3f6;
  --backdrop: rgba(14, 16, 22, 0.5);
  --topbar-bg: rgba(246, 245, 241, 0.88);

  --shadow-1: 0 1px 2px rgba(20, 22, 30, 0.05), 0 1px 3px rgba(20, 22, 30, 0.06);
  --shadow-2: 0 2px 4px rgba(20, 22, 30, 0.04), 0 8px 22px rgba(20, 22, 30, 0.08);
  --shadow-3: 0 18px 40px rgba(20, 22, 30, 0.18), 0 4px 12px rgba(20, 22, 30, 0.08);
  --ring: 0 0 0 3px rgba(51, 71, 184, 0.26);
  /* answer choices (sort categories, options): a raised fill and a visible edge, so they read as tappable */
  --choice-bg: var(--surface);
  --choice-border: var(--border-strong);
  --choice-edge: var(--border);

  /* shape, space, type, motion */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --radius-pill: 999px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-read: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;
  --container: 1080px;
  --gutter: 16px;
  --topbar-h: 60px;
  --bottomnav-h: 0px;
  --tap: 44px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --dur-1: 120ms;
  --dur-2: 200ms;
  --dur-3: 320ms;

  accent-color: var(--accent);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111317;
    --surface: #181b21;
    --surface-2: #1e222a;
    --surface-3: #282d36;
    --border: #272c35;
    --border-strong: #3a404c;
    --text: #e9ebf0;
    --text-2: #b4b9c5;
    --text-3: #9399a7;
    --accent: #8b9cff;
    --accent-hover: #a2b0ff;
    --accent-active: #b6c1ff;
    --accent-soft: rgba(139, 156, 255, 0.14);
    --accent-soft-2: rgba(139, 156, 255, 0.28);
    --accent-text: #a9b6ff;
    --on-accent: #10153a;
    --success: #45cf80;  --success-soft: rgba(69, 207, 128, 0.12);  --success-border: rgba(69, 207, 128, 0.36);  --success-text: #6fdc9c;
    --warn: #f2b04a;     --warn-soft: rgba(242, 176, 74, 0.12);     --warn-border: rgba(242, 176, 74, 0.36);     --warn-text: #f5c26f;
    --danger: #ff6b6b;   --danger-soft: rgba(255, 107, 107, 0.12);  --danger-border: rgba(255, 107, 107, 0.4);   --danger-text: #ff8e8e;
    --info: #5fb8d6;     --info-soft: rgba(95, 184, 214, 0.12);     --info-border: rgba(95, 184, 214, 0.36);     --info-text: #8acde3;
    --on-danger: #2a0507;
    --r-none: #4a505c;     --r-none-bg: #20242b;     --r-none-text: #a6acb8;     --r-none-border: #2f343d;
    --r-taught: #8c92a0;   --r-taught-bg: transparent; --r-taught-text: #c0c5cf; --r-taught-border: #6c7280;
    --r-learning: #f0776d; --r-learning-bg: rgba(240, 119, 109, 0.14); --r-learning-text: #ff9d94; --r-learning-border: rgba(240, 119, 109, 0.42);
    --r-building: #f2b04a; --r-building-bg: rgba(242, 176, 74, 0.14);  --r-building-text: #f6c46f; --r-building-border: rgba(242, 176, 74, 0.42);
    --r-secure: #4ec3d4;   --r-secure-bg: rgba(78, 195, 212, 0.14);   --r-secure-text: #86d9e5;   --r-secure-border: rgba(78, 195, 212, 0.42);
    --r-ready: #3fbf74;    --r-ready-bg: #3fbf74;    --r-ready-text: #04220f;    --r-ready-border: #3fbf74;
    --r-ready-soft: rgba(63, 191, 116, 0.12); --r-ready-soft-border: rgba(63, 191, 116, 0.36);
    --toast-bg: #e9ebf0;
    --toast-fg: #14171c;
    --backdrop: rgba(0, 0, 0, 0.62);
    --topbar-bg: rgba(17, 19, 23, 0.86);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-2: 0 2px 4px rgba(0, 0, 0, 0.3), 0 8px 22px rgba(0, 0, 0, 0.32);
    --shadow-3: 0 18px 44px rgba(0, 0, 0, 0.6), 0 4px 12px rgba(0, 0, 0, 0.4);
    --ring: 0 0 0 3px rgba(139, 156, 255, 0.38);
    --choice-bg: #222731;
    --choice-border: #5d6575;
    --choice-edge: #3a404c;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111317;
  --surface: #181b21;
  --surface-2: #1e222a;
  --surface-3: #282d36;
  --border: #272c35;
  --border-strong: #3a404c;
  --text: #e9ebf0;
  --text-2: #b4b9c5;
  --text-3: #9399a7;
  --accent: #8b9cff;
  --accent-hover: #a2b0ff;
  --accent-active: #b6c1ff;
  --accent-soft: rgba(139, 156, 255, 0.14);
  --accent-soft-2: rgba(139, 156, 255, 0.28);
  --accent-text: #a9b6ff;
  --on-accent: #10153a;
  --success: #45cf80;  --success-soft: rgba(69, 207, 128, 0.12);  --success-border: rgba(69, 207, 128, 0.36);  --success-text: #6fdc9c;
  --warn: #f2b04a;     --warn-soft: rgba(242, 176, 74, 0.12);     --warn-border: rgba(242, 176, 74, 0.36);     --warn-text: #f5c26f;
  --danger: #ff6b6b;   --danger-soft: rgba(255, 107, 107, 0.12);  --danger-border: rgba(255, 107, 107, 0.4);   --danger-text: #ff8e8e;
  --info: #5fb8d6;     --info-soft: rgba(95, 184, 214, 0.12);     --info-border: rgba(95, 184, 214, 0.36);     --info-text: #8acde3;
  --on-danger: #2a0507;
  --r-none: #4a505c;     --r-none-bg: #20242b;     --r-none-text: #a6acb8;     --r-none-border: #2f343d;
  --r-taught: #8c92a0;   --r-taught-bg: transparent; --r-taught-text: #c0c5cf; --r-taught-border: #6c7280;
  --r-learning: #f0776d; --r-learning-bg: rgba(240, 119, 109, 0.14); --r-learning-text: #ff9d94; --r-learning-border: rgba(240, 119, 109, 0.42);
  --r-building: #f2b04a; --r-building-bg: rgba(242, 176, 74, 0.14);  --r-building-text: #f6c46f; --r-building-border: rgba(242, 176, 74, 0.42);
  --r-secure: #4ec3d4;   --r-secure-bg: rgba(78, 195, 212, 0.14);   --r-secure-text: #86d9e5;   --r-secure-border: rgba(78, 195, 212, 0.42);
  --r-ready: #3fbf74;    --r-ready-bg: #3fbf74;    --r-ready-text: #04220f;    --r-ready-border: #3fbf74;
  --r-ready-soft: rgba(63, 191, 116, 0.12); --r-ready-soft-border: rgba(63, 191, 116, 0.36);
  --toast-bg: #e9ebf0;
  --toast-fg: #14171c;
  --backdrop: rgba(0, 0, 0, 0.62);
  --topbar-bg: rgba(17, 19, 23, 0.86);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-2: 0 2px 4px rgba(0, 0, 0, 0.3), 0 8px 22px rgba(0, 0, 0, 0.32);
  --shadow-3: 0 18px 44px rgba(0, 0, 0, 0.6), 0 4px 12px rgba(0, 0, 0, 0.4);
  --ring: 0 0 0 3px rgba(139, 156, 255, 0.38);
  --choice-bg: #222731;
  --choice-border: #5d6575;
  --choice-edge: #3a404c;
}

@media (min-width: 720px) {
  :root { --gutter: 24px; }
}

/* ================================================================ base */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  overflow-x: clip;
  padding-bottom: var(--bottomnav-h);
  -webkit-tap-highlight-color: transparent;
}

html.has-modal, html.has-modal body { overflow: hidden; }

img, svg, video, canvas { max-width: 100%; }
svg.icon { flex: none; display: inline-block; vertical-align: middle; }

h1, h2, h3, h4, .h1, .h2, .h3, .h4 {
  margin: 0 0 0.5em;
  line-height: 1.2;
  letter-spacing: -0.015em;
  font-weight: 700;
  color: var(--text);
  text-wrap: balance;
  overflow-wrap: break-word;
}
h1, .h1 { font-size: clamp(1.55rem, 1.15rem + 1.6vw, 2.2rem); letter-spacing: -0.022em; }
h2, .h2 { font-size: var(--text-xl); }
h3, .h3 { font-size: var(--text-lg); }
h4, .h4 { font-size: var(--text-md); }

p { margin: 0 0 0.75em; overflow-wrap: break-word; }
p:last-child { margin-bottom: 0; }
ul, ol { margin: 0 0 0.75em; padding-left: 1.25em; }
li + li { margin-top: 0.25em; }

a { color: var(--accent-text); text-underline-offset: 2px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }

hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-5) 0; }

code, .mono { font-family: var(--font-mono); }
code { font-size: 0.9em; background: var(--surface-2); border: 1px solid var(--border); padding: 0.05em 0.35em; border-radius: 5px; }
pre { font-family: var(--font-mono); font-size: var(--text-sm); overflow: auto; }

::selection { background: var(--accent-soft-2); }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.lead { font-size: var(--text-lg); color: var(--text-2); line-height: 1.5; }
.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.small { font-size: var(--text-sm); }
.xsmall { font-size: var(--text-xs); }
.strong { font-weight: 650; }
.eyebrow {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-text);
  margin: 0 0 var(--space-2);
}
.num, .tabular { font-variant-numeric: tabular-nums; }
.text-center { text-align: center; }
.nowrap { white-space: nowrap; }
.prose { max-width: 68ch; }
.reading { font-family: var(--font-read); font-size: 1.05rem; line-height: 1.65; }
.md { overflow-wrap: break-word; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}
.hidden, [hidden] { display: none !important; }

.skip-link {
  position: absolute;
  left: var(--space-3);
  top: -60px;
  z-index: 300;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus { top: var(--space-3); }

/* ================================================================ layout */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}
.container-narrow { max-width: 760px; }

.screen-root { display: block; padding-top: var(--space-5); padding-bottom: var(--space-8); min-height: 60vh; }
.screen-root:focus { outline: none; }
.screen { animation: screen-in var(--dur-3) var(--ease); min-width: 0; }
@keyframes screen-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.boot-loading {
  display: flex; align-items: center; justify-content: center; gap: var(--space-3);
  min-height: 40vh; color: var(--text-3);
}

.page-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: var(--space-3); margin-bottom: var(--space-5);
}
.page-head h1 { margin: 0; }
.page-head p { margin: var(--space-2) 0 0; }

/* stack = vertical rhythm; row = horizontal group (wraps by default) */
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.stack > * { margin-top: 0; margin-bottom: 0; min-width: 0; }
.stack-xs { gap: var(--space-1); }
.stack-sm { gap: var(--space-2); }
.stack-lg { gap: var(--space-5); }
.stack-xl { gap: var(--space-6); }

.row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); min-width: 0; }
.row > * { min-width: 0; }
.row-xs { gap: var(--space-1); }
.row-sm { gap: var(--space-2); }
.row-lg { gap: var(--space-5); }
.row-nowrap { flex-wrap: nowrap; }
.row-top { align-items: flex-start; }
.row-between { justify-content: space-between; }
.row-end { justify-content: flex-end; }
.row-center { justify-content: center; }
.spacer, .grow { flex: 1 1 auto; }

.grid { display: grid; gap: var(--space-4); grid-template-columns: minmax(0, 1fr); }
.grid > * { min-width: 0; }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); }
.grid-auto-sm { grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr)); }
.grid-2-phone { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 640px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 960px) {
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.span-all { grid-column: 1 / -1; }

.m-0 { margin: 0 !important; }
.mt-0 { margin-top: 0 !important; }
.mt-2 { margin-top: var(--space-2) !important; }
.mt-4 { margin-top: var(--space-4) !important; }
.mt-6 { margin-top: var(--space-6) !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-2 { margin-bottom: var(--space-2) !important; }
.mb-4 { margin-bottom: var(--space-4) !important; }
.w-full { width: 100%; }

/* ================================================================ top bar & nav */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg);
  background: var(--topbar-bg);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar__inner {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  height: var(--topbar-h);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--text);
  text-decoration: none;
  font-weight: 750;
  font-size: 1.06rem;
  letter-spacing: -0.015em;
  white-space: nowrap;
  border-radius: var(--radius-sm);
}
.brand:hover { text-decoration: none; }
.brand__mark { width: 28px; height: 28px; flex: none; display: block; }
.brand__name { overflow: hidden; text-overflow: ellipsis; }
.brand__tag {
  font-size: var(--text-xs); font-weight: 600; color: var(--text-3);
  letter-spacing: 0; padding-left: 10px; border-left: 1px solid var(--border);
  overflow: hidden; text-overflow: ellipsis;
}

.nav { margin-left: auto; display: flex; align-items: center; gap: 2px; }
.nav__link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 8px 12px;
  border-radius: 10px;
  color: var(--text-2);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.93rem;
  line-height: 1.2;
  transition: background var(--dur-1), color var(--dur-1);
}
.nav__link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav__link.is-active, .nav__link[aria-current="page"] { color: var(--accent-text); background: var(--accent-soft); }
.nav__icon { display: inline-flex; width: 18px; height: 18px; }
.nav__icon svg { width: 100%; height: 100%; }

@media (max-width: 960px) and (min-width: 721px) {
  .brand__tag { display: none; }
  .nav__link { padding: 8px 10px; }
}

/* Narrow screens: nav becomes a sticky bottom tab bar */
@media (max-width: 720px) {
  :root { --bottomnav-h: 64px; --topbar-h: 52px; }
  .topbar {
    /* backdrop-filter would trap the fixed bottom bar inside the header */
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: var(--bg);
  }
  .brand__tag { display: none; }
  .nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 60;
    margin: 0;
    justify-content: space-around;
    gap: 0;
    height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px));
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.05);
  }
  .nav__link {
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    padding: 4px 2px;
    font-size: 0.7rem;
    border-radius: 12px;
  }
  .nav__label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav__link.is-active, .nav__link[aria-current="page"] { background: transparent; }
  .nav__link.is-active .nav__icon, .nav__link[aria-current="page"] .nav__icon { background: var(--accent-soft); }
  .nav__icon { width: 48px; height: 28px; padding: 3px 0; border-radius: 999px; justify-content: center; }
  .nav__icon svg { width: 22px; height: 22px; }
  body { padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px)); }
  .screen-root { padding-top: var(--space-4); padding-bottom: var(--space-6); }
}

/* ================================================================ notices */
.notice {
  background: var(--info-soft);
  border-bottom: 1px solid var(--info-border);
  color: var(--text);
  font-size: var(--text-sm);
}
.notice--warn { background: var(--warn-soft); border-bottom-color: var(--warn-border); }
.notice__inner { display: flex; align-items: center; gap: var(--space-3); padding-block: var(--space-2); }
.notice__icon { display: inline-flex; color: var(--info-text); }
.notice--warn .notice__icon { color: var(--warn-text); }
.notice__text { flex: 1 1 auto; min-width: 0; }
.notice__close {
  flex: none; display: inline-grid; place-items: center;
  width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent;
  color: var(--text-2); cursor: pointer;
}
.notice__close:hover { background: rgba(127, 127, 127, 0.15); color: var(--text); }

/* ================================================================ buttons */
.btn {
  --btn-h: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--btn-h);
  max-width: 100%;
  padding: 6px 16px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease),
              color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease), transform var(--dur-1) var(--ease);
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); background: var(--surface-3); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn .icon { width: 18px; height: 18px; }

.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--on-accent);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { background: var(--accent-active); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-ghost:active { background: var(--surface-3); }

.btn-soft { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); }
.btn-soft:hover { background: var(--accent-soft-2); }

.btn-danger { background: var(--danger); border-color: transparent; color: var(--on-danger); }
.btn-danger:hover { background: var(--danger); filter: brightness(1.08); }
.btn-danger-ghost { background: transparent; border-color: var(--danger-border); color: var(--danger-text); }
.btn-danger-ghost:hover { background: var(--danger-soft); }

.btn-sm { --btn-h: 36px; padding: 4px 12px; font-size: var(--text-sm); border-radius: 8px; gap: 6px; }
.btn-sm .icon { width: 16px; height: 16px; }
.btn-lg { --btn-h: 52px; padding: 8px 24px; font-size: 1.05rem; border-radius: 12px; gap: 10px; }
.btn-lg .icon { width: 20px; height: 20px; }
.btn-xl { --btn-h: 64px; padding: 10px 32px; font-size: 1.2rem; border-radius: 16px; }

.btn-icon { padding: 0; width: var(--btn-h); flex: none; }
.btn-block { display: flex; width: 100%; }

.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.btn:disabled:hover, .btn[aria-disabled="true"]:hover { background: var(--surface); filter: none; }
.btn-primary:disabled:hover, .btn-primary[aria-disabled="true"]:hover { background: var(--accent); }
.btn-ghost:disabled:hover, .btn-ghost[aria-disabled="true"]:hover { background: transparent; }
.btn-soft:disabled:hover, .btn-soft[aria-disabled="true"]:hover { background: var(--accent-soft); }
.btn-danger:disabled:hover, .btn-danger[aria-disabled="true"]:hover { background: var(--danger); }

.btn-group { display: inline-flex; flex-wrap: wrap; gap: var(--space-2); }

/* ================================================================ cards & tiles */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: var(--space-5);
  min-width: 0;
}
.card-sm { padding: var(--space-4); border-radius: var(--radius); }
.card-flat { box-shadow: none; }
.card-muted { background: var(--surface-2); box-shadow: none; }
.card-accent { background: var(--accent-soft); border-color: var(--accent-soft-2); box-shadow: none; }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); flex-wrap: wrap; }
.card__title { margin: 0; font-size: var(--text-lg); }
.card__foot { margin-top: var(--space-4); padding-top: var(--space-4); border-top: 1px solid var(--border); display: flex; gap: var(--space-2); flex-wrap: wrap; }
@media (max-width: 520px) { .card { padding: var(--space-4); } }

.card-interactive, .tile {
  cursor: pointer;
  transition: border-color var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease), transform var(--dur-2) var(--ease);
}
.card-interactive:hover, .tile:hover { border-color: var(--accent-soft-2); box-shadow: var(--shadow-2); transform: translateY(-1px); }
.card-interactive:active, .tile:active { transform: translateY(0); }

.tile {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  width: 100%;
  min-height: 64px;
  padding: var(--space-4);
  text-align: left;
  font: inherit;
  color: var(--text);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
}
.tile:hover { text-decoration: none; }
.tile:disabled { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: var(--shadow-1); }
.tile__icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 42px; height: 42px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-text);
}
.tile__body { min-width: 0; flex: 1 1 auto; }
.tile__title { display: block; font-weight: 650; font-size: 1rem; line-height: 1.3; }
.tile__desc { display: block; margin-top: 2px; color: var(--text-2); font-size: var(--text-sm); line-height: 1.45; }
.tile__arrow { flex: none; color: var(--text-3); align-self: center; transition: transform var(--dur-2) var(--ease); }
.tile:hover .tile__arrow { transform: translateX(3px); color: var(--accent-text); }

.hero {
  position: relative;
  overflow: hidden;
  padding: var(--space-6);
  border-radius: var(--radius-xl);
  background:
    radial-gradient(120% 140% at 100% 0%, var(--accent-soft) 0%, transparent 55%),
    var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-1);
}
.hero h1 { max-width: 22ch; }
.hero .lead { max-width: 56ch; }
@media (max-width: 520px) { .hero { padding: var(--space-5) var(--space-4); } }

/* ================================================================ chips, badges, kbd */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}
.chip-static { min-height: 0; padding: 1px 9px; white-space: normal; }
button.chip { cursor: pointer; transition: background var(--dur-1), color var(--dur-1), border-color var(--dur-1); }
button.chip:hover { background: var(--surface-2); color: var(--text); }
.chip.is-active, .chip[aria-pressed="true"] { background: var(--accent); border-color: transparent; color: var(--on-accent); }
.chip .icon { width: 16px; height: 16px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.5;
  letter-spacing: 0.01em;
  white-space: nowrap;
  vertical-align: middle;
}
.badge-accent { background: var(--accent-soft); border-color: var(--accent-soft-2); color: var(--accent-text); }
.badge-success { background: var(--success-soft); border-color: var(--success-border); color: var(--success-text); }
.badge-warn { background: var(--warn-soft); border-color: var(--warn-border); color: var(--warn-text); }
.badge-danger { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger-text); }
.badge-info { background: var(--info-soft); border-color: var(--info-border); color: var(--info-text); }
.badge-solid { background: var(--accent); border-color: transparent; color: var(--on-accent); }

kbd, .kbd {
  display: inline-block;
  min-width: 1.7em;
  padding: 0.1em 0.45em;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.82em;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  white-space: nowrap;
}

.skill-tag {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2.2em; padding: 0 6px;
  border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-2);
  font-size: var(--text-xs); font-weight: 750; line-height: 1.6; letter-spacing: 0.02em;
}

/* ================================================================ rating pills */
.rating-pill {
  --rp-dot: var(--r-none); --rp-bg: var(--r-none-bg); --rp-text: var(--r-none-text); --rp-border: var(--r-none-border);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px 2px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--rp-border);
  background: var(--rp-bg);
  color: var(--rp-text);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.6;
  white-space: nowrap;
  vertical-align: middle;
}
.rating-pill__dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--rp-dot); }
.rating-pill--sm { padding: 0 8px 0 6px; font-size: 0.7rem; gap: 5px; }
.rating-pill--sm .rating-pill__dot { width: 7px; height: 7px; }
.rating-pill[data-rating="taught"] { --rp-dot: transparent; --rp-bg: var(--r-taught-bg); --rp-text: var(--r-taught-text); --rp-border: var(--r-taught-border); border-style: dashed; }
.rating-pill[data-rating="taught"] .rating-pill__dot { border: 1.5px solid var(--r-taught); }
.rating-pill[data-rating="learning"] { --rp-dot: var(--r-learning); --rp-bg: var(--r-learning-bg); --rp-text: var(--r-learning-text); --rp-border: var(--r-learning-border); }
.rating-pill[data-rating="building"] { --rp-dot: var(--r-building); --rp-bg: var(--r-building-bg); --rp-text: var(--r-building-text); --rp-border: var(--r-building-border); }
.rating-pill[data-rating="secure"] { --rp-dot: var(--r-secure); --rp-bg: var(--r-secure-bg); --rp-text: var(--r-secure-text); --rp-border: var(--r-secure-border); }
.rating-pill[data-rating="exam-ready"] { --rp-dot: var(--r-ready-text); --rp-bg: var(--r-ready-bg); --rp-text: var(--r-ready-text); --rp-border: var(--r-ready-border); }

.rating-legend { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: 0; padding: 0; list-style: none; }
.rating-legend > li + li { margin-top: 0; }

/* A whole-course stacked bar: <div class="stack-bar"><span data-rating="secure" style="width:12%"></span>…</div> */
.stack-bar { display: flex; height: 12px; border-radius: var(--radius-pill); overflow: hidden; background: var(--surface-3); gap: 2px; }
.stack-bar > span { display: block; min-width: 0; background: var(--r-none); transition: width var(--dur-3) var(--ease); }
.stack-bar > [data-rating="taught"] { background: repeating-linear-gradient(-45deg, var(--r-taught) 0 2px, transparent 2px 5px); }
.stack-bar > [data-rating="learning"] { background: var(--r-learning); }
.stack-bar > [data-rating="building"] { background: var(--r-building); }
.stack-bar > [data-rating="secure"] { background: var(--r-secure); }
.stack-bar > [data-rating="exam-ready"] { background: var(--r-ready); }

/* ================================================================ meter & strand bars */
.cc-meter { position: relative; height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; min-width: 40px; }
.cc-meter__fill { position: absolute; top: 0; bottom: 0; left: 0; border-radius: inherit; background: var(--accent); transition: width var(--dur-3) var(--ease); }
.cc-meter__tick { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--surface); }
.cc-meter[data-band="learning"] .cc-meter__fill { background: var(--r-learning); }
.cc-meter[data-band="building"] .cc-meter__fill { background: var(--r-building); }
.cc-meter[data-band="secure"] .cc-meter__fill { background: var(--r-secure); }
.cc-meter[data-band="exam-ready"] .cc-meter__fill { background: var(--r-ready); }

.strand-bars { display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 0; list-style: none; }
.strand-bars > li + li { margin-top: 0; }
.strand-bar {
  display: grid;
  grid-template-columns: 28px minmax(72px, 7.5em) minmax(0, 1fr) 2.4em;
  align-items: center;
  gap: 10px;
  font-size: var(--text-sm);
}
.strand-bar__key {
  display: grid; place-items: center;
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-weight: 800; font-size: 0.8rem; color: var(--text-2);
}
.strand-bar__name { color: var(--text-2); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.strand-bar__value { text-align: right; font-weight: 700; color: var(--text); }
.strand-bar[data-band="none"] .strand-bar__value { color: var(--text-3); font-weight: 600; }
.strand-bar .cc-meter { height: 10px; }
.strand-bars--compact { gap: 6px; }
.strand-bars--compact .strand-bar { grid-template-columns: 22px minmax(0, 1fr) 2.2em; gap: 8px; }
.strand-bars--compact .strand-bar__key { width: 22px; height: 22px; border-radius: 6px; font-size: 0.72rem; }
.strand-bars--compact .strand-bar__name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.strand-bars--compact .cc-meter { height: 7px; }
@media (max-width: 340px) {
  .strand-bar { grid-template-columns: 26px minmax(0, 1fr) 2.2em; }
  .strand-bar__name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}

/* ================================================================ level badges */
.level-badge {
  display: inline-flex; align-items: center;
  padding: 1px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.6;
  white-space: nowrap;
  vertical-align: middle;
}
.level-badge[data-level="3"] { background: var(--surface-2); border-color: var(--border-strong); color: var(--text-2); }
.level-badge[data-level="2"] { background: var(--accent-soft); border-color: var(--accent-soft-2); color: var(--accent-text); }
.level-badge[data-level="1"] { background: var(--accent-soft-2); border-color: transparent; color: var(--accent-text); }
.level-badge[data-level="0"] { background: var(--accent); border-color: transparent; color: var(--on-accent); }

/* ================================================================ topic map */
.topic-map { display: flex; flex-direction: column; gap: var(--space-6); }
.topic-theme__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--space-2) var(--space-3); margin-bottom: var(--space-3); }
.topic-theme__title { margin: 0; font-size: var(--text-lg); }
.topic-theme__meta { font-size: var(--text-sm); color: var(--text-3); }
.topic-group { margin-top: var(--space-4); }
.topic-group:first-child { margin-top: 0; }
.topic-group__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-2); }
.topic-group__title { margin: 0; font-size: var(--text-sm); font-weight: 700; color: var(--text-2); letter-spacing: 0.01em; }
.topic-group__meta { font-size: var(--text-xs); color: var(--text-3); white-space: nowrap; }

.topic-grid {
  display: grid;
  gap: var(--space-2);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 148px), 1fr));
  margin: 0;
  padding: 0;
  list-style: none;
}
.topic-grid > li + li { margin-top: 0; }
@media (max-width: 359px) { .topic-grid { grid-template-columns: minmax(0, 1fr); } }

.topic-tile {
  --tile-bar: var(--r-none);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  min-height: 96px;
  padding: 10px 12px 10px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  overflow: hidden;
  transition: border-color var(--dur-1), box-shadow var(--dur-2), transform var(--dur-1);
}
.topic-tile::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--tile-bar); }
.topic-tile:hover { border-color: var(--accent-soft-2); box-shadow: var(--shadow-2); text-decoration: none; }
.topic-tile:active { transform: scale(0.99); }
.topic-tile__id { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-3); font-weight: 600; }
.topic-tile__title {
  font-weight: 650; font-size: 0.9rem; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
.topic-tile__foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 6px; min-width: 0; }
.topic-tile__tick { display: inline-flex; color: var(--text-3); }
.topic-tile__tick .icon { width: 16px; height: 16px; }
.topic-tile[data-rating="taught"] { --tile-bar: transparent; }
.topic-tile[data-rating="taught"]::before { border-right: 2px dashed var(--r-taught); width: 6px; }
.topic-tile[data-rating="learning"] { --tile-bar: var(--r-learning); }
.topic-tile[data-rating="building"] { --tile-bar: var(--r-building); }
.topic-tile[data-rating="secure"] { --tile-bar: var(--r-secure); }
.topic-tile[data-rating="exam-ready"] { --tile-bar: var(--r-ready); background: var(--r-ready-soft); border-color: var(--r-ready-soft-border); }
.topic-tile.is-covered .topic-tile__tick { color: var(--accent-text); }
.topic-tile.is-due { outline: 2px dashed var(--r-building); outline-offset: -4px; }
.topic-tile.is-next { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.topic-tile.is-coming { cursor: default; opacity: 0.6; background: var(--surface-2); }
.topic-tile.is-coming:hover { box-shadow: none; border-color: var(--border); }

/* filter bar above the map */
.filter-bar { display: flex; gap: var(--space-2); overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; margin-bottom: var(--space-4); }
.filter-bar::-webkit-scrollbar { display: none; }
.filter-bar .chip { flex: none; }

/* ================================================================ daily plan (from Cube Coach home) */
.cc-plan { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.cc-plan > li + li { margin-top: 0; }
.cc-plan__item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--space-3); align-items: start; padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.cc-plan__item.is-next { border-color: var(--accent-soft-2); box-shadow: 0 0 0 1px var(--accent-soft-2); }
.cc-plan__item.is-done { background: var(--surface-2); }
.cc-plan__item.is-done .cc-plan__title { color: var(--text-2); text-decoration: line-through; text-decoration-thickness: 1px; }
/* 44px tap target; the visible circle is the 32px icon inside it */
.cc-plan__check { flex: none; display: grid; place-items: center; width: var(--tap); height: var(--tap); margin: -6px 0 0 -6px; padding: 0; border-radius: 50%; border: 0; background: transparent; color: transparent; cursor: pointer; }
.cc-plan__check .icon { width: 32px; height: 32px; padding: 5px; border-radius: 50%; border: 2px solid var(--border-strong); background: var(--surface); transition: background var(--dur-1), border-color var(--dur-1), color var(--dur-1); }
.cc-plan__check:hover .icon { border-color: var(--accent); color: var(--text-3); }
.cc-plan__check[aria-pressed="true"] .icon { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.cc-plan__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 4px; font-size: var(--text-xs); color: var(--text-3); font-weight: 600; }
.cc-plan__meta .icon { width: 14px; height: 14px; }
.cc-plan__title { margin: 0 0 2px; font-size: 1rem; font-weight: 650; line-height: 1.3; }
.cc-plan__why { margin: 0; font-size: var(--text-sm); color: var(--text-2); }
.cc-plan__tip { margin: 6px 0 0; font-size: var(--text-sm); color: var(--text-2); padding-left: 10px; border-left: 3px solid var(--accent-soft-2); }
.cc-plan__actions { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.cc-plan__alt { font-size: var(--text-xs); }
@media (max-width: 600px) { .cc-plan__item { grid-template-columns: auto minmax(0, 1fr); } .cc-plan__actions { grid-column: 2; flex-direction: row; flex-wrap: wrap; align-items: center; } }
.cc-plan__summary { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.cc-plan__summary .progress { flex: 1 1 140px; }

/* ================================================================ progress */
.progress {
  position: relative;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  overflow: hidden;
}
.progress__bar {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--accent);
  transition: width var(--dur-3) var(--ease);
}
.progress-sm { height: 5px; }
.progress-lg { height: 12px; }
progress {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  overflow: hidden;
  color: var(--accent);
}
progress::-webkit-progress-bar { background: var(--surface-3); border-radius: var(--radius-pill); }
progress::-webkit-progress-value { background: var(--accent); border-radius: var(--radius-pill); }
progress::-moz-progress-bar { background: var(--accent); border-radius: var(--radius-pill); }

/* progress dots for a practice session */
.dots { display: flex; flex-wrap: wrap; gap: 5px; margin: 0; padding: 0; list-style: none; }
.dots > li + li { margin-top: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--surface-3); }
.dot.is-current { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft-2); }
.dot.is-right { background: var(--r-ready); }
.dot.is-partial { background: var(--r-building); }
.dot.is-wrong { background: var(--r-learning); }
.dot.is-done { background: var(--text-3); }

/* ================================================================ tabs & segmented control */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  margin-bottom: var(--space-4);
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  appearance: none;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 10px 14px;
  margin-bottom: -1px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  cursor: pointer;
  border-radius: 8px 8px 0 0;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.is-active, .tab[aria-selected="true"] { color: var(--accent-text); border-bottom-color: var(--accent); }

.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  max-width: 100%;
  gap: 2px;
  padding: 3px;
  border-radius: 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.segmented > button, .segmented > label {
  appearance: none;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 4px 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--dur-1), color var(--dur-1), box-shadow var(--dur-1);
}
.segmented > button:hover, .segmented > label:hover { color: var(--text); }
.segmented > button[aria-pressed="true"], .segmented > button[aria-checked="true"], .segmented > button.is-active,
.segmented > label:has(input:checked) {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-1);
}
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.segmented > label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
.segmented-block { display: flex; }
.segmented-block > button, .segmented-block > label { flex: 1 1 0; }

/* ================================================================ forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-weight: 600; font-size: var(--text-sm); color: var(--text); }
.hint { font-size: 0.82rem; color: var(--text-3); }

.input, .select, textarea.input {
  width: 100%;
  min-height: var(--tap);
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: max(16px, 1rem); /* 16px+ stops iOS zooming into the field */
  transition: border-color var(--dur-1), box-shadow var(--dur-1);
}
.input::placeholder { color: var(--text-3); }
.input:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.input:disabled, .select:disabled { opacity: 0.55; cursor: not-allowed; }
.input[readonly] { background: var(--surface-2); }
textarea.input { min-height: 96px; resize: vertical; line-height: 1.5; }
.select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237d8894' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  cursor: pointer;
}
.select-inline { width: auto; }
.code-box { font-family: var(--font-mono); font-size: 0.8rem !important; line-height: 1.45; word-break: break-all; }

.toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.toggle__track {
  position: relative;
  flex: none;
  width: 44px;
  height: 26px;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
  transition: background var(--dur-2) var(--ease);
}
.toggle__track::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform var(--dur-2) var(--ease);
}
.toggle input:checked + .toggle__track { background: var(--accent); }
.toggle input:checked + .toggle__track::after { transform: translateX(18px); }
.toggle input:focus-visible + .toggle__track { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle input:disabled + .toggle__track { opacity: 0.45; }
.toggle:has(input:disabled) { cursor: not-allowed; }
.toggle__label { font-weight: 500; }

.range, input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; }

.check { display: inline-flex; align-items: center; gap: 10px; min-height: var(--tap); cursor: pointer; }
.check input { flex: none; width: 20px; height: 20px; accent-color: var(--accent); }

/* stepper for entering marks: [−] 6 [+] */
.stepper { display: inline-flex; align-items: center; gap: 0; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface); overflow: hidden; }
.stepper button { width: var(--tap); height: var(--tap); border: 0; background: transparent; color: var(--text); font: inherit; font-size: 1.2rem; cursor: pointer; }
.stepper button:hover { background: var(--surface-2); }
.stepper button:disabled { opacity: 0.4; cursor: not-allowed; }
.stepper button:focus-visible { outline-offset: -3px; }   /* the stepper clips anything outside it */
.stepper__value { min-width: 3.2em; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border);
}
.setting-row:first-child { padding-top: 0; }
.setting-row:last-child { border-bottom: 0; padding-bottom: 0; }
.setting-row__text { min-width: 0; flex: 1 1 220px; }
.setting-row__title { font-weight: 600; }
.setting-row__desc { font-size: var(--text-sm); color: var(--text-2); margin-top: 2px; }
.setting-row__control { flex: 0 1 auto; display: flex; justify-content: flex-end; min-width: 0; }
@media (max-width: 520px) {
  .setting-row { flex-wrap: wrap; }
  .setting-row__control { justify-content: flex-start; }
}

/* ================================================================ callouts */
.callout {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  border: 1px solid var(--info-border);
  background: var(--info-soft);
  color: var(--text);
  font-size: 0.95rem;
}
.callout__icon { flex: none; display: inline-flex; color: var(--info-text); margin-top: 2px; }
.callout__body { min-width: 0; flex: 1 1 auto; }
.callout__title { font-weight: 700; margin: 0 0 2px; }
.callout-tip { background: var(--accent-soft); border-color: var(--accent-soft-2); }
.callout-tip .callout__icon { color: var(--accent-text); }
.callout-warn { background: var(--warn-soft); border-color: var(--warn-border); }
.callout-warn .callout__icon { color: var(--warn-text); }
.callout-success { background: var(--success-soft); border-color: var(--success-border); }
.callout-success .callout__icon { color: var(--success-text); }
.callout-danger { background: var(--danger-soft); border-color: var(--danger-border); }
.callout-danger .callout__icon { color: var(--danger-text); }

/* ================================================================ question cards */
.qcard {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}
.qcard > * { margin: 0; min-width: 0; }
.qcard > :empty { display: none; }
@media (max-width: 520px) { .qcard { padding: var(--space-4); gap: var(--space-3); border-radius: var(--radius); } }
.qcard__head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.qcard__kind { font-size: var(--text-xs); font-weight: 750; letter-spacing: 0.07em; text-transform: uppercase; color: var(--accent-text); margin-right: auto; }
.qcard__marks { font-variant-numeric: tabular-nums; }
.qcard__prompt { font-weight: 650; font-size: 1.05rem; line-height: 1.45; }
.qcard__prompt--hint { font-weight: 500; font-size: var(--text-sm); color: var(--text-2); }
.qcard__stem { font-size: 1.08rem; font-weight: 600; line-height: 1.5; margin: 0; }
.qcard__body { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.qcard__body > * { margin: 0; }
.qcard__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.qcard__actions:empty { display: none; }
@media (max-width: 520px) { .qcard__actions > .btn-primary { flex: 1 1 auto; } }
.qcard__feedback:empty { display: none; }
/* once answered, spent controls get out of the way */
.qcard.is-answered .qcard__actions > .btn:disabled { display: none; }
.qcard.is-answered .parsons__handle { visibility: hidden; }
.qcard__model:empty, .qcard__marking:empty { display: none; }
.qcard__marking { display: flex; flex-direction: column; gap: var(--space-2); }

.structure-line { font-size: var(--text-sm); color: var(--text-2); line-height: 1.9; }

/* hint ladder */
.qcard__hints { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2); }
.qcard__hints:empty { display: none; }
.hint-lines { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; width: 100%; }
.hint-lines:empty { display: none; }
.hint-lines > li + li { margin-top: 0; }
.hint-line {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  font-size: var(--text-sm);
  color: var(--text);
}
.hint-line__label { display: inline-block; margin-right: 8px; font-size: var(--text-xs); font-weight: 750; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent-text); }
.hint-btn { margin-left: -8px; }

/* feedback */
.feedback {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  animation: fade-in var(--dur-2) var(--ease);
}
.feedback > * { margin: 0; }
.feedback__head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-weight: 750; }
.feedback__sub { font-weight: 500; color: var(--text-2); font-size: var(--text-sm); }
.feedback__explain { color: var(--text); }
.feedback.is-correct { background: var(--success-soft); border-color: var(--success-border); }
.feedback.is-correct .feedback__head { color: var(--success-text); }
.feedback.is-partial { background: var(--warn-soft); border-color: var(--warn-border); }
.feedback.is-partial .feedback__head { color: var(--warn-text); }
.feedback.is-wrong { background: var(--danger-soft); border-color: var(--danger-border); }
.feedback.is-wrong .feedback__head { color: var(--danger-text); }
.feedback.is-neutral { background: var(--accent-soft); border-color: var(--accent-soft-2); }
.feedback.is-neutral .feedback__head { color: var(--accent-text); }
.saved-note { display: flex; align-items: center; gap: 6px; font-size: var(--text-sm); color: var(--text-2); margin: 0; }

.model-answer {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
}
.model-answer__label { margin: 0 0 4px; font-size: var(--text-xs); font-weight: 750; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent-text); }
.model-answer__text { font-family: var(--font-read); line-height: 1.6; }
.chain-list { margin: 0; padding-left: 1.4em; }
.chain-list > li { padding-left: 4px; }

/* ================================================================ option buttons (mcq, gap, lens, fixes) */
.option-list { display: grid; gap: var(--space-2); margin: 0; padding: 0; list-style: none; grid-template-columns: minmax(0, 1fr); }
.option-list > li + li { margin-top: 0; }
.option-item { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.option {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 52px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1.5px solid var(--choice-edge);
  background: var(--choice-bg);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  transition: border-color var(--dur-1), background var(--dur-1), opacity var(--dur-2), transform var(--dur-1);
}
.option:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.option:active:not(:disabled) { transform: scale(0.99); }
.option:disabled { cursor: default; }
.option__key {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: var(--text-xs);
  font-weight: 750;
}
.option__text { min-width: 0; flex: 1 1 auto; overflow-wrap: anywhere; }
.option__sub { display: block; margin-top: 2px; font-weight: 450; font-size: var(--text-sm); color: var(--text-2); }
.option.is-selected { border-color: var(--accent); background: var(--accent-soft); }
.option.is-selected .option__key { background: var(--accent); border-color: transparent; color: var(--on-accent); }
.option.is-correct { border-color: var(--success); background: var(--success-soft); opacity: 1; }
.option.is-correct .option__key { background: var(--success); border-color: transparent; color: #fff; }
.option.is-wrong { border-color: var(--danger); background: var(--danger-soft); opacity: 1; animation: shake 0.35s var(--ease); }
.option.is-wrong .option__key { background: var(--danger); border-color: transparent; color: #fff; }
.option.is-dim { opacity: 0.6; }
.option__why { margin: 0 0 4px 44px; font-size: var(--text-sm); color: var(--text-2); line-height: 1.45; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ================================================================ flashcards & self-rating */
.flashcard {
  display: flex; flex-direction: column; gap: var(--space-3);
  min-height: 160px;
  padding: var(--space-5) var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  text-align: center;
  justify-content: center;
}
.flashcard__prompt { margin: 0; }
.flashcard__front { font-size: 1.2rem; font-weight: 700; line-height: 1.35; }
.flashcard__back {
  padding-top: var(--space-3);
  border-top: 1px dashed var(--border-strong);
  font-family: var(--font-read);
  font-size: 1.05rem;
  line-height: 1.6;
  animation: fade-in var(--dur-2) var(--ease);
}
.self-rate { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-2); width: 100%; }
.self-rate:has(> :nth-child(2):last-child) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.self-rate__btn { min-height: 52px; flex-direction: column; gap: 2px; padding: 6px 8px; font-size: 0.9rem; }
.self-rate__key { font-size: var(--text-xs); color: var(--text-3); font-weight: 700; }
.self-rate__btn--again { border-color: var(--r-learning-border); }
.self-rate__btn--partly { border-color: var(--r-building-border); }
.self-rate__btn--knew { border-color: var(--r-secure-border); }
.self-rate__btn.is-selected { background: var(--accent-soft); border-color: var(--accent); opacity: 1; }
.self-rate__btn:disabled:not(.is-selected) { opacity: 0.4; }

/* ================================================================ define */
.define-term { font-size: 1.15rem; line-height: 1.4; }
.define-term strong { font-weight: 750; }
.define-input { min-height: 88px !important; }
.component-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.component-list > li + li { margin-top: 0; }
.component {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 6px;
  border-radius: var(--radius-pill);
  font-size: var(--text-sm); font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
}
.component .icon { width: 16px; height: 16px; }
.component.is-found { border-color: var(--success-border); color: var(--success-text); background: var(--surface); }
.component.is-missing { border-color: var(--danger-border); color: var(--danger-text); border-style: dashed; }
.component.is-overruled { border-style: dotted; }

/* ================================================================ sort deck */
.sort-text {
  padding: var(--space-4);
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 1.1rem;
  font-weight: 650;
  line-height: 1.45;
  text-align: center;
}
.sort-text.is-long { text-align: left; font-size: 1.02rem; font-weight: 600; line-height: 1.55; }
.sort-cats { display: grid; gap: var(--space-2); grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 640px) { .sort-cats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); } }
.sort-cat {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 64px;
  padding: 10px 8px;
  border-radius: var(--radius);
  border: 1.5px solid var(--choice-border);
  background: var(--choice-bg);
  color: var(--text);
  font: inherit; font-weight: 700; font-size: 1rem; line-height: 1.25;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--dur-1), background var(--dur-1), transform var(--dur-1);
}
.sort-cat:last-child:nth-child(odd) { grid-column: 1 / -1; }
@media (min-width: 640px) { .sort-cat:last-child:nth-child(odd) { grid-column: auto; } }
.sort-cat:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.sort-cat:active:not(:disabled) { transform: scale(0.98); }
.sort-cat:disabled { cursor: default; opacity: 0.55; }
.sort-cat__key { font-size: var(--text-xs); color: var(--text-2); font-weight: 700; }
.sort-cat.is-selected { border-color: var(--accent); background: var(--accent-soft); opacity: 1; }
.sort-cat.is-correct { border-color: var(--success); background: var(--success-soft); opacity: 1; }
.sort-cat.is-wrong { border-color: var(--danger); background: var(--danger-soft); opacity: 1; animation: shake 0.35s var(--ease); }

/* ================================================================ drag-to-order (Parsons) */
.parsons { display: flex; flex-direction: column; gap: var(--space-2); }
.parsons__label { margin: var(--space-2) 0 0; font-size: var(--text-xs); font-weight: 750; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-3); }
.parsons__label:first-child { margin-top: 0; }
.parsons__answer, .parsons__bank { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.parsons__answer > li + li, .parsons__bank > li + li { margin-top: 0; }
.parsons__answer { min-height: 60px; padding: 6px; border-radius: var(--radius); border: 1.5px dashed var(--border-strong); background: var(--surface-2); counter-reset: none; }
.parsons__empty { padding: 12px; text-align: center; font-size: var(--text-sm); color: var(--text-3); }
.parsons__item {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  min-width: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  transition: border-color var(--dur-1), box-shadow var(--dur-1), opacity var(--dur-1);
}
.parsons__handle {
  flex: none;
  display: grid; place-items: center;
  width: 36px;
  min-height: var(--tap);
  color: var(--text-3);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.parsons__item.is-locked .parsons__handle { cursor: default; }
.parsons__num { flex: none; align-self: center; width: 1.6em; font-size: var(--text-sm); font-weight: 750; color: var(--accent-text); }
.parsons__text {
  flex: 1 1 0;
  min-width: 0;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  overflow-wrap: anywhere;
}
.parsons__text:disabled { cursor: default; color: var(--text); }
.parsons__answer .parsons__text { padding-left: 2px; }
.parsons__bank .parsons__item:hover { border-color: var(--accent); }
.parsons__bank .parsons__text::before { content: "+"; display: inline-block; width: 1.1em; margin-right: 4px; color: var(--accent-text); font-weight: 800; }
.parsons__item.is-selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft-2); }
.parsons__item.is-locked { background: var(--surface-2); box-shadow: none; }
.parsons__item.is-dragging { opacity: 0.85; border-color: var(--accent); box-shadow: var(--shadow-3); z-index: 2; }
.parsons__controls { display: flex; gap: 2px; align-items: center; margin-left: auto; padding: 0 4px 4px; width: 100%; justify-content: flex-end; }
.parsons__item.is-ok { border-color: var(--success-border); background: var(--success-soft); }
.parsons__item.is-misplaced { border-color: var(--warn-border); background: var(--warn-soft); }
.parsons__item.is-distractor { border-color: var(--danger-border); background: var(--danger-soft); }
.parsons__item.is-distractor .parsons__text { text-decoration: line-through; text-decoration-thickness: 1px; }
.parsons__why { flex: 1 1 100%; margin: 0; padding: 0 12px 10px 48px; font-size: var(--text-sm); color: var(--danger-text); }
.parsons:has(.is-dragging) { user-select: none; -webkit-user-select: none; }

/* ================================================================ chain with a gap */
.chain { display: flex; flex-direction: column; align-items: stretch; gap: 2px; margin: 0; padding: 0; list-style: none; }
.chain > li + li { margin-top: 0; }
.chain__link, .chain__gap {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  line-height: 1.45;
}
.chain__arrow { display: flex; justify-content: center; color: var(--text-3); line-height: 1; padding: 1px 0; }
.chain__arrow .icon { width: 16px; height: 16px; }
.chain__gap { border: 1.5px dashed var(--accent); background: var(--accent-soft); padding: 0; }
.chain__gap-btn {
  display: block; width: 100%; min-height: var(--tap);
  padding: 10px 14px;
  border: 0; background: transparent; color: var(--accent-text);
  font: inherit; font-weight: 650; text-align: left; cursor: pointer;
}
.chain__gap-btn:disabled { cursor: default; }
.chain__gap.is-filled { border-style: solid; background: var(--surface); }
.chain__gap.is-filled .chain__gap-btn { color: var(--text); font-weight: 550; }
.chain__gap.is-ok { border-color: var(--success); background: var(--success-soft); }
.chain__gap.is-wrong { border-color: var(--danger); background: var(--danger-soft); }
.chain__fix, .chain__why { margin: 0; padding: 0 14px 10px; font-size: var(--text-sm); }
.chain__fix { color: var(--text); font-weight: 600; }
.chain__why { color: var(--text-2); }

/* ================================================================ lens & argument */
.argument {
  margin: 0;
  padding: var(--space-3) var(--space-4);
  border-left: 3px solid var(--border-strong);
  background: var(--surface-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-family: var(--font-read);
  font-size: 1.05rem;
  line-height: 1.6;
}
.context-line { margin: 0; font-size: var(--text-sm); color: var(--text-2); }
.context-line__label { display: inline-block; margin-right: 8px; font-size: var(--text-xs); font-weight: 750; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); }
.lens-options .option { align-items: flex-start; }
.lens-options .option__key { margin-top: 1px; }

/* ================================================================ extracts */
.extract {
  margin: 0;
  padding: var(--space-4);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.extract__top { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-2); }
.extract__title { font-weight: 750; }
.extract__label { text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.7rem; }
.extract__text { font-family: var(--font-read); line-height: 1.65; }
.extract__source { margin: var(--space-2) 0 0; }
.extract__caption { margin: var(--space-3) 0 0; font-size: var(--text-sm); font-weight: 650; color: var(--text-2); }
.extract__caption + .table-wrap { margin-top: var(--space-2); }
.extract__kicker { margin: 0 0 4px; font-size: var(--text-xs); font-weight: 750; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); }
.table-wrap { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; margin-top: var(--space-3); }
.data-table { border-collapse: collapse; width: 100%; font-size: var(--text-sm); font-variant-numeric: tabular-nums; }
.data-table th, .data-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
/* on a phone the row labels and headings wrap, so the numbers stay in view without sideways scrolling */
.data-table th, .data-table tr > td:first-child { white-space: normal; }
.data-table th { min-width: 4.5em; }
.data-table tr > td:first-child { min-width: 6em; }
.data-table th { font-weight: 700; color: var(--text-2); background: var(--surface); vertical-align: bottom; }

/* ================================================================ spot the error */
/* phrases are inline spans (role=button) so the sentence wraps like text; the tall line-height and
   vertical padding give each wrapped fragment a tap height close to 44px */
.phrase-text { margin: 0; font-size: 1.08rem; line-height: 2.9; }
.phrase {
  display: inline;
  padding: 10px 3px;
  border-radius: 6px;
  background: var(--surface-2);
  box-shadow: inset 0 -2px 0 var(--border-strong);
  color: var(--text);
  cursor: pointer;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  transition: background var(--dur-1), box-shadow var(--dur-1);
}
.phrase:hover:not([aria-disabled="true"]) { background: var(--accent-soft); box-shadow: inset 0 -2px 0 var(--accent); }
.phrase:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.phrase[aria-disabled="true"] { cursor: default; }
.phrase.is-picked { background: var(--accent-soft-2); box-shadow: inset 0 -2px 0 var(--accent); }
.phrase.is-ok { background: var(--success-soft); box-shadow: inset 0 -2px 0 var(--success); }
.phrase.is-wrong { background: var(--danger-soft); box-shadow: inset 0 -2px 0 var(--danger); text-decoration: line-through; }
.phrase.is-answer { background: var(--warn-soft); box-shadow: inset 0 -2px 0 var(--warn); }
.error-fix { display: flex; flex-direction: column; gap: var(--space-2); }
.error-fix__q { margin: 0; font-weight: 600; }
.error-fix__answer { margin: 0; padding: var(--space-3); border-radius: var(--radius-sm); background: var(--surface-2); }

/* ================================================================ be the examiner (sample) */
.sample-q { padding: var(--space-3) var(--space-4); border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }
.sample-q__label { margin: 0 0 4px; font-size: var(--text-xs); font-weight: 750; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); }
.sample-q__stem { margin: 0; font-weight: 650; line-height: 1.5; }
.sample-ctx { border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); padding: 0 var(--space-4); }
.sample-ctx > summary { min-height: var(--tap); display: flex; align-items: center; cursor: pointer; font-size: var(--text-sm); font-weight: 650; color: var(--text-2); }
.sample-ctx > summary:hover { color: var(--text); }
.sample-ctx[open] { padding-bottom: var(--space-3); }
.sample-ctx .extract { padding: 0; border: 0; background: transparent; }
.sample-ctx__text { margin: 0; font-family: var(--font-read); line-height: 1.6; }
.sample-answer { display: flex; flex-direction: column; gap: 4px; }
.sample-answer__text {
  margin: 0;
  padding: var(--space-3) var(--space-4);
  border-left: 3px solid var(--border-strong);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface-2);
  font-family: var(--font-read);
  font-size: 1.02rem;
  line-height: 1.65;
  overflow-wrap: anywhere;
}
.sample-answer__text > p { margin: 0; }
.sample-answer__text > p + p { margin-top: 0.8em; }
.sample-marks { display: flex; flex-direction: column; gap: var(--space-4); }
.sample-mark { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; margin: 0; padding: 0; border: 0; }
.sample-mark__legend { padding: 0; margin-bottom: var(--space-2); font-size: var(--text-sm); line-height: 1.4; }
.sample-mark__levels { width: 100%; box-sizing: border-box; }
.segmented > .sample-mark__lv { flex-direction: column; gap: 0; min-height: 48px; padding: 4px 6px; line-height: 1.2; }
.sample-mark__lvname { font-weight: 700; }
.sample-mark__lvrange { font-size: var(--text-xs); font-weight: 600; color: inherit; opacity: 0.8; }
.segmented > .sample-mark__lv[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow-1); }
.segmented > .sample-mark__lv:disabled { cursor: default; }
.sample-mark__row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); }
.sample-mark__marklabel { font-size: var(--text-sm); font-weight: 650; }
.sample-mark__note { flex: 1 1 12em; min-width: 0; }
.sample-tags { display: flex; flex-direction: column; gap: var(--space-2); }
.sample-tags__label { margin: 0; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px var(--space-2); font-size: var(--text-sm); font-weight: 650; }
.sample-tags__count { color: var(--text-3); font-weight: 600; }
.sample-tags__list { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip.sample-tag { white-space: normal; text-align: left; max-width: 100%; }
.chip.sample-tag:disabled { cursor: default; opacity: 0.5; }
.chip.sample-tag[aria-pressed="true"]:disabled { opacity: 1; }
.sample-compare { margin-top: 0; }
.sample-compare .data-table th, .sample-compare .data-table td { background: transparent; }
.sample-compare tr.is-exact td:nth-child(2) { color: var(--success-text); font-weight: 700; }
.sample-compare tr.is-off td:nth-child(2) { color: var(--danger-text); font-weight: 700; }
.sample-fbtags { display: flex; flex-direction: column; gap: 6px; }
.sample-fbtags > .model-answer__label { margin: 0; }
.sample-fbtags__list { display: flex; flex-wrap: wrap; gap: 6px; }
.sample-fbtag { white-space: normal; font-size: var(--text-sm); padding: 3px 10px; }
.sample-fbtag .icon { width: 14px; height: 14px; }
.sample-fbtag.is-wrong { text-decoration: line-through; }

/* ================================================================ writing area */
.writer { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.writer__input {
  min-height: 180px !important;
  font-family: var(--font-read) !important;
  font-size: max(16px, 1.02rem) !important;
  line-height: 1.6 !important;
  padding: 12px 14px !important;
}
.writer__foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); font-size: var(--text-sm); color: var(--text-2); }
.writer__count { font-weight: 650; }
.writer[data-target="under"] .writer__count { color: var(--text-2); }
.writer[data-target="ok"] .writer__count { color: var(--success-text); }
.writer[data-target="over"] .writer__count { color: var(--warn-text); }
.on-paper { font-size: var(--text-sm); color: var(--text-2); }

/* ================================================================ mark checklist */
.mark-list { display: flex; flex-direction: column; gap: var(--space-2); }
.mark-list__items { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.mark-list__items > li + li { margin-top: 0; }
.mark-item__label {
  display: flex; align-items: flex-start; gap: var(--space-3);
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: border-color var(--dur-1), background var(--dur-1);
}
.mark-item__label:hover { border-color: var(--accent-soft-2); }
.mark-item__label input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.mark-item__box {
  flex: none; display: grid; place-items: center;
  width: 24px; height: 24px; margin-top: 1px;
  border-radius: 7px; border: 2px solid var(--border-strong);
  background: var(--surface); color: transparent;
  transition: background var(--dur-1), border-color var(--dur-1);
}
.mark-item__box .icon { width: 16px; height: 16px; }
.mark-item__label input:focus-visible + .mark-item__box { outline: 2px solid var(--accent); outline-offset: 2px; }
.mark-item.is-ticked .mark-item__label { border-color: var(--accent-soft-2); background: var(--accent-soft); }
.mark-item.is-ticked .mark-item__box { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.mark-item__text { flex: 1 1 auto; min-width: 0; line-height: 1.45; }
.mark-item__meta { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: var(--text-xs); color: var(--text-3); font-weight: 650; }
.mark-list.is-disabled .mark-item__label { cursor: default; }
.mark-list__foot { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); padding: 0 4px; }
.mark-list__total { font-size: var(--text-lg); font-weight: 750; }

/* ================================================================ timers & stats */
.exam-timer {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.exam-timer .icon { width: 18px; height: 18px; color: var(--text-3); }
.exam-timer.is-running .icon { color: var(--accent-text); }
.exam-timer.is-warning { border-color: var(--warn-border); background: var(--warn-soft); color: var(--warn-text); }
.exam-timer.is-warning .icon { color: var(--warn-text); }
.exam-timer.is-over { border-color: var(--danger-border); background: var(--danger-soft); color: var(--danger-text); }
.exam-timer.is-over .icon { color: var(--danger-text); }
.exam-timer--sticky { position: sticky; top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px) + 8px); z-index: 20; box-shadow: var(--shadow-2); }

.timer {
  font-variant-numeric: tabular-nums;
  font-size: clamp(2.6rem, 11vw, 5rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
  text-align: center;
  color: var(--text);
  white-space: nowrap;
}
.timer__label { text-align: center; color: var(--text-3); font-size: var(--text-sm); margin-top: var(--space-2); }

.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat__label { font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); }
.stat__value { font-size: var(--text-2xl); font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat__sub { font-size: var(--text-sm); color: var(--text-2); }

/* ================================================================ empty state, skeleton, spinner, errors */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-7) var(--space-4);
  text-align: center;
  color: var(--text-2);
}
.empty-state--inline { padding: var(--space-4); }
.empty-state h2, .empty-state h3 { margin: 0; color: var(--text); }
.empty-state p { max-width: 46ch; margin: 0; }
.empty-state__icon {
  display: grid;
  place-items: center;
  width: 60px; height: 60px;
  border-radius: 18px;
  background: var(--surface-2);
  color: var(--text-3);
}
.placeholder-card .row { margin-top: var(--space-2); }

.skeleton {
  display: block;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 40%, var(--surface-2) 60%);
  background-size: 300% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}
.skeleton-text { height: 0.9em; margin: 0.35em 0; }
.skeleton-title { height: 1.4em; width: 50%; margin-bottom: 0.6em; }
@keyframes skeleton-shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

.spinner {
  display: inline-block;
  flex: none;
  width: 20px; height: 20px;
  border: 2.5px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.spinner-lg { width: 36px; height: 36px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.error-card { border-color: var(--danger-border); }
.error-card__icon {
  display: inline-grid; place-items: center; flex: none;
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--danger-soft); color: var(--danger-text);
}
.error-card__msg {
  margin: 0;
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
}
.error-card__details summary { cursor: pointer; color: var(--text-2); font-size: var(--text-sm); }
.error-card__stack { font-size: var(--text-xs); color: var(--text-3); white-space: pre-wrap; word-break: break-word; max-height: 240px; }

/* ================================================================ modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: var(--space-4);
  background: var(--backdrop);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fade-in var(--dur-2) var(--ease);
  overflow-y: auto;
}
.modal {
  position: relative;
  width: min(520px, 100%);
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: var(--space-5);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-3);
  animation: pop-in var(--dur-2) var(--ease);
}
.modal--wide { width: min(780px, 100%); }
.modal__close { position: absolute; top: 12px; right: 12px; }
.modal__title { margin: 0 40px var(--space-2) 0; font-size: var(--text-xl); }
.modal__body { color: var(--text-2); }
.modal__body > * + * { margin-top: var(--space-3); }
.modal__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-5); }
@media (max-width: 520px) {
  .modal-backdrop { place-items: end center; padding: 0; }
  .modal { width: 100%; border-radius: var(--radius-xl) var(--radius-xl) 0 0; max-height: 92vh; max-height: 92dvh; padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom, 0px)); animation: sheet-in var(--dur-3) var(--ease); }
  .modal__actions .btn { flex: 1 1 auto; }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ================================================================ toast */
.toast-region {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px) + var(--space-4));
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  width: min(460px, calc(100% - 2 * var(--space-4)));
  pointer-events: none;
}
/* While a modal (or bottom sheet) is open, toasts move to the top so they never cover its buttons */
html.has-modal .toast-region { bottom: auto; top: calc(env(safe-area-inset-top, 0px) + var(--space-4)); }
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: 8px 8px 8px 14px;
  border-radius: var(--radius);
  background: var(--toast-bg);
  color: var(--toast-fg);
  box-shadow: var(--shadow-3);
  font-size: var(--text-sm);
  font-weight: 500;
  animation: toast-in var(--dur-2) var(--ease);
  transition: opacity var(--dur-2) var(--ease), transform var(--dur-2) var(--ease);
}
.toast.is-leaving { opacity: 0; transform: translateY(6px); }
.toast__icon { flex: none; display: inline-flex; opacity: 0.85; }
.toast--success .toast__icon { color: #3fcf7f; }
.toast--warn .toast__icon { color: #f2b04a; }
.toast--error .toast__icon { color: #ff7a7a; }
:root[data-theme="dark"] .toast--success .toast__icon { color: #17803f; }
:root[data-theme="dark"] .toast--warn .toast__icon { color: #a35f00; }
:root[data-theme="dark"] .toast--error .toast__icon { color: #c0262d; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .toast--success .toast__icon { color: #17803f; }
  :root:not([data-theme="light"]) .toast--warn .toast__icon { color: #a35f00; }
  :root:not([data-theme="light"]) .toast--error .toast__icon { color: #c0262d; }
}
.toast__text { flex: 1 1 auto; min-width: 0; line-height: 1.4; }
.toast__action, .toast__close {
  flex: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  border-radius: 8px;
}
.toast__action { min-height: 36px; padding: 6px 10px; text-decoration: underline; text-underline-offset: 2px; }
.toast__close { display: inline-grid; place-items: center; width: 36px; height: 36px; opacity: 0.7; }
.toast__action:hover, .toast__close:hover { background: rgba(127, 127, 127, 0.2); opacity: 1; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ================================================================ misc */
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain > li + li { margin-top: 0; }
.divided > * + * { border-top: 1px solid var(--border); }
.placeholder-note {
  display: flex; gap: var(--space-2); align-items: center;
  font-size: var(--text-sm); color: var(--text-3);
}

/* landing page (repo root) */
.landing { max-width: 720px; margin-inline: auto; padding: var(--space-7) var(--gutter) var(--space-8); }
.landing__mark { width: 48px; height: 48px; margin-bottom: var(--space-4); }
.landing__grid { display: grid; gap: var(--space-3); grid-template-columns: minmax(0, 1fr); margin-top: var(--space-5); }
@media (min-width: 560px) { .landing__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.subject-card { display: flex; flex-direction: column; gap: var(--space-2); min-height: 150px; padding: var(--space-5); border-radius: var(--radius-lg); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-1); color: var(--text); text-decoration: none; transition: border-color var(--dur-2), box-shadow var(--dur-2), transform var(--dur-2); }
a.subject-card:hover { border-color: var(--accent-soft-2); box-shadow: var(--shadow-2); transform: translateY(-1px); text-decoration: none; }
.subject-card > .badge { align-self: flex-start; }
.subject-card__name { margin: 0; font-size: var(--text-xl); }
.subject-card__desc { margin: 0; color: var(--text-2); font-size: var(--text-sm); }
.subject-card__foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); font-weight: 650; color: var(--accent-text); }
.subject-card.is-soon { background: var(--surface-2); box-shadow: none; color: var(--text-2); }
.subject-card.is-soon .subject-card__foot { color: var(--text-3); }

/* ================================================================ touch: generous tap targets */
@media (pointer: coarse) {
  .btn-sm { --btn-h: 44px; }
  .chip { min-height: 44px; }
  .chip-static { min-height: 0; }
  .notice__close, .toast__close { width: 44px; height: 44px; }
  .toast__action { min-height: 44px; }
  .segmented > button, .segmented > label { min-height: 44px; }
  .exam-timer { min-height: 40px; }
}

/* ================================================================ reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .option.is-wrong, .sort-cat.is-wrong { animation: none; }
}
