/* Test-Med — the whole app's stylesheet (no build step). The contract is docs/design.md. */

/* ===== Font (vendored, SIL OFL 1.1 — static/vendor/onest/OFL.txt) ===== */
@font-face { font-family: "Onest"; src: url("vendor/onest/onest-cyrillic.fe2bd26ae82a.woff2") format("woff2"); font-weight: 100 900; font-display: swap; unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Onest"; src: url("vendor/onest/onest-cyrillic-ext.11a468877c94.woff2") format("woff2"); font-weight: 100 900; font-display: swap; unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F; }
@font-face { font-family: "Onest"; src: url("vendor/onest/onest-latin.3db826ed1c5d.woff2") format("woff2"); font-weight: 100 900; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2212, U+2215, U+FEFF, U+FFFD; }

/* ===== Tokens ===== */
:root {
  color-scheme: light dark;
  /* Surfaces and text */
  --canvas: #f2f4f7;
  --surface: #ffffff;
  --sunken: #f5f6f9;
  --ink: #141b2d;
  --muted: #566175;
  --line: #e0e4ea;
  --line-strong: #8b95a5;
  /* Ink: what the user does (primary buttons, their own marks) */
  --action: #141b2d;
  --action-hover: #2b3653;
  --on-action: #ffffff;
  /* Teal: where the user is (brand, links, active section, progress, focus) */
  --accent: #0e7c86;
  --accent-strong: #0a5d65;
  --accent-soft: #e1f2f3;
  /* Outcomes only */
  --ok: #17794d;
  --ok-soft: #e3f4ea;
  --ok-line: #a8d8bd;
  --bad: #c0282d;
  --bad-strong: #9d1f24;
  --bad-soft: #fdeaea;
  --bad-line: #f0b5b7;
  --on-bad: #ffffff;
  --warn: #92550a;
  --warn-soft: #fdf1d9;
  --warn-line: #ecc98a;
  --flag: #d9820a;
  /* Layers above the page */
  --scrim: rgb(13 18 32 / .6);
  --cover: #0d1220;
  --on-cover: #ffffff;
  --on-cover-muted: #c3cad8;
  --shadow-pop: 0 18px 48px -12px rgb(13 18 32 / .28), 0 2px 6px rgb(13 18 32 / .08);
  --shadow-raised: 0 1px 2px rgb(13 18 32 / .14);
  --watermark-opacity: .13;
  /* Type: one family, a 1.2 scale */
  --font: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --text-xs: .8125rem;
  --text-sm: .875rem;
  --text-md: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.3125rem;
  --text-2xl: clamp(1.5rem, 1.3rem + 1.1vw, 1.9375rem);
  --text-display: clamp(3.25rem, 2.2rem + 6vw, 5rem);
  /* Space, radii, control heights */
  --s-1: .25rem;
  --s-2: .5rem;
  --s-3: .75rem;
  --s-4: 1rem;
  --s-5: 1.5rem;
  --s-6: 2rem;
  --s-7: 3rem;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-pill: 999px;
  --h-sm: 2.25rem;
  --h-md: 2.75rem;
  --h-lg: 3.25rem;
  --bar-h: 3.75rem;
  --narrow: 34rem;
  --gutter: max(1.25rem, env(safe-area-inset-left), env(safe-area-inset-right));
  /* Motion */
  --fast: 120ms;
  --slow: 240ms;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%237a8496' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1.5 6 6.5l5-5'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #0d111d;
    --surface: #161b2a;
    --sunken: #1c2233;
    --ink: #e9ecf3;
    --muted: #a2abbe;
    --line: #2a3145;
    --line-strong: #6a7590;
    --action: #e9ecf3;
    --action-hover: #ffffff;
    --on-action: #141b2d;
    --accent: #4fc3cc;
    --accent-strong: #86dde3;
    --accent-soft: #12343a;
    --ok: #5ccf97;
    --ok-soft: #13301f;
    --ok-line: #256043;
    --bad: #ff8c87;
    --bad-strong: #ffaeaa;
    --bad-soft: #3a1b1e;
    --bad-line: #74343a;
    --on-bad: #2a0b0d;
    --warn: #f1b860;
    --warn-soft: #35270f;
    --warn-line: #6b4f1c;
    --flag: #f1a13a;
    --scrim: rgb(0 0 0 / .68);
    --cover: #080b14;
    --shadow-pop: 0 18px 48px -12px rgb(0 0 0 / .7), 0 0 0 1px var(--line);
    --shadow-raised: 0 1px 2px rgb(0 0 0 / .5);
    --watermark-opacity: .16;
  }
}

