/* FILE: css/homework.css */
/*
 * homework.css — the homework subsystem, restyled to sit inside the
 * academic site rather than beside it.
 *
 * Everything is scoped under .hw-root, so this file can never reach the
 * nav, the publication list, or anything else on the page. Colours are
 * only ever the variables defined in main.css, so light/dark and any
 * future palette change come along for free. There is no font-size
 * override on <html> any more: the homework inherits the site's type
 * scale, including ctrl+scroll zoom.
 *
 * The old file's Orbitron headings, cyan glow and 10px cards are gone.
 * The one visual idea kept from it is the logged-out ring, which is a
 * genuinely useful signal — but it now draws around the homework block
 * instead of the whole browser viewport.
 */

/* ── Root ──────────────────────────────────────────────────────────── */

.hw-root {
  --hw-ring: var(--red);
  font-family: var(--sans);
  box-shadow: inset 0 0 0 2px var(--hw-ring);
  border-radius: 4px;
  padding: 1.4rem 1.5rem 1.6rem;
  transition: box-shadow var(--t-slow, 240ms ease);
}
.hw-root.hw-logged-in { --hw-ring: var(--rule); }

.hw-root h3, .hw-root h4 { font-family: var(--sans); }

/* ── Cards & buttons ───────────────────────────────────────────────── */

.hw-card {
  background: var(--bg-warm);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 0.95rem 1.05rem;
}

.hw-btn {
  font-family: var(--sans);
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  padding: 0.35rem 0.75rem;
  border-radius: 3px;
  border: 1px solid var(--rule);
  background: var(--bg);
  color: var(--body);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color var(--t-fast, 120ms ease), color var(--t-fast, 120ms ease);
}
.hw-btn:hover:not(:disabled) { border-color: var(--muted); color: var(--head); }
.hw-btn.pri { border-color: var(--link); color: var(--link); font-weight: 500; }
.hw-btn.pri:hover:not(:disabled) { background: var(--tag-bg); }
.hw-btn.sm { padding: 0.25rem 0.6rem; font-size: 0.7rem; }
.hw-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.hw-btn:focus-visible,
.hw-root :focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

/* ── Sign-in strip ─────────────────────────────────────────────────── */

.hw-login-card {
  display: flex; align-items: center; gap: 0.5rem;
  flex-wrap: wrap; margin-bottom: 1.1rem;
}
.hw-login-inp {
  font-family: var(--mono);
  font-size: 0.78rem;
  padding: 0.35rem 0.55rem;
  border-radius: 3px;
  border: 1px solid var(--rule);
  background: var(--bg);
  color: var(--body);
  min-width: 8rem;
}
.hw-login-inp::placeholder { color: var(--muted); }
.hw-login-status { font-size: 0.76rem; color: var(--body); margin-left: auto; }
.hw-login-status.muted { color: var(--muted); font-style: italic; }
.hw-login-status b { font-family: var(--mono); font-weight: 500; }

.hw-notice {
  font-size: 0.78rem; color: var(--body); line-height: 1.55;
  background: var(--bg-warm); border-left: 2px solid var(--accent);
  padding: 0.6rem 0.8rem; margin-bottom: 1.1rem;
}

/* ── Toolbar ───────────────────────────────────────────────────────── */

.hw-toolbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  margin-bottom: 1.3rem; padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--rule);
}
.hw-toggle {
  display: flex; align-items: center; gap: 0.4rem;
  font-size: 0.76rem; color: var(--muted); cursor: pointer;
}
.hw-toolbar-status { font-size: 0.74rem; color: var(--accent); }

/* ── Section headings ──────────────────────────────────────────────── */

.hw-section-title {
  font-size: 0.72rem; font-weight: 600;
  letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--muted);
  margin: 1.8rem 0 0.9rem;
}
.hw-section-title .hw-section-hint {
  font-weight: 400; text-transform: none; letter-spacing: normal;
  font-size: 0.72rem; font-style: italic; margin-left: 0.5rem;
}

