:root {
  --bg: #f7f8fb;
  --panel: #ffffff;
  --border: #e2e5eb;
  --hover-bg: #f2f4f8;
  --text: #1c2230;
  --text-muted: #667085;
  --accent: #3457d5;
  --accent-hover: #2843b0;
  --accent-soft: #eaefff;
  --very-easy: #4a5568;
  --very-easy-bg: #eef1f5;
  --easy: #1a7f4f;
  --easy-bg: #e6f6ee;
  --medium: #9a6b00;
  --medium-bg: #fdf2da;
  --difficult: #c2540a;
  --difficult-bg: #fdeadb;
  --very-difficult: #b3271f;
  --very-difficult-bg: #fbe7e5;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

/* Dark palette: applied when the OS prefers dark and the user hasn't
   explicitly picked light (below), and again when the user explicitly
   picks dark regardless of the OS setting (see js/store.js applyTheme()). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161f;
    --panel: #1c1f2b;
    --border: #383e50;
    --hover-bg: #262a38;
    --text: #e8eaf0;
    --text-muted: #9099ad;
    --accent: #6d87ff;
    --accent-hover: #8298ff;
    --accent-soft: #26304f;
    --very-easy: #aeb7c9;
    --very-easy-bg: #262b3a;
    --easy: #57d495;
    --easy-bg: #163828;
    --medium: #f0c94d;
    --medium-bg: #3a2f11;
    --difficult: #ff9d5c;
    --difficult-bg: #3d2814;
    --very-difficult: #ff8080;
    --very-difficult-bg: #3d1a1a;
  }
}

:root[data-theme="dark"] {
  --bg: #14161f;
  --panel: #1c1f2b;
  --border: #383e50;
  --hover-bg: #262a38;
  --text: #e8eaf0;
  --text-muted: #9099ad;
  --accent: #6d87ff;
  --accent-hover: #8298ff;
  --accent-soft: #26304f;
  --very-easy: #aeb7c9;
  --very-easy-bg: #262b3a;
  --easy: #57d495;
  --easy-bg: #163828;
  --medium: #f0c94d;
  --medium-bg: #3a2f11;
  --difficult: #ff9d5c;
  --difficult-bg: #3d2814;
  --very-difficult: #ff8080;
  --very-difficult-bg: #3d1a1a;
}

* { box-sizing: border-box; }

input[type="text"],
textarea {
  background: var(--bg);
  color: var(--text);
}

/* Native MathML islands (see js/mathml.js) should size-match surrounding text.
   math-style: normal draws inline fractions full size instead of the
   browser's default superscript-sized ones, which are hard to read. */
math { font-size: 1em; math-style: normal; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  gap: 12px;
}

.topbar h1 {
  font-size: 18px;
  margin: 0;
  justify-self: start;
}

.topbar-actions { justify-self: end; }

.tabs {
  display: flex;
  gap: 0;
  justify-self: center;
}

@media (max-width: 640px) {
  .topbar {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }
  .topbar h1 { justify-self: center; }
  .topbar-actions { justify-self: center; }
}

/* ---------- Desmos calculator window ---------- */
.calc-toggle.active { background: var(--accent); border-color: var(--accent); color: white; }

/* A floating window over the page. Its position and size are set inline by
   js/calculator.js (dragged by the header, resized from any edge/corner). */
.calc-panel {
  position: fixed;
  z-index: 9;
  display: flex;
  flex-direction: column;
  min-width: 300px;
  min-height: 260px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
  /* No overflow: hidden, so the resize strips can poke out past the edges;
     the header and iframe round their own corners instead. */
}
.calc-panel[hidden], .calc-toggle[hidden] { display: none; }

.calc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  border-radius: 10px 10px 0 0;
  font-size: 13px;
  cursor: move;
  user-select: none;
  touch-action: none;
}
.calc-header strong { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.calc-header-actions { display: flex; flex-shrink: 0; gap: 6px; cursor: default; }
.calc-header-actions .btn { white-space: nowrap; }
.calc-header-actions a.btn { text-decoration: none; }
/* Reset after its first click, waiting for the confirming second one. */
#calc-reset.armed {
  background: var(--very-difficult);
  border-color: var(--very-difficult);
  color: white;
  animation: calc-reset-pulse 1s ease-in-out infinite;
}
@keyframes calc-reset-pulse {
  50% { opacity: 0.7; }
}