/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--bar-h) + 1rem); }
body { margin: 0; min-height: 100dvh; background: var(--canvas); color: var(--ink); font: 400 var(--text-md)/1.55 var(--font); font-feature-settings: "tnum" 0; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.015em; text-wrap: balance; }
h1 { font-size: var(--text-2xl); line-height: 1.15; letter-spacing: -.025em; margin-bottom: var(--s-3); }
h2 { font-size: var(--text-xl); line-height: 1.25; margin: var(--s-6) 0 var(--s-3); }
h3 { font-size: var(--text-md); line-height: 1.35; margin: var(--s-5) 0 var(--s-2); }
p { margin: 0 0 var(--s-3); }
a { color: var(--accent-strong); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--ink); }
strong { font-weight: 650; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: var(--text-sm); }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.lede { color: var(--muted); max-width: 62ch; margin: 0; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ===== App shell ===== */
.skip-link { position: absolute; left: var(--s-4); top: -4rem; z-index: 200; padding: var(--s-2) var(--s-4); border-radius: var(--r-sm); background: var(--action); color: var(--on-action); }
.skip-link:focus { top: var(--s-2); color: var(--on-action); }
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar__inner { max-width: 1160px; min-height: var(--bar-h); margin: 0 auto; padding: 0 var(--gutter); display: flex; align-items: center; gap: var(--s-6); }
.brand { display: inline-flex; align-items: center; gap: .6rem; color: var(--ink); font-weight: 700; font-size: var(--text-lg); letter-spacing: -.02em; text-decoration: none; }
.brand__mark { width: 1.75rem; height: 1.75rem; flex: none; background: url("favicon.516248db99d8.svg") center / contain no-repeat; }
.nav { display: flex; flex: 1; align-items: center; justify-content: space-between; gap: var(--s-4); min-width: 0; }
.nav__links, .nav__account { display: flex; align-items: center; gap: var(--s-1); }
.nav__links { flex-shrink: 0; }
.nav__account { min-width: 0; }
.nav a { position: relative; display: inline-flex; align-items: center; min-height: var(--bar-h); padding: 0 var(--s-3); color: var(--muted); font-weight: 550; font-size: var(--text-sm); text-decoration: none; white-space: nowrap; transition: color var(--fast); }
.nav a:hover { color: var(--ink); }
.nav a.is-active { color: var(--ink); }
.nav a.is-active::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); }
.nav a:focus-visible { outline-offset: -4px; border-radius: var(--r-sm); }
.nav a.nav__admin { min-height: var(--h-sm); margin-left: var(--s-2); padding: 0 var(--s-3); border: 1px solid var(--line-strong); border-radius: var(--r-pill); color: var(--ink); }
.nav a.nav__admin:hover { background: var(--sunken); }
.nav a.nav__admin:focus-visible { outline-offset: 2px; border-radius: var(--r-pill); }
.nav a.nav__user { color: var(--ink); max-width: 18rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; display: block; line-height: var(--bar-h); }
.nav__logout { margin: 0; flex-shrink: 0; }
.nav-toggle { display: none; margin-left: auto; width: var(--h-md); height: var(--h-md); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); cursor: pointer; place-items: center; }
.nav-toggle__bars, .nav-toggle__bars::before, .nav-toggle__bars::after { display: block; width: 1.1rem; height: 2px; border-radius: 2px; background: var(--ink); transition: transform var(--slow) var(--ease), opacity var(--fast); }
.nav-toggle__bars { position: relative; }
.nav-toggle__bars::before, .nav-toggle__bars::after { content: ""; position: absolute; left: 0; }
.nav-toggle__bars::before { top: -6px; }
.nav-toggle__bars::after { top: 6px; }
.nav-toggle[aria-expanded="true"] .nav-toggle__bars { background: transparent; }
.nav-toggle[aria-expanded="true"] .nav-toggle__bars::before { transform: translateY(6px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] .nav-toggle__bars::after { transform: translateY(-6px) rotate(-45deg); }
.page { max-width: 1160px; margin: 0 auto; padding: var(--s-6) var(--gutter) 5rem; }
.page--wide { max-width: 1400px; }
body:has(.page--wide) .topbar__inner { max-width: 1400px; }
.page--exam { max-width: 1200px; }
.page--auth { display: grid; place-items: center; min-height: 100dvh; padding-top: var(--s-5); padding-bottom: var(--s-5); }
.page--auth > .card--narrow { width: 100%; }
.messages { margin-bottom: var(--s-4); }
.messages:has(+ .card--narrow) { max-width: var(--narrow); margin-left: auto; margin-right: auto; }

/* The menu folds into a sheet under the bar before it has to wrap. */
@media (max-width: 960px) {
  .nav-toggle { display: grid; }
  .nav { display: none; position: absolute; left: 0; right: 0; top: 100%; flex-direction: column; align-items: stretch; gap: 0; padding: var(--s-2) var(--gutter) var(--s-4); background: var(--surface); border-bottom: 1px solid var(--line); box-shadow: var(--shadow-pop); max-height: calc(100dvh - var(--bar-h)); overflow-y: auto; }
  .nav.is-open { display: flex; }
  .nav__links, .nav__account { flex-direction: column; align-items: stretch; gap: 0; }
  .nav__account { margin-top: var(--s-2); padding-top: var(--s-2); border-top: 1px solid var(--line); }
  .nav a, .nav a.nav__user { min-height: 3rem; line-height: 3rem; padding: 0 var(--s-2); font-size: var(--text-md); max-width: none; }
  .nav a.nav__user { display: flex; align-items: center; white-space: normal; overflow: visible; text-overflow: clip; overflow-wrap: anywhere; line-height: 1.35; padding-block: var(--s-3); }
  .nav a.is-active::after { left: -.25rem; right: auto; top: .9rem; bottom: .9rem; width: 3px; height: auto; border-radius: 3px; }
  .nav a.nav__admin, .nav a.nav__admin:focus-visible { border-radius: var(--r-md); }
  .nav a.nav__admin { margin: var(--s-2) 0; justify-content: center; min-height: var(--h-md); }
  .nav__logout .btn { width: 100%; margin-top: var(--s-2); min-height: var(--h-md); font-size: var(--text-md); border-radius: var(--r-md); }
}

/* ===== Page head ===== */
.breadcrumbs { display: flex; flex-wrap: wrap; font-size: var(--text-sm); color: var(--muted); margin-bottom: var(--s-2); }
.breadcrumbs a { color: var(--muted); text-decoration: none; }
.breadcrumbs a:hover { color: var(--ink); text-decoration: underline; }
.breadcrumbs a:not(:last-child)::after { content: "/"; margin: 0 .5em; color: var(--line-strong); display: inline-block; }
.back-link { display: inline-flex; align-items: center; min-height: var(--h-sm); margin-bottom: var(--s-2); color: var(--muted); font-size: var(--text-sm); font-weight: 550; text-decoration: none; }
.back-link:hover { color: var(--ink); }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--s-4) var(--s-5); flex-wrap: wrap; margin-bottom: var(--s-5); }
.page-head h1 { margin: 0; overflow-wrap: anywhere; }
.page-head .lede { margin-top: var(--s-2); }
.page-head__actions { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
.page-head__actions form { margin: 0; }
.page > h1 { margin-bottom: var(--s-5); overflow-wrap: anywhere; }

/* ===== Surfaces and layout ===== */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s-5); margin-bottom: var(--s-4); }
.card--narrow { max-width: var(--narrow); margin-left: auto; margin-right: auto; }
.card > h1:first-child, .card > h2:first-child, .card > form > h2:first-of-type, .card > input[type=hidden] + h2 { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
.grid { display: grid; gap: var(--s-4); margin-bottom: var(--s-4); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(min(22rem, 100%), 1fr)); align-items: start; }
.grid > .card { margin-bottom: 0; min-width: 0; }
.row { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.empty { margin: 0; padding: var(--s-5) var(--s-4); border: 1px dashed var(--line-strong); border-radius: var(--r-md); color: var(--muted); text-align: center; }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2); min-height: var(--h-md); padding: .5rem 1.15rem; border: 1px solid var(--action); border-radius: var(--r-md); background: var(--action); color: var(--on-action); font-weight: 600; font-size: var(--text-md); line-height: 1.2; text-align: center; text-decoration: none; cursor: pointer; transition: background var(--fast), border-color var(--fast), color var(--fast), transform var(--fast); }
.btn:hover { background: var(--action-hover); border-color: var(--action-hover); color: var(--on-action); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn--secondary { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.btn--secondary:hover { background: var(--sunken); border-color: var(--ink); color: var(--ink); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--ink); }
.btn--ghost:hover { background: var(--sunken); border-color: var(--line); color: var(--ink); }
.btn--danger { background: var(--bad); border-color: var(--bad); color: var(--on-bad); }
.btn--danger:hover { background: var(--bad-strong); border-color: var(--bad-strong); color: var(--on-bad); }
.btn--sm { min-height: var(--h-sm); padding: .3rem .85rem; font-size: var(--text-sm); border-radius: 10px; }
.btn--lg { min-height: var(--h-lg); padding: .7rem 1.6rem; font-size: var(--text-lg); border-radius: 14px; }
.btn--block { width: 100%; }
.actions { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; margin-top: var(--s-5); }
.actions--center { justify-content: center; }
.pager { justify-content: center; gap: var(--s-4); }

/* ===== Form controls ===== */
.label { display: block; margin: var(--s-4) 0 .35rem; font-weight: 600; font-size: var(--text-sm); }
.field, .form input[type=text], .form input[type=number], .form input[type=password], .form input[type=search], .form input[type=datetime-local], .form select, .form textarea, .filters select {
  width: 100%; min-height: var(--h-md); padding: .55rem .8rem; border: 1px solid var(--line-strong); border-radius: var(--r-md); background: var(--surface); color: var(--ink); transition: border-color var(--fast), box-shadow var(--fast);
}
.form select, .filters select { appearance: none; padding-right: 2.2rem; background: var(--surface) var(--chevron) right .85rem center / .75rem no-repeat; text-overflow: ellipsis; }
.form textarea { min-height: 5rem; resize: vertical; }
.field:hover, .form input:hover, .form select:hover, .form textarea:hover, .filters select:hover { border-color: var(--ink); }
.field:focus, .form input:focus, .form select:focus, .form textarea:focus, .filters select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent); }
.field[aria-invalid="true"], .form :is(input, select, textarea)[aria-invalid="true"] { border-color: var(--bad); }
.field[aria-invalid="true"]:focus, .form :is(input, select, textarea)[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 25%, transparent); }
.field::placeholder, .form input::placeholder { color: var(--muted); opacity: 1; }
.field:disabled, .form input:disabled, .form select:disabled { background-color: var(--sunken); color: var(--muted); cursor: not-allowed; }
.field--narrow { width: 7.5rem; }
.help { display: block; margin-top: .3rem; color: var(--muted); font-size: var(--text-sm); }
.row + .help { margin-top: var(--s-2); }
.field-error { margin-top: .3rem; color: var(--bad); font-size: var(--text-sm); font-weight: 550; }
input[type=checkbox] { appearance: none; display: inline-grid; place-content: center; flex: none; width: 1.3rem; height: 1.3rem; margin: 0; border: 1.5px solid var(--line-strong); border-radius: 6px; background: var(--surface); cursor: pointer; transition: background var(--fast), border-color var(--fast); }
input[type=checkbox]::after { content: ""; width: .72rem; height: .72rem; background: var(--on-action); clip-path: polygon(13% 47%, 0 62%, 40% 100%, 100% 22%, 86% 8%, 38% 70%); transform: scale(0); transition: transform var(--fast) var(--ease); }
input[type=checkbox]:checked { background: var(--action); border-color: var(--action); }
input[type=checkbox]:checked::after { transform: scale(1); }
input[type=checkbox]:disabled { opacity: .5; cursor: not-allowed; }
.check { display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-2) 0; cursor: pointer; }
.check input { margin-top: .15rem; }
.filters { display: flex; align-items: flex-end; gap: var(--s-3); flex-wrap: wrap; margin-bottom: var(--s-4); }
.filters label { display: block; margin-bottom: .25rem; color: var(--muted); font-size: var(--text-xs); font-weight: 600; }
.filters select { min-width: 11rem; max-width: 100%; }
.filters .btn { min-height: var(--h-md); }

/* Chips: one of many categories. Segmented: one of a few modes. */
.chips { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.chip { position: relative; }
.chip input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
/* Half the one-line height: a pill on one line, a rounded plate when a long name wraps. */
.chip > span { display: inline-flex; align-items: center; gap: .35rem; min-height: var(--h-sm); padding: .35rem .85rem; border: 1px solid var(--line-strong); border-radius: calc(var(--h-sm) / 2); background: var(--surface); font-weight: 500; transition: background var(--fast), border-color var(--fast), color var(--fast); }
.chip:hover > span { border-color: var(--ink); }
.chip__count { color: var(--muted); font-size: var(--text-sm); }
.chip input:checked + span { background: var(--action); border-color: var(--action); color: var(--on-action); }
.chip input:checked + span > .chip__count { color: inherit; opacity: .75; }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.segmented { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--sunken); }
.segmented label { position: relative; flex: 1 0 auto; }
.segmented input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.segmented span { display: block; min-height: var(--h-sm); padding: .4rem .95rem; border-radius: 9px; color: var(--muted); font-weight: 550; text-align: center; transition: background var(--fast), color var(--fast); }
.segmented label:hover span { color: var(--ink); }
.segmented input:checked + span { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-raised), 0 0 0 1px var(--line); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ===== Feedback ===== */
.alert { padding: var(--s-3) var(--s-4); margin-bottom: var(--s-3); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); color: var(--ink); }
.alert--success { background: var(--ok-soft); border-color: var(--ok-line); }
.alert--error { background: var(--bad-soft); border-color: var(--bad-line); }
.alert--warning { background: var(--warn-soft); border-color: var(--warn-line); }
.alert .rules { margin: var(--s-2) 0; }
.alert--action { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3) var(--s-4); flex-wrap: wrap; margin-bottom: var(--s-5); padding: var(--s-4) var(--s-5); }
.alert--action p { margin: 0; max-width: 62ch; }
.badge { display: inline-flex; align-items: center; gap: .25em; min-height: 1.5rem; padding: 0 .6rem; border-radius: var(--r-pill); background: var(--sunken); box-shadow: inset 0 0 0 1px var(--line); color: var(--muted); font-size: var(--text-xs); font-weight: 600; line-height: 1; white-space: nowrap; vertical-align: middle; }
.badge--ok { background: var(--ok-soft); box-shadow: none; color: var(--ok); }
.badge--bad { background: var(--bad-soft); box-shadow: none; color: var(--bad); }
.badge--warn { background: var(--warn-soft); box-shadow: none; color: var(--warn); }
.badge--info { background: var(--accent-soft); box-shadow: none; color: var(--accent-strong); }
.tag { display: inline-flex; align-items: center; min-height: 1.5rem; padding: 0 .55rem; border-radius: 6px; background: var(--sunken); color: var(--muted); font-size: var(--text-xs); font-weight: 550; }
.toast { position: fixed; left: 50%; bottom: var(--s-5); transform: translateX(-50%); z-index: 130; width: max-content; max-width: min(92vw, 32rem); padding: var(--s-3) var(--s-4); border-radius: var(--r-md); background: var(--bad); color: var(--on-bad); font-weight: 600; text-align: center; box-shadow: var(--shadow-pop); cursor: pointer; }
.modal { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: var(--s-4); background: var(--scrim); }
.modal__box { width: 100%; max-width: 32rem; padding: var(--s-5); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-pop); }
.modal__box h2 { margin-top: 0; }
.modal__box .actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); align-items: stretch; }
.modal__box .actions .btn { white-space: nowrap; }

