/* ==========================================================================
   LDS exercises — stylesheet
   Token names are the interface for exercise modules (DESIGN.md). Values may change.
   ========================================================================== */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --bg:#f6f7f9; --card:#ffffff; --surface-2:#f2f3f6; --fg:#14161c; --fg-2:#3f4451; --muted:#5b6170;
  --border:#e4e6eb; --ctl-border:#80868f; --ctl-border-strong:#5b6170;
  --accent:#4650c8; --accent-hover:#3b44b0; --accent-fg:#ffffff; --accent-soft:#eef0fd;
  --accent-ring:rgba(70, 80, 200, .28);
  --neutral-soft:#eceef2; --row-hover:#f6f7fa;
  --ok:#157a3c; --ok-bg:#e9f7ee; --bad:#b42318; --bad-bg:#fdeeec; --warn:#94580a; --warn-bg:#fdf5e3;

  --shadow-xs:0 1px 2px rgba(16, 20, 32, .05);
  --shadow-sm:0 1px 2px rgba(16, 20, 32, .04), 0 1px 3px rgba(16, 20, 32, .06);
  --shadow-md:0 2px 4px rgba(16, 20, 32, .04), 0 8px 24px -6px rgba(16, 20, 32, .10);
  --header-bg:rgba(255, 255, 255, .82);

  --radius:10px; --radius-sm:7px; --radius-lg:14px;
  --s1:4px; --s2:8px; --s3:12px; --s4:16px; --s5:24px; --s6:32px; --s7:48px;
  --fs-xs:.8125rem; --fs-sm:.875rem; --fs-lg:1.125rem;
  --dur:140ms; --ease:cubic-bezier(.2, .7, .3, 1);

  --sans:"Inter",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
  --mono:ui-monospace,SFMono-Regular,Menlo,Consolas,"Liberation Mono",monospace;
  --math:KaTeX_Main,KaTeX_AMS,"Latin Modern Math","STIX Two Math","Cambria Math",serif;
  --math-it:KaTeX_Math,KaTeX_Main,"Latin Modern Math","STIX Two Math","Cambria Math",serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg:#0d0e11; --card:#15171c; --surface-2:#1b1e24; --fg:#e8eaee; --fg-2:#c9cdd6; --muted:#9ba3af;
    --border:#262a31; --ctl-border:#6a717e; --ctl-border-strong:#8b929e;
    --accent:#9ba6ff; --accent-hover:#b2baff; --accent-fg:#0b0d1f; --accent-soft:#1d2140;
    --accent-ring:rgba(155, 166, 255, .32);
    --neutral-soft:#22252c; --row-hover:#1a1d22;
    --ok:#7ddc9f; --ok-bg:#12261a; --bad:#f7a3a0; --bad-bg:#2c1617; --warn:#f1c86a; --warn-bg:#2a2312;
    --shadow-xs:0 1px 2px rgba(0, 0, 0, .3);
    --shadow-sm:0 1px 2px rgba(0, 0, 0, .3), 0 1px 3px rgba(0, 0, 0, .2);
    --shadow-md:0 2px 4px rgba(0, 0, 0, .25), 0 10px 28px -8px rgba(0, 0, 0, .5);
    --header-bg:rgba(21, 23, 28, .8);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:#0d0e11; --card:#15171c; --surface-2:#1b1e24; --fg:#e8eaee; --fg-2:#c9cdd6; --muted:#9ba3af;
  --border:#262a31; --ctl-border:#6a717e; --ctl-border-strong:#8b929e;
  --accent:#9ba6ff; --accent-hover:#b2baff; --accent-fg:#0b0d1f; --accent-soft:#1d2140;
  --accent-ring:rgba(155, 166, 255, .32);
  --neutral-soft:#22252c; --row-hover:#1a1d22;
  --ok:#7ddc9f; --ok-bg:#12261a; --bad:#f7a3a0; --bad-bg:#2c1617; --warn:#f1c86a; --warn-bg:#2a2312;
  --shadow-xs:0 1px 2px rgba(0, 0, 0, .3);
  --shadow-sm:0 1px 2px rgba(0, 0, 0, .3), 0 1px 3px rgba(0, 0, 0, .2);
  --shadow-md:0 2px 4px rgba(0, 0, 0, .25), 0 10px 28px -8px rgba(0, 0, 0, .5);
  --header-bg:rgba(21, 23, 28, .8);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--fg);
  font: 16px/1.55 var(--sans); font-optical-sizing: auto;
  font-feature-settings: "cv05";                     /* Inter: lower-case l with tail (l vs I vs 1) */
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--accent-soft); color: var(--fg); }
p { margin: 0 0 var(--s3); }
h1 { font-size: 1.75rem; line-height: 1.2; font-weight: 650; margin: 0; letter-spacing: -.022em; }
h2, .section-title { font-size: var(--fs-lg); line-height: 1.35; font-weight: 600; margin: 0 0 var(--s3); letter-spacing: -.011em; }
h3 { font-size: 1rem; font-weight: 600; margin: 0 0 var(--s2); letter-spacing: -.006em; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.num { font-variant-numeric: tabular-nums; }

.wrap { max-width: 920px; margin: 0 auto; padding: 0 var(--s5); }
.wrap.wide { max-width: 1240px; }
main.wrap { padding-bottom: var(--s7); }

/* Zero-specificity resets so module classes can override margins. */
:where(.ex-root, .part) > * { margin-top: 0; margin-bottom: 0; }
.ex-root { display: flex; flex-direction: column; gap: var(--s5); margin-top: var(--s5); }

/* ---------- Surfaces ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--s5); margin: var(--s4) 0; box-shadow: var(--shadow-xs);
}
:where(.ex-root) > .card { margin: 0; }
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
.card.table-wrap { padding: 0; margin-top: var(--s5); }
.part { display: flex; flex-direction: column; gap: var(--s4); }
.part > .section-title { margin: 0; }
.part-desc { color: var(--muted); font-size: .9375rem; max-width: 70ch; margin: 0; }

.given {
  position: relative; display: grid; gap: var(--s3);
  background: linear-gradient(180deg, var(--accent-soft), color-mix(in srgb, var(--accent-soft) 35%, var(--card)));
  border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--border));
  border-radius: var(--radius-lg); padding: var(--s4) var(--s5) var(--s4) calc(var(--s5) + 2px);
  overflow: hidden;
}
.given::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent);
}
.given-row {
  display: grid; grid-template-columns: max-content minmax(0, 1fr); column-gap: var(--s5); row-gap: var(--s1);
  align-items: baseline;
}
.given-label {
  font-size: .75rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: color-mix(in srgb, var(--accent) 70%, var(--fg)); min-width: 5.5em;
}
/* Formula labels (e.g. P(x)) keep their case: variables are lower-case. */
.given-label.math { text-transform: none; }
.given-body { overflow-x: auto; min-width: 0; }
.given-body > p { margin: 0; color: var(--fg-2); max-width: 70ch; }

kbd {
  font-family: var(--mono); font-size: .75rem; padding: 1px 6px; line-height: 1.6;
  border: 1px solid var(--border); border-bottom-color: var(--ctl-border); border-radius: 5px;
  background: var(--card); color: var(--fg-2); white-space: nowrap;
}
.preview { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s2) var(--s3); min-height: 28px; }
.preview-error { color: var(--bad); font-size: var(--fs-sm); }
.ex-root input[aria-invalid=true] { border-color: var(--bad); }
.ex-root input[aria-invalid=true]:focus-visible { box-shadow: 0 0 0 3px var(--bad-bg); }