.calc-frame {
  flex: 1;
  width: 100%;
  border: 0;
  border-radius: 0 0 10px 10px;
  background: #fff;
}

/* Invisible grab strips along each edge and corner, half outside the window. */
.calc-resize { position: absolute; z-index: 1; touch-action: none; }
.calc-resize[data-dir="n"], .calc-resize[data-dir="s"] { left: 12px; right: 12px; height: 10px; cursor: ns-resize; }
.calc-resize[data-dir="e"], .calc-resize[data-dir="w"] { top: 12px; bottom: 12px; width: 10px; cursor: ew-resize; }
.calc-resize[data-dir="n"] { top: -5px; }
.calc-resize[data-dir="s"] { bottom: -5px; }
.calc-resize[data-dir="e"] { right: -5px; }
.calc-resize[data-dir="w"] { left: -5px; }
.calc-resize[data-dir="ne"], .calc-resize[data-dir="nw"],
.calc-resize[data-dir="se"], .calc-resize[data-dir="sw"] { width: 18px; height: 18px; z-index: 2; }
.calc-resize[data-dir="ne"] { top: -6px; right: -6px; cursor: nesw-resize; }
.calc-resize[data-dir="sw"] { bottom: -6px; left: -6px; cursor: nesw-resize; }
.calc-resize[data-dir="nw"] { top: -6px; left: -6px; cursor: nwse-resize; }
.calc-resize[data-dir="se"] { bottom: -6px; right: -6px; cursor: nwse-resize; }
/* A visible grip in the bottom-right corner. */
.calc-resize[data-dir="se"]::after {
  content: "";
  position: absolute;
  right: 9px;
  bottom: 9px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  opacity: 0.7;
}

/* Snapped to a side: square off the corners that touch the screen edge. */
.calc-panel[data-snapped] { border-radius: 0; border-top: 0; }
.calc-panel[data-snapped] .calc-header,
.calc-panel[data-snapped] .calc-frame { border-radius: 0; }
.calc-panel[data-snapped="left"] { border-left: 0; }
.calc-panel[data-snapped="right"] { border-right: 0; }

/* ...and the page moves over to make room for it. */
body[data-calc-snapped="left"] #app {
  margin-left: max(var(--calc-snap-w), (100% - 1200px) / 2);
  margin-right: auto;
}
body[data-calc-snapped="right"] #app {
  margin-right: max(var(--calc-snap-w), (100% - 1200px) / 2);
  margin-left: auto;
}

/* A thin glowing bar on the screen edge the window will snap to. */
.calc-snap-preview {
  position: fixed;
  z-index: 10;
  width: 4px;
  background: var(--accent);
  box-shadow: 0 0 14px 2px var(--accent);
  pointer-events: none;
}
.calc-snap-preview[hidden] { display: none; }

/* While dragging or resizing, the iframe would swallow the mouse. */
body.calc-moving { user-select: none; }
body.calc-moving .calc-frame { pointer-events: none; }

/* Phones: no room for a window, so it fills the screen under the top bar. */
@media (max-width: 700px) {
  .calc-panel {
    inset: var(--topbar-h, 69px) 0 0 0 !important;
    width: auto !important;
    height: auto !important;
    border-radius: 0;
    border-width: 1px 0 0;
  }
  .calc-header, .calc-frame { border-radius: 0; }
  body[data-calc-snapped] #app { margin-left: auto; margin-right: auto; }
  .calc-header { cursor: default; }
  .calc-resize { display: none; }
}

.tab {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-muted);
  padding: 10px 20px;
  border-radius: 0;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  position: relative;
  transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease, color 0.14s ease;
}

.tab + .tab { margin-left: -1px; }

.tab:hover {
  background: var(--hover-bg);
  color: var(--text);
  transform: scale(1.1);
  z-index: 2;
  box-shadow: 0 6px 14px rgba(28, 34, 48, 0.14);
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  z-index: 1;
}