/* ===== Data ===== */
.stats, .facts { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 1px; margin: 0 0 var(--s-4); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--line); overflow: hidden; }
.stat, .fact { display: flex; flex-direction: column; gap: .15rem; padding: var(--s-4) var(--s-5); background: var(--surface); }
.stat__label { order: -1; }
/* Pinned to the bottom: values of one row line up whatever the label length. */
.stat__value, .fact dd { margin: auto 0 0; font-size: var(--text-2xl); font-weight: 650; line-height: 1.15; letter-spacing: -.025em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat__label, .fact dt { color: var(--muted); font-size: var(--text-sm); line-height: 1.3; }
.fact dd small { font-size: .55em; font-weight: 550; color: var(--muted); letter-spacing: 0; }
.dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--s-3) var(--s-5); margin: 0 0 var(--s-4); }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; font-weight: 550; overflow-wrap: anywhere; }
.kbd { display: inline-block; padding: .1em .4em; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--sunken); color: var(--ink); font: 500 var(--text-xs)/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: nowrap; }
.table-wrap { position: relative; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th, .table td { padding: .7rem .75rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th:first-child, .table td:first-child { padding-left: 0; }
.table th:last-child, .table td:last-child { padding-right: 0; }
.table th { color: var(--muted); font-size: var(--text-xs); font-weight: 600; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .cell-title { font-weight: 550; font-size: var(--text-md); overflow-wrap: anywhere; }
.table .cell-title .small { font-weight: 400; }
.table--matrix th, .table--matrix td { text-align: center; white-space: nowrap; }
.table--matrix th:first-child, .table--matrix td:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); text-align: left; padding-right: var(--s-3); }
.table--matrix td:first-child, .table--matrix th:first-child { min-width: 12rem; max-width: 16rem; white-space: normal; overflow-wrap: break-word; box-shadow: 1px 0 0 var(--line); }
/* Exam titles wrap into narrow columns, so the names keep their room. */
.table--matrix thead th:not(:first-child) { max-width: 7.5rem; white-space: normal; vertical-align: bottom; font-size: var(--text-sm); line-height: 1.25; }
.row-alert td { background: var(--bad-soft); }
.row-flash td { animation: flash 2.4s ease-out; }
.row-alert .badge--bad { box-shadow: inset 0 0 0 1px var(--bad-line); }
.stat--bad .stat__value { color: var(--bad); }
.table--live th, .table--live td { padding: .45rem .4rem; }
.table--live th:first-child, .table--live td:first-child { padding-left: var(--s-3); }
.table--live th:last-child, .table--live td:last-child { padding-right: var(--s-3); }
.table--live .cell-title { width: 100%; min-width: 7.5rem; max-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table--live td:nth-child(2), .table--live .cell-action { white-space: nowrap; }
.table--live .badge { margin-block: 1px; }
@media (min-width: 1200px) { .table--live td:nth-child(3) { white-space: nowrap; } }
.live-progress .bar { display: inline-block; width: 3rem; min-width: 0; height: .4rem; margin-left: var(--s-2); vertical-align: middle; }
.live-progress .bar__fill { display: block; background: var(--accent); }
@keyframes flash { from { background: var(--bad-line); } }
.assignment { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3) var(--s-5); padding: var(--s-4) 0; border-top: 1px solid var(--line); }
.assignment:first-of-type { border-top: 0; padding-top: var(--s-1); }
.assignment:last-child { padding-bottom: 0; }
.assignment > div:first-child { min-width: 0; }
.assignment__title { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; font-weight: 600; font-size: var(--text-lg); line-height: 1.3; overflow-wrap: anywhere; }
.assignment__title a { color: var(--ink); text-decoration: none; }
.assignment__title a:hover { text-decoration: underline; }
.assignment__meta { margin-top: .2rem; color: var(--muted); font-size: var(--text-sm); }
.assignment .btn { flex: none; }
.assignment__actions { display: flex; flex: none; align-items: center; gap: var(--s-2); }
.bar { height: .5rem; min-width: 5rem; border-radius: var(--r-pill); background: var(--line); overflow: hidden; }
.bar__fill { height: 100%; border-radius: var(--r-pill); background: var(--ok); }
.bar__fill--warn { background: var(--flag); }
.bar__fill--bad { background: var(--bad); }
.meter { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .3rem var(--s-4); align-items: baseline; padding: .55rem 0; }
.meter__name { font-weight: 550; overflow-wrap: anywhere; }
.meter__value { color: var(--muted); font-size: var(--text-sm); font-variant-numeric: tabular-nums; white-space: nowrap; }
.meter__value strong { color: var(--ink); }
.meter .bar { grid-column: 1 / -1; }
.meters--cols { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(22rem, 100%), 1fr)); column-gap: var(--s-6); }
.chart svg { display: block; width: 100%; height: auto; }
.chart__grid { stroke: var(--line); stroke-width: 1; }
.chart__label { fill: var(--muted); font-size: var(--text-xs); font-variant-numeric: tabular-nums; }
.chart__line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.chart__dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart__dot--exam { fill: var(--surface); stroke: var(--action); stroke-width: 2.5; }
.chart__dot--small { stroke-width: 1.25; }
.chart__bar { fill: var(--accent); }
.chart-key { display: flex; gap: var(--s-4); flex-wrap: wrap; margin-top: var(--s-2); color: var(--muted); font-size: var(--text-sm); }
.chart-key i { display: inline-block; width: .65rem; height: .65rem; margin-right: .35rem; border-radius: 50%; background: var(--accent); }
.chart-key i.is-exam { background: var(--surface); box-shadow: inset 0 0 0 2px var(--action); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 4.6rem minmax(0, 1fr); gap: var(--s-3); padding: .55rem 0; border-top: 1px solid var(--line); font-size: var(--text-sm); }
.timeline li:first-child { border-top: 0; }
.timeline time { color: var(--muted); font-variant-numeric: tabular-nums; }
.plain-list { margin: 0; padding: 0; list-style: none; }
.plain-list li { display: flex; justify-content: space-between; gap: var(--s-4); padding: .55rem 0; border-top: 1px solid var(--line); }
.plain-list li:first-child { border-top: 0; }

/* ===== Sign-in ===== */
.auth { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .85fr); width: 100%; max-width: 52rem; border: 1px solid var(--line); border-radius: calc(var(--r-lg) + 6px); background: var(--surface); overflow: hidden; }
.auth__form { padding: clamp(1.5rem, 5vw, 3rem); }
.auth__brand { display: flex; align-items: center; gap: .6rem; margin: 0 0 var(--s-2); font-size: var(--text-xl); font-weight: 700; letter-spacing: -.02em; }
.auth__form .lede { margin-bottom: var(--s-5); }
.auth__form .btn--block { margin-top: var(--s-5); }
.auth__note { margin: var(--s-5) 0 0; color: var(--muted); font-size: var(--text-sm); }
/* The one loud element: an answer sheet, the object every student here knows. */
.sheet { display: grid; align-content: center; justify-content: center; gap: .7rem; padding: var(--s-6); background: var(--cover); color: var(--on-cover-muted); }
.sheet__row { display: grid; grid-template-columns: 1.6rem repeat(5, 2rem); gap: .55rem; align-items: center; }
.sheet__num { font-size: var(--text-xs); font-variant-numeric: tabular-nums; text-align: right; padding-right: .3rem; opacity: .7; }
.sheet__bubble { display: grid; place-items: center; width: 2rem; height: 2rem; border: 1.5px solid color-mix(in srgb, var(--on-cover-muted) 55%, transparent); border-radius: 50%; font-size: var(--text-xs); font-weight: 600; }
.sheet__bubble.is-filled { background: var(--on-cover); border-color: var(--on-cover); color: var(--cover); }
@media (max-width: 720px) {
  .auth { grid-template-columns: 1fr; max-width: 26rem; }
  .sheet { order: -1; padding: var(--s-4); gap: .45rem; }
  .sheet__row:nth-child(n+3) { display: none; }
  .sheet__row { grid-template-columns: 1.4rem repeat(5, 1.75rem); }
  .sheet__bubble { width: 1.75rem; height: 1.75rem; }
}

/* ===== Student home ===== */
.welcome { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4) var(--s-5); flex-wrap: wrap; margin-bottom: var(--s-5); }
.welcome h1 { margin: 0 0 var(--s-2); overflow-wrap: anywhere; }

