/* Shared surfaces and type: a warm reading environment for a working library. */
:root {
  color-scheme: light;
  --paper: #f7f5ef;
  --surface: #fffefa;
  --surface-soft: #f1eee6;
  --ink: #302e28;
  --muted: #716d62;
  --line: #dedbd2;
  --line-soft: #ece9e1;
  --accent: #9e4936;
  --accent-hover: #843b2c;
  --accent-soft: #f2e5dc;
  --green: #46684e;
  --green-soft: #eaf0e7;
  --blue: #4d6275;
  --blue-soft: #e9eef1;
  --serif: Georgia, 'Noto Serif CJK SC', 'Source Han Serif SC', serif;
  --sans: 'Noto Sans CJK SC', 'Microsoft YaHei', Arial, sans-serif;
  --radius: 8px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; scroll-padding-top: 20px; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 14px/1.6 var(--sans); }
button, input, textarea, select { color: inherit; font: inherit; }
input, textarea, select { min-width: 0; max-width: 100%; }
input[type='text'], input[type='search'], input[type='number'], textarea, select {
  border: 1px solid var(--line); border-radius: 5px; background: var(--surface); padding: 9px 11px;
}
textarea { display: block; width: 100%; min-height: 110px; resize: vertical; line-height: 1.75; }
input[type='checkbox'], input[type='radio'] { accent-color: var(--accent); flex-shrink: 0; width: 16px; height: 16px; }
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 38px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 5px;
  background: transparent; color: var(--ink); font-size: 13px; line-height: 1.5;
  text-decoration: none; cursor: pointer; transition: background-color .14s, border-color .14s, color .14s;
}
button:hover, .btn:hover { background: var(--surface-soft); border-color: #c8c2b5; }
button:disabled, .btn[aria-disabled='true'] { opacity: .45; cursor: default; }
button:disabled:hover { background: transparent; border-color: var(--line); }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible,
[tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
button.primary, .btn.primary { border-color: var(--accent); background: var(--accent); color: #fffefa; }
button.primary:hover, .btn.primary:hover { border-color: var(--accent-hover); background: var(--accent-hover); }
button.danger, .btn.danger { border-color: #d7b3a8; color: var(--accent); }
button.danger:hover, .btn.danger:hover { background: var(--accent-soft); }
button.text, .btn.text, button.text-button { border-color: transparent; padding-inline: 7px; color: var(--muted); }
.icon-button { min-width: 33px; min-height: 33px; padding: 4px 8px; }
a { color: var(--accent); text-underline-offset: 3px; }
svg { flex-shrink: 0; vertical-align: middle; }
img { max-width: 100%; height: auto; }
h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3 { font-weight: 500; }
small { font-size: 12px; }
::selection { background: #e8d5c7; color: var(--ink); }
.muted, small, .empty-note { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-variant-numeric: tabular-nums; }
.key, kbd {
  display: inline-block; padding: 0 5px; border: 1px solid var(--line); border-radius: 3px;
  color: var(--muted); font: 11px/1.7 var(--sans); white-space: nowrap;
}
.tag, .badge, .status {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%; padding: 2px 7px;
  border-radius: 4px; background: var(--surface-soft); color: #656052; font-size: 11px; line-height: 1.6;
  vertical-align: middle; overflow-wrap: anywhere;
}
.status { white-space: nowrap; }
.status.reviewed, .status.passed, .tag.reviewed, .badge.reviewed { background: var(--green-soft); color: var(--green); }
.status.published, .tag.published, .badge.published { background: var(--blue-soft); color: var(--blue); }
.status.extracted { background: #f0ece3; color: #7a6852; }
.tag.flag, .badge.flag, .flag-tag { background: var(--accent-soft); color: var(--accent); }
.badge.warning { background: var(--accent-soft); color: var(--accent); }
.flag-tag { display: inline-block; border-radius: 4px; font-size: 11px; padding: 2px 6px; margin-top: 4px; }

/* Shared navigation: links and buttons use the same layout on all four views. */
.app-shell { min-width: 0; min-height: 100dvh; }
.app-header {
  display: flex; align-items: center; gap: 60px; min-height: 66px; padding: 0 max(32px, calc((100vw - 1376px) / 2));
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; flex-shrink: 0; }
.brand-logo { display: block; width: 140px; height: auto; }
.primary-nav { display: flex; align-self: stretch; gap: 34px; min-width: 0; }
.primary-nav > :is(button, a) {
  display: inline-flex; align-items: center; justify-content: center; position: relative;
  min-height: 38px; border: 0; border-radius: 0; padding: 0 2px; background: transparent;
  color: var(--muted); font: 400 14px/1.5 var(--sans); text-decoration: none;
}
.primary-nav > :is(button, a):hover { background: transparent; color: var(--ink); }
.primary-nav > :is(button, a).active { color: var(--accent); font-weight: 600; }
.primary-nav > :is(button, a).active::after { position: absolute; right: 0; bottom: -1px; left: 0; height: 3px; background: var(--accent); content: ''; }
.header-tools { display: flex; align-items: center; gap: 17px; margin-left: auto; }
.mask-toggle { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; cursor: pointer; min-height: 40px; }
.mask-toggle input { margin: 0; }
.avatar-button { min-width: 35px; max-width: 140px; min-height: 35px; border: 1px solid #e0d4c5; border-radius: 20px; padding: 4px 10px; background: #efe6d9; color: #715540; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.main-content { width: 100%; max-width: 1800px; min-width: 0; margin: 0 auto; padding: 18px 32px 22px; }
.heading-row, .page-heading { display: flex; justify-content: space-between; align-items: center; gap: 24px; margin-bottom: 13px; }
.heading-row .page-heading { display: block; margin: 0; }
.page-heading h1 { font: 27px/1.4 var(--serif); letter-spacing: .4px; }
.overview-strip { display: flex; align-items: center; gap: 0; flex-shrink: 0; }
.metric { min-width: 90px; padding: 0 21px; border-left: 1px solid var(--line); }
.metric:first-child { border-left: 0; }
.metric:last-child { padding-right: 0; }
.metric button { display: block; border: 0; border-radius: 3px; padding: 2px 0; text-align: left; }
.metric > div { display: block; padding: 2px 0; }
.metric button:hover { color: var(--accent); background: transparent; }
.metric strong { display: block; font: 27px/1.2 var(--serif); font-variant-numeric: tabular-nums; }
.metric small { display: block; margin-top: 4px; font-size: 11px; }
.metric.warn strong, .metric.flagged strong { color: var(--accent); }

/* Search and every optional filter stay on a single, visible level. */
.filter-shell { min-width: 0; margin-bottom: 13px; }
.subject-tabs { display: flex; flex-wrap: wrap; gap: 19px; align-items: center; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.subject-tabs button {
  min-height: 35px; border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 5px 1px;
  margin-bottom: -1px; color: var(--muted); font-size: 13px;
}
.subject-tabs button:hover { color: var(--ink); background: transparent; }
.subject-tabs button.active { border-bottom-color: var(--accent); color: var(--ink); font-weight: 600; }
.search-row { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; min-width: 0; }
.searchbox { display: flex; align-items: center; gap: 9px; min-width: 0; flex: 1; border: 1px solid #d1ccc0; border-radius: 6px; padding: 0 12px; background: var(--surface); color: var(--muted); }
.searchbox input { flex: 1; width: 100%; min-width: 0; height: 39px; border: 0; padding: 8px 0; background: transparent; font-size: 13px; outline: none; box-shadow: none; }
.searchbox:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px #9e493612; }
.searchbox .key { flex-shrink: 0; }
.search-row > button { min-height: 41px; white-space: nowrap; }
#filter-toggle.active, #filter-toggle[aria-expanded='true'] { background: var(--accent-soft); border-color: #d2b19e; color: var(--accent); }
.queue-tabs { display: flex; align-items: center; flex-wrap: wrap; gap: 3px 5px; }
.queue-tabs button { min-height: 33px; border-color: transparent; padding: 5px 9px; color: var(--muted); font-size: 12px; }
.queue-tabs button.active { color: var(--surface); background: var(--ink); border-color: var(--ink); }
.queue-tabs button .count { color: #8a8579; font-size: 11px; font-variant-numeric: tabular-nums; }
.queue-tabs button.active .count { color: #d9d4c8; }
.queue-tabs .divider, .queue-divider { display: block; width: 1px; height: 16px; background: var(--line); margin: 0 6px; }
.filter-panel { padding: 13px 16px; margin-top: 9px; border: 1px solid var(--line); border-radius: 6px; background: #f0ede5; }
.filter-row { display: flex; align-items: flex-start; gap: 14px; margin: 4px 0 10px; }
.filter-row:last-child { margin-bottom: 0; }
.filter-label { flex: 0 0 58px; padding-top: 9px; font-size: 12px; color: var(--muted); }
.filter-options { display: flex; flex: 1; flex-wrap: wrap; gap: 4px; min-width: 0; }
.filter-options button { min-height: 34px; padding: 5px 9px; border-color: transparent; font-size: 12px; text-align: left; overflow-wrap: anywhere; }
.filter-options button.active { background: var(--surface); color: var(--accent); border-color: #d9c6b5; }
.filter-options input { flex: 1 1 150px; width: auto; max-width: 280px; min-height: 36px; font-size: 12px; }
.filter-options .catalog-roots { display: flex; flex-wrap: wrap; gap: 4px; width: 100%; }
.filter-note { color: var(--muted); font-size: 12px; margin-top: 10px; }
.active-filters { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.active-filters:empty { display: none; }
.filter-chip { max-width: 100%; min-height: 29px; padding: 3px 8px; color: var(--accent); background: var(--accent-soft); border-color: #e2cbbc; font-size: 11px; overflow-wrap: anywhere; }
.directory-picker { padding-top: 12px; margin-top: 12px; border-top: 1px solid #d9d4c8; }
.directory-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.directory-toolbar b { font-size: 12px; font-weight: 500; flex-shrink: 0; }
.directory-toolbar input { width: 320px; min-height: 36px; padding: 7px 10px; font-size: 12px; }
.directory-breadcrumb { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; min-width: 0; margin: 7px 0; font-size: 11px; color: var(--muted); }
.directory-breadcrumb > span { min-width: 0; overflow-wrap: anywhere; }
.directory-breadcrumb button { min-height: 31px; font-size: 11px; padding-inline: 5px; }
.directory-breadcrumb button:last-child:not(:first-child) { margin-left: auto; }
.directory-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; max-height: 272px; overflow: auto; scrollbar-width: thin; padding: 2px 3px 3px; }
.directory-node { display: flex; align-items: stretch; min-width: 0; border: 1px solid var(--line); border-radius: 5px; background: #f8f6f0; }
.directory-node.active { border-color: #c5a387; background: var(--accent-soft); }
.directory-node > button:first-child { display: block; flex: 1; min-width: 0; padding: 7px 10px; border: 0; text-align: left; font-size: 12px; overflow-wrap: anywhere; }
.directory-node > button:first-child small { display: block; font-size: 10px; margin-top: 3px; }
.directory-node.active > button:first-child { color: var(--accent); }
.directory-node > button:last-child:not(:first-child) { flex: 0 0 32px; border: 0; border-left: 1px solid var(--line); border-radius: 0 4px 4px 0; font-size: 18px; }
.directory-picker > p, #directory-options > p { margin-top: 9px; font-size: 11px; }

/* Day-to-day work: a scan-friendly list alongside one complete atom. */
.workspace { display: grid; grid-template-columns: minmax(0, 46fr) minmax(0, 54fr); gap: 20px; min-width: 0; align-items: start; }
.list-panel, .detail-panel, .review-tools { min-width: 0; min-height: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
/* Only the result list scrolls independently; the complete question follows the page. */
.list-panel { position: sticky; top: 16px; display: flex; flex-direction: column; height: clamp(320px, calc(100dvh - 250px), 760px); overflow: hidden; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 55px; padding: 10px 16px; border-bottom: 1px solid var(--line-soft); }
.panel-heading h2 { font-size: 14px; font-weight: 600; }
.panel-heading .result-count, .result-count { margin-left: 7px; color: var(--muted); font-size: 12px; font-weight: 400; }
.list-tools { display: flex; align-items: center; gap: 10px; }
.density-switch { display: flex; padding: 2px; border: 1px solid var(--line); border-radius: 5px; background: var(--paper); }
.density-switch button { min-height: 27px; padding: 3px 8px; border: 0; font-size: 11px; color: var(--muted); }
.density-switch button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px #302e2812; }
.table-scroll { flex: 1; min-height: 0; overflow: auto; scrollbar-width: thin; scrollbar-color: #cec8bc transparent; }
.question-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 12px; }
.question-table th { position: sticky; top: 0; z-index: 1; padding: 9px 11px; background: #f6f3ec; color: var(--muted); font-size: 11px; font-weight: 400; text-align: left; border-bottom: 1px solid var(--line); }
.question-table th:first-child { width: 56%; padding-left: 16px; }
.question-table th:nth-child(2) { width: 14%; }
.question-table th:nth-child(3) { width: 14%; }
.question-table th:last-child { width: 16%; }
.question-table td { padding: 13px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; overflow-wrap: anywhere; }
.question-table td:first-child { padding-left: 16px; }
.question-table .section-row th { position: static; width: auto; padding: 8px 16px; background: #ece7dc; color: #706047; font-size: 12px; font-weight: 500; }
.question-table tr[data-id], .question-table tr[data-action] { cursor: pointer; }
.question-table tbody tr:hover { background: #f6f2e9; }
.question-table tbody tr.selected { background: #f4ece0; }
.question-table tbody tr.selected td:first-child { box-shadow: inset 3px 0 var(--accent); }
.question-table .question-button, .question-table .row-button, .question-table td:first-child > button {
  display: block; width: 100%; min-width: 0; padding: 0; border: 0; background: transparent; text-align: left; border-radius: 2px;
}
.row-title { display: -webkit-box; overflow: hidden; -webkit-line-clamp: 2; -webkit-box-orient: vertical; color: var(--ink); font-size: 13px; font-weight: 500; line-height: 1.7; }
.row-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 3px 8px; margin-top: 5px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.row-meta > span { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.row-meta .tag { padding: 1px 5px; }
.row-preview, .row-summary { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 7px; font-size: 12px; color: var(--muted); line-height: 1.75; }
.question-table.compact td, .list-panel.compact .question-table td { padding-top: 9px; padding-bottom: 9px; }
.question-table.compact .row-title, .list-panel.compact .row-title { -webkit-line-clamp: 1; }
.difficulty-dots { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.difficulty-dots i { display: block; width: 5px; height: 5px; border-radius: 50%; background: #ded9ce; }
.difficulty-dots i.on, .difficulty-dots i.active { background: #a77c57; }
.difficulty-dots small, .difficulty-dots span { font-size: 11px; color: var(--muted); margin-left: 3px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 56px; padding: 10px 15px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.pager > div, .pager .pager-actions { display: flex; align-items: center; gap: 8px; }
.pager button { min-width: 32px; min-height: 32px; padding: 4px 7px; font-size: 11px; }
.list-note { padding: 9px 15px; border-top: 1px solid var(--line-soft); color: var(--muted); font-size: 11px; }
.detail-panel { position: relative; display: flex; flex-direction: column; }
.detail-header { display: flex; flex-shrink: 0; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 22px 0; font-size: 11px; color: var(--muted); }
.detail-header > div { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 5px; }
.detail-header > span { flex-shrink: 0; }
.detail-header .text-button { min-height: 32px; font-size: 12px; }
.detail-header > .detail-top, .detail-header > .row { display: flex; align-items: center; justify-content: space-between; gap: 9px; }
.detail-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; margin: 7px 0 10px; font-size: 12px; color: var(--muted); }
.detail-panel > .detail-meta { margin: 7px 0 8px; padding-inline: 22px; }
.provenance { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 11px; margin: 9px 0 4px; border: 1px solid var(--line-soft); border-radius: 5px; background: var(--paper); color: var(--muted); font-size: 11px; }
.provenance > :first-child { min-width: 0; overflow-wrap: anywhere; }
.provenance button { flex-shrink: 0; min-height: 30px; padding: 3px 6px; font-size: 11px; }
.provenance .source-line, .provenance .source-meta { margin: 0; }
.masked { letter-spacing: 1px; color: #8c8476; }
.detail-tabs { display: flex; align-items: center; gap: 19px; min-width: 0; margin: 7px 0 0; border-bottom: 1px solid var(--line); }
.detail-panel > .detail-tabs { flex-shrink: 0; padding-inline: 22px; margin-top: 0; }
.detail-tabs button { min-height: 39px; border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 7px 0; margin-bottom: -1px; color: var(--muted); font-size: 12px; }
.detail-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.detail-tabs button:hover { background: transparent; color: var(--ink); }
.detail-scroll { position: relative; min-width: 0; padding: 21px 22px 24px; }
.detail-scroll > .provenance:first-child { margin-top: 0; margin-bottom: 18px; }
.detail-pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-shrink: 0; min-height: 42px; padding: 4px 15px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.detail-pager button { min-height: 32px; font-size: 11px; }
.question-paper { min-width: 0; font-size: 14px; line-height: 1.95; overflow-wrap: anywhere; }
.question-paper > h3 { font: 19px/1.6 var(--serif); margin-bottom: 16px; }
.solution-section { margin-top: 24px; padding-top: 19px; border-top: 1px solid var(--line); }
.solution-section > h3, .solution-section > h4 { color: var(--accent); font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.solution-section .authority { margin-top: 14px; color: var(--muted); font-size: 11px; }
.answer-toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 35px; margin: 0 0 11px; padding: 2px 0; border: 0; color: var(--accent); font-size: 13px; font-weight: 500; text-align: left; }
.answer-toggle:hover { background: transparent; color: var(--accent-hover); }
.answer-toggle > span { color: var(--muted); font-size: 11px; font-weight: 400; white-space: nowrap; }
.source-view { min-width: 0; }
.source-view img { display: block; width: 100%; border: 1px solid var(--line); background: #fff; }
.source-view .source-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 13px; }
.source-links { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 15px; }
.source-links .btn { font-size: 12px; }
.source-page { margin: 17px 0 0; }
.source-page figcaption { margin-bottom: 8px; color: var(--muted); font-size: 12px; }
.student-view { padding: 18px 20px; border: 1px solid var(--line); background: #fff; border-radius: 3px; }

/* Question renderer: preserve long passages, grouped items, and figure ownership. */
.stem-content, .subq-prompt, .choice-body, .stimulus-block, .solution-block { min-width: 0; overflow-wrap: anywhere; }
.stem-content { font-size: 14px; line-height: 1.95; }
.stem-content p + p, .stimulus-block p + p, .solution-block p + p { margin-top: 10px; }
.instructions { margin-bottom: 14px; color: var(--muted); font-size: 13px; line-height: 1.85; }
.subq-block { margin: 20px 0; padding-top: 16px; border-top: 1px solid var(--line-soft); }
.subq-block:first-child { margin-top: 0; }
.subq-prompt { font-size: 14px; line-height: 1.95; }
.subq-label { display: inline-block; margin-right: 6px; font-weight: 600; }
.choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px 15px; margin: 13px 0; }
.choice { display: flex; align-items: flex-start; gap: 8px; min-width: 0; padding: 7px 9px; border-radius: 4px; background: #f7f5ee; font-size: 13px; line-height: 1.8; }
label.choice { cursor: pointer; }
.choice input { margin-top: 5px; }
.choice-label { flex-shrink: 0; color: #8d6b48; font-family: var(--serif); }
.choice-body { flex: 1; }
.interaction-input { display: block; width: 100%; margin: 11px 0 5px; min-height: 40px; background: #fff; }
.interaction-note { margin-top: 6px; color: var(--muted); font-size: 12px; }
.stimulus { margin: 18px 0; padding: 15px 18px; border-left: 2px solid #b8a48c; border-radius: 0 4px 4px 0; background: #f6f2e8; }
.stimulus-block { font-size: 14px; line-height: 1.95; }
.stimulus-block + .stimulus-block { margin-top: 12px; }
.choice-pool { margin: 15px 0; padding: 12px 14px; border: 1px solid #dcd4c5; border-radius: 5px; background: #fcfaf3; font-size: 13px; line-height: 1.9; overflow-wrap: anywhere; }
.choice-pool-title { margin-bottom: 8px; color: var(--muted); font-size: 12px; font-weight: 500; }
.choice-pool .choices { margin-bottom: 0; }
.figures { display: grid; gap: 15px; margin: 18px 0; }
.figure-wrap, .figure-pair, .figure-item { min-width: 0; }
.figure-pair { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: center; gap: 12px; }
.figure-item { flex: 1 1 260px; max-width: 100%; text-align: center; }
.figure-item > a { display: block; }
.figure-item img { display: block; max-width: 100%; width: auto; height: auto; margin: 0 auto; border: 1px solid var(--line-soft); border-radius: 3px; background: #fff; }
.figure-caption { color: var(--muted); font-size: 11px; line-height: 1.7; margin-top: 6px; overflow-wrap: anywhere; }
.figure-actions { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.figure-actions button { min-height: 31px; padding: 4px 8px; font-size: 11px; }
.solution-block { font-size: 13px; line-height: 1.95; }
.solution-block + .solution-block { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line-soft); }
.solution-block h4 { margin: 12px 0 6px; color: var(--muted); font-size: 12px; font-weight: 500; }
.answer { margin-bottom: 12px; padding: 10px 12px; background: #f2efe5; border-radius: 4px; line-height: 1.9; overflow-wrap: anywhere; }
.source-line, .source-meta { margin-top: 8px; color: var(--muted); font-size: 11px; line-height: 1.75; overflow-wrap: anywhere; }
.kp { display: inline-block; max-width: 100%; overflow-wrap: anywhere; }
.katex { font-size: 1.08em; }
.question-paper .katex, .solution-block .katex, .answer .katex {
  display: inline-block; max-width: 100%; padding-block: 3px; overflow-x: auto; overflow-y: hidden;
  vertical-align: middle; scrollbar-width: thin;
}
.katex-display { max-width: 100%; overflow-x: auto; overflow-y: hidden; padding-block: 3px; scrollbar-width: thin; }
.katex-display > .katex { display: block; max-width: none; padding: 0; overflow: visible; white-space: nowrap; }

/* Review controls remain attached to the current question. */
.review-panel { padding: 14px 22px; border-top: 1px solid var(--line); background: #f6f3eb; flex-shrink: 0; }
.review-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 11px; }
.review-heading h3 { font-size: 13px; font-weight: 600; }
.review-heading .muted, .review-heading small { font-size: 11px; }
.rating-line { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; font-size: 12px; }
.rating-buttons { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: center; gap: 6px; }
.rating-buttons button { flex-direction: column; gap: 1px; min-width: 36px; min-height: 43px; padding: 4px 3px; background: var(--surface); font: 15px/1.4 var(--serif); }
.rating-buttons button small { color: var(--muted); font: 11px/1.4 var(--sans); }
.rating-buttons button.active { color: var(--accent); border-color: #bc8d70; background: var(--accent-soft); }
.difficulty-scale { display: flex; justify-content: space-between; margin-top: 4px; color: var(--muted); font-size: 11px; }
.review-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.review-actions > button { flex: 1; min-height: 39px; }
.review-actions .secondary-actions, .secondary-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.auto-next { display: flex; align-items: center; gap: 7px; margin-top: 12px; color: var(--muted); font-size: 12px; cursor: pointer; }
.auto-next input { margin: 0; }
.review-note, .session-note { margin-top: 9px; color: var(--muted); font-size: 11px; }
.review-heading > span { font-size: 11px; color: var(--muted); }
.flag-form { padding-top: 12px; margin-top: 12px; border-top: 1px solid #dccabc; }
.flag-form label, .edit-form label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 5px; }
.flag-form textarea { min-height: 85px; background: var(--surface); }
.flag-form .actions, .edit-form .actions, .edit-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.edit-form { min-width: 0; }
.edit-form textarea { margin-top: 5px; min-height: 125px; font-size: 13px; }
.edit-form .notice { margin-bottom: 14px; }
.edit-field { display: block; margin-bottom: 16px; }
.edit-field > span { display: block; margin-bottom: 5px; }
.reviewer-field { width: 100%; }
.reviewer-line { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 12px; font-size: 12px; }
.reviewer-line input { width: 150px; min-width: 0; min-height: 35px; }

/* Continuous review uses the same components in a focused three-column frame. */
.workspace.review-mode { grid-template-columns: 230px minmax(0, 1fr) 300px; gap: 14px; }
.review-mode.student-mode .detail-panel { grid-column: 2 / -1; }
.review-mode .panel-heading { padding-inline: 13px; }
.review-mode .list-tools { display: none; }
.review-mode .detail-header { padding-inline: 21px; }
.review-mode .detail-scroll { padding: 20px 21px 24px; }
.review-mode .question-paper { padding: 19px 22px; background: #fffefa; border: 1px solid var(--line); border-radius: 3px; }
.review-mode .detail-panel { background: #f5f2e9; }
.review-mode .detail-header { background: var(--surface); }
.review-mode .pager { padding-inline: 10px; flex-wrap: wrap; justify-content: center; }
.queued { padding: 7px; }
/* Keep KaTeX's absolute accessibility layer inside the scrolling queue. */
.review-queue { position: relative; padding: 7px; }
.queue-item { display: block; min-width: 0; width: 100%; margin: 0 0 5px; border: 1px solid transparent; border-radius: 5px; background: transparent; }
button.queue-item, .queue-item > button { display: block; text-align: left; width: 100%; padding: 12px 10px; min-width: 0; border: 0; background: transparent; }
.queue-item:hover { background: #f6f1e6; }
.queue-item.selected, .queue-item.active { border-color: #d8c4af; background: #f2e8d9; box-shadow: inset 2px 0 var(--accent); }
.queue-item .row-title { font-size: 12px; line-height: 1.85; }
.queue-item .row-meta { margin-top: 6px; gap: 4px 7px; }
.queue-item .status { margin-top: 8px; }
.queue-item .difficulty-dots { margin-left: 6px; }
.queue-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 7px; margin-top: 7px; color: var(--muted); font-size: 11px; }
.queue-meta .status { margin-top: 0; }
.queue-meta > span:last-child:not(.status):not(.badge) { margin-left: auto; font-size: 10px; }
.queue-item > .row-meta:first-child { margin-top: 0; margin-bottom: 6px; }
.review-tools { position: relative; }
.review-tools .review-panel { border: 0; padding: 17px 18px; background: transparent; }
.review-tools .review-heading { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.review-tools .solution-section { padding-top: 0; margin-top: 0; border: 0; }
.review-tools > .solution-section { padding: 14px 18px 8px; border-bottom: 1px solid var(--line); }
.review-tools .solution-block { font-size: 12px; }
.review-tools .rating-line { display: block; }
.review-tools .rating-buttons { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); margin-top: 9px; }
.review-tools .rating-buttons button { min-width: 0; min-height: 36px; }
.review-tools .rating-line > small { display: block; margin-top: 7px; }
.review-tools .review-actions { display: grid; grid-template-columns: 1fr; }
.review-tools .review-actions > button { width: 100%; }
.review-tools .notice { margin-top: 14px; }

/* Materials: real outputs and drafts are peer-level destinations. */
.materials-view { min-width: 0; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 0 15px; margin-top: 16px; border-bottom: 1px solid var(--line); }
.section-heading h2 { font: 21px/1.5 var(--serif); }
.section-heading p { color: var(--muted); font-size: 12px; margin-top: 4px; }
.material-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin: 19px 0 28px; }
.material-grid > .empty-state { grid-column: 1 / -1; min-height: 180px; border: 1px dashed var(--line); border-radius: var(--radius); }
.material-card { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; padding: 23px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.material-card::before { display: block; width: 27px; height: 3px; margin-bottom: 20px; background: #b69571; content: ''; }
.material-card h2, .material-card h3 { font: 21px/1.5 var(--serif); overflow-wrap: anywhere; }
.material-card p { margin-top: 9px; color: var(--muted); font-size: 12px; line-height: 1.85; }
.material-meta { display: flex; flex-wrap: wrap; gap: 5px 13px; margin: 13px 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.material-actions { display: flex; flex-wrap: wrap; gap: 7px; width: 100%; margin-top: auto; padding-top: 20px; }
.material-actions .btn, .material-actions button { font-size: 12px; }
.material-kind { margin-bottom: 8px; color: var(--muted); font-size: 11px; }
.material-card > .btn { margin-top: 18px; }
.material-card .quality-note { width: 100%; }
.material-detail-heading { margin-bottom: 16px; }
.material-detail-heading .section-heading { align-items: center; padding-top: 0; margin-top: 0; }
.material-detail-heading .section-heading > div:first-child { min-width: 0; }
.material-detail-heading .section-heading h2 { margin-top: 4px; overflow-wrap: anywhere; }
.material-detail-heading .material-actions { justify-content: flex-end; width: auto; max-width: 50%; margin-top: 0; padding-top: 0; }
.material-detail-heading .material-actions .btn { flex-direction: column; gap: 2px; }
.material-detail-heading .material-actions small { font-size: 10px; }
.material-detail-heading > .muted { margin-top: 10px; font-size: 12px; }
.quality-note { padding: 13px 16px; border-left: 2px solid #b99b70; border-radius: 0 5px 5px 0; background: #efebdf; color: #74664f; font-size: 12px; line-height: 1.9; }
.future-note { display: flex; flex-wrap: wrap; align-items: center; gap: 9px 20px; margin-top: 26px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.future-note strong { font-weight: 500; color: var(--ink); }

/* Dialogs and asynchronous states share the same visible focus and feedback. */
dialog.app-dialog { width: min(740px, calc(100vw - 40px)); max-height: calc(100dvh - 60px); padding: 0; overflow: auto; border: 1px solid #cec5b6; border-radius: 10px; background: var(--paper); color: var(--ink); box-shadow: 0 20px 100px #302e2830; }
dialog.app-dialog::backdrop { background: #302e2869; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 19px 24px; border-bottom: 1px solid var(--line); }
.dialog-heading h2 { font: 23px/1.5 var(--serif); }
.dialog-heading button { min-width: 34px; min-height: 34px; border-color: transparent; padding: 3px; }
.dialog-body { padding: 22px 24px; font-size: 13px; line-height: 1.85; overflow-wrap: anywhere; }
.dialog-body > p + p { margin-top: 12px; }
.dialog-body label { display: block; margin: 12px 0 6px; font-size: 12px; }
.dialog-body input[type='text'] { width: 100%; }
.dialog-body .text-input { display: block; width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); }
.dialog-body .text-input + p { margin-top: 12px; font-size: 12px; }
.shortcut-list p { margin-bottom: 12px; }
.dialog-body .paper { padding: 22px; margin: 13px 0; border: 1px solid var(--line); background: var(--surface); }
.dialog-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding: 14px 24px; border-top: 1px solid var(--line); }
.crop-stage { position: relative; width: fit-content; max-width: 100%; margin: 15px auto; line-height: 0; touch-action: none; user-select: none; cursor: crosshair; overflow: hidden; }
.crop-stage img { display: block; max-width: 100%; max-height: 60dvh; width: auto; object-fit: contain; pointer-events: none; }
.crop-box { position: absolute; border: 2px solid var(--accent); background: #9e493618; box-shadow: 0 0 0 9999px #302e2838; pointer-events: none; }
.crop-note { margin-top: 12px; font-size: 12px; color: var(--muted); }
.toast { position: fixed; bottom: 23px; left: 50%; z-index: 50; max-width: min(620px, calc(100vw - 30px)); padding: 11px 18px; border: 1px solid #595144; border-radius: 6px; background: var(--ink); color: var(--surface); box-shadow: 0 5px 24px #302e2822; font-size: 13px; opacity: 0; transform: translate(-50%, 12px); transition: opacity .18s, transform .18s; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.notice { margin: 10px 0; padding: 11px 13px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface-soft); color: var(--muted); font-size: 12px; line-height: 1.8; }
.notice.error, .notice.warning { border-color: #e1c9b4; background: #f8ede3; color: #8f543b; }
.notice.error { border-color: #e2beb3; color: #933e30; }
.notice button { margin: 6px 0 0 7px; font-size: 12px; }
.inline-error { margin-top: 7px; color: var(--accent); font-size: 12px; }
.empty-state, .loading-state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 11px; min-height: 240px; padding: 40px 24px; text-align: center; color: var(--muted); }
.empty-state h3 { color: var(--ink); font: 22px/1.5 var(--serif); }
.empty-state p, .loading-state p { max-width: 340px; font-size: 12px; line-height: 1.9; }
.empty-state svg, .loading-state svg { color: #a09682; }
.loading-state::before { width: 21px; height: 21px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; content: ''; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive workspaces: reading takes precedence over preserving columns. */
@media (min-width: 1600px) {
  .main-content { padding-inline: 42px; }
  .app-header { padding-inline: 42px; }
  .workspace.review-mode { grid-template-columns: 245px minmax(0, 1fr) 325px; gap: 18px; }
  .detail-scroll { padding-inline: 28px; }
}
@media (max-width: 1180px) {
  .app-header { gap: 30px; padding-inline: 22px; }
  .main-content { padding-inline: 22px; }
  .metric { padding-inline: 12px; }
  .metric button { gap: 6px; }
  .metric strong { font-size: 24px; }
  .workspace { gap: 14px; grid-template-columns: minmax(0, 44fr) minmax(0, 56fr); }
  .question-table th:first-child { width: 63%; }
  .question-table th:nth-child(2), .question-table td:nth-child(2) { display: none; }
  .question-table th:nth-child(3) { width: 17%; }
  .question-table th:last-child { width: 20%; }
  .question-table td { padding-inline: 8px; }
  .detail-header, .detail-scroll, .review-panel { padding-left: 18px; padding-right: 18px; }
  .detail-panel > .detail-meta, .detail-panel > .detail-tabs { padding-inline: 18px; }
  .workspace.review-mode { grid-template-columns: 190px minmax(0, 1fr) 270px; gap: 11px; }
  .review-mode .detail-header, .review-mode .detail-scroll { padding-left: 16px; padding-right: 16px; }
  .review-mode .question-paper { padding: 17px; }
  .review-tools .review-panel { padding: 15px; }
  .review-tools > .solution-section { padding-inline: 15px; }
  .directory-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  .app-header { gap: 26px; }
  .primary-nav { gap: 20px; }
  .header-tools { gap: 12px; }
  .page-heading h1 { font-size: 25px; }
  .metric button { display: block; text-align: left; }
  .metric small { display: block; margin-top: 3px; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .list-panel { position: static; height: auto; min-height: 300px; }
  .table-scroll { max-height: 365px; }
  .question-table th:first-child { width: 58%; }
  .question-table th:nth-child(2), .question-table td:nth-child(2) { display: table-cell; }
  .question-table th:nth-child(2) { width: 14%; }
  .question-table th:nth-child(3), .question-table th:last-child { width: 14%; }
  .detail-panel { scroll-margin-top: 14px; }
  .review-panel { padding-block: 17px; }
  .workspace.review-mode { grid-template-columns: 180px minmax(0, 1fr); grid-template-rows: auto auto; gap: 14px; }
  .review-mode .list-panel { position: sticky; top: 14px; grid-column: 1; grid-row: 1 / 3; min-height: 0; height: clamp(320px, calc(100dvh - 250px), 760px); }
  .review-mode .table-scroll { max-height: none; }
  .review-mode .detail-panel { grid-column: 2; }
  .review-tools { grid-column: 2; }
  .review-tools .review-panel { padding: 18px 20px; }
  .review-tools .review-actions { grid-template-columns: 1fr 1fr; }
  .review-tools .rating-buttons { max-width: 320px; }
  .review-mode .pager { padding: 10px 7px; }
  .material-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .directory-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .app-header { display: grid; grid-template-columns: 1fr auto; grid-template-rows: minmax(40px, auto) auto; gap: 0 14px; padding: 11px 16px 0; }
  .brand { gap: 7px; }
  .brand-logo { width: 112px; }
  .header-tools { grid-column: 2; grid-row: 1; gap: 9px; }
  .mask-toggle { font-size: 11px; gap: 5px; }
  .mask-toggle .key, .mask-toggle kbd { display: none; }
  .avatar-button { min-width: 31px; max-width: 95px; min-height: 31px; padding-inline: 8px; font-size: 11px; }
  .header-tools > .icon-button { display: none; }
  .primary-nav { grid-column: 1 / -1; grid-row: 2; justify-content: space-between; gap: 20px; min-height: 43px; margin-top: 10px; }
  .primary-nav > :is(button, a) { min-height: 43px; padding: 0 10px 8px; font-size: 13px; }
  .primary-nav > :is(button, a).active::after { left: 10px; right: 10px; }
  .main-content { padding: 17px 14px 25px; }
  .heading-row, .page-heading { display: block; margin-bottom: 12px; }
  .page-heading h1 { font-size: 25px; }
  .overview-strip { margin-top: 13px; justify-content: flex-start; }
  .metric { min-width: 0; padding: 0 12px; flex: 1; }
  .metric:first-child { padding-left: 0; }
  .metric button { display: block; }
  .metric strong { font-size: 22px; }
  .metric small { font-size: 10px; margin-top: 3px; }
  .subject-tabs { gap: 0 14px; margin-bottom: 10px; }
  .subject-tabs button { min-height: 38px; font-size: 12px; padding-inline: 2px; }
  .search-row { flex-wrap: wrap; gap: 7px; }
  .searchbox { flex: 1 1 calc(100% - 63px); padding-inline: 10px; }
  .searchbox input { font-size: 12px; height: 40px; }
  .searchbox .key, .searchbox kbd { display: none; }
  .search-row > button { padding-inline: 10px; font-size: 12px; min-height: 42px; }
  .queue-tabs { gap: 2px; }
  .queue-tabs button { min-height: 36px; padding-inline: 8px; font-size: 11px; }
  .queue-tabs .divider, .queue-divider { display: none; }
  .filter-panel { padding: 10px 11px; }
  .filter-row { gap: 7px; margin-bottom: 8px; }
  .filter-label { flex-basis: 42px; font-size: 11px; padding-top: 10px; }
  .filter-options { gap: 3px; }
  .filter-options button { min-height: 38px; padding-inline: 8px; font-size: 11px; }
  .filter-options input { max-width: 100%; }
  .filter-chip { min-height: 32px; }
  .directory-toolbar { flex-wrap: wrap; gap: 8px; }
  .directory-toolbar input { width: 100%; min-height: 40px; }
  .directory-grid { grid-template-columns: minmax(0, 1fr); max-height: 280px; }
  .directory-node > button:first-child { min-height: 40px; }
  .directory-node > button:last-child:not(:first-child) { flex-basis: 38px; }
  .directory-breadcrumb button { min-height: 38px; }
  .workspace { gap: 15px; }
  .panel-heading { padding: 10px 12px; min-height: 54px; }
  .panel-heading h2 { font-size: 13px; }
  .panel-heading .result-count { font-size: 11px; margin-left: 4px; }
  .density-switch button { min-height: 30px; padding-inline: 7px; }
  .table-scroll { max-height: 340px; }
  .question-table th:first-child { width: 75%; padding-left: 13px; }
  .question-table th:nth-child(2), .question-table td:nth-child(2),
  .question-table th:nth-child(3), .question-table td:nth-child(3) { display: none; }
  .question-table th:last-child { width: 25%; }
  .question-table td { padding-top: 12px; padding-bottom: 12px; }
  .question-table td:first-child { padding-left: 13px; }
  .row-title { font-size: 12px; }
  .row-meta { font-size: 10px; }
  .pager { padding: 10px 12px; font-size: 10px; flex-wrap: wrap; }
  .pager button { min-width: 37px; min-height: 37px; }
  .detail-header { padding: 14px 16px 0; }
  .detail-panel > .detail-meta, .detail-panel > .detail-tabs { padding-inline: 16px; }
  .detail-meta { gap: 5px; }
  .provenance { padding: 8px 9px; align-items: flex-start; }
  .detail-tabs { gap: 19px; }
  .detail-tabs button { min-height: 43px; }
  .detail-scroll { padding: 19px 16px 22px; }
  .detail-pager { padding: 7px 11px; }
  .detail-pager button { min-height: 38px; }
  .choices { grid-template-columns: minmax(0, 1fr); gap: 5px; }
  .stimulus { padding: 12px 13px; }
  .stimulus-block { font-size: 13px; }
  .figure-actions button { min-height: 37px; }
  .student-view { padding: 16px 13px; }
  .review-panel { padding: 15px 16px; }
  .rating-buttons button { min-width: 40px; min-height: 39px; }
  .review-actions > button { min-height: 42px; font-size: 12px; }
  .review-heading { align-items: flex-start; }
  .review-heading h3 { flex-shrink: 0; }
  .review-heading small { font-size: 10px; text-align: right; }
  .workspace.review-mode { display: flex; flex-direction: column; gap: 14px; }
  .review-mode .list-panel { position: static; min-width: 0; min-height: 0; width: 100%; max-width: 100%; height: auto; }
  .review-mode .table-scroll {
    flex: none; min-width: 0; width: 100%; max-width: 100%; max-height: none; overflow: visible;
  }
  .review-mode .table-scroll.queued, .review-mode .queued, .review-mode .review-queue {
    display: flex; flex-direction: row; gap: 7px; min-width: 0; width: 100%; max-width: 100%;
    padding: 8px 10px; max-height: 173px;
    overflow-x: auto; overflow-y: hidden; scroll-snap-type: x proximity;
  }
  .review-mode .queue-item { flex: 0 0 200px; width: 200px; margin: 0; scroll-snap-align: start; }
  .review-mode .queue-item > button, .review-mode button.queue-item { padding: 10px; }
  .review-mode .queue-item .row-title { -webkit-line-clamp: 2; }
  .review-mode .pager { justify-content: space-between; padding: 8px 12px; }
  .review-mode .detail-panel { min-height: 0; }
  .review-mode .detail-header { padding-inline: 14px; }
  .review-mode .detail-scroll { padding: 15px 12px 18px; }
  .review-mode .question-paper { padding: 16px 14px; }
  .review-tools .review-panel { padding: 17px 16px; }
  .review-tools > .solution-section { padding: 14px 16px 8px; }
  .review-tools .review-actions { grid-template-columns: 1fr; }
  .review-tools .rating-buttons { max-width: none; }
  .review-tools .rating-buttons button { min-height: 40px; }
  .material-grid { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .material-card { padding: 21px; }
  .section-heading { align-items: flex-start; }
  .section-heading h2 { font-size: 21px; }
  .material-detail-heading .section-heading { align-items: flex-start; flex-direction: column; gap: 13px; }
  .material-detail-heading .material-actions { justify-content: flex-start; max-width: 100%; }
  .future-note { gap: 8px 14px; }
  dialog.app-dialog { width: calc(100vw - 24px); max-height: calc(100dvh - 30px); }
  .dialog-heading { padding: 15px 18px; }
  .dialog-heading h2 { font-size: 21px; }
  .dialog-body { padding: 18px; }
  .dialog-actions { padding: 13px 18px; }
  .dialog-actions button { min-height: 42px; }
  .dialog-body .paper { padding: 16px; }
  .toast { bottom: 16px; padding: 10px 14px; font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
