/* Platform stylesheet.
   1 fonts and tokens (the only place a hex colour may appear)
   2 reset and base
   3 typography
   4 background layers
   5 glass
   6 utilities
   7 buttons and icons
   8 badges and tags
   9 cards and empty state
   10 tables and forms
   11 alerts, toasts, dialog, accordion
   12 progress, KPI tiles, charts
   13 lesson content and people
   14 layout: header, course sidebar, helpers, glass surfaces, style guide
   legacy rules at the end until the B tasks migrate them. */

/* == 1. fonts and tokens == */

@font-face { font-family: "Inter"; font-style: normal; font-weight: 400; font-display: swap; src: url(../fonts/inter-400.woff2) format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 500; font-display: swap; src: url(../fonts/inter-500.woff2) format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 600; font-display: swap; src: url(../fonts/inter-600.woff2) format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 700; font-display: swap; src: url(../fonts/inter-700.woff2) format("woff2"); }
@font-face { font-family: "JetBrains Mono"; font-style: normal; font-weight: 400; font-display: swap; src: url(../fonts/jetbrains-mono-400.woff2) format("woff2"); }
@font-face { font-family: "Playfair Display"; font-style: normal; font-weight: 700; font-display: swap; src: url(../fonts/playfair-display-700.woff2) format("woff2"); }

/* dark is the default; theme.js sets data-theme from localStorage or the OS preference */
:root {
  color-scheme: dark;

  --bg-0: #101412;
  --bg-1: #171c19;
  --bg-2: #1e2521;
  --bg-3: #262e29;
  --border: #2f3934;
  --border-strong: #66736b;
  --text: #ece7dc;
  --text-muted: #a8a397;
  --text-faint: #8f8b80;
  --th-bg: #232b26;
  --th-text: #f2d06b;
  --accent: #86a8d0;
  --accent-strong: #a8c4e4;
  --on-accent: #101412;
  --cta: #f5b82e;
  --on-cta: #1a1408;
  --chart-progress: #80a8d5;
  --chart-quiz: #4f7fae;
  --chart-track: #29322d;
  --pip-fair: #e9b949;
  --tint-1: #222a2b;
  --tint-2: #2c373c;
  --tint-3: #36434c;
  --tint-4: #41515f;
  --tint-5: #4c5f71;
  --on-danger: #101412;
  --ok: #9fd88b;
  --warn: #f2a56b;
  --danger: #f0715b;
  --info: #6bcac9;
  --burgundy: #d98a95;
  --ok-text: #9fd88b;
  --warn-text: #f2a56b;
  --danger-text: #f0715b;
  --info-text: #6bcac9;
  --accent-text: #86a8d0;
  --burgundy-text: #d98a95;
  --m1: #f2d06b;
  --m2: #f2b48c;
  --m3: #b7dfa3;
  --m4: #4fd1b3;
  --m5: #c8942d;
  --m6: #f0715b;
  --m7: #d98a95;
  --m8: #6fb08a;
  --code-bg: #0d1210;
  --code-text: #ece7dc;
  --code-accent: #a8c4e4;
  --glass-bg: rgb(23 28 25 / .72);
  --glass-edge: rgb(255 255 255 / .08);
  --glass-highlight: rgb(255 255 255 / .06);
  --glow-a: rgb(134 168 208 / .14);
  --glow-b: rgb(245 184 46 / .08);
  --noise-opacity: .06;
  --scrim: rgb(0 0 0 / .85);
  --backdrop: rgb(0 0 0 / .55);
  --shadow-1: 0 1px 2px rgb(0 0 0 / .4);
  --shadow-2: 0 12px 40px rgb(0 0 0 / .5);
  --focus: 0 0 0 3px rgb(134 168 208 / .45);

  --font-body: Inter, "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", Consolas, ui-monospace, monospace;
  --font-display: "Playfair Display", Georgia, serif;
  --fs-xs: .78rem;
  --fs-sm: .875rem;
  --fs-md: 1rem;
  --fs-lg: 1.15rem;
  --fs-xl: 1.35rem;
  --fs-2xl: 1.7rem;
  --fs-3xl: 2.4rem;

  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;
  --r-pill: 999px;
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --t: 180ms ease;
  --z-sticky: 10;
  --z-sidebar: 20;
  --z-topbar: 30;
  --z-backdrop: 40;
  --z-toast: 60;
}

:root[data-theme="light"] {
  color-scheme: light;

  --bg-0: #e6e1d4;
  --bg-1: #eeeae0;
  --bg-2: #f3f0e8;
  --bg-3: #dfd9cb;
  --border: #c9c2b1;
  --border-strong: #827d70;
  --text: #1b1f1d;
  --text-muted: #565d59;
  --text-faint: #5a5f5b;
  --th-bg: #dad2bf;
  --th-text: #705604;
  --accent: #335a85;
  --accent-strong: #274a6f;
  --on-accent: #ffffff;
  --cta: #f5b82e;
  --on-cta: #1a1408;
  --chart-progress: #335a85;
  --chart-quiz: #4d76a1;
  --chart-track: #d9d3c4;
  --pip-fair: #9a6a00;
  --tint-1: #dfded9;
  --tint-2: #ced2d1;
  --tint-3: #bac2c7;
  --tint-4: #a3b0bc;
  --tint-5: #899caf;
  --on-danger: #ffffff;
  --ok: #286a3d;
  --warn: #9b4414;
  --danger: #ad311e;
  --info: #115e5e;
  --burgundy: #8c2f39;
  --ok-text: #1f5a33;
  --warn-text: #8a3a0e;
  --danger-text: #8f2718;
  --info-text: #0a4f4f;
  --accent-text: #274a6f;
  --burgundy-text: #6e2530;
  --m1: #765a04;
  --m2: #94481a;
  --m3: #366a23;
  --m4: #0b6a5b;
  --m5: #59441f;
  --m6: #ad311e;
  --m7: #8c2f39;
  --m8: #245c3b;
  --code-bg: #0d1210;
  --code-text: #ece7dc;
  --code-accent: #a8c4e4;
  --glass-bg: rgb(238 234 224 / .78);
  --glass-edge: rgb(27 31 29 / .10);
  --glass-highlight: rgb(255 255 255 / .45);
  --glow-a: rgb(245 184 46 / .18);
  --glow-b: rgb(51 90 133 / .10);
  --noise-opacity: .045;
  --scrim: rgb(0 0 0 / .85);
  --backdrop: rgb(27 31 29 / .35);
  --shadow-1: 0 1px 2px rgb(27 31 29 / .06);
  --shadow-2: 0 12px 40px rgb(27 31 29 / .12);
  --focus: 0 0 0 3px rgb(51 90 133 / .35);
}

/* without JS data-theme is never set: follow the OS preference (same values as the block above) */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    color-scheme: light;

    --bg-0: #e6e1d4;
    --bg-1: #eeeae0;
    --bg-2: #f3f0e8;
    --bg-3: #dfd9cb;
    --border: #c9c2b1;
    --border-strong: #827d70;
    --text: #1b1f1d;
    --text-muted: #565d59;
    --text-faint: #5a5f5b;
    --th-bg: #dad2bf;
    --th-text: #705604;
    --accent: #335a85;
    --accent-strong: #274a6f;
    --on-accent: #ffffff;
    --cta: #f5b82e;
    --on-cta: #1a1408;
    --chart-progress: #335a85;
    --chart-quiz: #4d76a1;
    --chart-track: #d9d3c4;
    --pip-fair: #9a6a00;
    --tint-1: #dfded9;
    --tint-2: #ced2d1;
    --tint-3: #bac2c7;
    --tint-4: #a3b0bc;
    --tint-5: #899caf;
    --on-danger: #ffffff;
    --ok: #286a3d;
    --warn: #9b4414;
    --danger: #ad311e;
    --info: #115e5e;
    --burgundy: #8c2f39;
    --ok-text: #1f5a33;
    --warn-text: #8a3a0e;
    --danger-text: #8f2718;
    --info-text: #0a4f4f;
    --accent-text: #274a6f;
    --burgundy-text: #6e2530;
    --m1: #765a04;
    --m2: #94481a;
    --m3: #366a23;
    --m4: #0b6a5b;
    --m5: #59441f;
    --m6: #ad311e;
    --m7: #8c2f39;
    --m8: #245c3b;
    --code-bg: #0d1210;
    --code-text: #ece7dc;
    --code-accent: #a8c4e4;
    --glass-bg: rgb(238 234 224 / .78);
    --glass-edge: rgb(27 31 29 / .10);
    --glass-highlight: rgb(255 255 255 / .45);
    --glow-a: rgb(245 184 46 / .18);
    --glow-b: rgb(51 90 133 / .10);
    --noise-opacity: .045;
    --scrim: rgb(0 0 0 / .85);
    --backdrop: rgb(27 31 29 / .35);
    --shadow-1: 0 1px 2px rgb(27 31 29 / .06);
    --shadow-2: 0 12px 40px rgb(27 31 29 / .12);
    --focus: 0 0 0 3px rgb(51 90 133 / .35);
  }
}

/* == end tokens == */

/* == 2. reset and base == */

*, *::before, *::after { box-sizing: border-box; }
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scrollbar-color: var(--border-strong) var(--bg-0);
  /* anchors (#task-x, #graded, #lessons) stop below the sticky 60 px header */
  scroll-padding-top: 80px;
}
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: var(--fs-md);
  line-height: 1.6;
  color: var(--text);
  background: var(--bg-0);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
img, video { max-width: 100%; height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a {
  color: var(--accent);
  text-decoration: none;
  text-underline-offset: .18em;
  transition: color var(--t);
}
a:hover { color: var(--accent-strong); text-decoration: underline; }
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
::selection { background: var(--accent); color: var(--on-accent); }
::placeholder { color: var(--text-faint); opacity: 1; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--s-5) 0; }
code, kbd, samp, pre { font-family: var(--font-mono); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
  html { scroll-behavior: auto; }
}

/* == 3. typography == */

h1, h2, h3, h4 { color: var(--text); line-height: 1.25; }
h1 { font-size: var(--fs-2xl); font-weight: 700; margin: 0 0 var(--s-4); }
h2 { font-size: var(--fs-xl); font-weight: 600; margin: var(--s-5) 0 var(--s-3); }
h3 { font-size: var(--fs-lg); font-weight: 600; margin: var(--s-5) 0 var(--s-2); }
p { margin: 0 0 var(--s-3); }
small { font-size: var(--fs-sm); }

.lesson-body { max-width: 76ch; line-height: 1.7; }
.lesson-body h3 { border-left: 3px solid var(--accent); padding-left: var(--s-3); }
.lesson-body a, .user-text a, .task-text a { text-decoration: underline; }

/* == 4. background layers == */

body::before, body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
body::before {
  background-image: url(../img/noise.svg);
  opacity: var(--noise-opacity);
}
body::after {
  background:
    radial-gradient(700px circle at 0 0, var(--glow-a), transparent),
    radial-gradient(600px circle at 100% 100%, var(--glow-b), transparent);
}
.app { position: relative; z-index: 1; }

/* == 5. glass == */

.glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-edge);
  box-shadow: var(--shadow-1), inset 0 1px 0 var(--glass-highlight);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  backdrop-filter: blur(14px) saturate(140%);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass { background: var(--bg-1); }
}
@media (prefers-reduced-transparency: reduce) {
  .glass {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: var(--bg-1);
  }
  body::after { display: none; }
}