/* ===== Quiz: the question card, shared by training and exam ===== */
.quiz { max-width: 50rem; margin: 0 auto; }
.quiz__bar { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-2) var(--s-4); flex-wrap: wrap; margin-bottom: var(--s-2); }
.quiz__title { font-weight: 600; overflow-wrap: anywhere; }
.quiz__count { color: var(--muted); font-size: var(--text-sm); font-variant-numeric: tabular-nums; }
.progress { height: .375rem; margin-bottom: var(--s-4); border-radius: var(--r-pill); background: var(--line); overflow: hidden; }
.progress__fill { width: 0; height: 100%; border-radius: var(--r-pill); background: var(--accent); transition: width var(--slow) var(--ease); }
.question-card { position: relative; overflow: hidden; padding: clamp(1.1rem, 2.6vw, 1.75rem); }
.question__num { margin-bottom: var(--s-2); color: var(--muted); font-size: var(--text-sm); font-weight: 550; font-variant-numeric: tabular-nums; }
.question__text { margin-bottom: var(--s-5); font-size: clamp(1.0625rem, 1rem + .35vw, 1.1875rem); font-weight: 500; line-height: 1.5; white-space: pre-line; overflow-wrap: anywhere; hyphens: auto; }
.options { display: grid; gap: var(--s-2); }
.option { display: flex; align-items: center; gap: var(--s-3); width: 100%; min-height: 3.5rem; padding: .7rem var(--s-4) .7rem .8rem; border: 1px solid var(--line-strong); border-radius: 14px; background: var(--surface); color: var(--ink); text-align: left; cursor: pointer; transition: border-color var(--fast), background var(--fast), box-shadow var(--fast); }
.option:hover:not(:disabled, .is-selected) { background: var(--sunken); }
.option:hover:not(:disabled) .option__letter { border-color: var(--action); }
.option:disabled { cursor: default; }
.option:disabled:not(.is-selected, .is-correct, .is-wrong) { opacity: .72; }
.option__letter { display: grid; place-items: center; flex: none; width: 2rem; height: 2rem; border: 1.5px solid var(--line-strong); border-radius: 50%; font-size: var(--text-sm); font-weight: 650; transition: background var(--fast), border-color var(--fast), color var(--fast); }
.option__text { flex: 1; min-width: 0; overflow-wrap: anywhere; hyphens: auto; }
.option.is-selected { border-color: var(--action); box-shadow: inset 0 0 0 1px var(--action); background: var(--sunken); }
.option.is-selected .option__letter { background: var(--action); border-color: var(--action); color: var(--on-action); }
.option.is-correct { border-color: var(--ok); box-shadow: inset 0 0 0 1px var(--ok); background: var(--ok-soft); }
.option.is-correct .option__letter { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.option.is-wrong { border-color: var(--bad); box-shadow: inset 0 0 0 1px var(--bad); background: var(--bad-soft); }
.option.is-wrong .option__letter { background: var(--bad); border-color: var(--bad); color: var(--on-bad); }
.option.is-correct::after, .option.is-wrong::after { flex: none; font-weight: 700; font-size: var(--text-lg); line-height: 1; }
.option.is-correct::after { content: "✓"; color: var(--ok); }
.option.is-wrong::after { content: "✕"; color: var(--bad); }
.canvas-text canvas { display: block; max-width: 100%; }
.verdict { display: inline-block; margin: 0 0 var(--s-3); padding: .3rem .8rem; border-radius: var(--r-pill); font-weight: 650; scroll-margin-top: calc(var(--bar-h) + 1rem); }
.verdict::before { margin-right: var(--s-2); font-weight: 700; }
.verdict--ok { background: var(--ok-soft); color: var(--ok); }
.verdict--ok::before { content: "✓"; }
.verdict--bad { background: var(--bad-soft); color: var(--bad); }
.verdict--bad::before { content: "✕"; }
.quiz__nav { display: flex; justify-content: space-between; gap: var(--s-2); flex-wrap: wrap; margin-top: var(--s-5); }
.quiz__nav .btn { min-height: 3rem; }
/* Stays in sight under the sticky top bar while the question scrolls. */
#net-error { position: sticky; top: calc(var(--bar-h) + var(--s-2)); z-index: 14; margin: 0 0 var(--s-3); box-shadow: var(--shadow-pop); }

/* ===== Exam ===== */
.exam-body, .exam-body * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.exam-top { position: sticky; top: 0; z-index: 15; background: var(--surface); border-bottom: 1px solid var(--line); }
.exam-top__inner { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); max-width: 1200px; min-height: var(--bar-h); margin: 0 auto; padding: var(--s-2) var(--gutter); }
.exam-top .quiz__title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exam-top__tools { display: flex; align-items: center; gap: var(--s-2); flex: none; min-width: 0; }
.exam-progress { height: 3px; background: var(--line); }
.exam-progress__fill { width: 0; height: 100%; background: var(--accent); transition: width var(--slow) var(--ease); }
.timer { flex: none; padding: .3rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--sunken); font-size: var(--text-lg); font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.3; }
.timer__digit { display: inline-block; width: .62em; text-align: center; }
.timer__sep { display: inline-block; width: .32em; text-align: center; }
.timer--low { border-color: var(--bad); background: var(--bad); color: var(--on-bad); animation: timer-pulse 1s ease-in-out infinite; }
@keyframes timer-pulse { 50% { box-shadow: 0 0 0 4px var(--bad-line); } }
.violations { color: var(--muted); font-size: var(--text-sm); font-weight: 600; white-space: nowrap; }
.violations.is-hot { padding: .3rem .65rem; border-radius: var(--r-pill); background: var(--bad-soft); color: var(--bad); }
.violations__short { display: none; }
.exam-layout { display: grid; grid-template-columns: minmax(0, 1fr) 19rem; gap: var(--s-4); align-items: start; }
.exam-layout .card { margin-bottom: 0; }
/* Short enough to fit above the page's 5rem bottom padding, so its head never slides under the top bar. */
.exam-side { position: sticky; top: calc(var(--bar-h) + 1.25rem); max-height: calc(100dvh - var(--bar-h) - 1.25rem - 5rem); padding: var(--s-4); overflow-y: auto; overscroll-behavior: contain; }
.exam-side__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-2); font-weight: 600; }
.qgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.5rem, 1fr)); gap: .4rem; margin-top: var(--s-3); padding: 4px; }
.exam-side .qgrid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.qgrid__item { position: relative; height: 2.5rem; padding: 0; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); color: var(--ink); font-size: var(--text-sm); font-weight: 600; font-variant-numeric: tabular-nums; cursor: pointer; transition: background var(--fast), border-color var(--fast); }
.qgrid__item:hover { border-color: var(--action); }
.qgrid__item.is-answered { background: var(--action); border-color: var(--action); color: var(--on-action); }
.qgrid__item.is-pending { border: 2px dashed var(--action); background: var(--surface); color: var(--ink); }
.qgrid__item.is-current { outline: 2px solid var(--accent); outline-offset: 2px; }
.qgrid__item.is-flagged::after { content: ""; position: absolute; top: -4px; right: -4px; width: .7rem; height: .7rem; border: 2px solid var(--surface); border-radius: 50%; background: var(--flag); }
.legend { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); margin-top: var(--s-3); color: var(--muted); font-size: var(--text-xs); }
.legend i { display: inline-block; width: .8rem; height: .8rem; margin-right: .35rem; border: 1px solid var(--line-strong); border-radius: 4px; vertical-align: -1px; }
.legend .l-answered { background: var(--action); border-color: var(--action); }
.legend .l-flagged { border: 0; border-radius: 50%; background: var(--flag); }
.legend .l-pending { border: 2px dashed var(--action); background: var(--surface); }
.legend .l-correct { background: var(--ok); border-color: var(--ok); }
.legend .l-wrong { position: relative; border: 2px solid var(--bad); background: var(--bad-soft); }
.legend .l-wrong::after { content: "✕"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--bad); font-size: .5rem; font-style: normal; font-weight: 700; line-height: 1; }
.legend .l-skipped { border-style: dashed; border-color: var(--warn); }
a.qgrid__item { display: grid; place-items: center; text-decoration: none; }
.qgrid__item.is-correct { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.qgrid__item.is-wrong { border: 2px solid var(--bad); background: var(--bad-soft); color: var(--bad-strong); }
.qgrid__item.is-wrong::after { content: "✕"; position: absolute; top: -5px; right: -5px; display: grid; place-items: center; width: .95rem; height: .95rem; border: 2px solid var(--surface); border-radius: 50%; background: var(--bad); color: var(--on-bad); font-size: .5rem; font-weight: 700; line-height: 1; }
.qgrid__item.is-skipped { border-style: dashed; border-color: var(--warn); color: var(--warn); }
.quiz--review { display: grid; grid-template-columns: minmax(0, 50rem) 19rem; column-gap: var(--s-4); max-width: calc(69rem + var(--s-4)); align-items: start; }
.quiz--review > .result, .review-list { grid-column: 1; }
.review-side { grid-column: 2; grid-row: 1 / span 2; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.review-item:target { outline: 2px solid var(--accent); outline-offset: 2px; }
.review-item__up { display: none; margin-left: auto; font-size: var(--text-xs); white-space: nowrap; }
.watermark { position: absolute; inset: 0; z-index: 5; overflow: hidden; pointer-events: none; opacity: var(--watermark-opacity); }
.watermark__inner { position: absolute; inset: -100%; display: flex; flex-direction: column; justify-content: center; gap: 2.6em; transform: rotate(-24deg); color: var(--ink); font-size: .8rem; font-weight: 600; line-height: 1; }
/* One line of tiles; --row (set by watermark.js) slides it so that its middle tile stays on the host's centre line. */
.watermark__row { display: flex; flex: none; gap: 3rem; height: 1em; transform: translateX(calc(var(--row, 0) * -1.603em)); }
.watermark__side { display: flex; flex: 1 1 0; gap: 3rem; min-width: 0; }
.watermark__side:first-child { justify-content: flex-end; }
.watermark__inner span { flex: none; white-space: nowrap; }
.watermark--narrow .watermark__inner { font-size: .7rem; }
/* The proctoring cover: opaque, nothing of the question shows through. */
.overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: var(--s-5); background: var(--cover); color: var(--on-cover); text-align: center; }
.overlay--top { z-index: 140; }
.overlay__box { max-width: 32rem; }
.overlay__box h2 { margin: 0 0 var(--s-3); font-size: var(--text-2xl); }
.overlay__box p { margin-bottom: var(--s-5); color: var(--on-cover-muted); font-size: var(--text-lg); }
.overlay .btn { background: var(--on-cover); border-color: var(--on-cover); color: var(--cover); min-height: var(--h-lg); padding-inline: var(--s-6); font-size: var(--text-lg); }
.overlay .btn:hover { background: var(--on-cover-muted); border-color: var(--on-cover-muted); }
.overlay:focus, .question-card:focus { outline: none; }
/* Time left and violations: the cover hides the top bar, not the clock. */
.overlay__box .overlay__status { margin: var(--s-4) 0 0; color: var(--on-cover); font-size: var(--text-lg); font-weight: 650; font-variant-numeric: tabular-nums; }
.overlay__status:empty { display: none; }
/* «Залишилось …» and «Порушення …» each stay whole: a narrow screen breaks only between them. */
.overlay__status-part { white-space: nowrap; }
/* Camera: red because it records. */
.camera-wrap { display: inline-flex; align-items: center; gap: var(--s-1); }
.camera { display: inline-flex; align-items: center; gap: var(--s-2); padding: 2px .6rem 2px 2px; border: 1.5px solid var(--bad); border-radius: 10px; background: var(--bad-soft); color: var(--bad); font-size: var(--text-xs); font-weight: 650; cursor: default; }
/* 36 px of video + padding and border stay within the bar's --h-md row. */
.camera video { width: 3rem; height: 2.25rem; border-radius: 7px; background: #000; object-fit: cover; transform: scaleX(-1); }
.camera__label { display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap; }
.camera__label::before { content: ""; width: .5rem; height: .5rem; border-radius: 50%; background: currentColor; }
.camera--off { background: var(--bad); color: var(--on-bad); cursor: pointer; padding-left: .6rem; min-height: var(--h-sm); }
.camera--off video { display: none; }
.camera--off + .camera-hide { display: none; }
/* Hidden from the student, still playing for the camera. */
.camera--compact { padding: .35rem .6rem; }
.camera--compact video { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.camera-hide { min-height: var(--h-sm); padding: 0 var(--s-2); border: 0; background: none; color: var(--muted); font-size: var(--text-xs); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; white-space: nowrap; cursor: pointer; }
.camera-hide:hover { color: var(--ink); }

/* ===== Exam rules page ===== */
.intro { max-width: 60rem; margin: 0 auto; }
.intro-head { margin-bottom: var(--s-4); }
.intro-head h1 { margin-bottom: var(--s-2); overflow-wrap: anywhere; }
.intro-head .lede { margin-bottom: var(--s-5); }
.camera-notice { display: grid; grid-template-columns: minmax(0, 1fr) 14rem; gap: var(--s-5); align-items: start; margin: 0 0 var(--s-4); padding: var(--s-5); border: 2px solid var(--bad); border-radius: var(--r-lg); background: var(--bad-soft); }
.camera-notice h2 { margin: 0 0 var(--s-3); color: var(--bad); }
.camera-notice__check { display: grid; gap: var(--s-3); text-align: center; }
.camera-notice__check .small { margin: 0; }
.camera-preview { width: 100%; height: auto; aspect-ratio: 4 / 3; border: 2px solid var(--bad); border-radius: var(--r-md); background: #000; object-fit: cover; transform: scaleX(-1); }
.camera-consent span { color: var(--bad); font-weight: 600; }
.rule-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-4); margin-bottom: var(--s-4); align-items: stretch; }
.rule-card { margin: 0; }
.rule-card h2 { font-size: var(--text-lg); }
.rule-card--strict { border-color: var(--bad-line); }
.rule-card--strict h2 { color: var(--bad); }
.rule-card__sum { margin: var(--s-4) 0 0; padding-top: var(--s-4); border-top: 1px solid var(--line); font-size: var(--text-sm); }
.rules { margin: 0; padding-left: 1.15rem; }
.rules li { margin-bottom: var(--s-2); padding-left: .15rem; }
.rules li::marker { color: var(--line-strong); }
.rule-card .rules { font-size: var(--text-sm); }
.start-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s-4) var(--s-6); align-items: center; border-color: var(--action); box-shadow: inset 0 0 0 1px var(--action); }
.start-card__go { text-align: center; }
.start-card__go p { margin: var(--s-2) 0 0; }