/* ── Sheet list ────────────────────────────────────────────────────── */

.hw-week-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.1rem;
}
.hw-week-title-lg {
  font-family: var(--serif); font-size: 1.15rem; font-weight: 400;
  color: var(--head); line-height: var(--lh-tight);
}

.hw-week-list { display: flex; flex-direction: column; gap: 0.5rem; }
.hw-week-card {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.8rem; width: 100%; text-align: left;
  text-decoration: none; cursor: pointer;
  font: inherit;
  transition: border-color var(--t-fast, 120ms ease);
}
.hw-week-card:hover { border-color: var(--muted); }
.hw-week-title { font-family: var(--serif); font-size: 0.95rem; color: var(--link); }
.hw-week-card:hover .hw-week-title { color: var(--head); }
.hw-week-go { color: var(--muted); font-size: 1.1rem; line-height: 1; }

/* ── Question card ─────────────────────────────────────────────────── */

.hw-list { display: flex; flex-direction: column; gap: 0.7rem; }

.hw-question-header {
  display: flex; align-items: center; gap: 0.8rem;
  flex-wrap: wrap; margin-bottom: 0.85rem;
}
.hw-question-title {
  font-size: 0.7rem; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--accent);
}
.hw-variant-select {
  font-family: var(--mono); font-size: 0.72rem;
  padding: 0.2rem 0.4rem; border-radius: 3px;
  border: 1px solid var(--rule); background: var(--bg); color: var(--body);
}
.hw-variant-count { font-family: var(--mono); font-size: 0.7rem; color: var(--muted); }

.hw-mini-progress-wrap { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }
.hw-mini-progress {
  width: 5rem; height: 2px; background: var(--rule); overflow: hidden;
}
.hw-mini-progress-fill {
  height: 100%; width: 0%; background: var(--accent);
  transition: width 200ms ease;
}
.hw-mini-progress-label { font-family: var(--mono); font-size: 0.68rem; color: var(--muted); min-width: 2.2rem; }

.hw-question-body { display: flex; flex-direction: column; gap: 1.1rem; }

/* ── Steps ─────────────────────────────────────────────────────────── */

.hw-step { display: flex; flex-direction: column; gap: 0.55rem; }
.hw-step-prompt {
  font-family: var(--serif); font-size: 0.92rem;
  color: var(--body); line-height: 1.6;
}

/* Marking: a rule down the left edge of the step, green or red. A
   numeric group with several fields splits that rule proportionally, so
   two right and one wrong reads at a glance without labelling anything. */
.hw-step-marked {
  border-left: 2px solid var(--hw-mark, var(--rule));
  padding-left: 0.85rem;
  margin-left: -0.85rem;
}
.hw-step-marked-split { border-image-slice: 1; }

.hw-pool-label {
  font-size: 0.7rem; color: var(--muted);
  letter-spacing: 0.07em; text-transform: uppercase;
  padding-top: 0.3rem; border-top: 1px solid var(--rule);
}

