:root {
  --ink: #1c1f24;
  --ink-soft: #4a525c;
  --line: #d9dde3;
  --paper: #ffffff;
  --paper-soft: #f6f7f9;
  /* The two faces of the site, after their ions: Ag⁺ blue-silver, Ca⁺ the brick red of
     calcium's flame. --accent, --problem and --drill follow the discipline in view. */
  --ag: #245b8a;
  --ca: #b0381f;
  --accent: var(--ag);
  --problem: #0e7c86;
  --drill: #b5532d;
  --flip-duration: 0.8s;
  --ok: #1e6b3a;
  --ok-bg: #edf7f0;
  --bad: #a23a2f;
  --bad-bg: #fbeeec;
  --serif: Georgia, "Times New Roman", "Noto Serif", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
}

html[data-discipline="calculus"],
.flip__face[data-discipline="calculus"] {
  --accent: var(--ca);
  --problem: #7f2414;
  --drill: var(--ca);
}

.flip__face[data-discipline="algebra"] {
  --accent: var(--ag);
  --problem: #0e7c86;
  --drill: #b5532d;
}

* { box-sizing: border-box; }

html { background: var(--paper); color: var(--ink); }

body {
  margin: 0;
  font: 17px/1.55 var(--sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); }
a:hover { color: var(--ink); }

.site-header {
  display: flex;
  align-items: baseline;
  gap: 2rem;
  padding: 0.8rem clamp(1rem, 4vw, 3rem);
  border-top: 3px solid var(--accent);
  border-bottom: 1px solid var(--line);
  transition: border-top-color 0.4s;
  /* A turning catalog page comes towards the viewer; it passes under the header. */
  position: relative;
  z-index: 5;
  background: var(--paper);
}

/* The double button at the left of the header: Ag⁺ | Ca⁺, each half in its own colour,
   the discipline in view filled. A narrow header keeps the marks only. */