.tab.active:hover {
  background: var(--accent-hover);
  color: white;
}

.badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  margin-left: 4px;
  border-radius: 999px;
  background: rgba(255,255,255,0.25);
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}

.tab:not(.active) .badge {
  background: var(--accent-soft);
  color: var(--accent);
}

#app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 24px 60px;
  /* Layouts inside respond to the space #app actually has, not to the
     whole window. */
  container: app / inline-size;
}

/* ---------- Browse layout ---------- */
.browse-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 20px;
  align-items: start;
}

/* Browse sits inside the Practice picker column, so it stacks based on that
   column's width. */
#pr-picker-panel { container: picker / inline-size; }
@container picker (max-width: 600px) {
  .browse-layout { grid-template-columns: 1fr; }
  .browse-layout .sidebar { position: static; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.sidebar { position: sticky; top: 76px; }

.sidebar h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 16px 0 8px;
}
.sidebar h3:first-child { margin-top: 0; }

.search-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}

.cat-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cat-nav-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: none;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.cat-nav-item:hover { background: var(--hover-bg); color: var(--text); }

.cat-nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-soft);
}

.sub-list-standalone {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sub-group-label {
  margin: 8px 0 2px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent);
}
.sub-group-label:first-child { margin-top: 0; }

.sub-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  padding: 3px 0;
  cursor: pointer;
}

.sub-label:hover, .cat-label:hover { color: var(--text); }

.diff-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.diff-chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  background: var(--bg);
  color: var(--text-muted);
}

.diff-chip.active[data-diff="Very Easy"] { background: var(--very-easy-bg); color: var(--very-easy); border-color: var(--very-easy); }
.diff-chip.active[data-diff="Easy"] { background: var(--easy-bg); color: var(--easy); border-color: var(--easy); }
.diff-chip.active[data-diff="Medium"] { background: var(--medium-bg); color: var(--medium); border-color: var(--medium); }
.diff-chip.active[data-diff="Difficult"] { background: var(--difficult-bg); color: var(--difficult); border-color: var(--difficult); }
.diff-chip.active[data-diff="Very Difficult"] { background: var(--very-difficult-bg); color: var(--very-difficult); border-color: var(--very-difficult); }

.clear-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  margin-top: 14px;
}

/* ---------- Problem list ---------- */
.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 10px;
}

.list-toolbar .count { color: var(--text-muted); font-size: 13px; }
.list-toolbar .actions { display: flex; gap: 8px; }

.btn {
  border: 1px solid var(--border);
  background: var(--bg);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}
.btn:hover { background: var(--hover-bg); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--very-difficult); border-color: var(--very-difficult-bg); }
.btn.danger:hover { background: var(--very-difficult-bg); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.small { padding: 4px 9px; font-size: 12px; }

.problem-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}

.problem-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

.tag.diff-Very-Easy { background: var(--very-easy-bg); color: var(--very-easy); }
.tag.diff-Easy { background: var(--easy-bg); color: var(--easy); }
.tag.diff-Medium { background: var(--medium-bg); color: var(--medium); }
.tag.diff-Difficult { background: var(--difficult-bg); color: var(--difficult); }
.tag.diff-Very-Difficult { background: var(--very-difficult-bg); color: var(--very-difficult); }

.problem-question { font-size: 14.5px; line-height: 1.5; margin: 6px 0 10px; }

.problem-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.problem-body { flex: 1; }

.add-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
}

.choices-preview {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
  display: grid;
  gap: 6px;
}

.choices-preview li {
  font-size: 13.5px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
}

.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--text-muted);
}

/* ---------- Grouped section headings ---------- */
.section-group {
  margin-bottom: 26px;
}

.section-heading {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 0 10px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}

.section-heading .section-cat {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--accent);
}

.section-heading .section-sub {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.section-heading .section-count {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
}

/* ---------- Practice view ---------- */
.practice-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 20px;
  align-items: start;
}

#pr-selected-panel {
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  padding-right: 2px;
}

@container app (max-width: 900px) {
  .practice-layout { grid-template-columns: 1fr; }
  #pr-selected-panel { position: static; max-height: none; overflow-y: visible; }
}