/* == 6. utilities == */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: absolute;
  left: var(--s-3);
  top: var(--s-3);
  z-index: var(--z-toast);
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-sm);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  transform: translateY(-200%);
  transition: transform var(--t);
}
.skip-link:focus, .skip-link:focus-visible { transform: none; color: var(--on-accent); text-decoration: none; }
.muted { color: var(--text-muted); }
/* shown only with JS, or only without it (theme.js sets data-js on <html>) */
:root:not([data-js]) .js-only, :root[data-js] .no-js-only { display: none !important; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.display { font-family: var(--font-display); font-weight: 700; font-size: clamp(1.8rem, 1.2rem + 2.6vw, var(--fs-3xl)); line-height: 1.25; overflow-wrap: break-word; }
/* Playfair ink runs past a tight line box (ascent 1.08 em, descent 0.25 em): display text is never clipped */
:root :is(.display, .lesson-title, .cs-title) { overflow: visible; text-overflow: clip; }
/* user-written text and long words or URLs must wrap inside their container */
.user-text, .task-text { overflow-wrap: anywhere; }

/* == 7. buttons and icons == */

.icon {
  width: 1.25em;
  height: 1.25em;
  flex-shrink: 0;
  vertical-align: -.25em;
  fill: none;
  stroke: currentColor;
}
[hidden] { display: none !important; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 40px;
  padding: var(--s-1) var(--s-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--bg-2);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: background-color var(--t), border-color var(--t), color var(--t), opacity var(--t), transform var(--t);
}
.btn .icon { width: 18px; height: 18px; }
.btn:hover:where(:not(:disabled)) { background: var(--bg-3); color: var(--text); text-decoration: none; }
.btn:active:where(:not(:disabled)) { transform: translateY(1px); }
.btn-primary { background: var(--cta); border-color: var(--cta); color: var(--on-cta); }
.btn-primary:hover:where(:not(:disabled)) { background: color-mix(in srgb, var(--cta) 88%, var(--on-cta)); color: var(--on-cta); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-accent:hover:where(:not(:disabled)) { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--on-accent); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--on-danger); }
.btn-danger:hover:where(:not(:disabled)) { background: color-mix(in srgb, var(--danger) 88%, var(--text)); color: var(--on-danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover:where(:not(:disabled)) { background: var(--bg-2); color: var(--text); }
.btn-link {
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 500;
}
.btn-link:hover:where(:not(:disabled)) { background: none; color: var(--accent-strong); text-decoration: underline; }
.btn-icon { width: 40px; padding: 0; }
.btn-sm { min-height: 32px; padding: 2px var(--s-3); font-size: var(--fs-xs); }
.btn-sm.btn-icon { width: 32px; padding: 0; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }

@media (max-width: 899px) {
  .btn, .btn-sm { min-height: 44px; }
  .btn-icon, .btn-sm.btn-icon { width: 44px; }
  .btn-link { min-height: 44px; }
}

/* == 8. badges and tags == */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: 2px 10px;
  border-radius: var(--r-pill);
  background: var(--bg-3);
  color: var(--text);
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  vertical-align: middle;
}
.badge .icon { width: 14px; height: 14px; }
.badge-ok { background: color-mix(in srgb, var(--ok) 16%, var(--bg-1)); color: var(--ok-text); }
.badge-warn { background: color-mix(in srgb, var(--warn) 16%, var(--bg-1)); color: var(--warn-text); }
.badge-danger { background: color-mix(in srgb, var(--danger) 16%, var(--bg-1)); color: var(--danger-text); }
.badge-info { background: color-mix(in srgb, var(--info) 16%, var(--bg-1)); color: var(--info-text); }
.badge-accent { background: color-mix(in srgb, var(--accent) 16%, var(--bg-1)); color: var(--accent-text); }
.badge-muted { background: var(--bg-3); color: var(--text-muted); }
.badge-score { font-family: var(--font-mono); font-weight: 400; font-variant-numeric: tabular-nums; }

/* module colour: .mN sets --m, the chip reads it; 12 percent tint keeps every mN at AA in both themes */
.m1 { --m: var(--m1); }
.m2 { --m: var(--m2); }
.m3 { --m: var(--m3); }
.m4 { --m: var(--m4); }
.m5 { --m: var(--m5); }
.m6 { --m: var(--m6); }
.m7 { --m: var(--m7); }
.m8 { --m: var(--m8); }
.tag, .module-tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--m, var(--accent)) 12%, var(--bg-1));
  color: var(--m, var(--accent-text));
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

/* == 9. cards and empty state == */

.card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: var(--s-5);
  margin: 0 0 var(--s-4);
  box-shadow: var(--shadow-1);
  min-width: 0;
  transition: border-color var(--t), opacity var(--t);
}
.card-title { margin: 0 0 var(--s-2); color: var(--text); font-size: var(--fs-md); font-weight: 600; line-height: 1.35; }
.card-title .badge { margin-left: var(--s-2); vertical-align: middle; }
.card-accent-ok { border-left: 3px solid var(--ok); }
.card-accent-warn { border-left: 3px solid var(--warn); }
.card-accent-danger { border-left: 3px solid var(--danger); background: color-mix(in srgb, var(--danger) 5%, var(--bg-1)); }
.card-accent-info { border-left: 3px solid var(--info); }
.card-accent-accent { border-left: 3px solid var(--accent); }
.card-accent-burgundy { border-left: 3px solid var(--burgundy); }

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-7) var(--s-5);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r);
  background: color-mix(in srgb, var(--bg-1) 70%, transparent);
  color: var(--text-muted);
  text-align: center;
}
.empty > .icon { width: 40px; height: 40px; color: var(--text-muted); }
.empty p { margin: 0; max-width: 48ch; }
.empty .btn { margin-top: var(--s-2); }

/* one rhythm inside every component: no trailing margin on the last child */
:is(.card, .callout, .alert, .dialog-body, .acc-body, .quiz, .task, .grade-body, .kpi, .task-answer) > :last-child { margin-bottom: 0; }
:is(.card, .callout, .dialog-body, .acc-body, .quiz, .task) > :first-child { margin-top: 0; }
/* prose wrappers inside a component: the last margin would escape and widen the bottom padding */
:is(.lesson-body, .callout-body) > :last-child { margin-bottom: 0; }

/* == 10. tables and forms == */

/* one table system: every .table sits in .table-wrap; one font and size in every cell, digits
   line up through tabular-nums; text, badges left; numbers, dates, actions right */
.table-wrap {
  position: relative;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  margin: 0 0 var(--s-4);
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--bg-1);
  box-shadow: var(--shadow-1);
  -webkit-overflow-scrolling: touch;
}
.table-wrap > .table { margin: 0; border: 0; }
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-1);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
  line-height: 1.45;
}
.table th, .table td {
  padding: var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--border);
  font-family: inherit;
  font-size: inherit;
  text-align: left;
  vertical-align: middle;
  overflow-wrap: normal;
  word-break: normal;
}
/* no monospace inside a table: score badges and .mono fall back to the table font */
.table .mono, .table .badge-score { font-family: inherit; font-variant-numeric: tabular-nums; }
/* user text wraps between words; only a single word longer than the column breaks */
.table .user-text, .table .task-text { overflow-wrap: break-word; }
/* text columns keep a floor, so a narrow screen scrolls the wrap instead of squeezing words */
.table-wrap > .table td:not(.num, .check-col, .actions) { min-width: 8rem; }
.table-top td { vertical-align: top; }
.table-wrap > .table td.col-wide { min-width: 15rem; }
.cell-grader { min-width: 0; }
.cell-date { display: block; white-space: nowrap; }
.cell-name { white-space: nowrap; }
/* one row per record under 600 px: label and value pairs instead of a scrolling grid */
@media (max-width: 599px) {
  .table-wrap > .table.table-stack { min-width: 0; }
  .table-stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .table-stack, .table-stack tbody, .table-stack tr { display: block; }
  .table-stack tbody tr { padding: var(--s-3) var(--s-3); border-bottom: 1px solid var(--border); }
  .table-stack tbody tr:last-child { border-bottom: 0; }
  .table-wrap > .table.table-stack td { display: flex; align-items: baseline; gap: var(--s-3); min-width: 0; padding: var(--s-1) 0; border: 0; text-align: left; white-space: normal; }
  .table-stack td::before { content: attr(data-label); flex: 0 0 5.5rem; color: var(--text-muted); font-size: var(--fs-xs); }
  .table-stack td:first-child { font-weight: 600; }
  .table-stack td:first-child::before { content: none; }
  .table-wrap > .table.table-stack td:empty { display: none; }
}
.table thead th {
  background: var(--th-bg);
  color: var(--th-text);
  font-weight: 600;
  white-space: nowrap;
}
.table tbody tr:last-child > * { border-bottom: 0; }
.table td, .table th { transition: background-color var(--t); }
.table tbody tr:hover > td { background: color-mix(in srgb, var(--accent) 6%, var(--bg-1)); }
.table td.table-none { color: var(--text-muted); }
.table .num { text-align: right; white-space: nowrap; }
.table thead th a { color: inherit; }
.table th.sortable a, .table th[aria-sort] a {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
  text-underline-offset: .25em;
}
.table th.sortable a:hover, .table th[aria-sort] a:hover { color: inherit; text-decoration-color: currentColor; }
.table th[aria-sort] a { text-decoration-color: currentColor; }
th[aria-sort] a::after {
  content: "";
  border: 4px solid transparent;
  border-top-color: currentColor;
  margin-top: 4px;
}
th[aria-sort="ascending"] a::after { border-top-color: transparent; border-bottom-color: currentColor; margin: -4px 0 0; }
.table th.num a { justify-content: flex-end; }
.table td.actions, .table th.actions { width: 1%; text-align: right; white-space: nowrap; }
.table td.actions > * { display: inline-flex; margin: 2px 0 2px var(--s-2); vertical-align: middle; }
.table td.actions > :first-child { margin-left: 0; }
.table td.actions > form > .btn { margin: 0; }
/* "Відкрити": the eye icon button of a row */
.btn.btn-open { width: 36px; min-height: 36px; padding: 0; }
/* every small icon button of a row action cell has the size of the eye button */
.table td.actions .btn-sm.btn-icon { width: 36px; min-height: 36px; padding: 0; }
.table .check-col { width: 44px; padding-left: 0; padding-right: 0; text-align: center; }
.check-col label { display: inline-flex; align-items: center; justify-content: center; width: 44px; min-height: 32px; cursor: pointer; }
.check-col input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); cursor: inherit; }

.field { display: flex; flex-direction: column; gap: var(--s-1); margin: 0 0 var(--s-4); min-width: 0; }
.field label, .field .label { color: var(--text); font-size: var(--fs-sm); font-weight: 600; }
.input, .select, .textarea {
  width: 100%;
  max-width: 640px;
  min-height: 40px;
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  background: var(--bg-2);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-md);
  line-height: 1.4;
  transition: border-color var(--t), background-color var(--t);
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-muted); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { border-color: var(--accent); outline-offset: 1px; }
.textarea { min-height: 160px; resize: vertical; line-height: 1.55; }
.select { cursor: pointer; }
.input:disabled, .select:disabled, .textarea:disabled {
  border-color: var(--border);
  background: var(--bg-3);
  color: var(--text-faint);
  cursor: not-allowed;
}
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.help { margin: 0; color: var(--text-muted); font-size: var(--fs-sm); }
.field-error { display: flex; align-items: flex-start; gap: var(--s-1); margin: 0; color: var(--danger-text); font-size: var(--fs-sm); font-weight: 500; }
.field-error .icon { width: 16px; height: 16px; margin-top: 3px; }
.check {
  display: flex;
  align-items: flex-start;
  gap: var(--s-2);
  min-height: 40px;
  padding: var(--s-2) 0;
  color: var(--text);
  font-size: var(--fs-sm);
  cursor: pointer;
}
.check input { width: 18px; height: 18px; margin: 2px 0 0; flex-shrink: 0; accent-color: var(--accent); cursor: inherit; }
.check:has(input:disabled) { color: var(--text-faint); cursor: not-allowed; }
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s-3); margin: 0 0 var(--s-4); }
.filters .field { flex: 1 1 180px; max-width: 280px; margin: 0; }
/* filters inside the "Фільтри" accordion: a plain inline form from 900 px (summary hidden, no
   frame), a closed-by-default accordion below (app.js filtersAcc) */