.discipline-switch {
  display: inline-flex;
  flex: none;
  align-self: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: var(--paper);
}
.discipline-switch__item {
  --tone: var(--ag);
  display: inline-flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.4rem 1rem 0.35rem;
  color: var(--tone);
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.25s, color 0.25s;
}
.discipline-switch__item[data-discipline="calculus"] { --tone: var(--ca); }
.discipline-switch__item + .discipline-switch__item { border-left: 1px solid var(--line); }
.discipline-switch__item:hover { background: color-mix(in srgb, var(--tone) 9%, transparent); color: var(--tone); }
.discipline-switch__item[aria-current] { background: var(--tone); color: #fff; }
.discipline-switch__item:focus-visible { outline: 3px solid color-mix(in srgb, var(--tone) 45%, transparent); outline-offset: -3px; }
.discipline-switch__mark { font: 700 1.3rem/1 var(--serif); letter-spacing: -0.02em; }
.discipline-switch__mark sup { font-size: 0.62em; }
.discipline-switch__text { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; }

.site-nav { flex: 1; align-self: center; display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; }
.site-nav a { text-decoration: none; font-weight: 600; }

/* The navigation menu behind three bars replaces the inline navigation on a phone. */
.nav-menu { display: none; position: relative; align-self: center; }
.nav-menu__toggle {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.nav-menu__toggle::-webkit-details-marker { display: none; }
.nav-menu__toggle svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.nav-menu__toggle:hover, .nav-menu[open] .nav-menu__toggle { background: var(--paper-soft); border-color: var(--line); }
.nav-menu__toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.nav-menu__panel {
  position: absolute;
  left: 0;
  top: calc(100% + 0.4rem);
  z-index: 10;
  display: flex;
  flex-direction: column;
  width: max-content;
  min-width: 14rem;
  max-width: calc(100vw - 2rem);
  padding: 0.5rem 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: 0 1px 2px rgb(28 31 36 / 4%), 0 8px 24px rgb(28 31 36 / 10%);
}
.nav-menu__panel a { padding: 0.55rem 1rem; color: var(--ink); font-weight: 600; text-decoration: none; }
.nav-menu__panel a:hover { background: var(--paper-soft); color: var(--accent); }
.nav-menu__panel a[aria-current="page"] { color: var(--accent); }

.site-actions {
  display: inline-flex;
  align-items: center;
  gap: 1rem;
  align-self: center;
}

.site-actions form { margin: 0; }

.language {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.language button {
  font: inherit;
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
  color: var(--accent);
  cursor: pointer;
}

.language__current { font-weight: 700; }

/* The account menu at the right end of the header: a round photo (or initial) and the first name. */
.user-menu { position: relative; }
.user-menu__toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.15rem 0.6rem 0.15rem 0.15rem;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--ink);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.user-menu__toggle::-webkit-details-marker { display: none; }
.user-menu__toggle::after { content: ""; width: 0.4rem; height: 0.4rem; margin: -0.2rem 0 0 0.1rem; border: solid var(--ink-soft); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); }
.user-menu[open] .user-menu__toggle::after { margin-top: 0.2rem; transform: rotate(-135deg); }
.user-menu__toggle:hover, .user-menu[open] .user-menu__toggle { background: var(--paper-soft); border-color: var(--line); }
.user-menu__toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.user-menu__avatar { width: 2rem; height: 2rem; flex: none; border-radius: 50%; object-fit: cover; border: 1px solid var(--line); background: var(--paper-soft); }
.user-menu__avatar--empty { display: inline-grid; place-items: center; color: var(--accent); font: 600 1rem/1 var(--serif); text-transform: uppercase; }
.user-menu__name { max-width: 10rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu__panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  z-index: 10;
  width: max-content;
  min-width: 14rem;
  max-width: min(20rem, 100vw - 2rem);
  padding: 0.5rem 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: 0 1px 2px rgb(28 31 36 / 4%), 0 8px 24px rgb(28 31 36 / 10%);
}
.user-menu__who { display: flex; flex-direction: column; margin: 0; padding: 0.35rem 1rem 0.6rem; border-bottom: 1px solid var(--line); line-height: 1.35; }
.user-menu__who span { color: var(--ink-soft); font-size: 0.85rem; }
.user-menu__links { list-style: none; margin: 0; padding: 0.35rem 0; border-bottom: 1px solid var(--line); }
.user-menu__links a, .user-menu .logout button {
  display: block;
  width: 100%;
  padding: 0.4rem 1rem;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.user-menu__links a:hover, .user-menu .logout button:hover { filter: none; background: var(--paper-soft); color: var(--accent); }
.user-menu__links a[aria-current="page"] { color: var(--accent); }
.user-menu .logout { padding-top: 0.35rem; }

.content {
  flex: 1;
  width: min(52rem, 100% - 2rem);
  margin: 0 auto;
  padding: 1.5rem 0 3rem;
}

h1, h2 { font-family: var(--serif); font-weight: 600; line-height: 1.2; }
h1 { font-size: 1.9rem; margin: 0.5rem 0 1rem; }
h2 { font-size: 1.25rem; margin: 1.5rem 0 0.75rem; }

.lead { color: var(--ink-soft); margin-top: 0; }
.breadcrumbs { font-size: 0.9rem; color: var(--ink-soft); margin: 0; }

/* Catalog: collapsible sections; inside each, problem titles that generate a new instance. */
.sections { margin: 1.25rem 0 2rem; border-bottom: 1px solid var(--line); }
.section { border-top: 1px solid var(--line); }

.section > summary {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.85rem 0;
  cursor: pointer;
  list-style: none;
}

.section > summary::-webkit-details-marker { display: none; }

.section > summary::before {
  content: "";
  flex: none;
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid var(--ink-soft);
  border-bottom: 2px solid var(--ink-soft);
  transform: translateY(-0.15rem) rotate(-45deg);
  transition: transform 0.15s;
}

.section[open] > summary::before { transform: translateY(-0.3rem) rotate(45deg); }
.section > summary:hover .section__title { color: var(--accent); }
.section > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.section__title { margin: 0; font-size: 1.3rem; }
.section__count { color: var(--ink-soft); font-size: 0.9rem; }

.catalog { list-style: none; padding: 0 0 0.75rem 1.25rem; margin: 0; }

.catalog__item { padding: 0.75rem 0; border-top: 1px dashed var(--line); }

.catalog__item form {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1.5rem;
  margin: 0;
}

.catalog__text { flex: 1; min-width: 0; }
.catalog__item h3 { margin: 0 0 0.2rem; font: 600 1.15rem/1.3 var(--serif); }
.catalog__item p { margin: 0; color: var(--ink-soft); }

/* A submit button that reads as a link: the title itself requests a new problem. */
.catalog__title {
  font: inherit;
  padding: 0;
  border: 0;
  background: none;
  color: var(--problem);
  text-align: left;
  white-space: normal;
  text-decoration: none;
}

.catalog__title:hover { filter: none; color: var(--ink); }
.catalog__title:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* A one-attempt drill sits in its topic section; its title is set apart by colour. */
.catalog__item--micro .catalog__title,
.catalog__title--micro,
.picker__item--micro .picker__check { color: var(--drill); }
.catalog__item--micro .catalog__title:hover,
.catalog__title--micro:hover { color: var(--ink); }

/* A link to a started problem takes the same colours as the catalog titles. */
.problem-link { color: var(--problem); text-decoration: none; }
.problem-link--micro { color: var(--drill); }
.problem-link:hover { color: var(--ink); }

/* The description: a tooltip that appears one second after hover or keyboard focus. */
.catalog__heading { position: relative; }
.catalog__tip {
  position: absolute;
  left: 0;
  top: calc(100% + 0.3rem);
  z-index: 5;
  width: max-content;
  max-width: min(32rem, 90vw);
  padding: 0.4rem 0.65rem;
  border-radius: 4px;
  background: var(--ink);
  color: var(--paper);
  font: 400 0.9rem/1.4 var(--sans);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.15s, visibility 0s linear 0.15s;
}
.catalog__title:hover + .catalog__tip,
.catalog__title:focus-visible + .catalog__tip {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.15s 1s, visibility 0s linear 1s;
}

button, .button {
  font: 600 1rem var(--sans);
  padding: 0.5rem 1.1rem;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}

button:hover { filter: brightness(1.1); }
button:disabled { cursor: not-allowed; opacity: 0.5; }
button.secondary, .button.secondary { background: var(--paper); color: var(--accent); }
a.button { display: inline-block; text-decoration: none; }

.confirm {
  max-width: 40rem;
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
}

.confirm p { margin: 0 0 0.75rem; }
.confirm__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; margin-top: 1.25rem; }
.confirm__actions form { margin: 0; }

.statement {
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper-soft);
}