.practice-layout > * { min-width: 0; }

.mode-toggle { display: flex; margin-bottom: 16px; }
.mode-btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-muted);
  padding: 8px 18px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
}
.mode-btn + .mode-btn { margin-left: -1px; }
.mode-btn:first-child { border-radius: 8px 0 0 8px; }
.mode-btn:last-child { border-radius: 0 8px 8px 0; }
.mode-btn:hover { background: var(--hover-bg); color: var(--text); }
.mode-btn.active { background: var(--accent); border-color: var(--accent); color: white; position: relative; }

/* ---------- Selection board ---------- */
.board-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.board-toolbar .count { font-size: 13px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.board-toolbar .actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* One panel, categories as accordion rows separated by dividers. */
.board-list { padding: 0; overflow: hidden; }

.board-cat + .board-cat { border-top: 1px solid var(--border); }

.board-cat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 0 0 16px;
}
.board-cat-head:hover { background: var(--hover-bg); }

.board-cat-toggle {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 14px 16px 14px 0;
  background: none;
  border: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.board-cat-name { font-size: 14.5px; font-weight: 600; }
.board-cat-meta { font-size: 12px; color: var(--text-muted); }

.board-count {
  margin-left: auto;
  font-size: 12.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.board-count.has-selection { color: var(--accent); font-weight: 600; }

.board-chevron {
  color: var(--text-muted);
  font-size: 14px;
  width: 14px;
  text-align: center;
  transition: transform 0.15s ease;
}
.board-cat.open .board-chevron { transform: rotate(90deg); }

@media (prefers-reduced-motion: reduce) {
  .board-chevron { transition: none; }
}

.board-subs {
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 4px 16px 6px 44px;
}

.board-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 9px 0;
}
.board-row + .board-row { border-top: 1px solid var(--border); }
.board-row.empty .board-sub { color: var(--text-muted); cursor: default; }

.board-sub {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 200px;
  min-width: 0;
  font-size: 13.5px;
  cursor: pointer;
}

.board-pills { display: flex; flex-wrap: wrap; gap: 6px; }

.board-row .board-count { margin-left: 0; width: 32px; text-align: right; }

/* "✓ 3 ✗ 1": how a section's questions went last time. */
.board-status { display: inline-flex; flex-shrink: 0; white-space: nowrap; gap: 6px; font-size: 11.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.board-status .st-correct { color: var(--easy); }
.board-status .st-missed { color: var(--very-difficult); }

.board-pill {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 11.5px;
  cursor: pointer;
}
.board-pill:hover { color: var(--text); border-color: var(--text-muted); }
.board-pill.on.diff-Very-Easy { background: var(--very-easy-bg); color: var(--very-easy); border-color: var(--very-easy); }
.board-pill.on.diff-Easy { background: var(--easy-bg); color: var(--easy); border-color: var(--easy); }
.board-pill.on.diff-Medium { background: var(--medium-bg); color: var(--medium); border-color: var(--medium); }
.board-pill.on.diff-Difficult { background: var(--difficult-bg); color: var(--difficult); border-color: var(--difficult); }
.board-pill.on.diff-Very-Difficult { background: var(--very-difficult-bg); color: var(--very-difficult); border-color: var(--very-difficult); }

.practice-start-panel {
  z-index: 5;
}

/* Practice mode / Test mode switch above the start button. */
.session-mode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
}
.session-mode-btn {
  padding: 7px 10px;
  border: none;
  border-radius: 7px;
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.session-mode-btn:hover { color: var(--text); }
.session-mode-btn.active { background: var(--accent); color: white; }
.session-mode-hint { margin: 8px 2px 12px; font-size: 12.5px; color: var(--text-muted); }

.practice-start-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}
.practice-start-row .count { font-size: 14px; font-weight: 600; }
.practice-start-row .shuffle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.practice-start-hint {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.practice-card {
  max-width: 640px;
  margin: 0 auto;
}

.progress-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 20px;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
}

.choice-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  transition: background 0.12s ease, border-color 0.12s ease;
}
.choice-btn:hover { border-color: var(--accent); background: var(--hover-bg); }
.choice-btn.correct { border-color: var(--easy); background: var(--easy-bg); }
.choice-btn.incorrect { border-color: var(--very-difficult); background: var(--very-difficult-bg); }
.choice-btn.reveal-correct { border-color: var(--easy); background: var(--easy-bg); }
.choice-btn.selected { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }
.choice-btn:disabled { cursor: default; }