details.acc.filters-acc > .acc-body { padding: 0; }
details.acc.filters-acc .filters { margin: 0; }
@media (min-width: 900px) {
  details.acc.filters-acc { margin: 0 0 var(--s-4); border: 0; border-radius: 0; background: none; }
  details.acc.filters-acc > summary.filters-summary { display: none; }
}
@media (max-width: 899px) {
  details.acc.filters-acc { margin: 0 0 var(--s-4); }
  details.acc.filters-acc > .acc-body { padding: var(--s-3) var(--s-4) var(--s-4); }
  summary.filters-summary > .icon + .icon { color: var(--accent-text); }
  /* the markup is open (no JS keeps the form usable); with JS the closed state applies from the first paint
     until app.js has run (data-app): by then filtersAcc has closed it, and if it failed the form stays open */
  :root[data-js]:not([data-app]) details.acc.filters-acc[data-active="0"] > .acc-body { display: none; }
  :root[data-js]:not([data-app]) details.acc.filters-acc[data-active="0"] > summary.acc-summary { border-bottom: 0; border-radius: var(--r); }
  :root[data-js]:not([data-app]) details.acc.filters-acc[data-active="0"] > summary.acc-summary > .icon:first-child { transform: none; }
}
/* table pagination (templates/_pager.html): size form left, page links right, wraps */
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3); margin-top: var(--s-3); }
.pager-size { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); margin: 0; font-size: var(--fs-sm); }
.pager-size label { color: var(--text-muted); }
.pager-size .select { width: auto; min-width: 5rem; font-size: var(--fs-sm); }
/* from 900 px the pager controls are all small (32 px), under 900 px all 44 px */
@media (min-width: 900px) {
  .pager-size .select { min-height: 32px; padding-top: 2px; padding-bottom: 2px; }
}
.pager-nav { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3); margin-left: auto; }
.pager-status { color: var(--text-muted); font-size: var(--fs-sm); white-space: nowrap; }
.pager-pages { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-1); margin: 0; padding: 0; list-style: none; }
.pager-num { min-width: 36px; justify-content: center; font-variant-numeric: tabular-nums; }
.pager-num[aria-current="page"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--bg-1)); color: var(--text); font-weight: 600; }
.pager-gap { padding: 0 var(--s-1); color: var(--text-muted); }
@media (max-width: 599px) {
  .pager-nav { margin-left: 0; }
  .pager-word { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .pager-num { min-width: 44px; }
}

@media (max-width: 899px) {
  .input, .select { min-height: 44px; }
  .check { min-height: 44px; }
  .check-col label { min-height: 44px; }
  .table th.sortable a, .table th[aria-sort] a { min-height: 44px; }
  .btn.btn-open { width: 44px; min-height: 44px; }
  .table td.actions .btn-sm.btn-icon { width: 44px; min-height: 44px; }
  /* text links in table cells: a 44 px tall hit area, the negative margin keeps the row height */
  .table td > a:only-child:not(.btn), .team-name-text > a:only-child {
    display: inline-block; padding: 12px 0; margin: -12px 0;
  }
}
@media (max-width: 599px) {
  .filters .field { flex-basis: 100%; max-width: none; }
  .filters > .btn { flex: 1 1 100%; }
}

/* == 11. alerts, toasts, dialog, accordion == */

.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  margin: 0 0 var(--s-3);
  padding: var(--s-3) var(--s-4);
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--bg-1);
  color: var(--text);
  font-size: var(--fs-sm);
}
.alert > .icon { width: 18px; height: 18px; margin-top: 2px; }
.alert p { margin: 0; }
.alert-success { border-color: color-mix(in srgb, var(--ok) 35%, var(--bg-1)); background: color-mix(in srgb, var(--ok) 12%, var(--bg-1)); color: var(--ok-text); }
.alert-error { border-color: color-mix(in srgb, var(--danger) 35%, var(--bg-1)); background: color-mix(in srgb, var(--danger) 12%, var(--bg-1)); color: var(--danger-text); }
.alert-info { border-color: color-mix(in srgb, var(--info) 35%, var(--bg-1)); background: color-mix(in srgb, var(--info) 12%, var(--bg-1)); color: var(--info-text); }
.alert-warning { border-color: color-mix(in srgb, var(--warn) 35%, var(--bg-1)); background: color-mix(in srgb, var(--warn) 12%, var(--bg-1)); color: var(--warn-text); }
.alert .toast-close { margin: -6px -8px -6px auto; color: inherit; }

.toast-stack {
  position: fixed;
  right: var(--s-4);
  bottom: var(--s-4);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  width: min(380px, calc(100vw - 2 * var(--s-4)));
  pointer-events: none;
}
.toast-stack > .alert { margin: 0; box-shadow: var(--shadow-2); pointer-events: auto; animation: rise var(--t); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

dialog.dialog {
  width: min(520px, calc(100vw - 2 * var(--s-4)));
  max-width: none;
  max-height: calc(100vh - 2 * var(--s-5));
  padding: 0;
  border: 1px solid var(--glass-edge);
  border-radius: var(--r-lg);
  color: var(--text);
}
dialog.dialog[open] { display: flex; flex-direction: column; animation: rise var(--t); }
dialog.dialog.dialog-lg { width: min(880px, calc(100vw - 2 * var(--s-4))); }
dialog.dialog::backdrop {
  /* raw fallback: ::backdrop does not inherit custom properties in older browsers, so the token can be missing here */
  background: var(--backdrop, rgb(0 0 0 / .55));
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-4) var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--border);
}
.dialog-head h2, .dialog-head h3 { margin: 0; font-size: var(--fs-lg); }
.dialog-body { flex: 1 1 auto; min-height: 0; overflow: auto; padding: var(--s-5); }
.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--s-2);
  padding: var(--s-4) var(--s-5);
  border-top: 1px solid var(--border);
}
.dl-grid { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--s-2) var(--s-5); margin: 0 0 var(--s-5); font-size: var(--fs-sm); }
.dl-grid dt { color: var(--text-muted); }
.dl-grid dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

details.acc {
  margin: 0 0 var(--s-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--bg-1);
}
summary.acc-summary {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-height: 44px;
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r);
  color: var(--text);
  font-weight: 600;
  list-style: none;
  cursor: pointer;
  transition: background-color var(--t);
}
summary.acc-summary::-webkit-details-marker { display: none; }
summary.acc-summary:hover { background: var(--bg-2); }
summary.acc-summary > .icon { color: var(--text-muted); transition: transform var(--t); }
details.acc[open] > summary.acc-summary { border-bottom: 1px solid var(--border); border-radius: var(--r) var(--r) 0 0; }
details.acc[open] > summary.acc-summary > .icon:first-child { transform: rotate(90deg); }
summary.acc-summary > .badge { margin-left: auto; }
.acc-body { padding: var(--s-4); }

/* == 12. progress, KPI tiles, charts == */

.progress { height: 6px; border-radius: var(--r-pill); background: var(--bg-3); overflow: hidden; }
.progress > svg { display: block; width: 100%; height: 100%; }
.progress-fill { fill: var(--accent); }

.kpi-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s-4); margin: 0 0 var(--s-5); }
.kpi {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  min-width: 0;
  padding: var(--s-4) var(--s-5);
  border-radius: var(--r-lg);
}
.kpi-label { color: var(--text-muted); font-size: var(--fs-xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
/* stat values: the text sans with proportional figures (tabular only where numbers align) */
.kpi-value { color: var(--text); font-size: var(--fs-2xl); font-weight: 600; letter-spacing: -.01em; line-height: 1.2; }
.kpi-hint { color: var(--text-muted); font-size: var(--fs-xs); }

/* dashboard (plan 5.5): view tabs, toolbars, the progress bullets (charts), the students x
   courses matrix (table) and the detail dialog loaded on demand */
.dash-section { margin: 0 0 var(--s-6); }
.view-tabs { display: flex; gap: var(--s-1); margin: 0 0 var(--s-4); border-bottom: 1px solid var(--border); }
.view-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 var(--s-4);
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  color: var(--text-muted);
  font-weight: 600;
  text-decoration: none;
  transition: color var(--t), background-color var(--t);
}
.view-tab:hover { background: var(--bg-2); color: var(--text); text-decoration: none; }
.view-tab[aria-selected="true"], .view-tab[aria-current="true"] { color: var(--text); }
.view-tab[aria-selected="true"]::after, .view-tab[aria-current="true"]::after { content: ""; position: absolute; left: var(--s-3); right: var(--s-3); bottom: -1px; height: 2px; border-radius: 2px 2px 0 0; background: var(--accent); }
.view-tab:focus-visible { outline-offset: -2px; }
.chart-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-2) var(--s-4); margin: 0 0 var(--s-3); }
.chart-toolbar .help { margin: 0; }
.order-links { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--border); border-radius: var(--r-sm); }
.order-link { display: inline-flex; align-items: center; min-height: 36px; padding: 0 var(--s-3); border-radius: 4px; color: var(--text-muted); font-size: var(--fs-sm); font-weight: 500; text-decoration: none; transition: background-color var(--t), color var(--t); }
.order-link:hover { background: var(--bg-2); color: var(--text); text-decoration: none; }
.order-link[aria-current="true"] { background: color-mix(in srgb, var(--accent) 12%, var(--bg-1)); color: var(--accent-text); font-weight: 600; }
.row-dialog-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3); margin: 0 0 var(--s-4); font-size: var(--fs-sm); }
[aria-busy="true"] { cursor: progress; }

/* grade pips: the grade is printed next to a filled pip; no grade is a hollow ring of the same
   size (the accessible name says "без оцінки") */
.pip { display: inline-block; flex: none; box-sizing: border-box; width: 8px; height: 8px; border-radius: 50%; }
.pip-bad { background: var(--danger); }
.pip-fair { background: var(--pip-fair); }
.pip-good { background: var(--ok); }
.pip-none { border: 1.5px solid var(--text-muted); background: transparent; }
/* on a tinted matrix cell the muted ink is below 3:1, the ring takes the text ink */
.cell:not(.t0) .pip-none { border-color: var(--text); }

/* legends: a definition list, one line per encoding, a bold label and chips (swatch plus text,
   never broken inside); the label stacks over its chips under 600 px. Inside the "Легенда"
   accordion (the filters pattern): a plain block from 900 px, closed by default below. */
details.acc.legend-acc { margin: 0 0 var(--s-4); }
.legend {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: start;
  gap: var(--s-2) var(--s-5);
  margin: 0;
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r);
  background: var(--bg-1);
  font-size: var(--fs-xs);
  line-height: 18px;
}
.legend-row { display: contents; }
.legend dt { margin: 0; color: var(--text); font-weight: 600; }
.legend dd { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-1) var(--s-4); margin: 0; color: var(--text-muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; min-height: 18px; white-space: nowrap; }
.legend-bullet { display: block; flex: none; }
.legend .swatch { flex: none; width: 12px; height: 12px; border-radius: 3px; box-shadow: inset 0 0 0 1px var(--border-strong); }
@media (max-width: 899px) {
  details.acc.legend-acc > .acc-body { padding: 0; }
  details.acc.legend-acc .legend { background: none; }
}
@media (max-width: 599px) {
  .legend { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .legend dd { margin: 0 0 var(--s-2); }
  .legend .legend-row:last-child dd { margin-bottom: 0; }
}
.sw-t0 { background: var(--bg-1); }
.sw-t1 { background: var(--tint-1); }
.sw-t2 { background: var(--tint-2); }
.sw-t3 { background: var(--tint-3); }
.sw-t4 { background: var(--tint-4); }
.sw-t5 { background: var(--tint-5); }

/* the summary line and bulk toggles above the admin groups */
.groups-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-1) var(--s-4); margin: 0 0 var(--s-2); }
.groups-summary { margin: 0; color: var(--text-muted); font-size: var(--fs-sm); }
.groups-bulk { display: inline-flex; gap: var(--s-4); }
.groups-bulk .btn-link { display: inline-flex; align-items: center; font-size: var(--fs-sm); }

/* group head toggle (bullets and matrix): title strongest, count badge muted */
.group-toggle { display: inline-flex; align-items: center; gap: var(--s-2); min-height: 44px; max-width: 100%; margin: 0; padding: 0 var(--s-2) 0 0; border: 0; border-radius: var(--r-sm); background: none; color: var(--text); font: inherit; font-size: var(--fs-sm); font-weight: 600; line-height: 1.3; text-align: left; text-decoration: none; cursor: pointer; }
.group-toggle:hover { color: var(--accent-text); text-decoration: none; }
.group-toggle > .icon { flex: none; color: var(--text-muted); transition: transform var(--t); }
.group-toggle[aria-expanded="true"] > .icon { transform: rotate(90deg); }
/* the title: the position on the first line, the whole name on the second, never split */
.group-title { display: flex; flex-direction: column; min-width: 0; }
.group-role { color: var(--text-muted); font-size: var(--fs-xs); font-weight: 500; }
.group-name { white-space: nowrap; }
@media (max-width: 1099px) {
  .group-name { white-space: normal; }
}
.group-toggle .badge { flex: none; font-weight: 500; }

/* progress bullets: overall progress on a 0..100 track with a 50 tick, quizzes under it;
   bar widths are percent rect attributes, the radius is rx */
.bullet { display: block; width: 100%; height: 18px; overflow: visible; }
.bl-track { fill: var(--chart-track); }
.bl-progress { fill: var(--chart-progress); }
.bl-quiz { fill: var(--chart-quiz); }
.bl-tick { fill: var(--border-strong); transform: translateX(-.75px); }

/* bar tooltips (hover and keyboard focus aid, never the only source): an empty zone over each
   bar and the grade carries data-tip, a cell's focus shows all three (data-focus-tip); the text
   is in the cell's accessible name, so the zones are aria-hidden */