.statement__text { margin: 0 0 0.75rem; font-family: var(--serif); font-size: 1.1rem; }

.math { overflow-x: auto; padding: 0.25rem 0; font-size: 1.1rem; }
.math mjx-container { margin: 0.5rem 0 !important; }

.math__fallback {
  border-collapse: collapse;
  font-family: var(--mono);
}

.math__fallback td { padding: 0.15rem 0.6rem; text-align: right; }
.math__fallback td.augmented { border-left: 1px solid var(--ink-soft); }
.math__fallback table { display: inline-table; margin-right: 1.5rem; vertical-align: middle; }
.math__fallback caption { caption-side: left; padding-right: 0.4rem; vertical-align: middle; }
.math[data-rendered] .math__fallback { display: none; }

/* Formulas inside prose: MathJax inline, <sub>/<sup> text without JavaScript. */
.tex[data-rendered] .tex__plain { display: none; }
.tex__plain { font-family: var(--serif); }
.tex mjx-container { font-size: 105%; }
code.example { font-family: var(--mono); font-size: 0.9em; font-weight: 400; padding: 0 0.25em; border-radius: 3px; background: var(--paper-soft); }

/* Problem page blocks: <details> with the catalog-section chevron, usable without JavaScript. */
.block { margin-top: 1.25rem; }
.block > summary {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.4rem 0.75rem;
  padding: 0.35rem 0;
  cursor: pointer;
  list-style: none;
}
.block > summary::-webkit-details-marker { display: none; }
.block > summary::before {
  content: "";
  flex: none;
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid var(--ink-soft);
  border-bottom: 2px solid var(--ink-soft);
  transform: translateY(-0.15rem) rotate(-45deg);
  transition: transform 0.15s;
}
.block[open] > summary::before { transform: translateY(-0.3rem) rotate(45deg); }
.block > summary:hover .block__title { color: var(--accent); }
.block > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.block__title { margin: 0; }
.block__meta { font-size: 0.95rem; }
.block > .statement { margin-top: 0.5rem; }

.problem-notes { margin: 0.75rem 0 0; color: var(--ink-soft); }
.problem-notes p { margin: 0.25rem 0; }