/* Layout primitives kept for existing modules. */
.row { display: flex; gap: var(--s3); align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }

/* ---------- Math ---------- */
.math {
  font-family: var(--math); font-size: 1.21em; line-height: 1.24; font-weight: 400;
  letter-spacing: 0; font-variant-numeric: normal; font-kerning: normal; font-feature-settings: normal;
}
.math .math, .btn .math { font-size: 1em; }
.math.display {
  display: block; font-size: 1.5rem; line-height: 1.4; overflow-x: auto; overflow-y: hidden; padding: 2px 0;
}
.math var { font-family: var(--math-it); font-style: italic; font-weight: 400; }
.math sub, .math sup { font-family: var(--math); font-style: normal; font-size: .7em; line-height: 0; position: relative; }
.math sub { vertical-align: baseline; top: .25em; }
.math sup { vertical-align: baseline; top: -.45em; }
.math .bin { margin: 0 .2222em; }   /* TeX medmuskip 4mu */
.math .rel { margin: 0 .2778em; }             /* TeX thickmuskip 5mu */
.math .punct { margin-right: .1667em; }       /* TeX thinmuskip after comma */
.math .colon { margin: 0 .2778em 0 .0556em; }
.math .not, .math .q { margin: 0; }
.math .mathrm { font-style: normal; font-family: var(--math); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: 38px; padding: 0 var(--s4); font: inherit; font-size: .9375rem; font-weight: 550; line-height: 1;
  border: 1px solid var(--ctl-border); border-radius: var(--radius); background: var(--card); color: var(--fg);
  box-shadow: var(--shadow-xs); cursor: pointer; text-decoration: none; white-space: nowrap; user-select: none;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease),
              color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--ctl-border-strong); color: var(--fg); }