.bt-bars { position: relative; display: block; }
.tip-zone { position: absolute; left: 0; right: 0; }
.tip-progress { top: 0; height: 12px; }
.tip-quiz { top: 12px; height: 7px; }
.bt-grade[data-tip] { position: relative; }
.bt-btn { position: relative; }
[data-tip]::after, [data-focus-tip]::after {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  z-index: calc(var(--z-sticky) + 5);
  width: max-content;
  max-width: 18rem;
  padding: 4px 8px;
  border-radius: var(--r-sm);
  background: var(--text);
  box-shadow: var(--shadow-2);
  color: var(--bg-1);
  font-size: var(--fs-xs);
  font-weight: 500;
  line-height: 1.4;
  text-align: left;
  white-space: pre-line;
  pointer-events: none;
}
.bt-cell:last-child [data-tip]::after, .bt-cell:last-child [data-focus-tip]::after { left: auto; right: 0; }
.bt-grade[data-tip]::after { left: -4px; }
.bt-cell:last-child .bt-grade[data-tip]::after { right: -4px; }
/* generated only while shown, so a hidden tooltip never widens the page */
@media (hover: hover) {
  [data-tip]:hover::after { content: attr(data-tip); }
}
.bt-btn:focus-visible[data-focus-tip]::after { content: attr(data-focus-tip); }
.bt-btn:focus-visible [data-tip]::after { content: none; }
/* Escape hides the tooltip shown (app.js tips) until the pointer or the focus moves on */
:root[data-tips-hidden] [data-tip]::after, :root[data-tips-hidden] [data-focus-tip]::after { content: none; }

/* charts tab: one grid for the head, the group rows and every student line */
.bt { display: flex; flex-direction: column; gap: var(--s-3); }
.bt-row {
  display: grid;
  grid-template-columns: 15rem;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  align-items: center;
  gap: 0 var(--s-4);
  padding: var(--s-1) var(--s-4);
}
.bt-head {
  position: sticky;
  top: 61px;
  z-index: var(--z-sticky);
  padding-top: var(--s-2);
  padding-bottom: var(--s-2);
  border-radius: var(--r);
  background: var(--bg-1);
  box-shadow: var(--shadow-1);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 600;
}
.bt-course { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.bt-course-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bt-group { border-radius: var(--r-lg); background: var(--bg-1); box-shadow: var(--shadow-1); }
.bt-sum-row { min-height: 60px; padding-top: var(--s-2); padding-bottom: var(--s-2); border-radius: var(--r-lg); background: var(--bg-2); }
.bt-sum-row:has(+ .bt-lines:not([hidden])) { border-radius: var(--r-lg) var(--r-lg) 0 0; }
.bt-lines { padding: var(--s-1) 0; }
.bt-line { min-height: 52px; }
.bt-name { min-width: 0; }
.bt-cell { min-width: 0; }
.bt-course-m { display: none; }
.bt-person { display: inline-flex; align-items: center; gap: var(--s-2); max-width: 100%; min-height: 44px; color: var(--text); font-size: var(--fs-sm); font-weight: 500; text-decoration: none; }
.bt-person:hover { color: var(--accent-text); text-decoration: none; }
.bt-person .avatar { flex: none; width: 26px; height: 26px; font-size: .68rem; }
.bt-person-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bt-btn {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 48px;
  margin: 0 -6px;
  padding: 6px;
  border-radius: var(--r-sm);
  color: var(--text);
  text-decoration: none;
  transition: background-color var(--t);
}
.bt-btn:hover { background: var(--bg-2); color: var(--text); text-decoration: none; }
.bt-btn:focus-visible { outline-offset: 0; }
.bt-sum { display: flex; flex-direction: column; gap: 3px; padding: 6px 0; }
.bt-values { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--s-2); color: var(--text-muted); font-size: var(--fs-xs); line-height: 1.35; white-space: nowrap; font-variant-numeric: tabular-nums; }
.bt-pct { display: inline-flex; align-items: center; gap: 3px; color: var(--text); font-size: var(--fs-sm); font-weight: 500; }
.bt-pct .icon { width: 12px; height: 12px; }
.bt-btn.is-zero .bt-pct { color: var(--text-muted); }
.bt-grade { display: inline-flex; align-items: center; gap: 4px; }
.bt-out { color: var(--text-muted); font-size: var(--fs-xs); }
.bt-none { margin: 0; padding: var(--s-3) var(--s-4); color: var(--text-muted); font-size: var(--fs-sm); }
.bt-more { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3); padding: var(--s-2) var(--s-4); }
.bt-more .help { margin: 0; }

/* matrix: students x courses, a head and a lines tbody per mentor group (Admin), sticky head
   and name column; cells are tinted by progress and set apart by the surface, not by lines */
.matrix-wrap { position: relative; max-height: 76vh; overflow: auto; border-radius: var(--r-lg); background: var(--bg-1); box-shadow: var(--shadow-1); }
.matrix-wrap:focus-visible { outline-offset: -2px; }
.matrix { width: 100%; min-width: max-content; border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.matrix th, .matrix td { padding: 0; border-bottom: 2px solid var(--bg-1); font-weight: 400; text-align: left; vertical-align: middle; }
.matrix thead th { position: sticky; top: 0; z-index: 3; padding: var(--s-3); background: var(--th-bg); color: var(--th-text); font-weight: 600; white-space: nowrap; }
.matrix thead th.m-course { min-width: 7.5rem; text-align: center; }
.m-course-title { display: block; max-width: 16rem; margin: 0 auto; overflow: hidden; text-overflow: ellipsis; }
.matrix .m-student { position: sticky; left: 0; z-index: 2; min-width: 11rem; max-width: 15rem; padding: 0 var(--s-3); background: var(--bg-1); }
.matrix thead th.m-student { z-index: 4; background: var(--th-bg); text-align: left; }
.m-head > th, .m-head > td, .matrix .m-head > .m-student { background: var(--bg-2); }
.matrix .m-sum { padding: var(--s-2) var(--s-3); color: var(--text-muted); font-size: var(--fs-xs); text-align: center; white-space: nowrap; }
.m-sum-pct { color: var(--text); font-size: var(--fs-sm); font-weight: 500; }
.m-sum-in { display: inline-flex; align-items: center; gap: var(--s-2); }
.m-name { display: inline-flex; align-items: center; gap: var(--s-2); max-width: 100%; min-height: 44px; color: var(--text); font-weight: 500; text-decoration: none; }
.m-name > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-name:hover { color: var(--accent-text); text-decoration: none; }
.m-name .avatar { flex: none; width: 26px; height: 26px; font-size: .68rem; }
.cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 52px;
  padding: var(--s-1) var(--s-2);
  border-left: 2px solid var(--bg-1);
  background: var(--bg-1);
  color: var(--text);
  text-align: center;
  text-decoration: none;
  transition: filter var(--t);
}
.cell:hover { color: var(--text); filter: brightness(1.08); text-decoration: none; }
.cell:focus-visible { outline-offset: -3px; }
.cell-pct { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-md); font-weight: 500; line-height: 1.15; }
.cell-pct .icon { width: 14px; height: 14px; }
.cell-sub { display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2); min-height: 1.1em; font-size: var(--fs-xs); white-space: nowrap; }
.cell-grade { display: inline-flex; align-items: center; gap: 4px; }
.cell.t0 { color: var(--text-muted); }
.cell.t1 { background: var(--tint-1); }
.cell.t2 { background: var(--tint-2); }
.cell.t3 { background: var(--tint-3); }
.cell.t4 { background: var(--tint-4); }
.cell.t5 { background: var(--tint-5); }
.cell-none { display: flex; align-items: center; justify-content: center; min-height: 52px; padding: var(--s-2); border-left: 2px solid var(--bg-1); color: var(--text-muted); font-size: var(--fs-xs); }
.m-none > td { padding: var(--s-3); color: var(--text-muted); }
.m-more-row > td { padding: var(--s-2) var(--s-3); }
.m-more-row .help { margin-left: var(--s-3); }

/* detail dialog: three stat tiles, counts, lessons, quizzes, tasks */
.stat-tri { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-3); margin: 0 0 var(--s-5); }
.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: var(--s-3) var(--s-4); border-radius: var(--r); background: var(--bg-2); }
.stat-label { color: var(--text-muted); font-size: var(--fs-xs); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.stat-value { display: inline-flex; align-items: center; gap: var(--s-2); color: var(--text); font-size: var(--fs-xl); font-weight: 600; line-height: 1.25; }
.stat-hint { color: var(--text-muted); font-size: var(--fs-xs); }
.stat .progress { margin-top: var(--s-2); }
.dialog-section { margin: var(--s-5) 0 var(--s-2); color: var(--text-muted); font-size: var(--fs-xs); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.lesson-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 var(--s-4); margin: 0; padding: 0; font-size: var(--fs-sm); list-style: none; }
.lesson-list li { display: flex; justify-content: space-between; gap: var(--s-2); min-width: 0; padding: var(--s-1) 0; border-bottom: 1px solid var(--border); }
.lesson-when { color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.dialog-body .table-wrap { box-shadow: none; }

@media (max-width: 1099px) {
  .bt-row { grid-template-columns: 12rem; gap: 0 var(--s-3); }
}
@media (max-width: 899px) {
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); }
  .kpi { padding: var(--s-3) var(--s-4); }
  .kpi-value { font-size: var(--fs-xl); }
  .order-link { min-height: 44px; }
  /* one card per student: the name, then the courses two or more per row, each named */
  .bt-head { display: none; }
  .bt { gap: var(--s-4); }
  .bt-row { grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); grid-auto-flow: row; gap: var(--s-1) var(--s-4); padding: var(--s-3); }
  .bt-row > .bt-name { grid-column: 1 / -1; }
  .bt-course-m { display: block; overflow: hidden; color: var(--text-muted); font-size: .7rem; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
  .bt-group { background: none; box-shadow: none; }
  .bt-sum-row, .bt-sum-row:has(+ .bt-lines:not([hidden])) { border-radius: var(--r-lg); box-shadow: var(--shadow-1); }
  .bt-lines { display: flex; flex-direction: column; gap: var(--s-2); padding: 0; }
  .bt-lines[hidden] { display: none; }
  .bt-group > .bt-sum-row + .bt-lines { margin-top: var(--s-2); }
  .bt-line { border-radius: var(--r-lg); background: var(--bg-1); box-shadow: var(--shadow-1); }
  .bt-none, .bt-more { border-radius: var(--r-lg); background: var(--bg-1); }
  .matrix-wrap { max-height: none; overflow-x: auto; overflow-y: visible; }
  .matrix .m-student { min-width: 8.5rem; max-width: 10.5rem; }
  .matrix thead th.m-course { min-width: 96px; }
  .m-course-title { max-width: 7rem; }
  .stat-tri { grid-template-columns: minmax(0, 1fr); }
}

/* == 13. lesson content and people == */

/* long URLs and words in lesson prose wrap instead of widening the page */
.lesson-body { overflow-wrap: break-word; }
.lesson-body > p, .lesson-body li { margin-bottom: var(--s-3); }
.lesson-body ul, .lesson-body ol { margin: 0 0 var(--s-4); padding-left: var(--s-5); }
.lesson-body li { margin-bottom: var(--s-1); }
.lesson-body strong { color: var(--text); font-weight: 600; }
.lesson-body :not(pre) > code {
  padding: 1px 5px;
  border-radius: var(--r-sm);
  background: var(--bg-3);
  font-size: .9em;
  overflow-wrap: anywhere;
}
.lesson-body table { width: 100%; margin: var(--s-4) 0; border-collapse: collapse; font-size: var(--fs-sm); }
.lesson-body th, .lesson-body td { padding: var(--s-2) var(--s-3); border: 1px solid var(--border); text-align: left; vertical-align: top; }
.lesson-body th { background: var(--bg-3); font-weight: 600; }
.lesson-body .ta-left { text-align: left; }
.lesson-body .ta-center { text-align: center; }
.lesson-body .ta-right { text-align: right; }
.lesson-body .table-wrap table { margin: 0; }
.lesson-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); margin: 0 0 var(--s-3); font-size: var(--fs-sm); }