.answer { margin-top: 0.25rem; }

.field {
  display: grid;
  gap: 0.35rem;
  padding: 0.75rem 0.9rem;
  margin: 0.5rem 0;
  border-left: 3px solid transparent;
  border-radius: 4px;
}

.field label { font-weight: 600; }
.field input, .field select, .field textarea {
  font: 1rem var(--sans);
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  max-width: 100%;
}

.field input { width: 18rem; }
.field select { width: max-content; max-width: 100%; }
.field textarea { font-family: var(--mono); line-height: 1.5; width: max-content; min-width: 14rem; resize: both; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.hint { color: var(--ink-soft); font-size: 0.85rem; }

.field--ok { border-left-color: var(--ok); background: var(--ok-bg); }
.field--bad { border-left-color: var(--bad); background: var(--bad-bg); }
.field--ok .outcome { color: var(--ok); }
.field--bad .outcome { color: var(--bad); }
.outcome { font-size: 0.9rem; font-weight: 600; }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 1.25rem; margin: 1rem 0 0 0.9rem; }
.attempts { color: var(--ink-soft); }

/* "Correct answer": the warning opens below the row, with no JavaScript. */
.reveal > summary { display: inline-block; list-style: none; }
.reveal > summary::-webkit-details-marker { display: none; }
.reveal > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.reveal[open] { flex-basis: 100%; }
.reveal__panel {
  display: flex;
  gap: 1rem;
  max-width: 40rem;
  margin-top: 0.75rem;
  padding: 1rem 1.25rem;
  border: 1px solid var(--bad);
  border-left-width: 4px;
  border-radius: 4px;
  background: var(--bad-bg);
  color: var(--ink);
}
.reveal__icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  background: var(--bad);
  color: #fff;
  font: 700 2rem/1 var(--sans);
}
.reveal__title { margin: 0 0 0.35rem; color: var(--bad); font-weight: 700; font-size: 1.1rem; text-transform: uppercase; letter-spacing: 0.04em; }
.reveal__text { margin: 0 0 1rem; font-weight: 700; }
.reveal__panel > div { min-width: 0; }
.reveal__panel button { white-space: normal; }
.solution { margin-top: 1.25rem; border-top: 1px solid var(--line); }
.solution h2 { margin-top: 0; }

.summary { padding: 0.75rem 1rem; border-radius: 4px; margin: 1.25rem 0 0; font-weight: 600; }
.summary--ok { color: var(--ok); background: var(--ok-bg); }
.summary--bad { color: var(--bad); background: var(--bad-bg); }
.notice { color: var(--ink-soft); margin: 1rem 0 0; }

.replace { display: flex; flex-wrap: wrap; align-items: center; gap: 1.25rem; margin: 2rem 0 0; padding-top: 1.25rem; border-top: 1px solid var(--line); }
.replace .parameters { flex-basis: 100%; max-width: 30rem; }

.catalog__options { flex: 0 0 21rem; display: flex; flex-direction: column; gap: 0.5rem; }
.catalog__options .notice { margin: 0; }
.parameters summary { cursor: pointer; color: var(--ink-soft); font-size: 0.95rem; }
/* A range (from-to selects) or a set (checkboxes) per parameter; the legend floats so that it
   lays out like an ordinary element beside the controls. */
.parameters__field { border: 0; padding: 0; margin: 0.5rem 0; min-width: 0; font-size: 0.95rem; }
.parameters__field::after { content: ""; display: block; clear: both; }
.parameters__field legend { float: left; padding: 0; margin: 0.3rem 0.75rem 0.3rem 0; }
.parameters__bounds, .parameters__options { float: right; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.3rem 0.75rem; }
.parameters__bounds label { display: flex; align-items: center; gap: 0.35rem; }
.parameters__bounds select { min-width: 6.5rem; }
.parameters__option { display: flex; align-items: center; gap: 0.3rem; white-space: nowrap; }
.parameters__field .hint { clear: both; padding-top: 0.2rem; }
.parameters .hint { display: block; max-width: 24rem; }