.btn:active:not(:disabled) { transform: translateY(1px); box-shadow: none; }
.btn.primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-fg);
  box-shadow: 0 1px 2px rgba(16, 20, 32, .12), inset 0 1px 0 rgba(255, 255, 255, .14);
}
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-fg); }
.btn:disabled { cursor: not-allowed; opacity: .55; box-shadow: none; }
.btn.primary:disabled { opacity: 1; background: var(--neutral-soft); border-color: var(--border); color: var(--muted); }
.btn.ghost { border-color: transparent; background: transparent; box-shadow: none; color: var(--fg-2); }
.btn.ghost:hover:not(:disabled) { background: var(--neutral-soft); border-color: transparent; color: var(--fg); }
.btn.sm { height: 32px; padding: 0 var(--s3); font-size: var(--fs-sm); border-radius: var(--radius-sm); }
.btn .icon { width: 16px; height: 16px; flex: none; }
.btn.link {
  height: auto; padding: 0; border: 0; background: none; box-shadow: none; color: var(--accent); font-weight: 500;
  border-radius: 3px;
}
.btn.link:hover:not(:disabled) { text-decoration: underline; text-underline-offset: 2px; background: none; color: var(--accent-hover); }
.btn.link:disabled { color: var(--muted); opacity: 1; }
.btn.link:active { transform: none; }