.callout {
  --c: var(--info);
  --c-text: var(--info-text);
  margin: var(--s-4) 0;
  padding: var(--s-4) var(--s-5);
  border: 1px solid color-mix(in srgb, var(--c) 22%, var(--bg-1));
  border-left: 3px solid var(--c);
  border-radius: var(--r);
  background: color-mix(in srgb, var(--c) 12%, var(--bg-1));
}
.callout-title { display: flex; align-items: center; gap: var(--s-2); margin: 0 0 var(--s-2); color: var(--c-text); font-size: var(--fs-sm); font-weight: 600; line-height: 1.4; }
.callout-title .icon { width: 18px; height: 18px; }
.callout p, .callout li { font-size: .95rem; }
.callout-info { --c: var(--info); --c-text: var(--info-text); }
.callout-tip { --c: var(--ok); --c-text: var(--ok-text); }
.callout-note { --c: var(--accent); --c-text: var(--accent-text); }
.callout-example { --c: var(--warn); --c-text: var(--warn-text); }
.callout-important { --c: var(--burgundy); --c-text: var(--burgundy-text); }
.callout-warning { --c: var(--danger); --c-text: var(--danger-text); }
.callout-neutral { --c: var(--border-strong); --c-text: var(--text); }

pre.code, .lesson-body pre {
  position: relative;
  margin: var(--s-3) 0 var(--s-4);
  padding: var(--s-3) var(--s-5);
  padding-right: 7rem;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--code-bg);
  color: var(--code-accent);
  font-family: var(--font-mono);
  font-size: .84rem;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow-x: auto;
}
pre.code code, .lesson-body pre code { font: inherit; color: inherit; background: none; padding: 0; }
pre.code :focus-visible, .lesson-body pre :focus-visible { outline-color: var(--code-accent); }
pre .copy-btn {
  position: absolute;
  top: var(--s-2);
  right: var(--s-2);
  min-height: 28px;
  padding: 2px var(--s-3);
  border: 1px solid color-mix(in srgb, var(--code-text) 18%, var(--code-bg));
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--code-text) 10%, var(--code-bg));
  color: var(--code-text);
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  font-weight: 500;
  opacity: 0;
}
pre:hover .copy-btn, pre:focus-within .copy-btn { opacity: 1; }
@media (hover: none) { pre .copy-btn { opacity: 1; } }
pre .copy-btn:hover { background: var(--code-accent); border-color: var(--code-accent); color: var(--code-bg); }

figure.lesson-image {
  margin: var(--s-5) 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--bg-1);
  transition: border-color var(--t);
}
figure.lesson-image:hover { border-color: var(--accent); }
figure.lesson-image img, figure.lesson-image svg { display: block; max-width: 100%; height: auto; margin: 0 auto; cursor: zoom-in; }
figure.lesson-image img { border: 0; border-radius: 0; }
figure.lesson-image figcaption { padding: var(--s-2) var(--s-4); border-top: 1px solid var(--border); color: var(--text-muted); font-size: var(--fs-xs); line-height: 1.5; }

.lesson-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--s-3);
  margin-top: var(--s-6);
  padding-top: var(--s-5);
  border-top: 1px solid var(--border);
}
.lesson-nav > :last-child { margin-left: auto; }

.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: calc(var(--z-topbar) + 1);
  height: 3px;
  pointer-events: none;
}
.reading-progress > svg { display: block; width: 100%; height: 100%; }
.reading-progress rect { fill: var(--accent); }
:root:not([data-js]) .reading-progress { display: none; }

.quiz, .task {
  margin: var(--s-5) 0;
  padding: var(--s-5);
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--bg-1);
}
.lesson-body :is(.quiz, .task) h3 { margin: 0 0 var(--s-3); padding-left: 0; border-left: 0; font-size: var(--fs-md); font-weight: 700; }
.task > h3 { display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--s-2); color: var(--warn-text); }
.quiz-q { margin: var(--s-4) 0 var(--s-2); color: var(--text); font-size: var(--fs-sm); font-weight: 600; }
.quiz-opt {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  min-height: 44px;
  margin: var(--s-1) 0;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--text) 3%, transparent);
  font-size: var(--fs-sm);
  transition: border-color var(--t), background-color var(--t), color var(--t);
}
label.quiz-opt { cursor: pointer; }
label.quiz-opt:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, var(--bg-1)); }
.quiz-opt:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--bg-1)); }
label.quiz-opt:has(input:disabled) { border-color: var(--border); background: color-mix(in srgb, var(--text) 3%, transparent); color: var(--text-faint); cursor: not-allowed; }
.quiz-opt input { width: 16px; height: 16px; margin: 3px 0 0; flex-shrink: 0; accent-color: var(--accent); cursor: inherit; }
.quiz-opt.correct { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, var(--bg-1)); color: var(--ok-text); }
.quiz-opt.wrong { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, var(--bg-1)); color: var(--danger-text); }
.quiz .btn { margin-top: var(--s-4); }
.quiz .alert { margin-top: var(--s-3); }

.task-text { margin: 0 0 var(--s-4); font-size: .95rem; }
.task-reveal { margin: var(--s-4) 0; }
.task-reveal > summary {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: var(--s-1) var(--s-4);
  border: 1px solid var(--warn);
  border-radius: var(--r-sm);
  color: var(--warn-text);
  font-size: var(--fs-sm);
  font-weight: 500;
  list-style: none;
  cursor: pointer;
  transition: background-color var(--t);
}
.task-reveal > summary::-webkit-details-marker { display: none; }
.task-reveal > summary:hover, .task-reveal[open] > summary { background: color-mix(in srgb, var(--warn) 10%, var(--bg-1)); }
.task-answer {
  margin-top: var(--s-3);
  padding: var(--s-4);
  border: 1px solid color-mix(in srgb, var(--warn) 22%, var(--bg-1));
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--warn) 6%, var(--bg-1));
  font-size: var(--fs-sm);
}

.grade-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: var(--s-2) var(--s-5);
  margin: var(--s-4) 0;
  padding: var(--s-4) var(--s-5);
  border: 1px solid color-mix(in srgb, var(--ok) 30%, var(--bg-1));
  border-left: 3px solid var(--ok);
  border-radius: var(--r);
  background: color-mix(in srgb, var(--ok) 8%, var(--bg-1));
}
.grade-score { display: flex; align-items: baseline; gap: var(--s-1); color: var(--ok-text); line-height: 1; white-space: nowrap; }
.grade-score .mono { font-size: var(--fs-3xl); }
.grade-of { color: var(--text-muted); font-size: var(--fs-sm); }
.card-title + .grade-card { margin-top: var(--s-3); }
.grade-body { min-width: 0; }
.grade-body p { margin: 0 0 var(--s-2); }
.grade-meta { color: var(--text-muted); font-size: var(--fs-xs); }

/* review detail: full-width blocks stacked in one column at every width; wide content scrolls
   inside its own .table-wrap or pre, never under a neighbour */
.breadcrumb ol {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-1) var(--s-2);
  margin: 0 0 var(--s-2);
  padding: 0;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  list-style: none;
}
.breadcrumb li { min-width: 0; overflow-wrap: anywhere; }
/* two content lines on purpose: the second (empty alt text) hides the slash from screen readers, the first is the fallback;
   the slash trails the previous item so a wrapped line never starts with it */
.breadcrumb li:not(:last-child)::after { content: "/"; content: "/" / ""; margin-left: var(--s-2); }
.review-page > * { min-width: 0; max-width: 100%; }
.review-page .lesson-body { max-width: none; }
.review-sample .acc-title { margin: 0; color: inherit; font-size: var(--fs-md); font-weight: 600; }
.review-sample .acc-body { padding: var(--s-4) var(--s-5); }
/* review queue by student and the student queue page (plan 5.3) */
.page-head.review-student-head { align-items: flex-start; }
.review-student-intro { gap: var(--s-3); min-width: 0; }
.review-student-head .person-name { margin: 0; font-size: var(--fs-xl); white-space: normal; overflow-wrap: break-word; }
.review-student-meta { margin: 0; }
/* dashboard student course page (plan 5.2 links, owner pagination) */
.page-head.student-course-head { align-items: flex-start; }
.student-course-intro { gap: var(--s-3); min-width: 0; }
.student-course-intro .breadcrumb ol { margin: 0; }
.student-course-head .person-name { margin: 0; font-size: var(--fs-xl); white-space: normal; overflow-wrap: break-word; }
.student-course-meta { margin: 0; }
.student-course .task-row:first-of-type { border-top: 0; padding-top: 0; }
.student-course .task-row .grade-meta { margin: var(--s-2) 0; }
.reset-form { margin: 0 0 var(--s-3); }
.reset-history { margin: 0; }
.reset-history .acc-body { padding: var(--s-3); }
.link-list { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-3); margin: 0; padding: 0; list-style: none; }
@media (max-width: 899px) {
  .link-list a { display: inline-flex; align-items: center; min-height: 44px; }
}
.review-course .acc-title { min-width: 0; margin: 0; color: inherit; font-size: var(--fs-md); font-weight: 600; overflow-wrap: break-word; }
.review-course .acc-summary { flex-wrap: wrap; }
.review-course .acc-body { padding: var(--s-4); }
.cell-note { display: block; min-width: 14rem; max-width: 40ch; margin-top: var(--s-1); }
@media (max-width: 599px) {
  .review-course .acc-body { padding: var(--s-2); }
}
/* results page and admin profile: one accordion per course, the meta line before the status */
.results-course .acc-meta { margin-left: auto; color: var(--text-muted); font-size: var(--fs-sm); font-weight: 400; }
.results-course .acc-meta + .badge { margin-left: 0; }
.results-course-link { margin: var(--s-3) 0 0; }
/* under 600 px: chevron, title and status on the first line, the meta line under the title */
@media (max-width: 599px) {
  .results-course > summary.acc-summary { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; gap: var(--s-1) var(--s-3); }
  .results-course > summary.acc-summary > .icon { grid-row: 1; margin-top: 1px; }
  .results-course > summary.acc-summary > .acc-meta { grid-column: 2 / -1; grid-row: 2; margin-left: 0; }
  .results-course > summary.acc-summary > .badge { grid-column: 3; grid-row: 1; }
}
/* several lines in one table cell (titles, badges): a column with the app gap, never touching */
.cell-stack { display: flex; flex-direction: column; align-items: flex-start; gap: var(--s-1); }
/* a person's course badges in a cell: the first one, the rest behind a "+ ще N" pill (details, no script) */
.more-badges > .cell-stack { margin-top: var(--s-1); }
summary.more-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  background: var(--bg-2);
  color: var(--text);
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  list-style: none;
  cursor: pointer;
  transition: background-color var(--t);
}
summary.more-toggle::-webkit-details-marker { display: none; }
summary.more-toggle:hover { background: var(--bg-3); }
.more-badges[open] > summary .more-open, .more-badges:not([open]) > summary .more-close { display: none; }
@media (max-width: 899px) {
  /* the pill keeps its look, the invisible area around it reaches 44 px */
  summary.more-toggle::after { content: ""; position: absolute; inset: -12px -6px; }
}
/* a lesson with a task and a quiz: two rows that read as one, each badge on the line of its titles */
.results-table tr.results-pair > td:not([rowspan]) { padding-bottom: var(--s-1); border-bottom: 0; }
.results-table tr.results-subrow > td { padding-top: var(--s-1); }
.results-table tbody tr.results-pair:nth-last-child(2) > td[rowspan] { border-bottom: 0; }
.results-table tr.results-pair:hover + tr.results-subrow > td,
.results-table tr.results-pair:has(+ tr.results-subrow:hover) > td { background: color-mix(in srgb, var(--accent) 6%, var(--bg-1)); }
/* the score and eye cells exist twice in a pair: spanning both rows in the grid, copied into the quiz row
   (.stack-only) for the stacked layout, so there the quiz line stays with its lesson; display: none keeps
   the hidden copy out of the accessibility tree */
@media (min-width: 600px) {
  .results-table td.stack-only { display: none; }
}
@media (max-width: 599px) {
  .table-wrap > .results-table.table-stack tr.results-pair > td[rowspan]:not(:first-child) { display: none; }
  .results-table.table-stack tbody tr.results-pair { padding-bottom: 0; border-bottom: 0; }
  .results-table.table-stack tbody tr.results-subrow { padding-top: 0; }
  .results-table.table-stack tr.results-subrow td:first-child { font-weight: inherit; }
  .results-table.table-stack tr.results-subrow td:first-child::before { content: attr(data-label); }
  .results-table.table-stack td.actions { text-align: left; }
  .results-table.table-stack td.actions > .btn-open { flex: none; }
}
.results-course-link a { display: inline-flex; align-items: center; min-height: 44px; }
.dialog-form { display: flex; flex: 1 1 auto; flex-direction: column; min-height: 0; }
.grade-form-body { margin-top: var(--s-4); }
.grade-form-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.counter { font-variant-numeric: tabular-nums; text-align: right; }
.counter.is-over { color: var(--danger-text); font-weight: 600; }
@media (max-width: 899px) {
  .breadcrumb a { display: inline-flex; align-items: center; min-height: 44px; }
}