/* ===== Result and review ===== */
.result { padding-block: var(--s-6); text-align: center; }
.result__title { margin: 0; color: var(--muted); font-size: var(--text-md); font-weight: 550; line-height: 1.55; letter-spacing: normal; text-wrap: wrap; overflow-wrap: anywhere; }
.result__voided { margin: 0 0 var(--s-3); font-size: var(--text-2xl); line-height: 1.15; letter-spacing: -.025em; }
.result__verdict { display: flex; align-items: center; justify-content: center; gap: var(--s-2); flex-wrap: wrap; margin-bottom: var(--s-3); }
.result .alert { margin: var(--s-4) auto 0; max-width: 36rem; text-align: left; }
.score { margin: var(--s-2) 0; font-size: var(--text-display); font-weight: 700; line-height: 1; letter-spacing: -.045em; font-variant-numeric: tabular-nums; }
.review-item { position: relative; overflow: hidden; }
.review-item__head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); margin-bottom: var(--s-2); }
.review-item__head .question__num { margin: 0; }
.review-item .question__text { margin-bottom: var(--s-4); font-size: var(--text-md); }
.review-option { display: flex; align-items: baseline; gap: var(--s-3); padding: .5rem .7rem; margin-bottom: var(--s-1); border: 1px solid transparent; border-radius: var(--r-sm); }
.review-option > span:last-child { flex: 1; min-width: 0; overflow-wrap: anywhere; hyphens: auto; }
.review-option__mark { flex: none; min-width: 4.2rem; color: var(--muted); font-size: var(--text-xs); font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.review-option__mark--letter { min-width: 2.2rem; font-size: var(--text-sm); }
/* The staff label «студента» is longer than «ваш»: a wider column keeps the option texts aligned. */
.review-item--long-mark .review-option__mark { min-width: 6.25rem; }
/* The teacher's attempt page has no result card: the list starts level with the panel. */
@media (min-width: 1024px) { .quiz--review .review-list > h2:first-child { margin-top: 0; } }
.review-option.is-correct { border-color: var(--ok-line); background: var(--ok-soft); }
.review-option.is-correct .review-option__mark { color: var(--ok); }
.review-option.is-wrong { border-color: var(--bad-line); background: var(--bad-soft); }
.review-option.is-wrong .review-option__mark { color: var(--bad); }
.snapshots { display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); gap: var(--s-4) var(--s-3); margin: 0; padding: 0; list-style: none; }
.snapshot { margin: 0; }
.snapshot__link { display: block; border-radius: var(--r-sm); }
.snapshot__link:hover img { border-color: var(--line-strong); }
.snapshot img { display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; border: 1px solid var(--line); border-radius: var(--r-sm); background: #000; object-fit: cover; }
.snapshot figcaption, .snapshot__caption { margin: .25rem 0 0; color: var(--muted); font-size: var(--text-xs); font-variant-numeric: tabular-nums; }

/* The proctoring journal: time column, the event, the nearest photo; violations on a red well. */
.journal__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--s-2) var(--s-4); margin-bottom: var(--s-3); }
.journal__head h2 { margin: 0; }
.journal__filter { padding: 0; font-size: var(--text-sm); }
.journal:has(#journal-only:checked) .journal__item:not(.is-violation) { display: none; }
.journal:has(#journal-only:checked) .journal__item { border-top: 0; margin-top: var(--s-2); }
.timeline--journal { margin-top: var(--s-3); }
.timeline--journal .journal__item { grid-template-columns: 5.5rem minmax(0, 1fr) auto; align-items: start; padding: var(--s-3) var(--s-2); }
.journal__item.is-violation { border-top-color: var(--bad-line); border-radius: var(--r-sm); background: var(--bad-soft); }
.journal__item.is-violation + .journal__item { border-top-color: var(--bad-line); }
.journal__item.is-violation .badge--bad { box-shadow: inset 0 0 0 1px var(--bad-line); }
.journal__when { display: flex; flex-direction: column; gap: .1rem; font-variant-numeric: tabular-nums; }
.journal__when time { color: var(--ink); font-weight: 600; }
.journal__offset, .journal__date { color: var(--muted); font-size: var(--text-xs); }
.journal__body { display: flex; flex-direction: column; gap: .2rem; min-width: 0; }
.journal__body p { margin: 0; }
.journal__title { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.journal__why { color: var(--muted); font-size: var(--text-xs); }
.journal__question { overflow-wrap: anywhere; }
.journal__facts { display: flex; flex-wrap: wrap; gap: 0 var(--s-3); color: var(--muted); font-size: var(--text-xs); }
.journal__facts:empty { display: none; }
.journal__photo { display: flex; flex-direction: column; gap: .2rem; width: 6rem; color: var(--muted); font-size: var(--text-xs); line-height: 1.25; text-decoration: none; }
.journal__photo img { display: block; width: 6rem; height: 4.5rem; border: 1px solid var(--line); border-radius: var(--r-sm); background: #000; object-fit: cover; }
.journal__photo:hover img { border-color: var(--line-strong); }

/* ===== Teacher: expandable questions, bank statistics, the exam form ===== */
.question-details summary { display: flex; align-items: baseline; gap: var(--s-3); list-style: none; cursor: pointer; }
.question-details summary::-webkit-details-marker { display: none; }
.question-details summary::after { content: ""; flex: none; order: 9; align-self: center; width: .5rem; height: .5rem; margin: 0 .2rem; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg) translate(-2px, -2px); transition: transform var(--fast); }
.question-details[open] summary::after { transform: rotate(-135deg) translate(-2px, -2px); }
.question-details summary:hover { color: var(--accent-strong); }
.question-details__body { margin: var(--s-3) 0 var(--s-1); }
.question-details__full { margin-bottom: var(--s-3); white-space: pre-line; }
.analysis-item { padding: var(--s-3) 0; border-top: 1px solid var(--line); }
.analysis-item:first-of-type { border-top: 0; }
.analysis-item__text { flex: 1; min-width: 0; }
.analysis-item[open] .analysis-item__text { font-weight: 600; }
.qlist-head { display: flex; align-items: baseline; justify-content: space-between; padding: 0 var(--s-5) var(--s-2); color: var(--muted); font-size: var(--text-sm); }
.qlist-head__legend, .qcard__stats { display: grid; grid-template-columns: repeat(2, 8.5rem); gap: var(--s-3); }
.qlist-head__legend { font-weight: 600; }
.qlist { display: grid; gap: var(--s-3); margin: 0; padding: 0; list-style: none; }
.qcard { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s-5); align-items: start; padding: var(--s-4) var(--s-5); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }
.qcard--off { background: var(--sunken); }
.qcard__num { flex: none; min-width: 2rem; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.qcard__text { flex: 1; min-width: 0; font-weight: 500; line-height: 1.5; }
.qcard .question-details__body { max-width: 78ch; margin-left: 2.75rem; padding-top: var(--s-3); border-top: 1px solid var(--line); }
.qcard__tags { display: flex; flex-wrap: wrap; gap: .35rem; margin: var(--s-3) 0 0 2.75rem; }
.qstat { padding: var(--s-2) var(--s-3) var(--s-3); border-radius: var(--r-md); background: var(--sunken); }
.qstat__label { display: none; color: var(--muted); font-size: var(--text-xs); font-weight: 600; }
.qstat__value { font-size: var(--text-xl); font-weight: 650; line-height: 1.25; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.qstat__value--none { color: var(--line-strong); }
.qstat .bar { min-width: 0; margin: .3rem 0 .35rem; }
.qstat__sub { color: var(--muted); font-size: var(--text-xs); }
.form-section h3 { margin-top: 0; }
.form-section__sub, .form-section h3.form-section__sub { margin-top: var(--s-5); padding-top: var(--s-5); border-top: 1px solid var(--line); }
.form-section__sub > h3:first-of-type { margin-top: 0; }
.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: var(--s-4) var(--s-5); }
.setting { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.setting--wide { grid-column: 1 / -1; }
.setting--grow { grid-column: span 2; }
.setting--error input:not([type=checkbox], [type=search]), .setting--error select { border-color: var(--bad); }
/* In a pick list the well is the field: it turns red, not the filter nor every box. */
.form .pick-list input[aria-invalid="true"]:not(:checked) { border-color: var(--line-strong); }
.form .pick-list input[aria-invalid="true"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent); }
.setting--error .pick-list--scroll { border-color: var(--bad); }
.form-section--error { border-color: var(--bad-line); }
.form-section__errors { margin: calc(-1 * var(--s-2)) 0 var(--s-3); }
/* Locked: the control is grey, the hint keeps its full contrast. */
.setting--locked .setting__label, .setting--locked .setting__toggle > span { color: var(--muted); }
.setting--locked select, .setting--locked input:not([type=checkbox]) { background-color: var(--sunken); color: var(--muted); }
.setting__toggle input[type=checkbox]:disabled { opacity: .6; }
.setting__extra { display: flex; flex-direction: column; gap: .35rem; }
.form input[type=datetime-local] { height: var(--h-md); }
.setting__label { font-weight: 600; font-size: var(--text-sm); }
.setting__help { color: var(--muted); font-size: var(--text-sm); line-height: 1.4; }
.setting__toggle { display: flex; align-items: flex-start; gap: var(--s-3); font-weight: 600; cursor: pointer; }
/* A setting that is on or off reads as a switch. */
.setting__toggle input[type=checkbox] { width: 2.5rem; height: 1.5rem; border-radius: var(--r-pill); place-content: center start; padding: 0 2px; background: var(--line-strong); border-color: var(--line-strong); }
.setting__toggle input[type=checkbox]::after { width: 1.05rem; height: 1.05rem; border-radius: 50%; clip-path: none; background: var(--surface); transform: none; transition: transform var(--fast) var(--ease); }
.setting__toggle input[type=checkbox]:checked { background: var(--action); border-color: var(--action); }
.setting__toggle input[type=checkbox]:checked::after { transform: translateX(1rem); background: var(--on-action); }
/* A focused box or switch shows the page-wide teal outline, not the faint input halo. */
.form input[type=checkbox]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; box-shadow: none; }
.pick-list { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-4); }
.pick-list--scroll { display: block; max-height: 15rem; padding: var(--s-2) var(--s-3); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--sunken); overflow-y: auto; }
.pick { display: flex; align-items: center; gap: var(--s-2); padding: .3rem 0; cursor: pointer; }
.pick--question { align-items: flex-start; padding: var(--s-2) 0; border-bottom: 1px solid var(--line); font-size: var(--text-sm); line-height: 1.45; }
.pick--question:last-child { border-bottom: 0; }
.pick--question input { margin-top: .1rem; }
.rule-row { display: grid; grid-template-columns: minmax(0, 1fr) 7rem auto; gap: var(--s-2); max-width: 46rem; margin: var(--s-2) 0; }
.rule-row + .btn, #rule-rows + template + .btn { margin-top: var(--s-2); }
.picked { display: grid; gap: var(--s-1); margin: var(--s-2) 0 var(--s-3); padding: 0; list-style: none; }
.picked__item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s-3); align-items: center; padding: var(--s-1) var(--s-1) var(--s-1) var(--s-3); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--sunken); font-size: var(--text-sm); }
.picked__item--off { border-color: var(--warn-line); background: var(--surface); }
.picker > summary { display: inline-flex; list-style: none; }
.picker > summary::-webkit-details-marker { display: none; }
.picker__filters { display: grid; grid-template-columns: minmax(0, 18rem) minmax(0, 1fr); gap: var(--s-2); margin: var(--s-3) 0 var(--s-2); }
.picker__results { max-height: 26rem; margin-bottom: var(--s-2); }
.form-errors ul { margin: var(--s-2) 0 0; padding-left: 1.2rem; }
.live-updated.is-stale { color: var(--bad); font-weight: 600; }