/* Practice choices: circled letter + answer, with a cross-out button
   beside it. */
.choice-row { display: flex; gap: 8px; margin-bottom: 8px; }
.choice-row .choice-btn {
  flex: 1;
  margin-bottom: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}
.choice-letter {
  flex-shrink: 0;
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  font-size: 13px;
  font-weight: 600;
}
.choice-btn:hover:not(:disabled) .choice-letter { border-color: var(--accent); color: var(--accent); }
.choice-btn.reveal-correct .choice-letter { border-color: var(--easy); color: var(--easy); }
.choice-btn.incorrect .choice-letter { border-color: var(--very-difficult); color: var(--very-difficult); }
.choice-btn.selected .choice-letter { border-color: var(--accent); background: var(--accent); color: white; }

/* Crossed out: the letter becomes a red ✕ and a line runs through just the
   answer (not the whole box), which is faded. */
.choice-btn.eliminated,
.choice-btn.eliminated:hover { background: transparent; border-style: dashed; box-shadow: none; }
.choice-btn.eliminated .choice-text { position: relative; color: var(--text-muted); }
.choice-btn.eliminated .choice-text > * { opacity: 0.5; }
.choice-btn.eliminated .choice-text::after {
  content: "";
  position: absolute;
  left: -4px;
  right: -4px;
  top: 50%;
  border-top: 2px solid var(--very-difficult);
}
.choice-btn.eliminated .choice-letter {
  border-color: var(--very-difficult);
  background: var(--very-difficult-bg);
  color: transparent;
  position: relative;
}
.choice-btn.eliminated .choice-letter::after {
  content: "✕";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--very-difficult);
  font-size: 13px;
  font-weight: 700;
}

.elim-btn {
  flex: 0 0 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.elim-btn:hover { border-color: var(--border); color: var(--very-difficult); }
.elim-btn.undo { font-size: 12px; color: var(--accent); }
.elim-btn.undo:hover { color: var(--accent); }

.q-timer { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
.q-timer.stopped { font-weight: 400; color: var(--text-muted); }
.summary-stats { display: flex; justify-content: center; gap: 12px; margin-top: 14px; }
.summary-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 130px;
  padding: 10px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.summary-stat-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.summary-stat-label { font-size: 12px; color: var(--text-muted); }
.review-time {
  font-size: 12.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.grid-input-row { display: flex; gap: 8px; margin-bottom: 10px; }
.grid-input-row input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14.5px;
}

.explanation {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--accent-soft);
  border-radius: 8px;
  font-size: 13.5px;
  line-height: 1.5;
}

.practice-footer {
  display: flex;
  justify-content: space-between;
  margin-top: 18px;
}
.practice-footer-nav { display: flex; gap: 8px; }
.test-badge {
  padding: 1px 8px;
  margin-right: 4px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
}

.summary-card { max-width: 480px; margin: 30px auto; text-align: center; }
.summary-score { font-size: 42px; font-weight: 700; margin: 10px 0; }
.summary-breakdown { text-align: left; margin: 20px 0; }
.summary-breakdown-row {
  display: flex;
  justify-content: space-between;
  font-size: 13.5px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.review-list { margin-top: 30px; }
.review-heading {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 14px;
}

.missed-section { margin: 0 0 28px; text-align: left; }
.missed-section .review-heading { color: var(--very-difficult); }
.missed-section .review-item { border-color: var(--very-difficult-bg); }
.missed-empty {
  font-size: 13.5px;
  color: var(--easy);
  background: var(--easy-bg);
  border-radius: 8px;
  padding: 10px 14px;
}

.review-group { margin-bottom: 20px; }
.review-group-heading {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 0 8px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--border);
}
.review-group-heading .cat {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--accent);
}
.review-group-heading .sub { font-size: 14.5px; font-weight: 600; color: var(--text); }