.avatar {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--bg-3);
  object-fit: cover;
  overflow: hidden;
}
.avatar-lg { width: 56px; height: 56px; }
.avatar-fallback {
  background: color-mix(in srgb, var(--accent) 18%, var(--bg-1));
  color: var(--accent-text);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: .02em;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
}
.avatar-lg.avatar-fallback { font-size: var(--fs-lg); }
.person { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.person > span:last-child, .person > .person-text { display: flex; flex-direction: column; min-width: 0; }
.person-name { overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.person-role { color: var(--text-muted); font-size: var(--fs-xs); }
/* a linked name keeps the global link colour and hover, like every other table link */
.person-name:not(a) { color: var(--text); }

/* profile page: the head person carries the page title, sections keep one rhythm */
.profile-person { gap: var(--s-4); }
.profile-person .person-name { margin: 0; white-space: normal; overflow-wrap: break-word; }
.profile-person .person-role { font-size: var(--fs-sm); }
.profile-section > h2 { margin: 0 0 var(--s-3); }
.profile-section .table-wrap { margin: 0; }
.profile-team { display: flex; flex-direction: column; gap: var(--s-2); margin: var(--s-3) 0 0; padding: 0; list-style: none; }
.profile-team .muted { margin-left: var(--s-2); font-size: var(--fs-xs); overflow-wrap: anywhere; }
.team-section > h2 { margin: 0 0 var(--s-3); }

/* platform settings page (plan 5.9): a short number field, not a full-width one */
.settings-form .input-percent { max-width: 8rem; }

/* "Мої студенти": team and pool tables, action bar, floating bar of staged changes */
.team-intro { max-width: 76ch; margin: 0 0 var(--s-5); color: var(--text-muted); }
.team-grid { align-items: start; }
.team-panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-2) var(--s-3); min-height: 40px; margin: 0 0 var(--s-3); }
.team-panel-head h2, .team-panel-head h3 { margin: 0; font-size: var(--fs-lg); }
.team-search { position: relative; flex: 1 1 200px; max-width: 280px; }
.team-search > .icon { position: absolute; left: 10px; top: 50%; width: 16px; height: 16px; color: var(--text-muted); transform: translateY(-50%); pointer-events: none; }
.team-search .input { width: 100%; min-height: 36px; padding: var(--s-1) var(--s-3) var(--s-1) 34px; font-size: var(--fs-sm); }
.team-panel .table-wrap { margin: 0; }
.team-name .badge { margin-left: var(--s-2); vertical-align: 1px; }
[data-pool-table] .col-since { display: none; }
.team-table tr.row-new > td { background: color-mix(in srgb, var(--accent) 9%, var(--bg-1)); }
.team-table tr.row-removed > td { background: color-mix(in srgb, var(--danger) 7%, var(--bg-1)); }
.team-table tr.row-removed .team-name-text { color: var(--text-muted); text-decoration: line-through; }
.team-none { margin: var(--s-3) 0 0; font-size: var(--fs-sm); }
.team-form-actions { display: flex; justify-content: flex-end; margin: var(--s-3) 0 0; }
.team-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); margin: var(--s-4) 0 0; }
.stage-bar {
  position: fixed;
  left: 50%;
  bottom: var(--s-4);
  z-index: var(--z-sticky);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2) var(--s-4);
  width: min(720px, calc(100vw - 2 * var(--s-4)));
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r);
  transform: translateX(-50%);
  box-shadow: var(--shadow-2), inset 0 1px 0 var(--glass-highlight);
  animation: rise var(--t);
}
.stage-text { margin: 0; color: var(--text); font-size: var(--fs-sm); font-weight: 600; }
.stage-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-left: auto; }
main:has(.stage-bar:not([hidden])) { padding-bottom: 120px; }
@media (max-width: 899px) {
  .team-search { max-width: none; }
  .team-search .input { min-height: 44px; }
  .stage-actions { width: 100%; }
  .stage-actions .btn { flex: 1 1 0; }
}

/* lesson page: head, callout without title, tables, figures, nav, lightbox, quiz and task details */
.lesson-head { margin: 0 0 var(--s-5); padding: 0 0 var(--s-4); border-bottom: 1px solid var(--border); }
.lesson-meta .lesson-module { min-width: 0; color: var(--text-muted); overflow-wrap: anywhere; }
.lesson-meta .lesson-count { margin-left: auto; color: var(--text-muted); font-size: var(--fs-xs); letter-spacing: .02em; white-space: nowrap; }
.lesson-title { margin: 0; font-family: var(--font-display); font-size: clamp(1.6rem, 1.2rem + 1.6vw, var(--fs-3xl)); line-height: 1.25; overflow-wrap: break-word; }
.lesson-body h3 { margin: var(--s-6) 0 var(--s-3); }
.lesson-body h4 { margin: var(--s-5) 0 var(--s-2); color: var(--accent-text); font-size: var(--fs-md); font-weight: 600; }
/* prose at the body size, about 75 characters a line; tables, code and callouts keep the column width */
.lesson-body > p, .lesson-body > ul, .lesson-body > ol { max-width: 70ch; font-size: var(--fs-md); }

.callout-bare { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s-3); align-items: start; }
.callout-bare > .callout-icon { width: 18px; height: 18px; margin-top: 3px; color: var(--c-text); }
.callout-body > :last-child { margin-bottom: 0; }

/* lesson tables scroll inside .table-wrap: the wrap draws the outer edge, cells draw the grid */
.lesson-body .table-wrap { margin: var(--s-4) 0; box-shadow: none; }
.lesson-body .table-wrap table { width: 100%; margin: 0; border: 0; }
.lesson-body .table-wrap th, .lesson-body .table-wrap td { border-width: 0 1px 1px 0; }
.lesson-body .table-wrap tr > :last-child { border-right: 0; }
.lesson-body .table-wrap tbody tr:last-child > * { border-bottom: 0; }
.lesson-body .table-wrap td { min-width: 7.5rem; }
.table-wrap:focus-visible { outline-offset: 2px; }
.callout .table-wrap { background: color-mix(in srgb, var(--bg-1) 70%, transparent); }

figure.lesson-image img[data-lightbox]:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; }
figure.lesson-image svg { cursor: default; }

.lesson-nav, .lesson-alert { max-width: 76ch; }
.lesson-nav-link { gap: var(--s-3); max-width: min(100%, 26rem); min-height: 56px; padding: var(--s-2) var(--s-4); text-align: left; }
.lesson-nav-next { text-align: right; }
.lesson-nav-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.lesson-nav-dir { font-size: var(--fs-xs); font-weight: 500; letter-spacing: .04em; text-transform: uppercase; opacity: .85; }
.lesson-nav-title { overflow-wrap: anywhere; white-space: normal; }
.lesson-nav-link > .icon { flex-shrink: 0; }

dialog.dialog.lightbox {
  width: auto;
  max-width: calc(100vw - 2 * var(--s-4));
  max-height: calc(100vh - 2 * var(--s-4));
  padding: var(--s-6) var(--s-4) var(--s-4);
  overflow: auto;
  border-color: var(--border);
  background: var(--bg-1);
  box-shadow: var(--shadow-2);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
dialog.dialog.lightbox[open] { align-items: center; }
dialog.lightbox::backdrop { background: var(--scrim, rgb(0 0 0 / .86)); }
.lightbox-close { position: absolute; top: var(--s-2); right: var(--s-2); }
.lightbox-figure { margin: 0; cursor: zoom-out; }
.lightbox-figure img { display: block; width: min(1200px, calc(100vw - 4 * var(--s-4) - 2px)); height: auto; max-height: calc(100vh - 9rem); object-fit: contain; margin: 0 auto; border-radius: var(--r-sm); }
.lightbox-caption { max-width: 72ch; margin: var(--s-3) auto 0; color: var(--text-muted); font-size: var(--fs-sm); text-align: center; }

.quiz-title, .task-title { display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--s-2); }
.quiz-title > .icon, .task-title > .icon { width: 20px; height: 20px; flex-shrink: 0; }
.quiz-title > span:first-of-type, .task-title > span:first-of-type { flex: 1 1 12rem; min-width: 0; }
.lesson-body .quiz-title { color: var(--text); }
.lesson-body .quiz-title > .icon { color: var(--accent-text); }
.quiz-meta { margin: 0 0 var(--s-3); color: var(--text-muted); font-size: var(--fs-sm); }
.quiz-set { min-width: 0; margin: 0; padding: 0; border: 0; }
.quiz-set + .quiz-set { margin-top: var(--s-2); }
legend.quiz-q, p.quiz-q { display: block; width: 100%; padding: 0; }
.quiz-opt > .icon { width: 16px; height: 16px; margin-top: 3px; flex-shrink: 0; color: var(--text-faint); }
.quiz-opt.correct > .icon, .quiz-opt.wrong > .icon { color: inherit; }
.quiz-opt > span { min-width: 0; overflow-wrap: anywhere; }
/* results pages: the option the student picked in the last attempt (the correct one keeps its
   colours and gets an inner edge) */
.quiz-opt.picked:not(.correct) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--bg-1)); }
.quiz-opt.picked:not(.correct) > .icon { color: var(--accent); }
.quiz-opt.correct.picked { box-shadow: inset 0 0 0 1px var(--ok); }
.quiz-preview .help { margin-top: var(--s-2); }
.task-title .badge { margin-left: auto; }
.task .callout { margin: 0 0 var(--s-4); }
.task form, .task .field { margin-top: var(--s-4); }
.task form .btn { margin-top: 0; }
.task-submitted { padding: var(--s-3) var(--s-4); border: 1px solid var(--border); border-radius: var(--r-sm); background: color-mix(in srgb, var(--text) 3%, transparent); font-size: var(--fs-sm); }
.grade-score { margin: 0; }

@media (max-width: 899px) {
  pre.code, .lesson-body pre { padding: calc(44px + var(--s-3)) var(--s-4) var(--s-3); }
  pre .copy-btn { min-height: 44px; opacity: 1; }
  .task-reveal > summary { min-height: 44px; }
}
@media (max-width: 599px) {
  .lesson-nav-link { max-width: none; width: 100%; }
  .lesson-meta .lesson-count { margin-left: 0; }
  .grade-card { grid-template-columns: minmax(0, 1fr); }
  .quiz, .task { padding: var(--s-4); }
  .callout { padding: var(--s-3) var(--s-4); }
}

/* == 14. layout: header, course sidebar, helpers == */