/* ===== Date-time picker (datetime_picker.js): a field, a calendar dialog, a bottom sheet on phones ===== */
.dtp { position: relative; }
.dtp input.dtp__native { position: absolute; left: 0; bottom: 0; width: 1px; height: 1px; min-height: 0; padding: 0; border: 0; opacity: 0; pointer-events: none; }
.dtp__field { display: flex; align-items: center; gap: .6rem; width: 100%; min-height: var(--h-md); padding: .55rem .8rem; border: 1px solid var(--line-strong); border-radius: var(--r-md); background: var(--surface); color: var(--ink); line-height: 1.3; text-align: left; font-variant-numeric: tabular-nums; cursor: pointer; transition: border-color var(--fast), box-shadow var(--fast); }
.dtp--optional .dtp__field { padding-right: 2.6rem; }
.dtp__field:hover { border-color: var(--ink); }
.dtp__field:focus-visible, .dtp.is-open .dtp__field { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent); }
.dtp__field[aria-invalid="true"], .setting--error .dtp__field { border-color: var(--bad); }
.dtp__field[aria-invalid="true"]:focus-visible, .setting--error .dtp__field:focus-visible,
.dtp.is-open .dtp__field[aria-invalid="true"], .setting--error .dtp.is-open .dtp__field { border-color: var(--bad); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 25%, transparent); }
.dtp__field:disabled { border-color: var(--line-strong); background: var(--sunken); color: var(--muted); cursor: not-allowed; }
.dtp__icon { flex: none; width: 1.25rem; height: 1.25rem; fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.dtp__field:not(:disabled):hover .dtp__icon, .dtp.is-open .dtp__icon { stroke: var(--accent); }
.dtp__text { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.dtp__text.is-empty { color: var(--muted); }
/* A narrow field shows «24 лист. 2026» instead of «24 листопада 2026», a narrower one «24.11.2026, 10:05». */
.dtp__field { container-type: inline-size; }
.dtp__short, .dtp__tight { display: none; }
@container (max-width: 16rem) {
  .dtp__long { display: none; }
  .dtp__short { display: inline; }
}
@container (max-width: 13.5rem) {
  .dtp__wide { display: none; }
  .dtp__tight { display: inline; }
}
.dtp__clear { position: absolute; top: 50%; right: .3rem; display: grid; place-items: center; width: var(--h-sm); height: var(--h-sm); padding: 0; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--muted); font-size: var(--text-sm); cursor: pointer; transform: translateY(-50%); }
.dtp__clear[hidden] { display: none; }
.dtp__clear:hover { background: var(--sunken); color: var(--ink); }
.dtp__clear:focus-visible { outline-offset: -2px; }
.dtp__pop { position: absolute; top: calc(100% + var(--s-2)); left: 0; z-index: 18; width: 21rem; max-width: calc(100vw - 2 * var(--gutter)); padding: var(--s-4); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-pop); scroll-margin-bottom: var(--s-4); animation: dtp-in var(--fast) var(--ease); }
.dtp__pop[hidden] { display: none; }
.dtp__pop--end { left: auto; right: 0; }
@keyframes dtp-in { from { opacity: 0; transform: translateY(-4px); } }
.dtp__title { display: none; }
.dtp__chips { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-bottom: var(--s-3); padding-bottom: var(--s-3); border-bottom: 1px solid var(--line); }
.dtp__chip { min-height: 2rem; padding: .2rem .75rem; border: 1px solid var(--line-strong); border-radius: var(--r-pill); background: var(--surface); color: var(--ink); font-size: var(--text-sm); font-weight: 500; cursor: pointer; transition: background var(--fast), border-color var(--fast); }
@media (hover: hover) {
  .dtp__chip:hover:not(:disabled) { border-color: var(--ink); background: var(--sunken); }
}
.dtp__chip:disabled { opacity: .45; cursor: not-allowed; }
.dtp__head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); margin-bottom: var(--s-1); }
.dtp__month { font-weight: 650; font-size: var(--text-md); letter-spacing: -.01em; }
.dtp__nav { display: grid; place-items: center; width: var(--h-sm); height: var(--h-sm); padding: 0; border: 1px solid transparent; border-radius: var(--r-sm); background: transparent; color: var(--ink); cursor: pointer; }
.dtp__nav:hover { border-color: var(--line); background: var(--sunken); }
.dtp__chevron { width: 1.1rem; height: 1.1rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.dtp__grid { width: 100%; border-collapse: collapse; table-layout: fixed; }
.dtp__grid th { height: 2rem; padding: 0; color: var(--muted); font-size: var(--text-xs); font-weight: 600; text-align: center; }
.dtp__grid td { padding: 1px 0; text-align: center; cursor: pointer; }
.dtp__grid td:focus { outline: none; }
.dtp__day { position: relative; display: grid; place-items: center; width: 2.5rem; height: 2.5rem; margin: 0 auto; border-radius: 50%; font-weight: 500; font-variant-numeric: tabular-nums; transition: background var(--fast), color var(--fast); }
/* A tap leaves no sticky hover on touch screens. */
@media (hover: hover) {
  .dtp__grid td:hover .dtp__day { background: var(--sunken); }
}
.dtp__grid td:focus-visible .dtp__day { outline: 2px solid var(--accent); outline-offset: 1px; }
.dtp__grid .is-outside .dtp__day { color: var(--muted); font-weight: 400; }
.dtp__grid .is-today .dtp__day { color: var(--accent-strong); font-weight: 650; }
.dtp__grid .is-today .dtp__day::after { content: ""; position: absolute; bottom: .3rem; left: 50%; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: currentColor; }
.dtp__grid .is-selected .dtp__day, .dtp__grid td.is-selected:hover .dtp__day { background: var(--action); color: var(--on-action); font-weight: 650; }
.dtp__grid .is-off { cursor: not-allowed; }
/* A saved day that is now before the opening stays visible as chosen; the server judges it. */
.dtp__grid .is-off:not(.is-selected) .dtp__day, .dtp__grid td.is-off:not(.is-selected):hover .dtp__day { background: transparent; color: var(--line-strong); font-weight: 400; }
.dtp__time { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-top: var(--s-3); padding-top: var(--s-3); border-top: 1px solid var(--line); }
.dtp__time-label { font-weight: 600; font-size: var(--text-sm); }
.dtp__clock { display: flex; align-items: center; gap: var(--s-1); }
.dtp__colon { font-weight: 650; font-size: var(--text-lg); color: var(--muted); }
.dtp__spin { display: inline-flex; align-items: stretch; height: var(--h-md); border: 1px solid var(--line-strong); border-radius: var(--r-md); background: var(--surface); transition: border-color var(--fast), box-shadow var(--fast); }
.dtp__spin:hover { border-color: var(--ink); }
.dtp__spin:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent); }
.dtp__step { width: 2rem; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: var(--text-lg); line-height: 1; cursor: pointer; }
.dtp__step:first-child { border-radius: var(--r-md) 0 0 var(--r-md); }
.dtp__step:last-child { border-radius: 0 var(--r-md) var(--r-md) 0; }
.dtp__step:hover { background: var(--sunken); color: var(--ink); }
.dtp input.dtp__num, .dtp input.dtp__num:hover, .dtp input.dtp__num:focus { width: 2.4rem; min-height: 0; height: auto; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; font-size: var(--text-lg); font-weight: 600; font-variant-numeric: tabular-nums; text-align: center; caret-color: var(--accent); }
.dtp__foot { display: flex; justify-content: flex-end; gap: var(--s-2); margin-top: var(--s-4); }
.dtp__reset { margin-right: auto; }
.dtp__scrim { display: none; }
@media (max-width: 479px) {
  .dtp.is-open .dtp__scrim { display: block; position: fixed; inset: 0; z-index: 84; background: var(--scrim); }
  .dtp__pop, .dtp__pop--end { --dtp-foot: calc(var(--s-3) + var(--h-md) + var(--s-4) + env(safe-area-inset-bottom)); position: fixed; inset: auto 0 0; z-index: 85; width: auto; max-width: none; max-height: 92dvh; overflow-y: auto; padding: var(--s-5) var(--gutter) 0; border-width: 1px 0 0; border-radius: var(--r-lg) var(--r-lg) 0 0; scroll-padding-bottom: calc(var(--dtp-foot) + var(--s-2)); animation-name: dtp-sheet; animation-duration: var(--slow); }
  .dtp__title { display: block; margin-bottom: var(--s-4); }
  .dtp__name { font-weight: 650; font-size: var(--text-lg); line-height: 1.3; }
  .dtp__summary { color: var(--muted); font-size: var(--text-sm); font-variant-numeric: tabular-nums; }
  .dtp__day { width: var(--h-md); height: var(--h-md); }
  .dtp__nav { width: var(--h-md); height: var(--h-md); }
  .dtp__chip { min-height: var(--h-sm); }
  /* On a short phone the sheet scrolls, and «Готово» stays in view at its bottom. */
  .dtp__foot { position: sticky; bottom: 0; z-index: 1; margin: var(--s-3) calc(-1 * var(--gutter)) 0; padding: var(--s-3) var(--gutter) calc(var(--s-4) + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); }
  .dtp__foot .btn { flex: 1; min-height: var(--h-md); }
  .dtp__reset { margin-right: 0; }
}
@media (max-width: 479px) and (max-height: 700px) {
  .dtp__pop, .dtp__pop--end { padding-top: var(--s-4); }
  .dtp__title { margin-bottom: var(--s-3); }
  .dtp__chips { margin-bottom: var(--s-2); padding-bottom: var(--s-2); }
  .dtp__time { margin-top: var(--s-2); padding-top: var(--s-2); }
  .dtp__day { width: 2.375rem; height: 2.375rem; }
}
/* A phone with its browser bars leaves ~550 px: the time row must still show above «Готово». */
@media (max-width: 479px) and (max-height: 600px) {
  .dtp__pop, .dtp__pop--end { --dtp-foot: calc(var(--s-2) + var(--h-md) + var(--s-3) + env(safe-area-inset-bottom)); padding-top: var(--s-3); }
  .dtp__title { margin-bottom: var(--s-2); }
  .dtp__summary { display: none; }
  .dtp__chip { min-height: 2rem; }
  .dtp__head { margin-bottom: 0; }
  .dtp__nav { width: var(--h-sm); height: var(--h-sm); }
  .dtp__grid th { height: 1.5rem; }
  .dtp__day { width: 2.125rem; height: 2.125rem; }
  .dtp__grid .is-today .dtp__day::after { bottom: .2rem; }
  .dtp__foot { margin-top: var(--s-2); padding-top: var(--s-2); padding-bottom: calc(var(--s-3) + env(safe-area-inset-bottom)); }
}
@keyframes dtp-sheet { from { opacity: .6; transform: translateY(1.5rem); } }
@media (pointer: coarse) {
  .dtp__step { width: var(--h-md); }
}
@media (max-width: 359px) {
  .dtp__time { gap: var(--s-2); }
  .dtp__step { width: var(--h-sm); }
}