.site-footer {
  padding: 1rem clamp(1rem, 4vw, 3rem);
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* The header keeps one line at any width: on a narrow screen the product line beside the mark
   goes first, then the navigation folds into the menu (staff have four links). */
@media (max-width: 1180px) and (min-width: 921px), (max-width: 700px) {
  .discipline-switch__text { display: none; }
}

@media (max-width: 920px) {
  .site-header { align-items: center; }
  .site-nav { display: none; }
  .nav-menu { display: block; margin-left: -0.5rem; }
  .site-actions { margin-left: auto; }
}

@media (max-width: 600px) {
  .site-header { gap: 0.5rem; padding-inline: 0.75rem; }
  .site-actions .button--compact { padding-inline: 0.6rem; }
  .catalog { padding-left: 0; }
  .catalog__item form { flex-direction: column; gap: 0.5rem; }
  .catalog__options { flex-basis: auto; align-self: stretch; }
  .field input { width: 100%; }
  .field textarea { max-width: 100%; }
}

/* Header sign-in and registration: outlined, then the accent colour. */
.button--compact { font-size: 0.9rem; padding: 0.3rem 0.9rem; border-radius: 6px; }
a.button:hover { filter: brightness(1.1); color: #fff; }
a.button.secondary:hover { filter: none; background: var(--paper-soft); color: var(--accent); }

.auth-card {
  width: min(26rem, 100%);
  margin: 2.5rem auto 0;
  padding: 2rem 2rem 1.5rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 1px 2px rgb(28 31 36 / 4%), 0 8px 24px rgb(28 31 36 / 6%);
}

.auth-card h1 { margin: 0 0 0.5rem; font-size: 1.75rem; }
.auth-card__intro { margin: 0 0 1.5rem; color: var(--ink-soft); }
.auth-card__notice { margin: 0 0 1.25rem; padding: 0.6rem 0.8rem; border-radius: 6px; background: var(--paper-soft); color: var(--ink-soft); }
.auth-card__notice--bad { background: var(--bad-bg); color: var(--bad); }
.auth-card .hint { margin: 0.75rem 0 0; }

.providers { display: flex; flex-direction: column; gap: 0.75rem; }

.provider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
  transition: border-color 0.15s, background-color 0.15s;
}

.provider:hover { border-color: var(--accent); background: var(--paper-soft); color: var(--ink); }
.provider:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.provider__icon { width: 1.25rem; height: 1.25rem; flex: none; }

.auth-card__divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.5rem 0;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.auth-card__divider::before, .auth-card__divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

.auth-card__dev { margin: 0; }
.auth-card__dev button { width: 100%; padding: 0.65rem 1rem; border-radius: 8px; }
.auth-card__staff { margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed var(--line); }
.auth-card__staff .hint { margin: 0 0 0.6rem; }
.auth-card__roles { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.auth-card__roles button { flex: 1 1 8rem; width: auto; }
.auth-card__switch { margin: 1.5rem 0 0; padding-top: 1.25rem; border-top: 1px solid var(--line); text-align: center; color: var(--ink-soft); font-size: 0.95rem; }
.auth-card__switch a { font-weight: 600; }

@media (max-width: 600px) {
  .auth-card { margin-top: 1rem; padding: 1.5rem 1.25rem 1.25rem; border: 0; box-shadow: none; }
  .site-actions { gap: 0.4rem; }
  .user-menu__name { display: none; }
  .user-menu__toggle { padding-right: 0.45rem; }
}

/* The narrowest phones keep only the switch to the other language. */
@media (max-width: 380px) {
  .language__current { display: none; }
}

.nav-menu__auth { display: none; }

/* Below this the sign-in buttons move into the menu and the switch tightens. */
@media (max-width: 440px) {
  .site-actions .button--compact { display: none; }
  .nav-menu__panel .nav-menu__auth { display: block; }
  .nav-menu__panel a:not(.nav-menu__auth) + .nav-menu__auth { margin-top: 0.35rem; padding-top: 0.85rem; border-top: 1px solid var(--line); }
  .discipline-switch__item { padding-inline: 0.7rem; }
  .discipline-switch__mark { font-size: 1.2rem; }
}

/* Administration */
.content:has(.admin) { width: min(78rem, 100% - 2 * clamp(1rem, 4vw, 3rem)); }
.admin h1 { margin-top: 0.5rem; }
.admin-nav { display: flex; flex-wrap: wrap; gap: 0.25rem; margin: 0 0 1.25rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--line); }
.admin-nav a { padding: 0.35rem 0.8rem; border-radius: 6px; color: var(--ink-soft); font-weight: 600; font-size: 0.95rem; text-decoration: none; }
.admin-nav a:hover { background: var(--paper-soft); color: var(--ink); }
.admin-nav a[aria-current="page"] { background: var(--paper-soft); color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }
.site-nav a[aria-current="page"] { color: var(--ink); }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: 1rem; margin: 0 0 2rem; }
.stats__item { padding: 1rem 1.25rem; border: 1px solid var(--line); border-radius: 10px; }
.stats__item dt { color: var(--ink-soft); font-size: 0.9rem; }
.stats__item dd { margin: 0.25rem 0 0; font: 600 1.9rem/1.2 var(--serif); }
.stats__note { margin: 0.35rem 0 0; color: var(--ink-soft); font-size: 0.8rem; }

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem 1rem; margin: 0 0 1rem; }
.filters label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; color: var(--ink-soft); }
.filters input, .filters select, .inline-form input, .row-actions input, .row-actions select {
  font: 0.95rem var(--sans); padding: 0.4rem 0.55rem; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); color: var(--ink);
}
.filters button { padding: 0.42rem 1rem; border-radius: 6px; }