.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 var(--s-5); }
.main { display: block; min-width: 0; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3) var(--s-4); margin: 0 0 var(--s-5); }
.page-head > * { min-width: 0; }
.page-head h1 { margin: 0; }
.page-head p { margin: var(--s-1) 0 0; }
.page-head h1 + .dl-grid { margin: var(--s-3) 0 0; }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
/* a ghost button has no frame: its label, not its padding, lines up with the content edge */
.page-actions > .btn-ghost:last-child, .page-actions > form:last-child > .btn-ghost:only-of-type { margin-right: calc(-1 * var(--s-4) - 1px); }
/* under 600 px a lone ghost action takes its own line under the title and lines up with the left edge */
@media (max-width: 599px) {
  .page-actions:has(> .btn-ghost:only-child, > form:only-child > .btn-ghost:only-of-type) { flex-basis: 100%; }
  .page-actions > .btn-ghost:only-child, .page-actions > form:only-child > .btn-ghost:only-of-type { margin-right: 0; margin-left: calc(-1 * var(--s-4) - 1px); }
}
/* centered single-card pages: login, 403, 404, lesson unavailable */
.login-card, .status-card { margin: var(--s-7) auto; padding: var(--s-6) var(--s-5); text-align: center; }
.login-card { max-width: 440px; }
.status-card { max-width: 560px; }
.login-card .display, .status-card .display { margin: 0 0 var(--s-3); }
.login-card .alert { text-align: left; }
.login-btn { width: 100%; }
.login-dev { margin: var(--s-4) 0 0; font-size: var(--fs-sm); }
.status-icon { display: block; width: 40px; height: 40px; margin: 0 auto var(--s-3); color: var(--accent); }
.status-card .btn { margin-top: var(--s-2); }
.stack { display: flex; flex-direction: column; gap: var(--s-4); }
.stack > *, .stack > details.acc { margin-top: 0; margin-bottom: 0; }
.grid-2, .grid-3 { display: grid; gap: var(--s-4); margin: 0 0 var(--s-4); }
.stack > .grid-2, .stack > .grid-3 { margin-bottom: 0; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 > *, .grid-3 > * { min-width: 0; margin-bottom: 0; }
@media (max-width: 599px) {
  .card:not(.login-card, .status-card, .empty) { padding: var(--s-4); }
}
@media (max-width: 899px) {
  .container { padding: 0 var(--s-4); }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
}

/* header */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  border-width: 0 0 1px;
  border-style: solid;
}
.topbar-inner {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--s-5);
  min-height: 60px;
  margin: 0 auto;
  padding: 0 var(--s-5);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  min-height: 44px;
  color: var(--text);
  font-weight: 700;
  letter-spacing: -.01em;
  text-decoration: none;
  white-space: nowrap;
}
.brand::before { content: ""; flex-shrink: 0; width: 12px; height: 12px; border-radius: 4px; background: var(--accent); box-shadow: 5px 5px 0 -1px var(--cta); margin-right: 5px; }
.brand:hover { color: var(--text); text-decoration: none; }
.main-nav { display: flex; flex: 1 1 auto; align-items: center; gap: var(--s-4); min-width: 0; }
.nav-item {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  min-height: 44px;
  padding: 0 var(--s-2);
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--t), background-color var(--t);
}
.nav-item .icon { width: 18px; height: 18px; }
.nav-item:hover { color: var(--text); text-decoration: none; }
.nav-item[aria-current="page"] { color: var(--text); }
.nav-item[aria-current="page"] .icon { color: var(--accent); }
.nav-item[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: var(--s-2);
  right: var(--s-2);
  bottom: -8px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--accent);
}
/* thin divider centred in the gap before every item but the first */
.nav-item + .nav-item::before {
  content: "";
  position: absolute;
  left: calc(var(--s-4) / -2 - .5px);
  top: 50%;
  width: 1px;
  height: 18px;
  transform: translateY(-50%);
  background: var(--border);
  pointer-events: none;
}
.nav-toggle { display: none; }
.user-menu { position: relative; margin-left: auto; margin-right: calc(-1 * var(--s-2) - 1px); }
.user-menu > .menu { right: calc(var(--s-2) + 1px); }
.user-btn, a.user-btn {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-height: 44px;
  padding: var(--s-1) var(--s-2);
  border: 1px solid transparent;
  border-radius: var(--r);
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  text-decoration: none;
  transition: background-color var(--t), border-color var(--t);
}
.user-btn:hover { background: var(--bg-2); color: var(--text); text-decoration: none; }
.user-btn[aria-expanded="true"] { border-color: var(--border); background: var(--bg-2); }
.user-btn > .icon { width: 16px; height: 16px; color: var(--text-muted); transition: transform var(--t); }
.user-btn[aria-expanded="true"] > .icon { transform: rotate(180deg); }
.user-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.user-name { max-width: 14rem; overflow: hidden; font-size: var(--fs-sm); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.user-role { color: var(--text-muted); font-size: var(--fs-xs); }
.menu {
  position: absolute;
  top: calc(100% + var(--s-2));
  right: 0;
  z-index: var(--z-topbar);
  min-width: 320px;
  padding: var(--s-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--bg-1);
  box-shadow: var(--shadow-2);
}
.menu:not([data-open]) { display: none; }
/* the person's name and position at the top of the user menu: not interactive, shown at every width */
.menu-head { display: flex; flex-direction: column; min-width: 0; padding: var(--s-2) var(--s-3) var(--s-3); border-bottom: 1px solid var(--border); margin-bottom: var(--s-2); line-height: 1.25; }
.menu-head-name { overflow: hidden; font-size: var(--fs-sm); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.menu-head-role { color: var(--text-muted); font-size: var(--fs-xs); }
/* without JS the user block is a plain link to the profile, with JS it is the menu button */
:root[data-js] .user-link { display: none; }
:root:not([data-js]) .user-trigger, :root:not([data-js]) .menu { display: none; }
.menu-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  min-height: 40px;
  padding: var(--s-2) var(--s-3);
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--text);
  font: inherit;
  font-size: var(--fs-sm);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--t);
}
.menu-item:hover, .menu-item:focus-visible { background: var(--bg-2); color: var(--text); text-decoration: none; }
.menu-item .icon { width: 18px; height: 18px; color: var(--text-muted); }
/* users table row menu: fixed to the viewport next to its "..." button (app.js rowMenu sets
   top and left), so the table wrap never clips it; under the sticky header when scrolled */