/* ===== Wide screens: a comfortable reading width for the exam ===== */
@media (min-width: 1500px) {
  .page--exam, .exam-top__inner { max-width: 1320px; }
  .exam-layout { grid-template-columns: minmax(0, 1fr) 21rem; }
}

/* ===== Tablets: one column, the question list under the question ===== */
@media (max-width: 1023px) {
  .exam-layout { grid-template-columns: minmax(0, 1fr); }
  .exam-side { position: static; max-height: none; overflow-y: visible; }
  .exam-side .qgrid { grid-template-columns: repeat(auto-fill, minmax(2.5rem, 1fr)); }
  .review-item__up { display: inline; }
  .quiz--review { grid-template-columns: minmax(0, 1fr); max-width: 50rem; }
  .review-side { grid-column: 1; grid-row: auto; }
  .rule-cards { grid-template-columns: 1fr; }
  .qcard { grid-template-columns: 1fr; gap: var(--s-3); }
  .qcard__stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .qstat__label { display: block; }
  .qlist-head__legend { display: none; }
  .qcard .question-details__body, .qcard__tags { margin-left: 0; }
}

/* ===== Phones: tighter gutters, stacked tables, actions under the thumb ===== */
@media (max-width: 767px) {
  .timeline--journal .journal__item { grid-template-columns: minmax(0, 1fr); gap: var(--s-2); }
  .journal__when { flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: 0 var(--s-2); }
  .snapshots { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .journal__photo { flex-direction: row; align-items: center; gap: var(--s-2); width: auto; }
  :root { --gutter: max(1rem, env(safe-area-inset-left), env(safe-area-inset-right)); --bar-h: 3.5rem; }
  .page { padding-top: var(--s-4); padding-bottom: var(--s-7); }
  .card { padding: var(--s-4); border-radius: 16px; }
  h2 { margin-top: var(--s-5); }
  .stats, .facts { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat, .fact { padding: var(--s-3) var(--s-4); }
  .stat:last-child:nth-child(odd), .fact:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .welcome .btn, .start-card .btn { width: 100%; }
  .assignment { flex-wrap: wrap; }
  .assignment .btn { width: 100%; }
  .assignment__actions { display: grid; grid-auto-columns: 1fr; grid-auto-flow: column; width: 100%; }
  .assignment .btn--sm { min-height: var(--h-md); }
  .page-head__actions { width: 100%; }
  .filters > div { flex: 1 1 9rem; }
  .filters select { min-width: 0; }
  .segmented { display: grid; grid-template-columns: repeat(auto-fit, minmax(3.4rem, 1fr)); width: 100%; }
  .segmented--stack { grid-template-columns: 1fr; }
  /* The verdict may take two lines here: a plate, not a pill. */
  .verdict { border-radius: var(--r-md); }
  .segmented span { padding-inline: .4rem; }
  .dl { grid-template-columns: 1fr; gap: 0; }
  .dl dt { font-size: var(--text-sm); }
  .dl dd { margin-bottom: var(--s-3); }
  .dl dd:last-child { margin-bottom: 0; }
  .modal { place-items: end center; padding: 0; }
  .modal__box { max-width: none; padding-bottom: calc(var(--s-5) + env(safe-area-inset-bottom)); border-radius: var(--r-lg) var(--r-lg) 0 0; }
  .modal__box .actions { grid-template-columns: 1fr; }
  .camera-notice { grid-template-columns: 1fr; padding: var(--s-4); }
  .camera-notice__check { max-width: 16rem; margin: 0 auto; }
  .start-card { grid-template-columns: 1fr; }
  .setting--grow { grid-column: 1 / -1; }
  /* The category gets the whole line; the count and ✕ go under it. */
  .rule-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "cat cat" "count remove"; padding-bottom: var(--s-2); border-bottom: 1px solid var(--line); }
  .rule-row select { grid-area: cat; }
  .rule-row input { grid-area: count; }
  .rule-row .rule-remove { grid-area: remove; }
  .picker__filters { grid-template-columns: 1fr; }
  .analysis-item summary { flex-wrap: wrap; }
  .analysis-item__text { flex-basis: 100%; }
  .review-option__mark { min-width: 4rem; }
  .review-option__mark--letter { min-width: 2.2rem; }
  /* «· студента» goes on a phone: ✕ and the item badge already tell the chosen option. */
  .review-item--long-mark .review-option__mark { min-width: 1.75rem; }
  .review-item--long-mark .review-option__who { display: none; }
  .table--matrix th:first-child, .table--matrix td:first-child { min-width: 9.5rem; max-width: 10rem; }
  .table--matrix .cell-title { font-size: var(--text-sm); }
  /* A table row becomes a card: the title cell on top, labelled values under it. */
  .table--stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .table--stack, .table--stack tbody { display: block; }
  .table--stack tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-2) var(--s-4); padding: var(--s-3) 0; border-top: 1px solid var(--line); }
  .table--stack tr:first-child { border-top: 0; padding-top: 0; }
  .table--stack tr:last-child { padding-bottom: 0; }
  .table--stack td, .table--stack td.num, .table--stack td:first-child, .table--stack td:last-child { display: block; padding: 0; border: 0; text-align: left; white-space: normal; }
  .table--stack td:empty { display: none; }
  .table--stack .row-idle td:not(.cell-title, [data-label="Група"], [data-label="Статус"]) { display: none; }
  .table--live .cell-title { width: auto; min-width: 0; max-width: none; overflow: visible; }
  .table--stack td[data-label="Статус"] { grid-column: 1 / -1; }
  .table--history td[data-label="Статус"] { grid-column: auto; }
  .table--stack:not(.table--history) td[data-label="Статус"] { order: -1; }
  .table--stack td[data-label]::before { content: attr(data-label); display: block; color: var(--muted); font-size: var(--text-xs); font-weight: 400; }
  .table--stack td .badge { max-width: 100%; padding-block: .2rem; line-height: 1.2; text-align: left; white-space: normal; }
  .table--stack .cell-title, .table--stack .cell-action { grid-column: 1 / -1; }
  .table--stack .cell-title { order: -1; }
  .table--stack .cell-action { order: 9; }
  /* A 44 px link target, its text still flush with the card; room for the focus ring. */
  .table--stack .cell-action a { display: inline-flex; align-items: center; min-height: var(--h-md); padding: 0 var(--s-2); margin-left: calc(-1 * var(--s-2)); }
  .table-wrap:has(> .table--stack) { padding-inline: var(--s-3); margin-inline: calc(-1 * var(--s-3)); }
  .table--stack tr.row-alert, .table--stack tr.row-alert:first-child { padding: var(--s-3); border-radius: var(--r-md); background: var(--bad-soft); box-shadow: inset 0 0 0 1px var(--bad-line); }
  .table--stack .row-alert td, .table--stack .row-alert td:first-child { background: none; box-shadow: none; padding-left: 0; }
  /* Alert cards stand apart by a gap, not a hairline against their frame. */
  .table--stack tr.row-alert { border-top: 0; margin-bottom: var(--s-2); }
  .table--stack tr.row-alert:last-child { margin-bottom: 0; }
  .table--stack tr.row-alert + tr { border-top: 0; }
  /* Quiz actions sit in a bar under the thumb. */
  .exam-body .page, .quiz { padding-bottom: 6rem; }
  .question-card .quiz__nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; gap: var(--s-2); margin: 0; padding: .6rem var(--gutter) calc(.6rem + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); }
  .exam-body .question-card .quiz__nav { grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr); }
  .quiz .question-card .quiz__nav { grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); }
  .quiz .question-card .quiz__nav:has(> .btn.hidden) { grid-template-columns: minmax(0, 1fr); }
  /* An option scrolled into view stops above the bar, not under it. */
  .question-card .option { scroll-margin-bottom: calc(5.5rem + env(safe-area-inset-bottom)); }
  .question-card .quiz__nav .btn { padding-inline: .7rem; font-size: var(--text-sm); }
  #net-error { position: fixed; top: auto; left: 50%; bottom: calc(4.6rem + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 120; width: calc(100vw - 1.5rem); margin: 0; font-size: var(--text-sm); box-shadow: var(--shadow-pop); }
  /* Room to scroll the last option out from under the banner. */
  .page:has(#net-error:not(.hidden)) { padding-bottom: 13rem; }
  /* An open dialog is a bottom sheet: the banner moves under the top bar, off its text and buttons. */
  body:has(.modal:not(.hidden)) #net-error { top: calc(var(--bar-h) + var(--s-2)); bottom: auto; }
  /* Under the top bar: the options and the bottom bar stay free to tap. */
  .toast { top: calc(var(--bar-h) + var(--s-2)); bottom: auto; }
  /* Exam top bar: short forms, so that it fits a 320 px screen. */
  .exam-top__inner { gap: var(--s-2); }
  .exam-top .quiz__title { display: none; }
  /* One row with the camera and violations too: a two-row sticky bar eats the screen.
     Sized to fit; should it ever not, it wraps instead of pushing the camera off the left edge. */
  .exam-top__tools { flex: 1; justify-content: flex-end; flex-wrap: wrap; gap: .35rem; }
  .exam-top__tools > * { flex-shrink: 0; }
  .exam-top .btn--sm { min-height: var(--h-md); padding-inline: .5rem; }
  .violations__long { display: none; }
  .violations__short { display: inline; }
  .violations.is-hot { padding: .3rem .35rem; }
  .timer { padding-inline: .45rem; font-size: var(--text-md); }
  .exam-top .camera-wrap { gap: 0; }
  .exam-top .camera video { width: 2.75rem; height: 2.0625rem; }
  .exam-top .camera:not(.camera--off) { padding: 2px; gap: 0; }
  .exam-top .camera .camera__label { font-size: 0; gap: 0; }
  .exam-top .camera:not(.camera--off) .camera__label::before { display: none; }
  .exam-top .camera--off { min-height: var(--h-md); }
  /* A switched-off camera is the red «● камера» button; aria-label and title say what it does. */
  .exam-top .camera--off { padding-inline: .6rem; }
  .exam-top .camera--off .camera__label::after { content: "камера"; font-size: var(--text-xs); margin-left: .35rem; }
  /* A hidden camera folds into one red «● камера» button that brings it back. */
  .exam-top .camera--compact:not(.camera--off) { width: 0; padding: 0; border: 0; overflow: hidden; visibility: hidden; }
  .camera-hide { min-height: var(--h-md); padding: 0 .2rem; font-size: 0; }
  .camera-hide::after { content: "сховати"; font-size: var(--text-xs); }
  .camera-hide[aria-pressed="true"]::after { content: "● камера"; color: var(--bad); font-weight: 650; }
  .camera-hide[aria-pressed="true"] { text-decoration: none; }
}
@media (max-width: 399px) {
  /* The limit is in the cover, the toast and the label: the badge keeps only the count. */
  .violations__max { display: none; }
}
@media (max-width: 359px) {
  .exam-top__inner { padding-inline: .5rem; }
  .exam-top__tools { gap: .25rem; }
  .exam-top .btn--sm { padding-inline: .45rem; }
  .timer { padding-inline: .35rem; font-size: var(--text-md); }
  .exam-top .camera video { width: 2rem; height: 1.5rem; }
  .exam-top .camera--off { padding-inline: .45rem; }
}