.hw-choice-grid { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.hw-choice-btn {
  font-family: var(--serif); font-size: 0.86rem; text-align: left;
  padding: 0.4rem 0.7rem; border-radius: 3px;
  border: 1px solid var(--rule); background: var(--bg);
  color: var(--body); cursor: pointer;
  transition: border-color var(--t-fast, 120ms ease), color var(--t-fast, 120ms ease);
}
.hw-choice-btn:hover { border-color: var(--muted); }
.hw-choice-btn.active {
  background: var(--tag-bg); color: var(--head);
  border-color: var(--link); font-weight: 500;
}

.hw-numeric-row { display: flex; flex-wrap: wrap; gap: 0.9rem; }
.hw-numeric-field {
  display: flex; flex-direction: column; gap: 0.25rem;
  font-size: 0.72rem; color: var(--muted);
}
.hw-numeric-line { display: flex; align-items: center; gap: 0.4rem; }
.hw-numeric-line .hw-del-btn { flex: 0 0 auto; }

.hw-numeric-field input {
  font-family: var(--mono); font-size: 0.85rem; width: 6.5rem;
  padding: 0.35rem 0.5rem; border-radius: 3px;
  border: 1px solid var(--rule); background: var(--bg); color: var(--body);
}

/* ── Hints ─────────────────────────────────────────────────────────── */

.hw-hint-row { display: flex; justify-content: flex-end; }
.hw-hint-btn {
  width: 1.3rem; height: 1.3rem; border-radius: 50%;
  border: 1px solid var(--red); background: transparent; color: var(--red);
  font-family: var(--sans); font-size: 0.68rem; font-weight: 600;
  line-height: 1; cursor: pointer;
}
.hw-hint-btn:hover { background: var(--tag-bg); }
.hw-hint-box {
  padding: 0.55rem 0.75rem; background: var(--bg);
  border-left: 2px solid var(--red);
  font-size: 0.82rem; color: var(--body); line-height: 1.55;
}
.hw-hint-explain { margin-top: 0.3rem; color: var(--muted); font-size: 0.78rem; }

/* ── Confirm ───────────────────────────────────────────────────────── */

.hw-confirm-box {
  background: var(--bg); border-left: 2px solid var(--link);
  padding: 0.8rem 0.95rem;
}
.hw-recap { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 0.7rem; }
.hw-recap-line {
  display: flex; justify-content: space-between; gap: 1rem;
  font-size: 0.74rem; color: var(--muted); line-height: 1.45;
}
.hw-recap-a { color: var(--accent); font-family: var(--mono); text-align: right; white-space: nowrap; }
.hw-confirm-sentence {
  font-family: var(--serif); font-size: 0.92rem;
  color: var(--head); line-height: 1.6; margin-bottom: 0.7rem;
}
.hw-confirm-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.hw-guest-note { font-size: 0.78rem; color: var(--muted); font-style: italic; }

/* ── Rest states ───────────────────────────────────────────────────── */

.hw-done-box { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; }
.hw-done-badge {
  font-size: 0.7rem; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--green);
}
.hw-redo-toggle {
  display: flex; align-items: center; gap: 0.4rem;
  font-size: 0.76rem; color: var(--muted); cursor: pointer;
}

.hw-answers-row {
  display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem 0.8rem;
  margin-top: 0.9rem;
}
.hw-answers-row:empty { display: none; }
.hw-answers-status { font-size: 0.74rem; color: var(--muted); font-style: italic; }

.hw-score-footer {
  font-family: var(--mono); font-size: 0.78rem; color: var(--accent);
  text-align: center; padding: 0.6rem; margin-top: 0.8rem;
  background: var(--tag-bg); border-radius: 3px; display: none;
}

.hw-error, .hw-loading {
  font-size: 0.86rem; color: var(--muted); font-style: italic; padding: 1.2rem 0;
}

/* ── Diagrams ──────────────────────────────────────────────────────── */

.hw-diagram { margin: 0.2rem 0 0.5rem; text-align: center; }
.hw-diagram img {
  max-width: 100%; height: auto; margin: 0 auto;
  border-radius: 3px; background: var(--bg-warm);
}
.hw-diagram-caption { font-size: 0.72rem; color: var(--muted); margin-top: 0.3rem; }

/* ── Modals (mounted on <body>, so deliberately unscoped) ──────────── */

.hw-modal-overlay {
  position: fixed; inset: 0; z-index: 10000;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; padding: 1.2rem;
}
.hw-modal-box {
  max-width: 24rem; width: 100%;
  background: var(--bg-warm); border: 1px solid var(--rule);
  border-radius: 4px; padding: 1.1rem 1.2rem;
  font-family: var(--sans);
}
.hw-modal-title {
  font-size: 0.72rem; font-weight: 600;
  letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 0.5rem;
}
.hw-modal-msg {
  font-family: var(--serif); font-size: 0.9rem;
  color: var(--body); line-height: 1.6; margin-bottom: 1rem;
}
.hw-modal-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ── Standalone pages ──────────────────────────────────────────────── */