.actions {
  display: flex; justify-content: flex-end; align-items: center; flex-wrap: wrap; gap: var(--s3);
  border-top: 1px solid var(--border); padding-top: var(--s4); margin: 0;
}
.actions-note { margin-right: auto; color: var(--muted); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.actions-note:empty { display: none; }
.actions-note.preview-error { color: var(--bad); }
/* The exercise's final action bar stays in reach at the bottom of the viewport. */
.ex-root > .actions:last-child {
  position: sticky; bottom: var(--s3); z-index: 5;
  border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--s3) var(--s3) var(--s3) var(--s5);
  background: color-mix(in srgb, var(--card) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(10px); backdrop-filter: saturate(1.4) blur(10px);
  box-shadow: var(--shadow-md);
}
.ex-root > .actions:last-child > .btn.primary { min-width: 132px; }

/* ---------- Segmented control ---------- */
.seg {
  display: inline-flex; flex-wrap: wrap; gap: 2px; position: relative; max-width: 100%; width: fit-content;
  padding: 3px; background: var(--surface-2); border: 1px solid var(--ctl-border); border-radius: var(--radius);
}
.seg input[type=radio] {
  position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none;
}
.seg label {
  display: inline-flex; align-items: center; justify-content: center; min-height: 34px; padding: 0 var(--s4);
  font-size: .9375rem; font-weight: 500; color: var(--fg-2); background: transparent;
  border: 0; border-radius: var(--radius-sm); margin: 0; cursor: pointer; user-select: none;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.seg label:hover { background: var(--card); color: var(--fg); }
.seg input:checked + label {
  background: var(--accent); color: var(--accent-fg); box-shadow: 0 1px 2px rgba(16, 20, 32, .18);
}
.seg input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg input:disabled + label { cursor: not-allowed; opacity: .6; }

/* Segmented control whose options are long text: a vertical list of option rows with a radio mark. */
.seg:has(> label:nth-of-type(3)) {
  display: flex; flex-direction: column; align-items: stretch; gap: 6px; width: auto;
  padding: 0; background: none; border: 0;
}
.seg:has(> label:nth-of-type(3)) > label {
  position: relative; height: auto; min-height: 44px; padding: 10px var(--s4) 10px 44px;
  white-space: normal; text-align: left; justify-content: flex-start; line-height: 1.45;
  color: var(--fg); background: var(--card); border: 1px solid var(--ctl-border); border-radius: var(--radius);
}
.seg:has(> label:nth-of-type(3)) > label::before {
  content: ""; position: absolute; left: var(--s4); top: 13px; width: 16px; height: 16px; border-radius: 50%;
  border: 1.5px solid var(--ctl-border); background: var(--card);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.seg:has(> label:nth-of-type(3)) > label:hover { border-color: var(--accent); background: var(--card); }
.seg:has(> label:nth-of-type(3)) > input:checked + label {
  background: var(--accent-soft); color: var(--fg); border-color: var(--accent); box-shadow: none;
}
.seg:has(> label:nth-of-type(3)) > input:checked + label::before {
  border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 3px var(--card);
}

.label-main { display: block; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px;
  font-size: .75rem; font-weight: 600; line-height: 1; letter-spacing: .01em; white-space: nowrap; border: 0;
  background: var(--neutral-soft); color: var(--fg-2);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 16%, transparent);
}
.badge.open, .badge.upcoming, .badge.closed { padding-left: 9px; }
.badge.open::before, .badge.upcoming::before, .badge.closed::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none;
}
.badge.open { background: var(--ok-bg); color: var(--ok); }
.badge.upcoming { background: var(--warn-bg); color: var(--warn); }
.badge.closed { color: var(--muted); }

/* ---------- Forms ---------- */
.form { display: grid; gap: var(--s4); }
.field { display: grid; gap: 6px; }
.field > span { font-size: var(--fs-sm); font-weight: 500; color: var(--fg-2); }
.field-hint { font-size: var(--fs-xs); color: var(--muted); margin: -8px 0 0; }
:where(input:not([type=radio]):not([type=checkbox]):not([type=range])), :where(select) {
  font: inherit; height: 40px; padding: var(--s2) var(--s3); width: 100%;
  border: 1px solid var(--ctl-border); border-radius: var(--radius); background: var(--card); color: var(--fg);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
textarea {
  font: inherit; min-height: 96px; line-height: 1.5; padding: var(--s2) var(--s3); width: 100%;
  border: 1px solid var(--ctl-border); border-radius: var(--radius); background: var(--card); color: var(--fg);
  box-shadow: var(--shadow-xs); resize: vertical;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
textarea.mono, input.mono { font-family: var(--mono); }
input.mono, textarea.mono { font-size: .9375rem; }
input:not([type=radio]):not([type=checkbox]):not([type=range]):hover:not(:disabled):not(:focus),
textarea:hover:not(:disabled):not(:focus), select:hover:not(:disabled):not(:focus) { border-color: var(--ctl-border-strong); }
input:not([type=radio]):not([type=checkbox]):not([type=range]):focus,
select:focus, textarea:focus {
  outline: 2px solid transparent; outline-offset: 0; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
input:disabled, textarea:disabled, select:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
::placeholder { color: var(--muted); opacity: .8; }
input[type=radio], input[type=checkbox] {
  width: 18px; height: 18px; margin: 0 var(--s2) 0 0; accent-color: var(--accent); vertical-align: middle; flex: none;
}
label:has(> input[type=radio]), label:has(> input[type=checkbox]) {
  display: inline-flex; align-items: center; min-height: 36px; margin-right: var(--s4); white-space: nowrap;
}

/* ---------- Site chrome ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20; height: 60px;
  background: var(--header-bg); border-bottom: 1px solid var(--border);
  -webkit-backdrop-filter: saturate(1.6) blur(12px); backdrop-filter: saturate(1.6) blur(12px);
}
.site-header .wrap {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s4); height: 100%;
}
.site-title {
  display: inline-flex; align-items: center; gap: 10px; min-width: 0;
  font-weight: 600; font-size: .9375rem; color: var(--fg); text-decoration: none; white-space: nowrap;
  border-radius: var(--radius-sm);
}
a.site-title:hover { color: var(--fg); }
.site-title .short { display: none; }
.brand-mark {
  display: inline-grid; place-items: center; width: 30px; height: 30px; flex: none; border-radius: 9px;
  color: #fff; background: linear-gradient(145deg, #5c65da, #3a3fa6);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22), 0 1px 2px rgba(16, 20, 32, .2);
}
.brand-mark svg { width: 18px; height: 18px; display: block; }
.brand-name { letter-spacing: -.012em; overflow: hidden; text-overflow: ellipsis; }
.brand-sep { color: var(--ctl-border); font-weight: 400; }
.brand-sub { color: var(--muted); font-weight: 500; }
.site-nav { display: flex; align-items: center; gap: var(--s2); font-size: .9375rem; white-space: nowrap; }
.site-nav a:not(.btn), .site-nav .btn.link { color: var(--accent); text-decoration: none; }
.site-nav a:not(.btn):hover { text-decoration: underline; }
.user-chip {
  display: inline-flex; align-items: center; gap: var(--s2); height: 32px; padding: 0 var(--s3);
  border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border);
  font-size: var(--fs-sm); color: var(--fg-2); font-weight: 500; max-width: 220px;
}
.user-name { overflow: hidden; text-overflow: ellipsis; }

.page-head { margin: var(--s6) 0 0; }
.page-head h1 { margin: 0; }
.page-sub { margin: var(--s2) 0 0; color: var(--muted); font-size: .9375rem; }
.page-title-row { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s3); }
.page-title-row .btn { margin-left: auto; }
.crumbs {
  display: flex; align-items: center; gap: 6px; margin: 0 0 var(--s2); font-size: var(--fs-sm); color: var(--muted);
}
.crumbs a {
  color: var(--muted); text-decoration: none; display: inline-flex; align-items: center; gap: 4px; border-radius: 4px;
  font-weight: 500;
}
.crumbs a:hover { color: var(--fg); }
.crumbs svg { width: 16px; height: 16px; }

.meta-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); margin-top: var(--s3); }
.meta { display: flex; flex-wrap: wrap; gap: var(--s2); margin: 0; padding: 0; font-size: var(--fs-sm); }
.meta > div {
  display: inline-flex; gap: 6px; align-items: center; height: 28px; padding: 0 var(--s3) 0 10px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--card); box-shadow: var(--shadow-xs);
}
.meta > div[class]::before {
  content: ""; width: 14px; height: 14px; flex: none; background: var(--muted);
  -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat;
}
.meta .m-due { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='5' width='18' height='16' rx='3'/%3E%3Cpath d='M3 10h18M8 3v4M16 3v4'/%3E%3C/svg%3E"); }
.meta .m-attempts { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 12a8 8 0 1 1-2.34-5.66'/%3E%3Cpath d='M20 4v5h-5'/%3E%3C/svg%3E"); }
.meta .m-best { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 21h8M12 17v4M7 4h10v5a5 5 0 0 1-10 0V4z'/%3E%3Cpath d='M17 6h3v2a3 3 0 0 1-3 3M7 6H4v2a3 3 0 0 0 3 3'/%3E%3C/svg%3E"); }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; font-weight: 600; color: var(--fg); font-variant-numeric: tabular-nums; }
#count { margin: var(--s3) 0; }

/* ---------- Sign-in ---------- */
.auth-shell {
  display: flex; align-items: flex-start; justify-content: center;
  padding: clamp(var(--s5), 9vh, 96px) var(--s4) var(--s7);
}
.auth-card {
  width: 100%; max-width: 420px; margin: var(--s6) auto; padding: var(--s6);
  border-radius: 18px; box-shadow: var(--shadow-md);
}
.auth-shell > .auth-card { margin: 0; }
.auth-brand { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s5); }
.auth-brand .brand-mark { width: 40px; height: 40px; border-radius: 12px; }
.auth-brand .brand-mark svg { width: 22px; height: 22px; }
.auth-brand-text { display: grid; line-height: 1.3; min-width: 0; }
.auth-brand-text strong { font-size: .9375rem; font-weight: 600; letter-spacing: -.01em; }
.auth-brand-text span { font-size: var(--fs-sm); color: var(--muted); }
.auth-card h1 { font-size: 1.375rem; letter-spacing: -.02em; margin: 0 0 var(--s4); }
.auth-card .actions { border-top: 0; padding-top: var(--s1); }
.auth-card .actions .btn.primary { width: 100%; height: 42px; }
.auth-card .form > p { margin: 0; }

/* ---------- Dashboard ---------- */
.stats {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s3); margin: var(--s5) 0 0; padding: 0;
}
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--s3) var(--s4); box-shadow: var(--shadow-xs); min-width: 0;
}
.stat dt { font-size: var(--fs-xs); color: var(--muted); font-weight: 500; }
.stat dd {
  margin: 2px 0 0; font-size: 1.125rem; font-weight: 600; letter-spacing: -.01em; font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stat dd small { font-size: var(--fs-sm); font-weight: 500; color: var(--muted); }

.asg-list {
  list-style: none; margin: var(--s5) 0 0; padding: 0;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.asg-list:empty { display: none; }
.asg-item {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) 200px 136px; align-items: center;
  gap: var(--s4); padding: var(--s4) var(--s5); transition: background-color var(--dur) var(--ease);
}
.asg-item + .asg-item { border-top: 1px solid var(--border); }
.asg-item:hover { background: var(--row-hover); }
.asg-icon {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent);
}
.asg-icon svg { width: 20px; height: 20px; }
.asg-item.is-submitted .asg-icon { background: var(--ok-bg); color: var(--ok); }
.asg-item.is-upcoming .asg-icon { background: var(--warn-bg); color: var(--warn); }
.asg-item.is-closed .asg-icon { background: var(--neutral-soft); color: var(--muted); }
.asg-main { min-width: 0; display: grid; gap: 4px; }
.asg-title-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px var(--s2); }
.asg-title { font-weight: 600; color: var(--fg); text-decoration: none; letter-spacing: -.008em; border-radius: 3px; }
a.asg-title:hover { color: var(--accent); }
.asg-dates {
  display: flex; flex-wrap: wrap; gap: 2px var(--s4); font-size: var(--fs-sm); color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.asg-dates b { font-weight: 500; color: var(--fg-2); }
.asg-progress { display: grid; gap: 6px; min-width: 0; }
.asg-progress-line {
  display: flex; justify-content: space-between; align-items: baseline; gap: var(--s2);
  font-size: var(--fs-sm); font-variant-numeric: tabular-nums;
}
.asg-score { font-weight: 600; color: var(--fg); }
.asg-score.none { font-weight: 400; color: var(--muted); }
.asg-attempts { color: var(--muted); font-size: var(--fs-xs); white-space: nowrap; }
.asg-action { display: flex; justify-content: flex-end; }
.asg-action .btn { min-width: 120px; }
.asg-empty { padding: var(--s6) var(--s5); text-align: center; color: var(--muted); }

.meter { position: relative; height: 6px; border-radius: 999px; background: var(--neutral-soft); overflow: hidden; }
.meter > span {
  position: absolute; inset: 0 auto 0 0; width: var(--pct, 0%); border-radius: inherit; background: var(--accent);
  transition: width 400ms var(--ease);
}

/* ---------- Alerts and result panel ---------- */
.alert {
  padding: var(--s3) var(--s4); border-radius: var(--radius); background: var(--bad-bg); color: var(--bad);
  border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent); margin: var(--s3) 0; font-size: .9375rem;
}
.result {
  position: relative; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--s5); margin-top: var(--s5); box-shadow: var(--shadow-md);
  overflow: hidden; scroll-margin: 84px 0 var(--s5);
  animation: result-in 260ms var(--ease) both;
}
.result::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 110px; pointer-events: none;
  background: linear-gradient(180deg, color-mix(in srgb, var(--tone, var(--muted)) 11%, transparent), transparent);
}
.result:focus { outline: none; }
.result:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.result > * { position: relative; }
.result-head {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--s2) var(--s4); margin: 0;
}
.result-summary { min-width: 0; display: grid; gap: 2px; }
.result-verdict { font-weight: 650; font-size: 1.0625rem; letter-spacing: -.01em; color: var(--tone, var(--fg)); }
.result-sub { color: var(--muted); font-size: var(--fs-sm); }
.result-score-box { text-align: right; display: grid; }
.result-score { font-size: 1.5rem; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.result .meter { margin-top: var(--s4); }
.result-fb-title {
  margin: var(--s5) 0 var(--s2); font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted);
}
.result-feedback { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.result-feedback li {
  position: relative; margin: 0; padding: var(--s2) var(--s3) var(--s2) 30px; border-radius: var(--radius-sm);
  background: var(--surface-2); font-size: .9375rem; line-height: 1.5;
}
.result-feedback li::before {
  content: ""; position: absolute; left: 13px; top: calc(var(--s2) + .75em - 3px); width: 6px; height: 6px;
  border-radius: 50%; background: var(--tone, var(--muted));
}
@keyframes result-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: .9375rem; }
.table th, .table td {
  text-align: left; padding: 11px var(--s4); border-bottom: 1px solid var(--border); vertical-align: middle;
}
.table th {
  font-weight: 600; font-size: .75rem; letter-spacing: .02em; color: var(--muted); background: var(--surface-2);
  white-space: nowrap;
}
.table tbody tr { transition: background-color var(--dur) var(--ease); }
.table tbody tr:hover { background: var(--row-hover); }
.table td.nowrap, .table .nowrap { white-space: nowrap; }
.table td.num, .table .num { white-space: nowrap; font-variant-numeric: tabular-nums; }
.table tbody tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.card.table-wrap > .table th:first-child, .card.table-wrap > .table td:first-child { padding-left: var(--s5); }