/* ===== A phone on its side: every pixel of height goes to the question ===== */
@media (max-height: 480px) and (orientation: landscape) {
  .exam-top, .topbar { position: static; }
  .question-card .quiz__nav { position: static; display: flex; margin-top: var(--s-4); padding: 0; border: 0; background: none; }
  .exam-body .page, .quiz { padding-bottom: var(--s-6); }
  #net-error { position: static; transform: none; width: auto; margin: 0 0 var(--s-3); box-shadow: none; }
  .page:has(#net-error:not(.hidden)) { padding-bottom: var(--s-6); }
}

/* ===== Touch screens: 44 px targets ===== */
@media (pointer: coarse) {
  .btn--sm, .camera-hide, .back-link { min-height: var(--h-md); }
  .table td a { display: inline-flex; align-items: center; min-height: var(--h-md); }
  .chip > span, .segmented span { min-height: var(--h-md); display: flex; align-items: center; justify-content: center; }
  .chip > span { border-radius: calc(var(--h-md) / 2); }
  .pick { min-height: var(--h-md); }
  .qgrid__item { height: var(--h-md); }
  .review-item__up { display: inline-flex; align-items: center; min-height: var(--h-md); }
}

@media print {
  .exam-body * { display: none !important; }
  .exam-body::before { content: "Друк під час іспиту вимкнено."; }
}