.row-menu-wrap { position: relative; }
.menu.row-menu {
  position: fixed;
  top: 0;
  right: auto;
  left: 0;
  z-index: var(--z-sidebar);
  min-width: 14rem;
  max-width: calc(100vw - 16px);
  text-align: left;
  white-space: nowrap;
}
.row-menu-btn[aria-expanded="true"] { border-color: var(--border-strong); background: var(--bg-2); }
@media (max-width: 599px) {
  .menu.row-menu .menu-item { min-height: 44px; }
}
/* theme switch: a radio group of visually hidden native radios, each label is a segment */
.segmented {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}
.seg {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 2px var(--s-1);
  min-width: 0;
  min-height: 36px;
  padding: var(--s-1) 6px;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: 500;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  transition: background-color var(--t), border-color var(--t), color var(--t);
}
.seg .icon { flex: none; width: 16px; height: 16px; }
.seg > span { min-width: 0; overflow-wrap: anywhere; }
.seg:hover { background: var(--bg-2); color: var(--text); }
.segmented input:checked + .seg {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-1));
  color: var(--accent-text);
  font-weight: 600;
}
.segmented input:focus-visible + .seg { outline: 2px solid var(--accent); outline-offset: 1px; }
@media (forced-colors: active) {
  .segmented input:checked + .seg { border-color: Highlight; background: Highlight; color: HighlightText; }
}
.menu-label { margin: var(--s-2) var(--s-3) var(--s-1); color: var(--text-muted); font-size: var(--fs-xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.menu-sep { margin: var(--s-2) 0; }

/* a five-item or longer nav (Admin roles): tighter spacing and a bounded user block so every label fits a 1280 px window */
@media (min-width: 900px) {
  .topbar-inner:has(.main-nav > .nav-item:nth-child(5)) { gap: var(--s-3); }
  .main-nav:has(> .nav-item:nth-child(5)) { gap: var(--s-2); }
  .main-nav:has(> .nav-item:nth-child(5)) > .nav-item { gap: 6px; padding: 0 var(--s-1); }
  .main-nav:has(> .nav-item:nth-child(5)) > .nav-item[aria-current="page"]::after { left: var(--s-1); right: var(--s-1); }
  .main-nav:has(> .nav-item:nth-child(5)) > .nav-item + .nav-item::before { left: calc(var(--s-2) / -2 - .5px); }
  .topbar-inner:has(.main-nav > .nav-item:nth-child(5)) .user-meta { max-width: 7.5rem; }
  .topbar-inner:has(.main-nav > .nav-item:nth-child(5)) .user-role { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
/* up to 1439 px such a nav takes the room of the name and position next to the avatar: they stay for
   screen readers (the user button keeps its accessible name), the avatar opens the menu, whose head line shows them */
@media (min-width: 900px) and (max-width: 1439px) {
  .topbar-inner:has(.main-nav > .nav-item:nth-child(5)) .user-meta { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
}
/* the header spans the window: the brand at the left, the user block at the right, the nav takes the room between
   (it never runs under the user block); without room for every label of its items (a small monitor, a narrow window)
   it shows icons only, the label stays for screen readers and as the title tooltip */
@media (min-width: 900px) {
  .topbar-inner > .brand, .topbar-inner > .user-menu { flex: none; }
  .main-nav { container: main-nav / inline-size; }
}
@container main-nav (max-width: 38rem) {
  .main-nav:has(> .nav-item:nth-child(4)) > .nav-item { justify-content: center; min-width: 44px; }
  .main-nav:has(> .nav-item:nth-child(4)) > .nav-item > span { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
}
@container main-nav (max-width: 44rem) {
  .main-nav:has(> .nav-item:nth-child(5)) > .nav-item { justify-content: center; min-width: 44px; }
  .main-nav:has(> .nav-item:nth-child(5)) > .nav-item > span { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
}
/* measured 2026-10-08 (Inter, the six Admin labels "Дашборд" to "Налаштування"): the labels need 805 px of nav;
   the nav gets 925 px at a 1280 px window and 1011 px at 1366 px with the name hidden, 965 px at 1440 px with
   the name shown; 54rem (864 px) keeps about 60 px of headroom on both sides, labels show from a 1220 px window */
@container main-nav (max-width: 54rem) {
  .main-nav:has(> .nav-item:nth-child(6)) > .nav-item { justify-content: center; min-width: 44px; }
  .main-nav:has(> .nav-item:nth-child(6)) > .nav-item > span { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
}

@media (max-width: 899px) {
  .topbar-inner { gap: var(--s-2); padding: 0 var(--s-4); flex-wrap: wrap; }
  :root[data-js] .topbar-inner { flex-wrap: nowrap; }
  .brand { flex: 1 1 auto; min-width: 0; overflow: hidden; }
  .nav-item + .nav-item::before { display: none; }
  /* the name and position stay for screen readers: they name the user button, the menu head line shows them */
  .user-meta { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
  .menu-item { min-height: 44px; }
  .seg { min-height: 44px; }
  /* with JS the nav folds into a dropdown under the header; without JS it stays a wrapped row */
  :root[data-js] .nav-toggle { display: inline-flex; order: 2; }
  :root[data-js] .user-menu { order: 3; margin-left: 0; }
  :root[data-js] .main-nav {
    position: absolute;
    top: calc(100% + var(--s-1));
    left: var(--s-3);
    right: var(--s-3);
    z-index: var(--z-topbar);
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: var(--s-2);
    border: 1px solid var(--border);
    border-radius: var(--r);
    background: var(--bg-1);
    box-shadow: var(--shadow-2);
  }
  :root[data-js] .main-nav:not([data-open]) { display: none; }
  :root[data-js] .main-nav .nav-item { min-height: 44px; padding: 0 var(--s-3); font-size: var(--fs-md); }
  :root[data-js] .main-nav .nav-item[aria-current="page"] { background: color-mix(in srgb, var(--accent) 10%, var(--bg-1)); }
  :root[data-js] .main-nav .nav-item[aria-current="page"]::after { top: var(--s-2); bottom: var(--s-2); left: 0; right: auto; width: 3px; height: auto; border-radius: 0 2px 2px 0; }
  :root:not([data-js]) .main-nav { order: 4; flex-basis: 100%; flex-wrap: wrap; gap: 0 var(--s-2); padding-bottom: var(--s-2); }
  :root:not([data-js]) .nav-item[aria-current="page"]::after { bottom: 0; }
}
@media (max-width: 599px) {
  .brand { font-size: var(--fs-sm); line-height: 1.15; white-space: normal; }
  .nav-toggle { padding: 0 var(--s-3); }
  .user-btn > .icon { display: none; }
  .menu { width: min(280px, calc(100vw - 2 * var(--s-4))); min-width: 0; }
  /* narrow menu: every segment stacks the label under the icon, so the three stay alike */
  .seg { flex-direction: column; }
}

/* course sidebar (4.2a) */
.course-layout {
  position: relative;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  align-items: start;
  transition: grid-template-columns 220ms ease;
}
.course-layout > * { min-width: 0; }
.course-layout > .course-sidebar { grid-column: 1; grid-row: 1; }
.course-layout > .main, .course-layout > .cs-toggle { grid-column: 2; grid-row: 1; }
.course-layout > .main { padding: var(--s-6) var(--s-6) var(--s-7); }
.course-sidebar {
  position: sticky;
  top: 60px;
  z-index: var(--z-sidebar);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 60px);
  overflow: hidden;
  border-width: 0 1px 0 0;
  border-style: solid;
}
.cs-head {
  position: relative;
  padding: var(--s-5) var(--s-4) var(--s-4);
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 9%, transparent), color-mix(in srgb, var(--cta) 6%, transparent));
}
.cs-title { margin: 0 var(--s-6) var(--s-1) 0; color: var(--text); font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 700; line-height: 1.25; }
.cs-meta { margin: 0 0 var(--s-2); color: var(--text-muted); font-size: var(--fs-xs); }
.cs-head .progress { height: 4px; }
.cs-close { position: absolute; top: var(--s-3); right: var(--s-3); display: none; }
.cs-search { position: relative; padding: var(--s-3) var(--s-4); }
.cs-search > .icon { position: absolute; left: calc(var(--s-4) + 10px); top: 50%; width: 16px; height: 16px; color: var(--text-muted); transform: translateY(-50%); pointer-events: none; }
.cs-search .input { min-height: 36px; padding: var(--s-1) var(--s-3) var(--s-1) 34px; background: var(--bg-0); font-size: var(--fs-sm); }
:root:not([data-js]) .cs-search { display: none; }
@media (max-width: 899px) {
  .cs-search .input { min-height: 44px; }
}
.cs-nav { position: relative; flex: 1 1 auto; min-height: 0; overflow-y: auto; padding-bottom: var(--s-4); overscroll-behavior: contain; }
.cs-module { border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent); }
.cs-module > summary {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-height: 44px;
  padding: var(--s-2) var(--s-4);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: 600;
  list-style: none;
  cursor: pointer;
  transition: color var(--t), background-color var(--t);
}
.cs-module > summary::-webkit-details-marker { display: none; }
/* inset rings: .cs-nav scrolls with overflow hidden on the sides and would clip an outside ring */
.cs-module > summary:focus-visible, .cs-lesson:focus-visible { outline-offset: -2px; }
.cs-module > summary:hover { background: color-mix(in srgb, var(--text) 4%, transparent); color: var(--text); }
.cs-module[open] > summary { color: var(--text); }
.cs-module > summary > .icon { width: 14px; height: 14px; margin-left: auto; transition: transform var(--t); }
.cs-module[open] > summary > .icon { transform: rotate(90deg); }
.cs-module-title { min-width: 0; overflow-wrap: anywhere; }
.module-tag { padding: 1px 7px; font-size: .68rem; }
.cs-lesson {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-height: 36px;
  padding: 6px var(--s-4) 6px 38px;
  border-left: 2px solid transparent;
  color: var(--text-muted);
  font-size: .82rem;
  line-height: 1.4;
  text-decoration: none;
  transition: color var(--t), background-color var(--t), border-color var(--t);
}
.cs-lesson:hover { background: color-mix(in srgb, var(--text) 3%, transparent); color: var(--text); text-decoration: none; }
.cs-lesson[aria-current="page"] { border-left-color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, transparent); color: var(--accent-text); font-weight: 600; }
.cs-lesson > span:last-child { min-width: 0; }
.cs-state {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  border: 2px solid var(--border-strong);
  border-radius: 50%;
  color: transparent;
  transition: background-color var(--t), border-color var(--t);
}
.cs-state .icon { width: 10px; height: 10px; stroke-width: 3; }
.cs-lesson[data-state="opened"] .cs-state { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.cs-lesson[data-state="complete"] .cs-state { border-color: var(--ok); background: var(--ok); color: var(--bg-0); }
.cs-lesson[data-state="complete"] { color: var(--text); }
.cs-exam .cs-lesson-title { font-weight: 600; }
.cs-empty { margin: 0; padding: var(--s-4); color: var(--text-muted); font-size: var(--fs-sm); }
.cs-foot { margin: 0; padding: var(--s-3) var(--s-4) 14px; border-top: 1px solid var(--border); color: var(--text-muted); font-family: var(--font-mono); font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; }
.cs-toggle {
  position: sticky;
  top: calc(60px + var(--s-4));
  z-index: calc(var(--z-sidebar) + 1);
  display: inline-grid;
  place-items: center;
  justify-self: start;
  width: 28px;
  height: 28px;
  margin: var(--s-4) 0 0 -14px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  background: var(--bg-1);
  color: var(--text-muted);
  box-shadow: var(--shadow-1);
  cursor: pointer;
  transition: color var(--t), border-color var(--t), transform var(--t);
}
.cs-toggle:hover { border-color: var(--accent); color: var(--accent); }
.cs-toggle .icon { width: 16px; height: 16px; }
.cs-drawer-btn, .cs-backdrop { display: none; }
:root[data-course-sidebar="collapsed"] .course-layout { grid-template-columns: 0 minmax(0, 1fr); }
:root[data-course-sidebar="collapsed"] .course-sidebar { visibility: hidden; }
:root[data-course-sidebar="collapsed"] .cs-toggle { margin-left: var(--s-3); }
:root[data-course-sidebar="collapsed"] .course-layout > .main { padding-left: calc(var(--s-3) + 28px + var(--s-5)); }
:root[data-course-sidebar="collapsed"] .cs-toggle .icon { transform: rotate(180deg); }

@media (max-width: 899px) {
  .course-layout, :root[data-course-sidebar="collapsed"] .course-layout { grid-template-columns: minmax(0, 1fr); }
  .course-layout > .course-sidebar, .course-layout > .main { grid-column: 1; grid-row: auto; }
  .course-layout > .main { padding: var(--s-5) var(--s-4) var(--s-7); }
  .cs-toggle { display: none; }
  /* without JS the outline sits above the content; with JS it is a drawer */
  .course-sidebar { position: static; height: auto; max-height: none; border-width: 0 0 1px; visibility: visible; }
  :root[data-js] .course-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: calc(var(--z-backdrop) + 1);
    width: min(320px, 86vw);
    height: 100%;
    border-width: 0 1px 0 0;
    box-shadow: var(--shadow-2);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 220ms ease, visibility 0s linear 220ms;
  }
  :root[data-js] .course-sidebar[data-open] { transform: none; visibility: visible; transition: transform 220ms ease; }
  :root[data-js] .cs-close { display: inline-flex; }
  :root[data-js] .cs-drawer-btn { display: inline-flex; margin-bottom: var(--s-4); }
  :root[data-js] .course-sidebar[data-open] ~ .cs-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: var(--z-backdrop);
    border: 0;
    /* fallback only, mirrors dialog::backdrop; the value itself lives in the --backdrop token */
    background: var(--backdrop, rgb(0 0 0 / .55));
    cursor: default;
  }
  .cs-lesson { min-height: 44px; }
}

/* course sidebar on the product pages: the layout sits outside .container, content gets its own column */
:root:not([data-js]) .cs-toggle { display: none; }
.cs-title a { color: inherit; text-decoration: none; }
.cs-title a:hover { color: var(--accent-text); text-decoration: none; }
.course-content { max-width: 960px; margin: 0 auto; }

/* course list and course page */
.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: var(--s-4); }
.course-grid > .card { margin: 0; }
.course-card { position: relative; display: flex; flex-direction: column; gap: var(--s-3); }
.course-card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.course-card-head { display: flex; align-items: center; gap: var(--s-4); }
.course-card-title { min-width: 0; }
.course-card .card-title { margin: 0 0 var(--s-1); font-size: var(--fs-lg); }
.course-link { color: var(--text); text-decoration: none; }
.course-link:hover { color: var(--accent-text); text-decoration: none; }
/* the whole card is the link target; the title keeps the focus ring */
.course-link::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.course-logo { flex-shrink: 0; width: 64px; height: 64px; border: 1px solid var(--border); border-radius: var(--r); background: var(--bg-2); object-fit: cover; }
.course-mono { display: inline-grid; place-items: center; background: color-mix(in srgb, var(--accent) 12%, var(--bg-2)); color: var(--accent-text); font-family: var(--font-display); font-size: var(--fs-xl); font-weight: 700; }
.course-stats { margin: 0; color: var(--text-muted); font-family: var(--font-mono); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
.course-desc { margin: 0; color: var(--text-muted); }
.course-progress { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3); }
.course-card .course-progress { margin-top: auto; }
.course-progress .progress { flex: 1 1 120px; min-width: 80px; }
/* the label is as wide as "Прогрес курсу: 100 %", so every bar has one length */
.course-percent { min-width: 11.5em; font-size: var(--fs-sm); font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.course-back { margin: 0 0 var(--s-4); font-size: var(--fs-sm); }
.course-back a { display: inline-flex; align-items: center; gap: var(--s-1); min-height: 32px; color: var(--text-muted); }
.course-back a:hover { color: var(--accent-text); }
.course-counts { margin: 0; color: var(--text-muted); font-size: var(--fs-sm); }
.lesson-list { margin: 0; padding: var(--s-1) 0; list-style: none; }
@media (max-width: 899px) {
  /* the drawer close button is 44 px here; keep the title clear of it */
  :root[data-js] .cs-title { margin-right: calc(44px + var(--s-3)); }
  /* the course title link: a 44 px tall hit area without moving the head */
  .cs-title a { display: inline-block; padding: 10px 0; margin: -10px 0; }
  .course-back a { min-height: 44px; }
}

/* glass surfaces (3.6): the recipe applied to the components that are glass by contract */
.card.glass, .topbar, .course-sidebar, dialog.dialog, .kpi {
  background: var(--glass-bg);
  border-color: var(--glass-edge);
  box-shadow: var(--shadow-1), inset 0 1px 0 var(--glass-highlight);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  backdrop-filter: blur(14px) saturate(140%);
}
.kpi { border: 1px solid var(--glass-edge); }
dialog.dialog { box-shadow: var(--shadow-2), inset 0 1px 0 var(--glass-highlight); }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .card.glass, .topbar, .course-sidebar, dialog.dialog, .kpi { background: var(--bg-1); }
}
@media (prefers-reduced-transparency: reduce) {
  .card.glass, .topbar, .course-sidebar, dialog.dialog, .kpi {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: var(--bg-1);
  }
}

/* dev style guide page only */
.sg-toc { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); padding: var(--s-3) var(--s-4); font-size: var(--fs-sm); }
.sg-section { margin: 0 0 var(--s-7); scroll-margin-top: 76px; }
.sg-section > h2 { margin: 0 0 var(--s-3); padding-bottom: var(--s-2); border-bottom: 1px solid var(--border); }
.sg-note { max-width: 76ch; color: var(--text-muted); font-size: var(--fs-sm); }
.sg-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); margin: 0 0 var(--s-4); }
.sg-grid-states { display: grid; grid-template-columns: max-content repeat(3, max-content); align-items: center; gap: var(--s-3) var(--s-5); margin: 0 0 var(--s-4); overflow-x: auto; padding: var(--s-1); }
.sg-grid-seg { grid-template-columns: max-content minmax(260px, 300px); }
.sg-grid-states code { color: var(--text-muted); font-size: var(--fs-xs); }
.sg-head { color: var(--text-muted); font-size: var(--fs-xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.sg-focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.sg-frame { position: relative; margin: 0 0 var(--s-4); border: 1px dashed var(--border-strong); border-radius: var(--r-lg); }
.sg-frame-header { min-height: 330px; }
.sg-frame-header .topbar { position: relative; border-radius: var(--r-lg) var(--r-lg) 0 0; }
.sg-frame-toasts { min-height: 150px; }
.sg-frame-toasts .toast-stack { position: absolute; }
.sg-frame-reading { padding: var(--s-4); overflow: hidden; }
.sg-frame-reading .reading-progress { position: absolute; }
.sg-frame-reading p { margin: 0; }
.sg-frame-course { overflow: hidden; }
.sg-frame-course .course-sidebar { top: 0; height: 520px; }
.sg-frame-course .cs-toggle { top: var(--s-4); }
.sg-frame-course .main { min-height: 520px; }
.sg-frame.container { padding: var(--s-5); }
.sg-narrow { max-width: 560px; }
.sg-progress { display: flex; flex-direction: column; gap: var(--s-2); max-width: 360px; margin: 0 0 var(--s-5); font-size: var(--fs-sm); }
@media (max-width: 899px) {
  .sg-frame-course .course-sidebar { height: auto; }
  :root[data-js] .sg-frame-course .course-sidebar { height: 100%; }
  .sg-frame-course .main { min-height: 0; padding: var(--s-4); }
}

/* == legacy, removed in B tasks ==
   today's component rules, repointed at the new tokens so existing pages keep rendering */

.inline { display: inline; }
main.container { padding-top: var(--s-5); padding-bottom: var(--s-7); }
.form-row { margin-bottom: var(--s-3); }
.form-row label { display: block; font-weight: 600; margin-bottom: var(--s-1); }
input[type=text]:not(.input), input[type=number]:not(.input), input[type=search]:not(.input), select:not(.select), textarea:not(.textarea) { width: 100%; max-width: 640px; padding: var(--s-2); border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--bg-2); color: var(--text); font: inherit; }
textarea:not(.textarea) { min-height: 160px; }
.filters .form-row { margin: 0; min-width: 160px; }
.task-row { border-top: 1px solid var(--border); padding: var(--s-3) 0; }
.task-row-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.task-row-head .btn { margin-left: auto; }