.is-pending { opacity: .7; transition: opacity var(--dur) var(--ease); }

/* ---------- Language switch (DE | EN) ---------- */
.lang-switch {
  display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--ctl-border); border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.lang-switch button {
  font: inherit; font-size: .75rem; font-weight: 600; letter-spacing: .04em;
  min-width: 34px; height: 26px; padding: 0 var(--s2); border: 0; border-radius: 5px;
  background: transparent; color: var(--fg-2); cursor: pointer;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.lang-switch button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); box-shadow: var(--shadow-xs); }
.lang-switch button:hover:not([aria-pressed="true"]) { color: var(--fg); background: var(--card); }
.lang-switch button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- Integration fixes ---------- */
:where(.part) :where(input:not([type=radio]):not([type=checkbox])) { max-width: 32rem; }

/* ---------- Medium screens ---------- */
@media (max-width: 820px) {
  .asg-item { grid-template-columns: 40px minmax(0, 1fr) 136px; row-gap: var(--s3); }
  .asg-progress { grid-column: 2; grid-row: 2; }
  .asg-action { grid-column: 3; grid-row: 1 / span 2; }
}

/* ---------- Narrow screens (≤ 640 px) ---------- */
@media (max-width: 640px) {
  .wrap { padding: 0 var(--s4); }
  .site-header { height: 56px; }
  .site-title .full { display: none; }
  .site-title .short { display: inline; }
  .brand-mark { width: 28px; height: 28px; border-radius: 8px; }
  .hide-narrow { display: none !important; }
  .site-nav { gap: var(--s1); }
  .site-nav .btn.ghost { padding: 0 var(--s2); }
  h1 { font-size: 1.5rem; }
  .page-head { margin-top: var(--s5); }
  .card { padding: var(--s4); border-radius: var(--radius); }
  .given { padding: var(--s3) var(--s4) var(--s3) calc(var(--s4) + 2px); border-radius: var(--radius); }
  .given-row { grid-template-columns: minmax(0, 1fr); }
  .math.display { font-size: 1.3rem; }
  .actions-note { flex-basis: 100%; margin-right: 0; }
  .actions > .btn.primary { flex: 1 1 auto; }
  .ex-root > .actions:last-child { bottom: var(--s2); padding: var(--s2) var(--s2) var(--s2) var(--s4); flex-wrap: nowrap; }
  .ex-root > .actions:last-child > .actions-note { flex: 1 1 auto; min-width: 0; font-size: var(--fs-xs); line-height: 1.4; }
  .ex-root > .actions:last-child > .btn.primary { flex: 0 0 auto; min-width: 116px; }
  .ex-root > .actions:last-child:not(:has(.actions-note:not(:empty))) > .btn.primary { flex: 1 1 auto; }
  .site-title .brand-sep, .site-title .brand-sub { display: none; }
  .brand-name { overflow: visible; }
  .meta > div { height: 26px; font-size: var(--fs-xs); }
  .auth-shell { padding: var(--s5) var(--s3) var(--s6); }
  .auth-card { padding: var(--s5); border-radius: var(--radius-lg); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats .stat:last-child { grid-column: 1 / -1; }
  .asg-item { grid-template-columns: 36px minmax(0, 1fr); gap: var(--s3); padding: var(--s4); }
  .asg-icon { width: 36px; height: 36px; border-radius: 10px; }
  .asg-progress { grid-column: 2; grid-row: auto; }
  .asg-action { grid-column: 2; grid-row: auto; justify-content: stretch; }
  .asg-action .btn { width: 100%; }
  .result { padding: var(--s4); }
  .result-head { grid-template-columns: minmax(0, 1fr); }
  .result-score-box { grid-column: 1 / -1; text-align: left; display: flex; align-items: baseline; gap: var(--s2); }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border-bottom: 1px solid var(--border); padding: var(--s2) var(--s4); }
  .card.table-wrap > .table td:first-child { padding-left: 0; }
  .table td { border: 0; padding: var(--s1) 0; display: flex; justify-content: space-between; gap: var(--s3); }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: var(--fs-sm); }
  .seg label { flex: 1 1 auto; padding: 0 var(--s3); }
}

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