.hw-page { max-width: 46rem; margin: 0 auto; padding: 2.5rem 1.5rem 4rem; }
.hw-page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
  padding-bottom: 1.1rem; margin-bottom: 1.6rem;
  border-bottom: 1px solid var(--rule);
}
.hw-page-head h1 {
  font-family: var(--serif); font-size: 1.4rem; font-weight: 400; color: var(--head);
}
.hw-page-head .hw-page-sub {
  font-family: var(--sans); font-size: 0.78rem; color: var(--muted); margin-top: 0.3rem;
}
.hw-page-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

/* ── Responsive ────────────────────────────────────────────────────── */

@media (max-width: 700px) {
  .hw-root { padding: 1rem 1rem 1.2rem; }
  .hw-login-status { margin-left: 0; width: 100%; }
  .hw-mini-progress-wrap { margin-left: 0; width: 100%; }
  .hw-numeric-field input { width: 5.5rem; }
  .hw-recap-line { flex-direction: column; gap: 0.1rem; }
  .hw-recap-a { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  .hw-root, .hw-btn, .hw-choice-btn, .hw-week-card, .hw-mini-progress-fill { transition: none; }
}

/* ── Separators between the parts of a question ─────────────────────
   A hairline that fades out well before either end, so a newly revealed
   part reads as a new part without a hard rule cutting the card in two. */

.hw-step-sep {
  height: 1px;
  border: 0;
  margin: 0.15rem 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    color-mix(in srgb, var(--muted) 6%,  transparent) 6%,
    color-mix(in srgb, var(--muted) 30%, transparent) 20%,
    color-mix(in srgb, var(--muted) 62%, transparent) 38%,
    color-mix(in srgb, var(--muted) 78%, transparent) 50%,
    color-mix(in srgb, var(--muted) 62%, transparent) 62%,
    color-mix(in srgb, var(--muted) 30%, transparent) 80%,
    color-mix(in srgb, var(--muted) 6%,  transparent) 94%,
    transparent 100%
  );
}

/* ── Step footer: the quiet note, and a reserved slot for the hint ──
   The slot keeps its width whether or not the button is in it, so the
   note never jumps sideways when a wrong answer reveals the button. */

.hw-step-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.7rem;
  min-height: 1.3rem;
}
.hw-step-note {
  font-size: 0.72rem;
  font-style: italic;
  color: var(--muted);
  opacity: 0.75;
  text-align: right;
  line-height: 1.4;
}
.hw-hint-slot {
  flex: 0 0 auto;
  width: 1.3rem;
  display: flex;
  justify-content: flex-end;
}

@media (max-width: 560px) {
  .hw-step-foot { flex-wrap: wrap; justify-content: flex-start; }
  .hw-step-note { width: 100%; text-align: left; order: 2; }
  .hw-hint-slot { order: 1; margin-left: auto; }
}

/* ── Editor-only delete controls ────────────────────────────────────
   Only ever rendered while the offline editor is open. */

.hw-step-editable { position: relative; }

.hw-del-btn, .hw-add-btn {
  width: 1.15rem;
  height: 1.15rem;
  padding: 0;
  border: none;
  border-radius: 2px;
  background: transparent;
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  opacity: 0.55;
  flex: 0 0 auto;
  transition: opacity 120ms ease, background 120ms ease;
}
.hw-del-btn { color: var(--red); }
.hw-add-btn { color: var(--green); }
.hw-del-btn:hover { opacity: 1; background: color-mix(in srgb, var(--red) 14%, transparent); }
.hw-add-btn:hover { opacity: 1; background: color-mix(in srgb, var(--green) 16%, transparent); }

.hw-step-editable { padding-right: 1.4rem; }
.hw-step-editable > .hw-del-btn { position: absolute; top: 0; right: 0; }

