:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f0f0ec;
  --text: #1c1d1f;
  --muted: #61646b;
  --border: #dddcd6;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --accent-soft: #e6ecfb;
  --ok: #1d7a46;
  --ok-soft: #e3f3e9;
  --bad: #b3261e;
  --bad-soft: #fbe7e5;
  --warn: #8a5a00;
  --warn-soft: #fdf3dc;
  --flag: #6b3fb5;
  --flag-soft: #efe7fb;
  --radius: 8px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131416;
    --surface: #1c1d20;
    --surface-2: #25272b;
    --text: #e8e8e6;
    --muted: #a0a3aa;
    --border: #34363b;
    --accent: #7c9cf0;
    --accent-text: #0f1730;
    --accent-soft: #233056;
    --ok: #5cc98a;
    --ok-soft: #173826;
    --bad: #f08a80;
    --bad-soft: #43201d;
    --warn: #e8b64c;
    --warn-soft: #3a2e12;
    --flag: #b99af0;
    --flag-soft: #33284a;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #131416; --surface: #1c1d20; --surface-2: #25272b; --text: #e8e8e6; --muted: #a0a3aa;
  --border: #34363b; --accent: #7c9cf0; --accent-text: #0f1730; --accent-soft: #233056;
  --ok: #5cc98a; --ok-soft: #173826; --bad: #f08a80; --bad-soft: #43201d; --warn: #e8b64c;
  --warn-soft: #3a2e12; --flag: #b99af0; --flag-soft: #33284a; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh; display: flex; flex-direction: column;     /* the footer sits at the bottom of short pages */
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0; overflow-wrap: anywhere; }
h2 { font-size: 1.2rem; margin: 2rem 0 0.75rem; }
h3 { font-size: 1rem; margin: 0 0 0.5rem; }
code { font-size: 0.9em; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.spacer { flex: 1; }
.ok-text { color: var(--ok); }
.bad-text { color: var(--bad); }
.warn-text { color: var(--warn); }

/* ---------------------------------------------------------------- layout */

.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.site-header-inner {
  max-width: 1100px; margin: 0 auto; padding: 0.75rem 16px;
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.site-header nav { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.site-header nav a {
  color: var(--muted); text-decoration: none; padding: 0.35rem 0.7rem; border-radius: var(--radius);
}
.site-header nav a.active { color: var(--text); background: var(--surface-2); }

body > main { flex: 1 0 auto; width: 100%; }
.page { max-width: 1100px; margin: 0 auto; padding: 1.5rem 16px 4rem; }

.site-footer {
  border-top: 1px solid var(--border); padding: 0.9rem 16px; text-align: center;
  font-size: 0.875rem; background: var(--surface);
}
.site-footer p { margin: 0; }

/* ---------------------------------------------------------------- home: floating quotes (js/home.js) */

.home-main { display: flex; flex-direction: column; }
.home-main > .banner { margin: 0.75rem 16px; }
.quote-field {
  flex: 1; display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 1rem;
  padding: 2rem 16px;
}
.solve-wrap { flex-basis: 100%; display: flex; flex-direction: column; align-items: center; gap: 0.6rem; margin-bottom: 1rem; }
.how-link { color: var(--muted); font-size: 0.95rem; }
.how-link:hover { color: var(--accent); }
.button.solve-button {
  font-size: 1.5rem; font-weight: 600; letter-spacing: 0.02em; padding: 0.9rem 3.2rem; border-radius: 999px;
  box-shadow: 0 6px 24px color-mix(in srgb, var(--accent) 35%, transparent); transition: transform 0.15s;
}
.button.solve-button:hover { transform: scale(1.05); }
/* Plain text, no cards: the padding is the breathing room between quotes. */
.quote { margin: 0; max-width: 280px; padding: 1rem 1.25rem; color: var(--muted); }
.quote[hidden] { display: none; }
.quote blockquote { margin: 0; font-family: Georgia, "Times New Roman", serif; font-style: italic; line-height: 1.5; }
.quote figcaption { margin-top: 0.35rem; font-size: 0.75rem; letter-spacing: 0.02em; }
.quote figcaption::before { content: "— "; }

.quote-field.floating { display: block; position: relative; overflow: hidden; min-height: 420px; padding: 0; }
.floating .solve-wrap { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 2; margin: 0; }
.floating .quote {
  position: absolute; left: 0; top: 0; width: max-content; max-width: min(280px, 75%);
  font-size: 0.95rem; opacity: 0; transition: opacity 0.8s, color 0.2s; will-change: transform;
}
.floating .quote.placed { opacity: 0.75; }
.floating .quote.placed:hover { opacity: 1; color: var(--text); z-index: 1; }
@media (max-width: 600px) {
  .floating .quote { font-size: 0.85rem; max-width: min(220px, 70%); padding: 0.75rem 0.9rem; }
  .button.solve-button { font-size: 1.3rem; padding: 0.8rem 2.6rem; }
}

.page-head { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.section-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; justify-content: space-between; }
.section-head h2 { margin-bottom: 0.75rem; }

/* ---------------------------------------------------------------- controls */

button, .button {
  font: inherit; font-size: 0.95rem; cursor: pointer; border-radius: var(--radius);
  padding: 0.5rem 1rem; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  text-decoration: none; display: inline-block; line-height: 1.3;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button.secondary { background: var(--surface); }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.link-button { border: none; background: none; color: var(--accent); padding: 0.25rem 0.4rem; }

select, input[type="text"], input[type="number"], input[type="password"], input[type="email"], textarea {
  font: inherit; font-size: 0.95rem; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0.45rem 0.6rem; width: 100%;
}
textarea { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 0.875rem; resize: vertical; }
label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.875rem; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; display: inline-flex; margin-right: 1rem; color: var(--text); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem; margin: 0; }
legend { font-size: 0.875rem; color: var(--muted); padding: 0 0.3rem; }

.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 1rem; }

.banner { padding: 0.75rem 1rem; border-radius: var(--radius); margin: 0.75rem 0; border: 1px solid; }
.banner.error { background: var(--bad-soft); border-color: var(--bad); color: var(--text); }
.banner.warn { background: var(--warn-soft); border-color: var(--warn); color: var(--text); }
.banner.ok { background: var(--ok-soft); border-color: var(--ok); color: var(--text); }
.banner ul { margin: 0.3rem 0 0; padding-left: 1.2rem; }

.chip, .topic, .status-pill {
  display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.75rem; padding: 0.1rem 0.5rem;
  border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.topic { background: var(--accent-soft); color: var(--text); }
.topic button { border: none; background: none; padding: 0 0.1rem; color: var(--muted); }
.chip.diff-1 { color: var(--ok); }
.chip.diff-2 { color: var(--warn); }
.chip.diff-3 { color: var(--bad); }
.chip.solved { background: var(--ok-soft); color: var(--ok); }
.chip.tried { background: var(--warn-soft); color: var(--warn); }
.status-pill.published { background: var(--ok-soft); color: var(--ok); }
.status-pill.needs_review { background: var(--warn-soft); color: var(--warn); }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; flex-wrap: wrap; }
.segmented button { border: none; border-radius: 0; padding: 0.35rem 0.75rem; font-size: 0.85rem; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button.active { background: var(--accent-soft); color: var(--text); font-weight: 600; }

/* ---------------------------------------------------------------- browse */

.filters {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.75rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem;
  align-items: end;
}
.custom-mock { display: grid; gap: 0.75rem; }
.multi-filter { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.875rem; color: var(--muted); min-width: 0; }
.multi-filter details { position: relative; }
.multi-filter summary {
  list-style: none; cursor: pointer; color: var(--text); font-size: 0.95rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0.45rem 1.8rem 0.45rem 0.6rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative;
}
.multi-filter summary::-webkit-details-marker { display: none; }
.multi-filter summary::after { content: "\25BE"; position: absolute; right: 0.6rem; color: var(--muted); }
.multi-filter details[open] summary { border-color: var(--accent); }
.multi-panel {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; min-width: 100%; width: max-content; max-width: 22rem;
  max-height: 16rem; overflow-y: auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 4px 14px rgb(0 0 0 / 0.15); padding: 0.3rem;
}
.multi-panel.align-right { left: auto; right: 0; }
.check-item { flex-direction: row; align-items: center; gap: 0.5rem; padding: 0.3rem 0.5rem; border-radius: 4px; color: var(--text); cursor: pointer; }
.check-item:hover { background: var(--accent-soft); }
.check-item input { width: auto; margin: 0; }
.multi-group { padding: 0.4rem 0.5rem 0.1rem; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.filter-hint { grid-column: 1 / -1; margin: 0; }
.load-more { text-align: center; margin: 1rem 0 0; }
.problem-list { list-style: none; padding: 0; margin: 1rem 0 0; display: grid; gap: 0.75rem; }
.problem-card {
  display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; color: var(--text); text-decoration: none; box-shadow: var(--shadow);
}
.problem-card:hover { border-color: var(--accent); }
.card-meta { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.source { font-weight: 600; font-size: 0.875rem; margin-right: 0.25rem; }
.card-statement {
  margin: 0.6rem 0; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card-statement .katex-display { margin: 0.2rem 0; }
.card-topics { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.empty { padding: 2rem; text-align: center; color: var(--muted); }

/* ---------------------------------------------------------------- solve */

.solve { max-width: 760px; margin: 0 auto; }
.solve-nav { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.solve-head { margin-bottom: 1rem; }
.solve-head .source { margin: 0 0 0.4rem; }
.statement { font-size: 1.05rem; margin: 1rem 0 1.25rem; overflow-wrap: break-word; }
.statement .katex-display, .solution .katex-display { overflow-x: auto; overflow-y: hidden; padding: 0.2rem 0; }
.notation { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 0.9rem; font-size: 0.9rem; }
.notation summary { cursor: pointer; color: var(--muted); }

.hint-box { margin: 0.75rem 0; }
/* Report a problem (Solve) and the reports on Review, see app/reports.py. */
.report-box { margin: 1.25rem 0 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 0.9rem; }
.report-box summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
.report-form { display: grid; gap: 0.75rem; margin-top: 0.75rem; }
.report-form fieldset { border: none; padding: 0; margin: 0; display: grid; gap: 0.15rem; }
.report-form legend { font-weight: 600; margin-bottom: 0.3rem; }
.report-form label { display: flex; flex-direction: column; gap: 0.3rem; }
.report-form .check-item { flex-direction: row; }
.report-item { border-top: 1px solid var(--border); padding: 0.6rem 0 0.2rem; margin-top: 0.5rem; }
.report-head { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin: 0 0 0.3rem; }
.report-message { white-space: pre-wrap; overflow-wrap: anywhere; }
.report-actions { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.4rem; }
.report-filters { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin: 0.5rem 0 1rem; }
.report-group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem 1rem; margin-bottom: 0.9rem; }
.report-group header { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.report-statement { color: var(--muted); margin: 0.4rem 0; }
.hint-box h3 { margin: 0 0 0.3rem; font-size: 0.85rem; color: var(--flag); text-transform: uppercase; letter-spacing: 0.02em; }
.hint-box > h3 + * { background: var(--flag-soft); border-radius: var(--radius); padding: 0.6rem 0.9rem; margin: 0; }

.options { display: grid; gap: 0.5rem; }
.options .hint { margin: 0; font-size: 0.875rem; color: var(--muted); }
.option {
  display: flex; align-items: flex-start; gap: 0.75rem; width: 100%; text-align: left;
  padding: 0.75rem 0.9rem; background: var(--surface);
}
.option:not(:disabled):hover { border-color: var(--accent); }
.option:disabled { opacity: 1; cursor: default; }
.option-letter {
  flex: none; width: 1.75rem; height: 1.75rem; border-radius: 50%; border: 1px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 0.85rem;
}
.multi .option-letter { border-radius: 5px; }
.option-text { flex: 1; min-width: 0; overflow-wrap: break-word; padding-top: 0.1rem; }
.option-tag { font-size: 0.75rem; font-weight: 600; padding-top: 0.25rem; white-space: nowrap; }
.option.chosen { border-color: var(--accent); background: var(--accent-soft); }
.option.chosen .option-letter { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.option.right { border-color: var(--ok); background: var(--ok-soft); }
.option.right .option-letter { background: var(--ok); border-color: var(--ok); color: #fff; }
.option.right .option-tag { color: var(--ok); }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.option.wrong .option-letter { background: var(--bad); border-color: var(--bad); color: #fff; }
.option.wrong .option-tag { color: var(--bad); }
.nat { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.nat input { max-width: 14rem; }
.nat.sa input { width: min(100%, 24rem); max-width: none; }
.nat input.right { border-color: var(--ok); background: var(--ok-soft); }
.nat input.wrong { border-color: var(--bad); background: var(--bad-soft); }
.nat-label { color: var(--text); font-size: 0.95rem; flex-direction: row; }
.nat-answer { color: var(--ok); font-weight: 600; }

.verdict { margin-top: 1.25rem; border-radius: var(--radius); padding: 1rem 1.25rem; border: 1px solid; }
.verdict h2 { margin: 0 0 0.25rem; }
.verdict.ok { background: var(--ok-soft); border-color: var(--ok); }
.verdict.ok h2 { color: var(--ok); }
.verdict.bad { background: var(--bad-soft); border-color: var(--bad); }
.verdict.bad h2 { color: var(--bad); }
.solution { margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px solid var(--border); }

/* ---------------------------------------------------------------- mock home */

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 0.75rem; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem;
  display: flex; flex-direction: column; gap: 0.25rem; box-shadow: var(--shadow);
}
.tile p { margin: 0; }
.tile button { margin-top: auto; align-self: flex-start; }
.tile h3 + p { margin-bottom: 0.5rem; }
.history { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.history li {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 1rem;
}
.history li > span:first-child { font-weight: 600; flex: 1; min-width: 12rem; }
.history .score { font-variant-numeric: tabular-nums; }
details.fold { margin: 1.5rem 0; border-top: 1px solid var(--border); padding-top: 0.5rem; }
details.fold > summary { display: flex; align-items: baseline; gap: 0.5rem; cursor: pointer; list-style: none; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::before { content: "▸"; display: inline-block; color: var(--muted); width: 1em; transition: transform 0.15s; }
details.fold[open] > summary::before { transform: rotate(90deg); }
details.fold > summary h2 { margin: 0.25rem 0; }
details.fold[open] > summary { margin-bottom: 0.75rem; }
.post-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.post-list li {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 1rem;
}
.post-list-head { display: flex; align-items: center; gap: 0.5rem 1rem; flex-wrap: wrap; }
.post-list-head a { font-weight: 600; }
.post-list-body { margin: 0.35rem 0 0; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- exam */

.exam-main { min-height: 100vh; }
.exam { display: flex; flex-direction: column; min-height: 100vh; }
.exam-bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 0.6rem 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.exam-title { font-weight: 700; flex: 1; min-width: 10rem; }
.timer {
  font-variant-numeric: tabular-nums; font-size: 1.25rem; font-weight: 700; padding: 0.15rem 0.7rem;
  border-radius: var(--radius); background: var(--surface-2);
}
.timer.low { background: var(--bad-soft); color: var(--bad); }
.save-state { font-size: 0.8rem; color: var(--muted); }
.save-state.offline { color: var(--bad); }
.exam > .banner { margin: 0.75rem 16px 0; }
.exam-body {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 1.5rem;
  max-width: 1200px; width: 100%; margin: 0 auto; padding: 1.25rem 16px 3rem;
}
.exam-question { min-width: 0; }
.q-label { font-weight: 600; margin: 0; }
.exam-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 1.5rem; }
.palette {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem;
  align-self: start; position: sticky; top: 4.5rem;
}
.palette-section + .palette-section { margin-top: 1rem; }
.palette-section h3 { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.palette-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.35rem; }
.pal {
  display: inline-flex; align-items: center; justify-content: center; position: relative;
  padding: 0; height: 2.1rem; font-size: 0.85rem; font-variant-numeric: tabular-nums;
}
.pal.new { background: var(--surface); }
.pal.seen { background: var(--bad-soft); border-color: var(--bad); }
.pal.done { background: var(--ok-soft); border-color: var(--ok); }
.pal.flag { background: var(--flag-soft); border-color: var(--flag); }
.pal.flag.done::after {
  content: ""; position: absolute; right: 3px; bottom: 3px; width: 6px; height: 6px; border-radius: 50%; background: var(--ok);
}
.pal.current { outline: 2px solid var(--accent); outline-offset: 1px; font-weight: 700; }
.legend { list-style: none; padding: 0; margin: 1rem 0 0.5rem; display: grid; gap: 0.3rem; }
.legend li { display: flex; align-items: center; gap: 0.5rem; }
.legend .pal { width: 1.1rem; height: 1.1rem; border: 1px solid var(--border); border-radius: 4px; }
.legend .pal.seen { border-color: var(--bad); }
.legend .pal.done { border-color: var(--ok); }
.legend .pal.flag { border-color: var(--flag); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgb(0 0 0 / 0.45); display: flex; align-items: center;
  justify-content: center; padding: 16px; z-index: 20;
}
.modal { background: var(--surface); border-radius: var(--radius); padding: 1.5rem; max-width: 440px; width: 100%; }
.modal h2 { margin-top: 0; }

/* ---------------------------------------------------------------- results */

.score-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0.75rem; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem;
  display: flex; flex-direction: column;
}
.stat.big { grid-column: span 2; }
.stat-value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.big .stat-value { font-size: 2.2rem; }
.stat-of { font-size: 1rem; color: var(--muted); font-weight: 500; }
.stat-label { font-size: 0.85rem; color: var(--muted); }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.55rem 0.8rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-weight: 600; color: var(--muted); font-size: 0.8rem; }
tbody tr:last-child td { border-bottom: none; }
td { font-variant-numeric: tabular-nums; }
.bar-cell { display: inline-flex; align-items: center; gap: 0.5rem; }
.bar { display: inline-block; width: 90px; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.review-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.review-list details { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.review-list summary { display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem 1rem; cursor: pointer; flex-wrap: wrap; }
.review-list .marks { font-variant-numeric: tabular-nums; min-width: 2.5rem; text-align: right; }
.review-body { padding: 0 1rem 1rem; border-top: 1px solid var(--border); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.correct { background: var(--ok); }
.dot.wrong { background: var(--bad); }
.dot.blank { background: var(--border); }

/* ---------------------------------------------------------------- auth + profile */

.google-signin { text-align: center; }
.profile-recs { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1.5rem; }
.chip.trend-improving { background: var(--ok-soft); color: var(--ok); }
.chip.trend-declining { background: var(--bad-soft); color: var(--bad); }
.chip.trend-steady { background: var(--surface-2); color: var(--muted); }
.chip.trend-not-enough-data { background: var(--surface-2); color: var(--muted); }

/* ---------------------------------------------------------------- review */

.token-gate { max-width: 420px; margin: 3rem auto; display: grid; gap: 0.75rem; }
.review-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 1.25rem; }
.review-sidebar { display: grid; gap: 0.75rem; align-content: start; }
.review-items { list-style: none; padding: 0; margin: 0; max-height: 70vh; overflow-y: auto; display: grid; gap: 0.25rem; }
.review-items button {
  width: 100%; text-align: left; display: flex; justify-content: space-between; gap: 0.5rem; align-items: center;
  font-size: 0.85rem; padding: 0.45rem 0.6rem;
}
.review-items button.active { border-color: var(--accent); background: var(--accent-soft); }
.editor { min-width: 0; }
.editor-head { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.editor-head h2 { margin: 0; }
.editor-grid {
  display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 1rem; margin-top: 1rem;
  grid-template-areas: "form preview" "form source";
}
.editor-form { grid-area: form; }
.editor-preview { grid-area: preview; }
.editor-source { grid-area: source; }
.editor-source p { overflow-wrap: anywhere; margin: 0; }
.review-sidebar .segmented { display: grid; grid-template-columns: 1fr 1fr; }
.review-sidebar .segmented button + button { border-left: none; }
.review-sidebar .segmented button:nth-child(even) { border-left: 1px solid var(--border); }
.review-sidebar .segmented button:nth-child(n + 3) { border-top: 1px solid var(--border); }
.editor-grid > section {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem;
  min-width: 0; display: grid; gap: 0.75rem; align-content: start;
}
.editor-source pre {
  margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 0.8rem; background: var(--surface-2);
  padding: 0.75rem; border-radius: var(--radius); max-height: 60vh; overflow: auto;
}
.editor-form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.option-edit { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }
.option-edit input[type="text"] { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.5rem; }
.editor-preview .statement { margin-top: 0; }
.sticky-actions {
  position: sticky; bottom: 0; background: var(--bg); padding: 0.75rem 0; border-top: 1px solid var(--border);
}

/* ---------------------------------------------------------------- notebook */

.page-wide { max-width: 1440px; }
.solve-layout { --nb-width: 460px; }
.solve-layout.notebook-open {
  display: grid; grid-template-columns: minmax(0, 1fr) 12px var(--nb-width); gap: 0.5rem; align-items: start;
}
/* Drag handle between the problem and the notebook. */
.nb-resize {
  align-self: stretch; position: relative; cursor: col-resize; touch-action: none; border-radius: 6px;
}
.nb-resize::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 3px; margin-left: -1.5px;
  border-radius: 2px; background: var(--border);
}
.solve-layout:not(.notebook-open) .nb-resize { display: none; }
.nb-resize:hover::after, .nb-resize.dragging::after, .nb-resize:focus-visible::after { background: var(--accent); }
.nb-resize:focus-visible { outline: none; }
body.nb-resizing { cursor: col-resize; user-select: none; }
body.nb-resizing .nb-canvas-wrap { pointer-events: none; }
.solve-layout.notebook-open .solve { margin: 0 auto; width: 100%; }
#nb-toggle[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.notebook {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem;
  position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; min-width: 0;
  display: grid; gap: 0.75rem; align-content: start; box-shadow: var(--shadow);
}
/* Scrolling inside the notebook (wheel, touch, pen) stays in the notebook; it never carries on to the page behind. */
.notebook { overscroll-behavior: contain; }
/* Full screen: the notebook covers the window and the page behind is locked. */
body.nb-fullscreen { overflow: hidden; }
.notebook.nb-full, .solve-layout.notebook-open .notebook.nb-full {
  position: fixed; inset: 0; z-index: 100; width: 100%; max-height: none; height: 100vh; height: 100dvh;
  margin: 0; border: none; border-radius: 0; box-shadow: none; padding: 1rem clamp(16px, 3vw, 2.5rem);
  box-sizing: border-box; overflow-y: auto;
}
.notebook.nb-full > * { width: 100%; max-width: 1400px; margin-inline: auto; box-sizing: border-box; }
.notebook.nb-full .nb-live { min-height: 60vh; }
.notebook.nb-drop { outline: 2px dashed var(--accent); outline-offset: -4px; }
.notebook h2 { margin: 0; }
.nb-head { display: flex; align-items: center; gap: 0.75rem; }
.nb-head .link-button { font-size: 1rem; }
.nb-icon-btn {
  display: inline-grid; place-items: center; width: 2rem; height: 2rem; padding: 0; border: none; border-radius: 6px;
  background: none; color: var(--muted); cursor: pointer;
}
.nb-icon-btn[hidden] { display: none; }
.nb-icon-btn:hover, .nb-icon-btn:focus-visible { color: var(--text); background: var(--surface-2); }
.nb-icon-btn .icon { margin: 0; vertical-align: 0; }
#nb-full .icon-exit, #nb-full[aria-pressed="true"] .icon-enter { display: none; }
#nb-full[aria-pressed="true"] .icon-exit { display: block; }
.nb-tabs { display: flex; gap: 0.25rem; overflow-x: auto; padding-bottom: 2px; border-bottom: 1px solid var(--border); }
.nb-tab {
  border: 1px solid transparent; border-bottom: none; border-radius: var(--radius) var(--radius) 0 0;
  background: none; color: var(--muted); padding: 0.35rem 0.75rem; font-size: 0.85rem; white-space: nowrap;
  max-width: 12rem; overflow: hidden; text-overflow: ellipsis; flex: none;
}
.nb-tab.active { background: var(--surface-2); color: var(--text); border-color: var(--border); font-weight: 600; }
.nb-add { font-weight: 700; color: var(--accent); }
.nb-empty { display: grid; gap: 0.5rem; justify-items: start; }
.nb-empty p { margin: 0; }
#nb-page { display: grid; gap: 0.75rem; }
#nb-page[hidden] { display: none; }
.nb-page-head { display: flex; gap: 0.5rem; align-items: center; }
.nb-page-head input { flex: 1; min-width: 0; font-weight: 600; }
.nb-page-head .segmented { flex: none; }
/* The notes editor (live_editor.js): lines are typeset, the one being edited is a textarea. */
.nb-live {
  min-height: 12rem; padding: 0.35rem 0.4rem; cursor: text; font-size: 0.95rem; line-height: 1.5;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.nb-live:focus-visible, .nb-live:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.nb-unit { min-height: 1.5em; padding: 0.1rem 0.4rem; white-space: pre-wrap; overflow-wrap: anywhere; border-radius: 4px; }
.nb-unit .katex-display { overflow-x: auto; overflow-y: hidden; margin: 0.4em 0; white-space: normal; }
.nb-ph { color: var(--muted); }
.nb-unit.nb-active { background: var(--surface-2); }
.nb-active textarea {
  display: block; width: 100%; min-height: 1.5em; margin: 0; padding: 0; resize: none; overflow: hidden;
  border: none; background: none; line-height: 1.5; outline: none;
}
.nb-unit-preview { margin: 0.25rem 0 0; padding-top: 0.25rem; font-size: 0.95rem; border-top: 1px dashed var(--border); white-space: normal; }
.nb-unit-preview[hidden] { display: none; }
.nb-help { margin-top: 0.5rem; }
.nb-help summary { cursor: pointer; color: var(--muted); }
.nb-help p { margin: 0.4rem 0; }
.nb-help table { border-collapse: collapse; }
.nb-help td { padding: 0.15rem 0.75rem 0.15rem 0; vertical-align: top; }
.nb-tools { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; margin-bottom: 0.5rem; }
.nb-tools button { padding: 0.3rem 0.6rem; font-size: 0.85rem; }
.nb-tools button[hidden] { display: none; }
.nb-tools select { width: auto; padding: 0.3rem 0.4rem; font-size: 0.85rem; }
.nb-pen.active, #nb-snap.active { border-color: var(--accent); background: var(--accent-soft); }
.swatch { display: inline-block; width: 0.9rem; height: 0.9rem; border-radius: 50%; vertical-align: middle; }
.swatch.ink { background: var(--text); }
.swatch.blue { background: var(--accent); }
.swatch.red { background: var(--bad); }
.swatch.green { background: var(--ok); }
/* The sketch pad is ruled like a notebook page; the spacing (--nb-line) is a setting. */
.notebook { --nb-line: 24px; }
.nb-canvas-wrap {
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  --grid: color-mix(in srgb, var(--border) 55%, transparent);
  background-color: var(--surface);
  background-image: linear-gradient(to bottom, transparent calc(var(--nb-line) - 1px), var(--grid) calc(var(--nb-line) - 1px));
  background-size: 100% var(--nb-line);
}
.notebook[data-lines="none"] .nb-canvas-wrap { background-image: none; }
.nb-canvas-wrap { position: relative; }
#nb-canvas { display: block; width: 100%; touch-action: none; cursor: crosshair; user-select: none; -webkit-touch-callout: none; }   /* notebook.js sets a pen cursor */
/* The eraser marker: follows the pointer (mouse or either end of a stylus) and shows how much it rubs out. */
.nb-eraser-ghost {
  position: absolute; pointer-events: none; border-radius: 50%; display: grid; place-items: center;
  border: 1.5px solid var(--text); background: color-mix(in srgb, var(--surface) 60%, transparent);
}
.nb-eraser-ghost[hidden] { display: none; }
.nb-eraser-ghost svg { width: 70%; height: 70%; fill: #f6b4c0; stroke: #222; stroke-width: 1.6; stroke-linejoin: round; }
.nb-eraser-ghost.pressed { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 18%, transparent); }
.nb-tools .icon { vertical-align: -3px; margin-right: 0.15rem; }
.nb-images { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 0.5rem; }
.nb-images li { position: relative; }
.nb-images img {
  display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface-2);
}
.nb-image-del {
  position: absolute; top: 4px; right: 4px; padding: 0 0.4rem; font-size: 0.9rem; line-height: 1.4;
  background: rgb(0 0 0 / 0.6); color: #fff; border: none;
}
.nb-foot { display: flex; align-items: center; gap: 0.5rem; }
label.nb-file { display: inline-block; color: var(--text); font-size: 0.85rem; padding: 0.35rem 0.75rem; position: relative; }
label.nb-file:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.nb-danger { color: var(--bad); font-size: 0.85rem; }
.nb-snippet { -webkit-line-clamp: 2; color: var(--muted); font-size: 0.9rem; }
/* Running notes: the switch on Solve, the search box, and the panel embedded on the Notebook screen. */
.nb-scope { display: flex; }
.nb-scope button { flex: 1; }
.nb-count { color: var(--muted); font-weight: 400; }
#nb-find[hidden] { display: none; }
.nb-running-pick { display: flex; gap: 0.5rem; }
.nb-running-pick[hidden], .nb-tabs[hidden] { display: none; }
.nb-running-pick select { flex: 1; min-width: 0; }
.nb-running-pick .nb-add { border: 1px solid var(--border); border-radius: var(--radius); background: none; padding: 0 0.75rem; }
.nb-from { margin: -0.4rem 0 0; }
.notebook-embedded { position: static; max-height: none; box-shadow: none; margin-bottom: 1.5rem; }
.running-dropdown { margin: 0 0 1.5rem; }
.running-dropdown > summary { list-style: none; display: inline-flex; align-items: center; gap: 0.35rem; cursor: pointer; }
.running-dropdown > summary::-webkit-details-marker { display: none; }
.running-dropdown > summary::after { content: "▾"; font-size: 0.8em; transition: transform 0.15s; }
.running-dropdown[open] > summary::after { transform: rotate(180deg); }
.running-dropdown[open] > summary { margin-bottom: 0.75rem; }
.notebook-embedded .nb-live { min-height: 8rem; }

/* Notebook screen: tickable rows and the download bar. */
.pick-list { list-style: none; padding: 0; margin: 0.5rem 0 0; display: grid; gap: 0.5rem; grid-template-columns: minmax(0, 1fr); }
.pick-row { display: flex; align-items: flex-start; gap: 0.6rem; min-width: 0; }
.pick-row > input { width: 1.15rem; height: 1.15rem; margin-top: 1.1rem; flex: none; accent-color: var(--accent); cursor: pointer; }
.pick-row > .problem-card { flex: 1; min-width: 0; }
.pick-row:has(> input:checked) > .problem-card { border-color: var(--accent); background: var(--accent-soft); }
.nb-group-head { margin-top: 1rem; }
.nb-group-head h3 { margin: 0; }
label.inline input[type="checkbox"] { margin: 0 0.35rem 0 0; accent-color: var(--accent); }
.select-bar {
  position: sticky; bottom: 0; z-index: 5; margin-top: 1.5rem; display: flex; align-items: center; gap: 0.75rem 1rem;
  flex-wrap: wrap; padding: 0.75rem 1rem; background: var(--surface); border: 1px solid var(--accent);
  border-radius: var(--radius); box-shadow: 0 -4px 16px rgb(0 0 0 / 0.12);
}
.select-bar select { width: auto; }
.select-bar label.inline { margin: 0; gap: 0.5rem; }

/* Print view: filters (hidden on paper). */
.print-filters { margin-bottom: 1.5rem; }
.print-selection { margin: 0; align-self: center; grid-column: 1 / -1; }
.print-problem h2 .topic { font-size: 0.7rem; font-weight: 500; vertical-align: middle; margin-left: 0.3rem; }

/* Print view: the browser's print dialog turns this into a PDF. */
.print-page { max-width: 820px; }
.print-problem { margin-top: 1rem; padding-top: 0.5rem; border-top: 1px solid var(--border); }
.print-problem h2 { margin: 0 0 0.25rem; font-size: 1.05rem; break-after: avoid; }
.print-problem .statement { margin: 0.25rem 0 0.5rem; }
.print-note h3 { break-after: avoid; }
.print-note { margin: 0.5rem 0 0 0; padding-left: 1rem; border-left: 3px solid var(--accent-soft); }
.print-body { overflow-wrap: break-word; }
.print-page { -webkit-print-color-adjust: exact; print-color-adjust: exact; }   /* keep the highlight on paper */
.print-options { margin: 0.4rem 0 0; gap: 0.25rem; }
.print-options .option { padding: 0.2rem 0.6rem; }
.print-options .option.chosen .option-text { font-weight: 600; }
.option.chosen .option-tag { color: var(--accent); }
.print-answer { margin: 0.4rem 0 0; }
.print-chosen { border-bottom: 2px solid var(--accent); }
.sketch-print { margin: 0.5rem 0; background: #fff; }
.sketch-print svg { display: block; width: 100%; height: auto; }
.print-image { display: block; max-width: 100%; max-height: 70vh; margin: 0.5rem 0; border-radius: var(--radius); }

/* The print view's frame (notebook_print.html); on screen it is invisible. */
.print-frame { width: 100%; border-collapse: collapse; table-layout: fixed; border: 0; }
.print-frame > * > tr > td { padding: 0; border: 0; vertical-align: top; }
.print-frame .print-gap { height: 0; }

@media print {
  :root, :root[data-theme="dark"], :root:not([data-theme="light"]) {
    --bg: #fff; --surface: #fff; --surface-2: #f3f3f0; --text: #000; --muted: #444; --border: #ccc;
    --accent: #2f5bd3; --accent-soft: #dfe6f8; color-scheme: light;
  }
  .no-print, .site-header, .site-footer { display: none !important; }
  .page { padding: 0; max-width: none; }
  .print-image { break-inside: avoid; }   /* notes and sketches flow on, so a problem and its working share a page */
  /* No page margin: browsers then have no room for their own header and footer lines (date, title, web
     address, page numbers). .print-frame's repeating header/footer rows make the top and bottom margins instead. */
  @page { margin: 0; }
  .print-frame .print-gap { height: 14mm; }
  .print-frame > tbody > tr > td { padding: 0 16mm; }
}

/* ---------------------------------------------------------------- settings */

.settings { max-width: 760px; margin: 0 auto; }
.settings-form { display: grid; gap: 1.25rem; }
.settings-form fieldset { padding: 1rem 1.1rem; background: var(--surface); }
.theme-choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.75rem; }
.theme-choice { cursor: pointer; color: var(--text); gap: 0.45rem; }
.theme-preview {
  display: grid; gap: 7px; align-content: start; height: 96px; padding: 10px;
  border-radius: var(--radius); border: 2px solid var(--border);
}
.theme-choice:has(input:checked) .theme-preview { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.theme-choice:has(input:focus-visible) .theme-preview { outline: 2px solid var(--accent); outline-offset: 3px; }
.theme-choice:has(input:checked) .theme-label::after { content: " ✓"; color: var(--accent); }
/* Each preview shows its own colours, whatever theme the page is in. */
.theme-light { background: #f7f7f5; --p-surface: #ffffff; --p-line: #dddcd6; --p-accent: #2f5bd3; }
.theme-dark { background: #131416; --p-surface: #25272b; --p-line: #34363b; --p-accent: #7c9cf0; }
.theme-system {
  background: linear-gradient(135deg, #f7f7f5 50%, #131416 50%);
  --p-surface: rgb(128 128 128 / 0.35); --p-line: rgb(128 128 128 / 0.6); --p-accent: #5a7be0;
}
.tp-bar { height: 14px; border-radius: 4px; background: var(--p-surface); }
.tp-line { height: 8px; width: 80%; border-radius: 4px; background: var(--p-line); }
.tp-line.short { width: 55%; }
.tp-button { height: 14px; width: 40%; border-radius: 4px; background: var(--p-accent); }
.theme-label { font-weight: 600; font-size: 0.9rem; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem 1rem; flex-wrap: wrap; }
.setting-row + .setting-row { margin-top: 0.9rem; }
.setting-row + .setting-help + .setting-row { margin-top: 0.5rem; }
.setting-name { font-weight: 600; }
.setting-help { margin: 0.4rem 0 0.75rem; }
.choice-pills { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.pill {
  flex-direction: row; cursor: pointer; padding: 0.4rem 0.85rem; font-size: 0.875rem;
  color: var(--text); background: var(--surface);
}
.pill + .pill { border-left: 1px solid var(--border); }
.pill:has(input:checked) { background: var(--accent-soft); font-weight: 600; }
.pill:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------------------------------------------------------------- narrow screens */

@media (max-width: 1000px) {
  .editor-grid { grid-template-columns: 1fr; grid-template-areas: "preview" "form" "source"; }
  .solve-layout.notebook-open { grid-template-columns: minmax(0, 1fr); gap: 1.5rem; }
  .nb-resize { display: none; }
  .notebook { position: static; max-height: none; }
}
@media (max-width: 800px) {
  .exam-body { grid-template-columns: 1fr; }
  .palette { position: static; }
  .review-layout { grid-template-columns: 1fr; }
  .review-items { max-height: 40vh; }
  .stat.big { grid-column: span 1; }
}

/* ---------------------------------------------------------------- phones */

.narrow-only { display: none !important; }
@media (max-width: 640px) {
  .wide-only { display: none !important; }
  .narrow-only { display: revert !important; }
  .site-header .user-menu-panel a.narrow-only { display: block !important; }

  /* Header: one row (brand, nav, account menu) instead of two. */
  .site-header-inner { gap: 0.5rem; padding: 0.5rem 16px; flex-wrap: nowrap; }
  .brand { white-space: nowrap; }
  .site-header nav { flex-wrap: nowrap; min-width: 0; }
  .site-header nav a { padding: 0.35rem 0.55rem; white-space: nowrap; }

  .page { padding-top: 1rem; }
  h1 { font-size: 1.4rem; }
  h2 { margin-top: 1.5rem; }

  /* iOS zooms into any field with text under 16px when it is focused. */
  select, input[type="text"], input[type="number"], input[type="password"], input[type="email"], textarea,
  .multi-filter summary { font-size: 16px; }

  /* Browse: two filters a row, so the problems start on the first screen. */
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem 0.6rem; padding: 0.75rem; }
  .multi-panel { max-width: calc(100vw - 32px); max-height: 50vh; }
  .check-item { padding: 0.5rem; }

  /* Solve: smaller buttons in the top bar. */
  .solve-nav { gap: 0.4rem; }
  .solve-nav .button, .solve-nav button { padding: 0.4rem 0.75rem; }
  .statement { font-size: 1rem; }

  /* Notebook: a sheet along the bottom of the screen, so the problem stays in view above it. */
  .solve-layout.notebook-open .notebook {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 15; max-height: 62vh; max-height: 62dvh;
    border-radius: 14px 14px 0 0; border-bottom: none; padding: 0.75rem 16px calc(0.75rem + env(safe-area-inset-bottom));
    box-shadow: 0 -6px 24px rgb(0 0 0 / 0.2);
  }
  .solve-layout.notebook-open .solve { padding-bottom: 62vh; }
  .nb-tools button { padding: 0.4rem 0.6rem; }

  /* Exam: keep the bar on one row and the answer buttons in a tidy grid. */
  .exam-bar { gap: 0.5rem; flex-wrap: nowrap; padding: 0.5rem 16px; }
  .exam-title {
    min-width: 0; font-size: 0.9rem; line-height: 1.25;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }
  .timer { font-size: 1.05rem; padding: 0.15rem 0.5rem; }
  .exam-bar .save-state { display: none; }
  .exam-bar .save-state.offline { display: inline; }
  .exam-bar #btn-submit { padding: 0.4rem 0.8rem; }
  .exam-body { padding-top: 1rem; gap: 1rem; }
  .exam-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .exam-actions > * { text-align: center; }
  .exam-actions > .narrow-only { display: block !important; grid-column: 1 / -1; }
  .palette { scroll-margin-top: 4rem; }
  .palette-grid { grid-template-columns: repeat(auto-fill, minmax(2.6rem, 1fr)); }

  /* Settings: the three theme pictures side by side. */
  .theme-choices { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.5rem; }
  .theme-preview { height: 64px; padding: 6px; gap: 5px; }
  .theme-label { font-size: 0.8rem; }
  /* Pills that wrap onto a second row: hairline gaps instead of per-pill borders, so the lines stay tidy. */
  .choice-pills { display: flex; gap: 1px; background: var(--border); }
  .pill { flex: 1 1 auto; justify-content: center; }
  .pill + .pill { border-left: none; }

  .verdict { padding: 0.85rem 1rem; }
  .tile, .problem-card, .stat { padding: 0.85rem; }
  .history li > span:first-child { min-width: 0; flex-basis: 100%; }

  /* Results: names in the first column wrap, so more of the numbers fit without scrolling. */
  th, td { padding: 0.5rem 0.6rem; }
  td:first-child { white-space: normal; min-width: 7.5rem; }
  .review-list summary { gap: 0.2rem 0.6rem; padding: 0.6rem 0.85rem; }
  .review-list summary > span:nth-child(2) { flex: 1 1 calc(100% - 2rem); }
  .review-list summary > span:nth-child(3) { flex-basis: calc(100% - 10px - 0.6rem); margin-left: calc(10px + 0.6rem); }
  .review-list summary > .spacer { display: none; }
  .review-list summary > span:nth-child(5) { margin-left: calc(10px + 0.6rem); }
  .review-list .marks { text-align: left; min-width: 0; }
}

/* ---------------------------------------------------------------- server-rendered forms (Flask) */

/* Options are <label>s around a visually hidden radio/checkbox, so the
   "chosen" state comes from the input itself. */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
label.option {
  font-size: 0.95rem; cursor: pointer; border-radius: var(--radius); border: 1px solid var(--border);
  color: var(--text); flex-direction: row; line-height: 1.3;
}
label.option.locked { cursor: default; }
label.option:not(.locked):hover { border-color: var(--accent); }
label.option:not(.right):not(.wrong):has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
label.option:not(.right):not(.wrong):has(input:checked) .option-letter {
  background: var(--accent); border-color: var(--accent); color: var(--accent-text);
}
label.option:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.solve form { margin: 0; }

.flash-list { list-style: none; padding: 0; margin: 0; }
.math .katex-error { color: var(--bad); }
.inline-form { display: inline; margin: 0; }

/* Review: paper files panel and upload */
.sources { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1.25rem; }
.sources summary { cursor: pointer; font-weight: 600; }
.sources table { margin-top: 0.75rem; }
.sources td { white-space: normal; }
.sources .err { color: var(--bad); }
.upload-row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; margin-top: 0.75rem; }
.upload-row input[type="file"] { font: inherit; font-size: 0.9rem; }
.editor-note { font-size: 0.85rem; color: var(--muted); }
.review-items a {
  width: 100%; display: flex; justify-content: space-between; gap: 0.5rem; align-items: center;
  font-size: 0.85rem; padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); text-decoration: none;
}
.review-items a.active { border-color: var(--accent); background: var(--accent-soft); }
.segmented a {
  border-radius: 0; padding: 0.35rem 0.75rem; font-size: 0.85rem; color: var(--text); text-decoration: none;
  background: var(--surface); text-align: center;
}
.segmented a.active { background: var(--accent-soft); font-weight: 600; }
.review-sidebar .segmented a:nth-child(even) { border-left: 1px solid var(--border); }
.review-sidebar .segmented a:nth-child(n + 3) { border-top: 1px solid var(--border); }
.results .segmented a + a { border-left: 1px solid var(--border); }
.site-header form button { padding: 0.35rem 0.7rem; }
[hidden] { display: none !important; }
.hint-box h3 + div { background: var(--flag-soft); border-radius: var(--radius); padding: 0.6rem 0.9rem; margin: 0; }
div.option { border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); }
.exam-question-wrap { min-width: 0; }
.exam-question-wrap .exam-question { min-width: 0; }
/* A wide formula must not stretch the card list past a phone screen. */
.problem-list { grid-template-columns: minmax(0, 1fr); }
.problem-card { min-width: 0; }
.card-statement .katex-display { overflow: hidden; }

/* ---------------------------------------------------------------- bookmarks */

.bm-toggle .bm-star { color: var(--muted); }
.bm-toggle.on { border-color: var(--warn); background: var(--warn-soft); }
.bm-toggle.on .bm-star { color: var(--warn); }
.chip.bookmarked { background: var(--warn-soft); color: var(--warn); }
.bm-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.6rem 0.9rem; margin-bottom: 1rem;
}
.bm-panel[hidden] { display: none; }
.bm-panel textarea, .bm-card textarea { font-family: inherit; font-size: 0.95rem; }
.bm-panel .save-state { display: block; min-height: 1.2em; margin-top: 0.2rem; }
.bm-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow); min-width: 0;
}
.bm-link { display: block; color: var(--text); text-decoration: none; }
.bm-link:hover .source { color: var(--accent); }
.bm-card form { margin-top: 0.4rem; }
.bm-actions { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.25rem; min-height: 1.6rem; }

/* ---------------------------------------------------------------- browse: subject / aptitude tabs */

.part-tabs { display: flex; gap: 0.25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); }
.part-tabs a {
  padding: 0.45rem 0.9rem; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.part-tabs a:hover { color: var(--text); }
.part-tabs a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------------------------------------------------------------- account menu (header) */

.user-menu { position: relative; }
.user-menu summary {
  list-style: none; cursor: pointer; width: 2.25rem; height: 2.25rem; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); background: var(--surface-2); border: 1px solid var(--border);
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover, .user-menu[open] summary { color: var(--text); border-color: var(--accent); }
.user-menu-panel {
  position: absolute; right: 0; top: calc(100% + 0.5rem); z-index: 20; min-width: 13rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.18); padding: 0.35rem; display: flex; flex-direction: column;
}
.user-menu-who {
  margin: 0; padding: 0.4rem 0.7rem 0.5rem; font-size: 0.8rem; color: var(--muted);
  border-bottom: 1px solid var(--border); margin-bottom: 0.25rem; overflow-wrap: anywhere;
}
.site-header .user-menu-panel a, .site-header .user-menu-panel button {
  display: block; width: 100%; text-align: left; border: none; background: none; font: inherit; font-size: 0.95rem;
  color: var(--text); text-decoration: none; padding: 0.45rem 0.7rem; border-radius: 6px; cursor: pointer;
}
.site-header .user-menu-panel a:hover, .site-header .user-menu-panel button:hover { background: var(--surface-2); }
.user-menu-panel a.active { background: var(--accent-soft); }
.user-menu-panel form { margin: 0; }
.user-menu-panel hr { border: none; border-top: 1px solid var(--border); margin: 0.3rem 0; }

/* ---------------------------------------------------------------- question timer */

.q-timer {
  display: inline-flex; align-items: baseline; gap: 0.4rem; margin: 0 0 0.5rem; padding: 0.15rem 0.7rem;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2);
  font-variant-numeric: tabular-nums; font-weight: 600;
}
.q-timer.over { color: var(--bad); border-color: var(--bad); background: var(--bad-soft); animation: q-timer-blink 1s steps(2, start) infinite; }
@keyframes q-timer-blink { 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .q-timer.over { animation: none; } }
label.setting-name { color: var(--text); font-size: 1rem; }
.narrow-input { width: 6rem; }

/* ---------------------------------------------------------------- community thread (solve) */

.community { margin-top: 2.5rem; border-top: 1px solid var(--border); padding-top: 0.5rem; }
.community-locked {
  background: var(--surface-2); border: 1px dashed var(--border); border-radius: var(--radius); padding: 1rem 1.25rem;
}
.thread { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.75rem; }
.post.answer {
  display: grid; grid-template-columns: auto 1fr; column-gap: 0.9rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem 1rem;
}
.post.answer > .comments, .post.answer > .add-comment, .post.answer > p { grid-column: 1 / -1; }
.vote { display: flex; flex-direction: column; align-items: center; gap: 0.1rem; }
.vote form { margin: 0; }
.vote-btn {
  border: none; background: none; padding: 0.15rem 0.4rem; color: var(--muted); font-size: 0.95rem; line-height: 1;
}
.vote-btn.on { color: var(--accent); }
.vote-btn:disabled { opacity: 0.35; }
.vote-score { font-weight: 700; font-variant-numeric: tabular-nums; }
.post-main { min-width: 0; }
.post-body { overflow-wrap: anywhere; }
.post-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.75rem; margin-top: 0.4rem; }
.post-meta form.inline { display: inline; margin: 0; }
.post-edit summary, .add-comment summary { cursor: pointer; color: var(--accent); }
.post-edit[open] { flex-basis: 100%; }
.post-edit textarea, .add-comment textarea, .answer-form textarea { width: 100%; margin-top: 0.4rem; }
.post-edit .actions, .add-comment .actions { margin-top: 0.4rem; }
.comments { list-style: none; margin: 0.75rem 0 0; padding: 0; display: grid; gap: 0.5rem; }
.comments:empty { display: none; }
.post.comment { border-left: 3px solid var(--border); padding: 0.1rem 0 0.1rem 0.75rem; font-size: 0.92rem; }
.add-comment { margin-top: 0.6rem; }
.answer-form { margin-top: 1.25rem; }
.answer-form label { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: baseline; }

/* ---------------------------------------------------------------- profile progress (rings + charts) */

.subject-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); gap: 1rem; }
.progress-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.1rem; box-shadow: var(--shadow); min-width: 0;
}
.progress-overall .progress-card { max-width: 700px; }
.progress-card > header { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.progress-card h3 { margin: 0; }
.progress-card h3 a { color: inherit; text-decoration: none; }
.progress-card h3 a:hover { text-decoration: underline; }
.rings { display: flex; justify-content: space-around; gap: 0.5rem; margin: 0.9rem 0 0.4rem; flex-wrap: wrap; }
.ring { margin: 0; display: flex; flex-direction: column; align-items: center; text-align: center; }
.ring figcaption { display: flex; flex-direction: column; font-size: 0.85rem; line-height: 1.3; margin-top: 0.2rem; }
.ring-track { fill: none; stroke: var(--surface-2); stroke-width: 8; }
.ring-fill { fill: none; stroke: var(--accent); stroke-width: 8; stroke-linecap: round; }
.ring-value { fill: var(--text); font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.compare { display: grid; grid-template-columns: 1fr; gap: 0.15rem; margin: 0.8rem 0 0; }
.compare dt { font-weight: 600; font-size: 0.9rem; margin-top: 0.35rem; }
.compare dd { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; font-variant-numeric: tabular-nums; }
.sparks { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.75rem; margin-top: 0.8rem; }
.spark { margin: 0; }
.spark figcaption { color: var(--muted); margin-bottom: 0.15rem; }
.spark svg { width: 100%; height: auto; display: block; overflow: visible; }
.spark .grid { stroke: var(--border); stroke-width: 1; }
.spark .axis { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.spark .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.spark .hit { fill: transparent; }
.spark .pt:hover .dot { r: 5.5; }

.pace-note { margin: .5rem 0 0; padding: .4rem .6rem; border-left: 3px solid var(--border, #ccc); }
.pace-rush { border-left-color: #c0392b; }
.pace-slow { border-left-color: #d68910; }