/* ---------- Sign-in details ---------- */
.site-header.bare {
  position: static; background: transparent; border-bottom-color: transparent;
  -webkit-backdrop-filter: none; backdrop-filter: none;
}
.notice {
  font-size: var(--fs-sm); color: var(--fg-2); background: var(--accent-soft); border-radius: var(--radius-sm);
  padding: 10px var(--s3); margin: 0; overflow-wrap: anywhere;
}
.notice:empty { display: none; }

/* ---------- Admin results ---------- */
.admin-table th:first-child, .admin-table td:first-child {
  position: sticky; left: 0; z-index: 1; background: var(--card); box-shadow: inset -1px 0 0 var(--border);
}
.admin-table th:first-child { background: var(--surface-2); }
.admin-table tbody tr:hover td:first-child { background: var(--row-hover); }
@media (max-width: 640px) {
  .admin-table th:first-child, .admin-table td:first-child { position: static; box-shadow: none; background: none; }
}


/* ---------- Access codes ---------- */
.code-input {
  font-family: var(--mono); font-size: 1.125rem; font-weight: 600; letter-spacing: .02em; text-align: center;
  text-transform: none; height: 52px; font-variant-numeric: tabular-nums;
}
.code-input::placeholder { color: var(--muted); font-weight: 400; opacity: .7; }
.codes-card { margin-top: var(--s5); display: grid; gap: var(--s4); }
.codes-card h2 { margin: 0; }
.codes-gen { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s3); }
.codes-gen .field { width: 150px; }
.codes-new { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--s3) var(--s4); display: grid; gap: var(--s3); }
.codes-new[hidden] { display: none; }
.codes-new-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); }
.codes-new-head strong { font-size: var(--fs-sm); }
.codes-new-head .btn:first-of-type { margin-left: auto; }
.codes-list {
  margin: 0; padding: 0; list-style: none; font-family: var(--mono); font-size: .9375rem; letter-spacing: .06em;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(20ch, 1fr)); gap: var(--s1) var(--s4);
  max-height: 260px; overflow: auto; user-select: all;
}
.codes-table-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; max-height: 460px; }
.codes-table-wrap .table th:first-child, .codes-table-wrap .table td:first-child { padding-left: var(--s4); }
.code-cell { font-family: var(--mono); letter-spacing: .06em; white-space: nowrap; }
.codes-table .btn { min-width: 112px; }
.code-cell::before { font-family: var(--sans); letter-spacing: normal; text-decoration: none; display: inline-block; }
tr.is-disabled .code-cell { color: var(--muted); text-decoration: line-through; }
@media (max-width: 640px) {
  .codes-gen .field { width: 100%; }
  .codes-gen .btn { width: 100%; }
  .codes-new-head .btn:first-of-type { margin-left: 0; }
  .codes-table-wrap { max-height: none; border: 0; }
  .codes-table tr { padding: var(--s3) 0; }
  .codes-table td:last-child { padding-top: var(--s2); }
  .codes-table .btn { width: 100%; }
}