.hw-choice-wrap, .hw-field-wrap { display: inline-flex; align-items: flex-start; gap: 0.2rem; }
.hw-choice-wrap { align-items: center; }
.hw-choice-wrap .hw-del-btn, .hw-field-wrap .hw-del-btn { width: 1rem; height: 1rem; font-size: 0.85rem; }

/* A row holding nothing but an add button, right-aligned under the thing
   it extends. */
.hw-add-row { display: flex; justify-content: flex-end; }
.hw-add-question { margin: -0.2rem 0 0.4rem; padding-right: 1.05rem; }

/* An answer area with nothing in it yet: the button sits where the first
   answer will go. */
.hw-empty-answers { min-height: 1.6rem; align-items: center; }

/* ── Marking answers correct ────────────────────────────────────────
   Only ever visible with the editor's Solutions mode switched on. */

.hw-choice-btn.hw-correct {
  border-bottom: 2px solid var(--green);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}
.hw-numeric-field.hw-correct-field input {
  border-bottom: 2px solid var(--green);
  color: var(--green);
}
html.ed-solutions .hw-choice-btn,
html.ed-solutions .hw-numeric-field input { cursor: copy; }

/* A part with no correct answer recorded. Editor-only: a reader never
   sees this, and assessed parts are exempt since their answers live in
   the separate solutions file. */
.hw-step-nosolution {
  outline: 1px solid color-mix(in srgb, var(--red) 55%, transparent);
  outline-offset: 6px;
  border-radius: 2px;
}
.hw-step-note-warn { color: var(--red); opacity: 0.85; font-style: normal; }

/* ── Sheet list, edit mode ──────────────────────────────────────────
   The card keeps its shape; the controls sit around it. */

.hw-week-row { display: flex; align-items: center; gap: 0.4rem; }
.hw-week-row .hw-week-card { flex: 1; }

html.ed-active .hw-week-card { cursor: default; }

.hw-week-open {
  font-family: var(--sans);
  font-size: 0.76rem;
  color: var(--muted);
  background: none;
  border: none;
  padding: 0.1rem 0.2rem;
  cursor: pointer;
  white-space: nowrap;
}
.hw-week-open:hover { color: var(--link); }

/* The circled S: green when a sheet's answers are complete, orange when
   a solutions file is linked but unfinished, grey when none is linked. */
.hw-sol-badge {
  width: 1.5rem;
  height: 1.5rem;
  flex: 0 0 auto;
  margin-left: auto;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  background: none;
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: background 120ms ease;
}
.hw-sol-badge:hover { background: color-mix(in srgb, currentColor 14%, transparent); }
.hw-sol-full { color: var(--green); }
.hw-sol-partial { color: var(--accent); }
.hw-sol-none { color: var(--muted); opacity: 0.5; }

/* ── Rejected number input ──────────────────────────────────────────
   A box that holds something that isn't a number says so, rather than
   quietly counting as unanswered. */

.hw-numeric-field input.hw-input-bad {
  border-color: var(--red);
  color: var(--red);
}
/* Sits beside the box, so a mistyped answer doesn't shove the rest of
   the row down the page. */
.hw-input-error {
  font-size: 0.68rem;
  color: var(--red);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* ── Print buttons on a finished question ───────────────────────────*/

.hw-print-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  margin-top: 0.7rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--rule);
}
.hw-btn-info { display: inline-flex; align-items: center; gap: 0.15rem; }

/* The secondary print options recede a little until you look at them, so
   the one most people want reads as the obvious choice without anything
   being shouted. */
.hw-btn-info:not(:has(.pri)) .hw-btn { color: var(--muted); }
.hw-btn-info:not(:has(.pri)):hover .hw-btn { color: var(--body); }
.hw-info-btn {
  width: 0.95rem;
  height: 0.95rem;
  padding: 0;
  border: 1px solid var(--muted);
  border-radius: 50%;
  background: none;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.6rem;
  font-style: italic;
  line-height: 1;
  cursor: help;
  opacity: 0.7;
}
.hw-info-btn:hover { opacity: 1; color: var(--link); border-color: var(--link); }
.hw-info-note {
  flex-basis: 100%;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--muted);
  font-style: italic;
  padding-top: 0.15rem;
}