.review-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  overflow: hidden;
}
/* Nested inside a .panel (e.g. Dashboard's session history) rather than
   directly on the page — needs contrast against the panel, not the page. */
.panel .review-item { background: var(--bg); }

.review-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text);
}
.review-row:hover { background: var(--hover-bg); }

.review-num { font-size: 12px; color: var(--text-muted); width: 18px; flex-shrink: 0; }
.review-name { flex: 1; font-weight: 500; }
.review-chevron { color: var(--text-muted); font-size: 11px; width: 12px; text-align: center; flex-shrink: 0; }

.review-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  flex-shrink: 0;
}
.review-badge.correct { background: var(--easy-bg); color: var(--easy); }
.review-badge.incorrect { background: var(--very-difficult-bg); color: var(--very-difficult); }

.review-detail {
  padding: 4px 16px 16px;
  border-top: 1px solid var(--border);
}
.review-detail .choice-btn { margin-bottom: 6px; }
.review-detail .choice-btn:last-of-type { margin-bottom: 0; }
.review-detail .problem-question { margin-top: 10px; }

/* ---------- Settings view ---------- */
.settings-page {
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.admin-banner {
  padding: 10px 14px;
  border: 1px dashed var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
  font-size: 13px;
  line-height: 1.5;
}
.admin-banner code {
  font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
}

.qb-step {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 22px 0 8px;
  font-size: 14px;
}
.qb-step:first-of-type { margin-top: 4px; }
.qb-step span {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 12px;
  flex-shrink: 0;
}

.req-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
}
@media (max-width: 520px) {
  .req-grid { grid-template-columns: 1fr; }
}

.req-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  min-width: 0;
}
.req-field > span { font-size: 12px; color: var(--text-muted); }
.req-field em { font-style: normal; opacity: 0.8; }
.req-field input,
.req-field select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
}
.req-field select:disabled { opacity: 0.55; }

.req-preview { max-height: none; margin: 4px 0 10px; }