/* ---------- Schedule editor ---------- */
.sched-card { margin-bottom: var(--s5); display: grid; gap: var(--s3); }
.sched-card h2, .sched-card .page-sub { margin: 0; }
.sched-list { display: grid; gap: var(--s3); }
.sched-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(15.5rem, 1fr)); gap: var(--s2) var(--s4);
  align-items: end; padding: var(--s3) var(--s4); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.sched-row.is-overridden { border-color: var(--accent); }
.sched-title { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); align-self: center; grid-column: 1 / -1; }
.sched-changed { background: var(--accent-soft); color: var(--accent); }
.sched-changed[hidden] { display: none; }
.sched-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); grid-column: 1 / -1; }
.sched-hint { margin: 0; grid-column: 1 / -1; }
.sched-hint[hidden], .sched-actions .btn[hidden] { display: none; }
.sched-msg { font-size: var(--fs-sm); color: var(--muted); }
.sched-msg.ok { color: var(--ok); }
.sched-msg.err { color: var(--bad); }
.sched-row input[aria-invalid=true] { border-color: var(--bad); }
.sched-row .seg { align-self: start; }
.sched-row input[type=datetime-local] { width: 100%; min-width: 0; box-sizing: border-box; }
.sched-row .seg label { white-space: nowrap; }
@media (min-width: 821px) {
  .sched-row { grid-template-columns: repeat(2, minmax(15.5rem, 17rem)) max-content; }
  .sched-title { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  .sched-row { grid-template-columns: 1fr; }
  .sched-actions .btn:not(.ghost) { flex: 1 1 auto; }
}

/* ---------- Reference answer (admin) ---------- */
.solution { margin-top: var(--s5); border-style: dashed; }
.solution > summary { cursor: pointer; font-weight: 600; color: var(--fg-2); }
.solution[open] > summary { margin-bottom: var(--s4); }
.solution-list { display: grid; grid-template-columns: minmax(10rem, max-content) 1fr; gap: var(--s2) var(--s4); margin: 0; }
.solution-list dt { color: var(--muted); font-size: var(--fs-sm); }
.solution-list dd { margin: 0; overflow-wrap: anywhere; }
.solution-text { white-space: pre-line; font-family: var(--mono); font-size: var(--fs-sm); }
@media (max-width: 640px) { .solution-list { grid-template-columns: 1fr; } .solution-list dd { margin-bottom: var(--s2); } }

/* ---------- Sample test (practice) ---------- */
.badge.practice { background: var(--accent-soft); color: var(--accent); }
.badge.practice::before { background: var(--accent); }
.practice-note { margin: var(--s3) 0 0; }