/* ═══ Print ═════════════════════════════════════════════════════════
   The printed document is built separately by js/homework/hw-print.js
   and lives in #hw-print-root. On screen it is never shown; while
   printing it is the only thing shown.
   ═══════════════════════════════════════════════════════════════════ */

.hw-print { display: none; }

@media print {
  /* Print only the built document. Everything else — nav, drawer, login,
     buttons — is screen furniture. */
  html.hw-printing body > *:not(#hw-print-root) { display: none !important; }
  html.hw-printing #hw-print-root { display: block; }
  html.hw-printing body::before { display: none !important; }   /* the login ring */

  @page { size: A4; margin: 20mm 18mm 18mm; }

  .hw-print {
    font-family: var(--serif);
    font-size: 10.5pt;
    line-height: 1.5;
    color: var(--body);
    background: none;
  }

  /* Fixed, so the browser repeats it at the top of every page. */
  .pr-runner {
    position: fixed;
    top: 0; left: 0; right: 0;
    display: flex;
    justify-content: space-between;
    gap: 1em;
    font-family: var(--sans);
    font-size: 8pt;
    letter-spacing: 0.04em;
    color: var(--muted);
    padding-bottom: 2mm;
    border-bottom: 0.4pt solid var(--rule);
  }
  .pr-who { font-family: var(--mono); }

  .pr-head {
    margin: 10mm 0 8mm;
    padding-bottom: 3mm;
    border-bottom: 1pt solid var(--rule);
  }
  .pr-head h1 {
    font-family: var(--serif);
    font-size: 16pt;
    font-weight: 400;
    line-height: 1.25;
    color: var(--head);
  }
  .pr-sub {
    font-family: var(--sans);
    font-size: 8.5pt;
    color: var(--muted);
    margin-top: 1.5mm;
  }
  .pr-sub b { font-family: var(--mono); font-weight: 500; }
  .pr-mark-note { margin-top: 1mm; }

  /* Wider spacing, when the reader has chosen it. The font needs nothing
     here, it arrives through --serif and --sans. Letter and word spacing
     come down from body. */
  html[data-a11y-spacing="wide"] .hw-print { line-height: var(--lh); }
  html[data-a11y-spacing="wide"] .pr-head h1 { line-height: var(--lh-tight); }
  html[data-a11y-spacing="wide"] .pr-part { margin-bottom: 6.5mm; }

  /* ---- questions ---- */

  .pr-q {
    margin-bottom: 9mm;
    padding-bottom: 1mm;
  }
  .pr-q + .pr-q { border-top: 0.4pt solid var(--rule); padding-top: 7mm; }

  /* The heading travels with its first part: a question that can't fit
     both moves to the next page whole, rather than leaving a title
     stranded at the foot of this one. */
  .pr-q-lead { break-inside: avoid; page-break-inside: avoid; }

  .pr-q-head {
    display: flex;
    align-items: baseline;
    gap: 0.7em;
    margin-bottom: 3mm;
  }
  .pr-q-head h2 {
    font-family: var(--sans);
    font-size: 10pt;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--head);
  }
  .pr-q-meta {
    font-family: var(--sans);
    font-size: 8pt;
    color: var(--muted);
    letter-spacing: 0.03em;
  }

  /* A part is never split down the middle. */
  .pr-part {
    break-inside: avoid;
    page-break-inside: avoid;
    margin-bottom: 4.5mm;
    orphans: 3;
    widows: 3;
  }
  .pr-part-head { display: flex; gap: 0.6em; align-items: baseline; }
  .pr-part-n {
    font-family: var(--mono);
    font-size: 8.5pt;
    color: var(--muted);
    min-width: 1.2em;
  }
  .pr-prompt { flex: 1; }

  /* ---- multiple choice ---- */

  .pr-options {
    list-style: none;
    margin: 2mm 0 0 1.8em;
    padding: 0;
  }
  .pr-option {
    display: flex;
    align-items: baseline;
    gap: 0.6em;
    margin-bottom: 1mm;
    break-inside: avoid;
  }
  .pr-box {
    flex: 0 0 auto;
    width: 1.05em;
    height: 1.05em;
    border: 0.6pt solid var(--muted);
    border-radius: 1pt;
    font-family: var(--sans);
    font-size: 8pt;
    line-height: 1.05em;
    text-align: center;
  }
  .pr-picked .pr-box { border-color: var(--body); border-width: 1pt; }
  .pr-picked .pr-option-text { font-weight: 500; }
  /* An answer known to be right is underlined, so a wrong pick and the
     right answer are both legible without colour. */
  .pr-correct .pr-option-text {
    text-decoration: underline;
    text-decoration-thickness: 0.6pt;
    text-underline-offset: 2pt;
  }

  /* ---- numeric ---- */

  .pr-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 4mm 7mm;
    margin: 2.5mm 0 0 1.8em;
  }
  .pr-field { break-inside: avoid; }
  .pr-field-label {
    font-family: var(--sans);
    font-size: 8pt;
    color: var(--muted);
    margin-bottom: 0.6mm;
  }
  .pr-field-value {
    font-family: var(--mono);
    font-size: 10.5pt;
    min-width: 4em;
    padding-bottom: 0.6mm;
    border-bottom: 0.6pt solid var(--rule);
  }
  .pr-field-want {
    font-family: var(--sans);
    font-size: 7.5pt;
    color: var(--muted);
    margin-top: 0.6mm;
  }
  .pr-blank { color: var(--muted); }

  .pr-mark { font-size: 9pt; margin-left: 0.4em; }
  .pr-right { color: var(--green); }
  .pr-wrong { color: var(--red); }

  /* ---- closing ---- */

  .pr-closing {
    margin: 3mm 0 0 1.8em;
    padding: 2mm 0 0;
    border-top: 0.4pt dotted var(--rule);
    font-style: italic;
    break-inside: avoid;
  }

  .pr-empty, .pr-foot-note {
    font-family: var(--sans);
    font-size: 8.5pt;
    color: var(--muted);
    font-style: italic;
    margin-top: 6mm;
  }

  /* MathJax leaves its own containers behind; keep them from breaking. */
  .hw-print mjx-container { break-inside: avoid; }

  /* ---- printer-friendly ----------------------------------------------
     Ink is expensive and photocopiers are unkind. Everything black on
     white, marks kept legible by shape rather than colour. */

  .hw-print-plain,
  .hw-print-plain * {
    background: #fff !important;
    color: #000 !important;
  }
  .hw-print-plain .pr-runner,
  .hw-print-plain .pr-q-meta,
  .hw-print-plain .pr-sub,
  .hw-print-plain .pr-field-label,
  .hw-print-plain .pr-field-want,
  .hw-print-plain .pr-part-n,
  .hw-print-plain .pr-blank,
  .hw-print-plain .pr-empty,
  .hw-print-plain .pr-foot-note { color: #444 !important; }
  .hw-print-plain .pr-runner,
  .hw-print-plain .pr-head,
  .hw-print-plain .pr-q + .pr-q,
  .hw-print-plain .pr-field-value,
  .hw-print-plain .pr-closing { border-color: #000 !important; }
  .hw-print-plain .pr-box { border-color: #000 !important; }
  .hw-print-plain .pr-wrong { font-weight: 700; }
}

/* Failure messages carry the technical detail and a way out, so a
   student can say what went wrong instead of "it does not work". */
.hw-error-detail {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-style: normal;
  color: var(--muted);
  margin-top: 0.5rem;
  word-break: break-word;
}
.hw-error-actions { margin-top: 0.8rem; }