.save-overview {
  margin-top: 4px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.ov-total { margin: 0 0 10px; font-size: 15px; }
.ov-row {
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 8px;
  align-items: start;
  margin-bottom: 8px;
  font-size: 13px;
}
.ov-label { color: var(--text-muted); font-size: 12px; padding-top: 2px; }
.ov-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.ov-sections { margin: 0; padding: 0; list-style: none; display: grid; gap: 3px; }
.ov-n {
  display: inline-block;
  min-width: 20px;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--hover-bg);
  color: var(--text-muted);
  font-size: 11.5px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.save-overview .qb-result { margin: 10px 0; }
.ov-filename { margin: 12px 0 10px; }
.ov-filename-input { display: flex; align-items: center; gap: 6px; }
.ov-filename-input input { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.ov-filename-input span { color: var(--text-muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
#save-paste {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace;
  resize: vertical;
}

.settings-section h3 { margin-top: 0; }

.theme-row { display: flex; gap: 0; }
.theme-btn {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  padding: 10px;
  cursor: pointer;
  font-size: 13.5px;
}
.theme-btn:not(:last-child) { border-right: none; }
.theme-btn:first-child { border-radius: 8px 0 0 8px; }
.theme-btn:last-child { border-radius: 0 8px 8px 0; }
.theme-btn:hover { background: var(--hover-bg); color: var(--text); }
.theme-btn.active { background: var(--accent); border-color: var(--accent); color: white; }

.settings-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  margin: 12px 0;
  cursor: pointer;
}

.settings-field { margin: 12px 0; }
.settings-field label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }

.settings-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.settings-hint {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 14px 0 0;
  line-height: 1.5;
}

/* ---------- Question bank (Settings) ---------- */
.qb-counts { font-size: 13.5px; margin: 0 0 8px; font-variant-numeric: tabular-nums; }

.settings-section code {
  font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
}

.qb-subheading {
  margin: 16px 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.qb-files {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.qb-files > li + li { border-top: 1px solid var(--border); }
.qb-file-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--bg);
  font-size: 13px;
}
.qb-file-name { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; word-break: break-all; }
.qb-file-status { font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.qb-file-status.ok { color: var(--easy); }
.qb-file-status.warn { color: var(--medium); }
.qb-file-status.error { color: var(--very-difficult); }
.qb-file-details {
  padding: 8px 12px 10px;
  font-size: 12.5px;
  line-height: 1.5;
  border-top: 1px dashed var(--border);
}
.qb-file-details p { margin: 0 0 4px; }
.qb-file-details ul { margin: 0; padding-left: 18px; }

.qb-details { margin: 12px 0 4px; }
.qb-details summary { cursor: pointer; font-size: 13px; color: var(--accent); }
.qb-prompt {
  margin: 10px 0 0;
  max-height: 320px;
  overflow: auto;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

#qb-paste {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace;
  resize: vertical;
}

.qb-paste-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.qb-result {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
  border: 1px solid transparent;
}
.qb-result p { margin: 0; }
.qb-result p + p { margin-top: 6px; }
.qb-result ul { margin: 6px 0 0; padding-left: 18px; max-height: 180px; overflow-y: auto; }
.qb-result.ok { background: var(--easy-bg); border-color: var(--easy); }
.qb-result.warn { background: var(--medium-bg); border-color: var(--medium); }
.qb-result.error { background: var(--very-difficult-bg); border-color: var(--very-difficult); }

.tag.tag-imported { background: var(--hover-bg); color: var(--text-muted); }
.tag.tag-status.correct { background: var(--easy-bg); color: var(--easy); }
.tag.tag-status.missed { background: var(--very-difficult-bg); color: var(--very-difficult); }
.tag.tag-status.new { background: var(--accent-soft); color: var(--accent); }
.start-note { font-size: 12.5px; color: var(--text-muted); }

/* ---------- Progress view ---------- */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.stat-value { font-size: 26px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.mastery-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 13.5px;
}
.mastery-name { width: 220px; flex-shrink: 0; color: var(--text-muted); }
.mastery-bar {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.mastery-bar-fill { height: 100%; border-radius: 999px; }
.mastery-bar-fill.tier-easy { background: var(--easy); }
.mastery-bar-fill.tier-medium { background: var(--medium); }
.mastery-bar-fill.tier-very-difficult { background: var(--very-difficult); }
.mastery-count { width: 48px; text-align: right; color: var(--text-muted); flex-shrink: 0; }

@media (max-width: 640px) {
  .mastery-name { width: 140px; }
}

/* ---------- Worksheet view ---------- */
.worksheet-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.worksheet-controls .title-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}
.worksheet-controls label { font-size: 12px; color: var(--text-muted); display: block; margin-bottom: 4px; }
.worksheet-controls .toggle-row { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-top: 4px; }
.worksheet-controls > div:last-child { display: flex; gap: 8px; margin-top: 4px; }
.worksheet-controls > div:last-child .btn { flex: 1; }

.ws-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  background: var(--panel);
}
.ws-item .num { color: var(--text-muted); font-size: 13px; width: 22px; }
.ws-item .ws-body { flex: 1; font-size: 14px; }
.ws-item .ws-controls { display: flex; gap: 4px; }

/* ---------- Printable worksheet ---------- */
#print-root { display: none; }

@media print {
  .topbar, .calc-panel, .browse-layout .sidebar, .list-toolbar, .worksheet-controls, .ws-item .ws-controls,
  #app > *:not(.print-only-wrapper) { display: none !important; }
  #print-root.active { display: block !important; }
  body { background: white; }
  .print-page { padding: 0; }
  .print-header { text-align: center; margin-bottom: 20px; }
  .print-header h2 { margin: 0 0 4px; }
  .print-meta-line { display: flex; justify-content: space-between; font-size: 13px; margin-top: 18px; border-bottom: 1px solid #000; padding-bottom: 6px; }
  .print-problem { margin-bottom: 18px; page-break-inside: avoid; font-size: 13.5px; }
  .print-problem .pq { font-weight: 600; margin-bottom: 6px; }
  .print-choices { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
  .print-choices li { font-size: 13px; }
  .print-answer-key { page-break-before: always; }
  .print-answer-key h2 { margin-top: 0; }
  .print-answer-key ol { columns: 2; font-size: 13px; }
}