.table-scroll { overflow-x: auto; margin: 0 0 1rem; border: 1px solid var(--line); border-radius: 10px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
.data-table th { text-align: left; font-weight: 600; color: var(--ink-soft); background: var(--paper-soft); padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #fafbfc; }
.data-table code { font-size: 0.8rem; white-space: nowrap; }
.data-table--fixed { table-layout: fixed; }
.data-table .details { color: var(--ink-soft); font-size: 0.88rem; }

.muted { color: var(--ink-soft); }
.nowrap { white-space: nowrap; }
.badge { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.badge--ok { background: var(--ok-bg); color: var(--ok); }
.badge--bad { background: var(--bad-bg); color: var(--bad); }
.badge--muted { background: var(--paper-soft); color: var(--ink-soft); }
.notice--bad { color: var(--bad); }

.row-actions { margin-top: 0.4rem; }
.row-actions summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.row-actions form { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; margin: 0.6rem 0 0; padding: 0.75rem; border: 1px solid var(--line); border-radius: 8px; background: var(--paper-soft); }
.row-actions .hint { flex-basis: 100%; margin: 0; }
button.danger { background: var(--paper); color: var(--bad); border-color: var(--bad); }

.inline-form { display: flex; gap: 0.5rem; align-items: center; }
.inline-form input { flex: 1; min-width: 8rem; }
.inline-form button { padding: 0.35rem 0.9rem; font-size: 0.9rem; border-radius: 6px; }

.scenario-group { margin: 0 0 2rem; }
.scenario-group h2 { font-size: 1.25rem; }
.pager { display: flex; justify-content: space-between; gap: 1rem; margin: 1rem 0; }
.pager a:only-child:last-child { margin-left: auto; }

/* Ratings: a 0-100 number with a thin bar; the number carries the meaning. */
.rating { display: inline-flex; align-items: center; gap: 0.4rem; vertical-align: middle; font: 600 0.9rem var(--sans); }
.rating__bar { position: relative; width: 3.5rem; height: 0.35rem; border-radius: 999px; background: var(--line); overflow: hidden; }
.rating__bar::after { content: ""; position: absolute; inset: 0 auto 0 0; width: var(--rating); background: var(--accent); }
.rating__value { min-width: 1.6rem; text-align: right; font-variant-numeric: tabular-nums; }
h3 .rating, h2 .rating { margin-left: 0.5rem; }

.scores { display: inline-flex; gap: 0.3rem; }
.scores__item { min-width: 2.2rem; padding: 0.05rem 0.35rem; border: 1px solid var(--line); border-radius: 4px; text-align: center; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.scores__item--empty { color: var(--ink-soft); border-style: dashed; }

.overall { font-size: 1.05rem; margin: 0 0 0.75rem; }
.overall strong { font: 600 1.6rem var(--serif); margin-left: 0.25rem; }

/* Required problems on the catalog page. */
.required { margin: 1.25rem 0 1.5rem; padding: 1rem 1.25rem; border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 6px; }
.required h2 { margin-top: 0; }
.required__cohort { margin: 0.5rem 0 0.25rem; color: var(--ink-soft); }
.required__list { list-style: none; margin: 0; padding: 0; }
.required__list li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.35rem 1rem; padding: 0.4rem 0; border-top: 1px dashed var(--line); }
.required__list li:first-child { border-top: 0; }
.required__params { flex: 1; color: var(--ink-soft); font-size: 0.9rem; }
.start-problem { display: inline; margin: 0; }
.start-problem .catalog__title { font: 600 1.05rem/1.3 var(--serif); }

.active ul { margin-top: 0; }
.active li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.35rem 0.5rem; }
.abandon { display: inline; margin: 0; }
.abandon--all { display: block; margin-top: 0.5rem; }
.confirm__list { margin: 0 0 0.75rem; padding-left: 1.25rem; }

.cohort-progress, .type-ratings, .join, .student-item { margin-top: 2rem; }
.invite code { font-size: 0.95rem; }
.invite__code { letter-spacing: 0.12em; font-weight: 600; }
.ratings-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.sort { color: var(--ink-soft); font-size: 0.92rem; }
.notice--ok { color: var(--ok); }

/* Photos: a 3:4 portrait as on a student card, cropped to fill; an initial when absent. */
.avatar { display: inline-block; flex: none; object-fit: cover; background: var(--paper-soft); border: 1px solid var(--line); vertical-align: middle; }
.avatar--empty { display: inline-grid; place-items: center; color: var(--ink-soft); font: 600 1rem var(--serif); text-transform: uppercase; }
.avatar--tiny { width: 1.5rem; height: 1.5rem; border-radius: 50%; margin-right: 0.4rem; }
.avatar--small { width: 1.9rem; height: 2.5rem; border-radius: 4px; margin-right: 0.6rem; }
.avatar--large { width: 7.5rem; height: 10rem; border-radius: 6px; font-size: 2.5rem; }
.person { display: flex; align-items: center; }
h1.person { gap: 0.75rem; }

.profile { display: flex; flex-wrap: wrap; gap: 1.5rem 2.5rem; align-items: flex-start; margin: 1rem 0 2rem; }
.profile__photo { display: flex; flex-direction: column; gap: 0.6rem; max-width: 18rem; }
.profile__photo .hint { margin: 0; }
.profile__data { flex: 1; min-width: 16rem; }
.profile__data h2 { margin-top: 0; }
.photo-form, .name-form { display: flex; flex-direction: column; gap: 0.6rem; max-width: 26rem; }
.name-form label, .photo-form label { display: flex; flex-direction: column; gap: 0.2rem; font-weight: 600; }
.name-form input { font: inherit; padding: 0.35rem 0.5rem; }
.photo-form button, .name-form button { align-self: flex-start; }
.name-form input[aria-invalid="true"] { border-color: var(--bad); }

.profile-reminder { margin: 0; padding: 0.6rem 1.5rem; background: #fff7e0; border-bottom: 1px solid #ecd9a0; }
.profile-reminder p { max-width: 60rem; margin: 0 auto; }
.profile-reminder a { font-weight: 600; margin-left: 0.4rem; }

/* A multi-problem picker: sections of checkboxes, each with its own parameters. */
.picker__list { list-style: none; margin: 0; padding: 0 0 0.5rem; }
.picker__item { padding: 0.5rem 0; border-top: 1px dashed var(--line); }
.picker__item:first-child { border-top: 0; }
.picker__check { display: flex; gap: 0.5rem; align-items: baseline; font: 600 1.02rem/1.3 var(--serif); cursor: pointer; }
.picker__item .parameters { margin: 0.3rem 0 0 1.6rem; }

/* Control works. */
.state { display: inline-block; padding: 0.05rem 0.5rem; border-radius: 999px; font: 600 0.78rem var(--sans); vertical-align: middle; background: var(--paper-soft); color: var(--ink-soft); }
.state--open { background: var(--ok-bg); color: var(--ok); }
.state--closed { background: #eef2f7; color: var(--accent); }
.control-work { margin: 1rem 0 1.5rem; }
.control-work h4 { margin: 0 0 0.25rem; font: 600 1.05rem var(--serif); }
.variant { white-space: nowrap; font-size: 0.9rem; }
.required--control { border-left-color: var(--ok); }
.required__title { font: 600 1.05rem/1.3 var(--serif); }
.ratings-summary { display: flex; flex-wrap: wrap; gap: 0.5rem 2.5rem; margin: 0.5rem 0 1rem; }
.ratings-summary dt { color: var(--ink-soft); font-size: 0.9rem; }
.ratings-summary dd { margin: 0; }
.ratings-summary .rating { font-size: 1.2rem; }

@media (max-width: 600px) {
  .profile-reminder { padding: 0.6rem 1rem; }
  .rating__bar { width: 1.75rem; }
  .scores__item { min-width: 1.9rem; }
}
.picker__weight { display: inline-flex; gap: 0.4rem; align-items: baseline; margin: 0.3rem 0 0 1.6rem; font-size: 0.9rem; color: var(--ink-soft); }
.weight-form { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }

/* Defaults at one scope: page settings, then per-type parameter ranges in topic sections. */
.defaults__setting { margin: 0.6rem 0 1rem; }
.defaults__setting label { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; }
.defaults__setting .hint { display: block; margin-top: 0.2rem; }
.defaults__title { margin: 0 0 0.2rem; }
.defaults__marker { font-size: 0.85rem; color: var(--ink-soft); border: 1px solid var(--line); border-radius: 0.6rem; padding: 0 0.4rem; margin-left: 0.4rem; }
.defaults__type .parameters { max-width: 34rem; margin: 0; }
.defaults__type > .hint { display: block; max-width: 40rem; }

/* The catalog is a card with a discipline on each face (as on argrig.github.io): the face
   turned away is hidden, so the page reads without JavaScript. While app.js turns it, and
   only then, the card is a 3D object; at rest nothing is transformed, so text stays crisp
   and nothing inside gets a new containing block. */
.face-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 0.6rem; }
.face-title__mark { font: 700 1em/1 var(--serif); letter-spacing: -0.02em; color: var(--accent); }
.face-title__mark sup { font-size: 0.6em; }

.flip__card { position: relative; display: grid; }
.flip__face { grid-area: 1 / 1; min-width: 0; }
.flip__face.is-hidden {
  visibility: hidden;
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.flip.is-turning { perspective: 2400px; }
.flip.is-turning .flip__card {
  transform-style: preserve-3d;
  transition: transform var(--flip-duration) cubic-bezier(0.4, 0.2, 0.2, 1);
}
.flip.is-turning.no-transition .flip__card { transition: none; }
.flip.is-turning .flip__card.is-flipped { transform: rotateY(180deg); }
.flip.is-turning .flip__face {
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  background: var(--paper);
}
.flip.is-turning .flip__face--back { transform: rotateY(180deg); }

/* Elsewhere the switch turns the page itself (app.js): the content turns away edge-on, then
   the page of the other discipline opens with #turn and turns in, so the two halves make one
   turn in the card's direction. */
@keyframes page-turn-out { to { transform: perspective(2400px) rotateY(90deg); } }
@keyframes page-turn-in { from { transform: perspective(2400px) rotateY(-90deg); } }
html.is-turning-out .content { animation: page-turn-out calc(var(--flip-duration) / 2) cubic-bezier(0.4, 0.2, 1, 1) forwards; }
html.is-turning-in .content { animation: page-turn-in calc(var(--flip-duration) / 2) cubic-bezier(0, 0, 0.2, 1) both; }

@media (prefers-reduced-motion: reduce) {
  .site-header, .discipline-switch__item { transition: none; }
  html.is-turning-out .content, html.is-turning-in .content { animation: none; }
}

/* The site's description before sign-in: a lead, one large sign-in, what the site does. */
.landing__lead { max-width: 40rem; font-size: 1.2rem; color: var(--ink-soft); }
.landing__action { margin: 1.75rem 0 2.25rem; }
.landing__sign-in { font-size: 1.25rem; padding: 0.8rem 2.6rem; border-radius: 8px; }
.landing__features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: 1rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.landing__features li { padding: 1rem 1.25rem; border: 1px solid var(--line); border-top: 3px solid var(--accent); border-radius: 8px; background: var(--paper); }
.landing__features h2 { margin: 0 0 0.4rem; font-size: 1.1rem; }
.landing__features p { margin: 0; color: var(--ink-soft); }
.landing__topics { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0; padding: 0; list-style: none; }
.landing__topics li { padding: 0.25rem 0.75rem; border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line)); border-radius: 999px; color: var(--accent); font-size: 0.95rem; }
