:root {
  color-scheme: light;
  --ink: #182e30;
  --muted: #526260;
  --accent: #06584b;
  --line: #d8e1db;
  --page: #eef2ee;
  --paper: #fff;
  --wash: #e0efe6;
  --warning: #765522;
  --error: #972c39;
  font-family: "Avenir Next", Avenir, system-ui, sans-serif;
  font-size: 16px;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--ink); }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3, p { margin: 0; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.52; }
:focus-visible { outline: 3px solid #318b75; outline-offset: 3px; }
[hidden] { display: none !important; }

.skip { position: fixed; z-index: 2; top: .5rem; left: 1rem; transform: translateY(-180%); background: white; padding: .5rem 1rem; }
.skip:focus { transform: none; }
.top { border-bottom: 1px solid #d2ddd5; background: #f8faf7; }
.top-inner { max-width: 1440px; margin: auto; padding: 13px 34px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 1.12rem; letter-spacing: -.02em; }
.brand-mark { color: #fff; display: grid; place-items: center; width: 31px; height: 33px; border-radius: 6px 6px 10px 6px; background: var(--accent); font-weight: 650; }
.local { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .84rem; }
.local i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #2e8064; }

main { max-width: 1440px; margin: 0 auto; padding: 32px 34px 24px; }
.intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.subject { font-size: .8rem; font-weight: 700; margin-bottom: 9px; color: var(--accent); }
.subject span { margin: 0 .35em; color: #58736a; }
.intro h1 { font-family: Georgia, serif; font-weight: 500; letter-spacing: -.048em; font-size: clamp(2.3rem, 4vw, 3.9rem); line-height: 1.02; margin-bottom: 10px; }
.intro p:last-child { color: var(--muted); line-height: 1.5; }
.intro-actions, .release-actions { display: flex; gap: 9px; flex-wrap: wrap; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: .48em; border-radius: 7px; min-height: 41px; padding: .5rem .83rem; border: 1px solid transparent; font-size: .87rem; font-weight: 700; line-height: 1.25; text-decoration: none; }
.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.primary:hover:not(:disabled) { background: #0a463b; }
.secondary { background: #fff; border-color: #b6c7bc; color: var(--accent); }
.secondary:hover:not(:disabled), .text:hover:not(:disabled) { background: var(--wash); }
.text { background: transparent; color: var(--accent); }
.small { min-height: 33px; padding: .4rem .58rem; font-size: .78rem; }
.wide { width: 100%; }

.batch-bar { display: flex; align-items: center; gap: 18px; background: #dde9df; border: 1px solid #cddbd0; border-radius: 8px; padding: 11px 15px; }
.batch-caption { color: var(--muted); font-size: .75rem; margin-bottom: 1px; }
.batch-bar strong { display: block; line-height: 1.25; min-width: 17ch; overflow-wrap: anywhere; }
.progress-info { margin-left: auto; display: flex; gap: 12px; align-items: center; font-size: .82rem; color: var(--muted); flex-shrink: 0; }
progress { width: clamp(65px, 10vw, 150px); height: 8px; accent-color: var(--accent); }
.status { min-height: 29px; display: flex; align-items: center; font-size: .84rem; color: var(--accent); overflow-wrap: anywhere; }
.request-update { min-height: 29px; }
.status:empty { display: none; }
.scan-progress { gap: .65rem; }
.scan-progress progress { width: 90px; flex: none; }

.work-grid { display: grid; grid-template-columns: minmax(174px, .71fr) minmax(0, 2fr) minmax(290px, 1.26fr); gap: 13px; align-items: stretch; }
.panel { min-width: 0; background: var(--paper); border: 1px solid var(--line); border-radius: 9px; }
.panel-head { min-height: 48px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: 0 13px; }
.panel h2 { font-size: .94rem; letter-spacing: -.01em; }
.counter { background: var(--wash); color: var(--accent); border-radius: 5px; padding: 3px 7px; font-size: .73rem; font-weight: 700; }
.upload { padding: 11px; margin: 12px; border: 1px dashed #a8bdb0; border-radius: 7px; background: #f6f9f6; display: grid; gap: 9px; }
.upload label { font-size: .89rem; font-weight: 700; }
.upload input { min-width: 0; width: 100%; font-size: .74rem; }
.upload input::file-selector-button { border: 1px solid #bdc9bf; background: #fff; color: var(--accent); border-radius: 4px; cursor: pointer; font: inherit; padding: .35rem .43rem; }
.upload p, .queue-empty, .template-link, .subtle, .evidence-label, .footnote { font-size: .79rem; line-height: 1.5; color: var(--muted); }
.queue-empty { padding: 0 13px 12px; }
.template-link { display: block; padding: 0 13px 14px; color: var(--accent); text-underline-offset: 3px; }
.worksheet-link { margin: 0 12px 12px; text-decoration: underline; text-underline-offset: 3px; }
.paper-list { list-style: none; margin: 0 12px 12px; padding: 0; display: grid; gap: 5px; max-height: 310px; overflow: auto; }
.paper-list:empty { display: none; }
.paper-select { border: 1px solid var(--line); background: white; border-radius: 6px; display: block; width: 100%; min-height: 48px; text-align: left; font-weight: 700; font-size: .84rem; padding: .36rem .5rem; }
.paper-select span { display: block; color: var(--muted); font-weight: 500; font-size: .72rem; }
.paper-select[aria-pressed="true"], .question-button[aria-pressed="true"], .error-groups button[aria-pressed="true"] { border-color: #77a394; background: var(--wash); color: var(--accent); }

.evidence { background: #f8faf7; }
.evidence .panel-head { background: #fff; border-radius: 8px 8px 0 0; }
.paper-viewport { background: #e9eee9; margin: 12px 12px 0; overflow: auto; max-height: 647px; padding: 14px; border-radius: 5px; scrollbar-color: #9eb5a5 transparent; }
.sheet { width: min(100%, 481px); position: relative; margin-inline: auto; background: white; box-shadow: 0 3px 11px #1c3c3426; }
.sheet img { display: block; width: 100%; height: auto; }
.zoomed .sheet { width: max(820px, 100%); }
.row-outline { position: absolute; left: 6.2%; width: 87.5%; height: 17.8%; pointer-events: none; border: 2px solid #279174; border-radius: 3px; box-shadow: 0 0 0 3px #65b49a38; }
.row-outline[data-row="0"] { top: 23.5%; }
.row-outline[data-row="1"] { top: 43.6%; }
.row-outline[data-row="2"] { top: 63.7%; }
.evidence-label { padding: 8px 12px 11px; }
.review-empty { padding: 25px 16px; }
.empty-mark { font: 2.05rem Georgia, serif; color: var(--accent); background: var(--wash); border-radius: 7px; width: 61px; height: 56px; display: grid; place-items: center; margin-bottom: 14px; }
.review-empty h3 { font-size: 1rem; margin-bottom: 6px; }
.review-empty p { font-size: .87rem; color: var(--muted); line-height: 1.55; max-width: 32ch; }
#review-body { padding: 12px 13px 8px; }
.pair, .review-form { display: grid; gap: 7px; }
.pair-row, .paper-actions { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.pair-row input { min-width: 0; flex: 1; }
.pair-row button { flex-shrink: 0; }
#match-questions { margin: 0; padding-inline-start: 1.35rem; color: var(--muted); font-size: .8rem; }
#match-questions li { padding: .12rem 0; overflow-wrap: anywhere; }
label { font-size: .8rem; font-weight: 700; }
input:not([type="file"], [type="checkbox"]), textarea { width: 100%; padding: .42rem .55rem; border-radius: 5px; border: 1px solid #bdc9c0; background: #fff; font-size: .87rem; }
textarea { resize: vertical; min-height: 41px; }
textarea:disabled, input:disabled { background: #f3f6f3; color: var(--muted); }
input[aria-invalid="true"] { border-color: var(--error); }
.field-error { color: var(--error); font-size: .8rem; }
.questions { display: flex; gap: 6px; margin: 11px 0; }
.question-button { flex: 1; min-height: 34px; padding: 3px 6px; border-radius: 5px; border: 1px solid var(--line); background: #fff; font-size: .81rem; font-weight: 700; }
.problem { font-size: .76rem; color: var(--muted); line-height: 1.4; }
.problem strong { font: 1.46rem Georgia, serif; display: block; color: var(--ink); overflow-wrap: anywhere; }
.draft { padding: 7px 9px; border-left: 3px solid #6eaa91; background: #edf5ef; border-radius: 4px; font-size: .78rem; overflow-wrap: anywhere; }
.draft strong, .draft span { display: block; }
.draft.manual { background: #f9f2e5; color: #654617; border-color: #b68d47; }
.score-row { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.score-row input { width: 90px; }
.check { display: flex; align-items: start; gap: 6px; color: var(--accent); font-weight: 600; }
.check input { accent-color: var(--accent); }
.paper-actions { margin-top: 6px; }

.release { margin-top: 13px; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 13px 16px; border-radius: 8px; background: #dce9df; border: 1px solid #cddbd0; }
.release h2 { font-size: 1rem; }
.release p { font-size: .84rem; color: var(--muted); margin-top: 2px; }
.batch-storage { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px; justify-content: space-between; margin-block-start: 10px; }
.batch-storage > div { display: flex; flex-wrap: wrap; gap: 6px; }
.footnote { margin-top: 14px; }

dialog { position: fixed; border: 1px solid var(--line); border-radius: 10px; padding: 17px; max-width: min(570px, calc(100% - 22px)); width: 100%; max-height: calc(100% - 24px); color: var(--ink); }
dialog::backdrop { background: #192b2b82; }
dialog p { font-size: .9rem; color: var(--muted); line-height: 1.45; }
.dialog-top { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.dialog-top h2, #print-area h2 { font-family: Georgia, serif; font-size: 1.55rem; font-weight: 500; }
#key-form, #warmup-form, #print-area { display: grid; gap: 9px; }
#key-fields { display: grid; gap: 6px; }
#key-fields fieldset { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 6px; gap: 8px; }
#key-fields legend { font: 1rem Georgia, serif; }
#key-fields label input { margin-top: 4px; }
.equation-field { grid-column: 1 / -1; }
.expected-codes-field { display: grid; gap: 4px; }
#worksheet-dialog { max-width: min(680px, calc(100% - 22px)); }
.worksheet-sheet { padding: 18px; margin-block: 8px 14px; border: 1px solid var(--line); background: #fff; color: #202925; }
.worksheet-sheet header { display: flex; justify-content: space-between; gap: 8px; font-size: .85rem; font-weight: 650; }
.worksheet-code { display: inline-block; width: 3.2em; border-bottom: 1px solid; }
.worksheet-sheet h2 { margin: .38em 0 .25em; font: clamp(1.35rem, 4vw, 2rem) Georgia, serif; overflow-wrap: anywhere; }
.worksheet-questions { list-style: none; padding: 0; display: grid; gap: .16in; }
.worksheet-questions li { display: grid; grid-template-columns: minmax(0, 34%) minmax(0, 1fr); min-height: 1.46in; border: 1px solid #a7b3aa; break-inside: avoid; }
.worksheet-questions li > :first-child { border-inline-end: 1px solid #a7b3aa; padding: .13in; }
.worksheet-questions li strong { font-size: .75rem; }
.worksheet-questions li p { margin-top: .34in; color: inherit; font: 1.1rem Georgia, serif; overflow-wrap: anywhere; }
.error-groups { display: grid; gap: 5px; margin: 9px 0; }
.error-groups button { justify-content: flex-start; text-align: left; }
#warmup-form { border-top: 1px solid var(--line); padding-top: 9px; }
#print-area { margin-top: 10px; padding: 9px; border-radius: 5px; border: 1px solid var(--line); }
#print-problem { white-space: pre-wrap; color: var(--ink); font-size: 1.12rem; }

@media (max-width: 920px) {
  .top-inner, main { padding-left: 18px; padding-right: 18px; }
  .work-grid { grid-template-columns: minmax(0, 1fr) minmax(280px, .95fr); }
  .queue { grid-column: 1 / -1; }
  .paper-list { grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); max-height: 150px; }
  .upload { display: flex; align-items: center; flex-wrap: wrap; }
  .upload input { width: auto; max-width: 100%; }
  .upload p br { display: none; }
}
@media (max-width: 620px) {
  main { padding-top: 22px; }
  .intro, .release { align-items: flex-start; flex-direction: column; }
  .intro { margin-bottom: 17px; }
  .intro-actions { gap: 6px; }
  .batch-bar { flex-wrap: wrap; gap: 6px 13px; }
  .batch-bar strong { min-width: auto; }
  .progress-info { margin-left: 0; }
  .work-grid { grid-template-columns: minmax(0, 1fr); }
  .queue { grid-column: auto; }
  .paper-viewport { max-height: 385px; padding: 8px; }
}
@media print {
  @page { size: letter; margin: .5in; }
  body > :not(dialog[open]), #debrief-dialog > :not(#print-area), #print-area button,
  #worksheet-dialog > :not(#worksheet-sheet) { display: none !important; }
  body, #debrief-dialog, #print-area, #worksheet-dialog, #worksheet-sheet { background: white; color: black; }
  #debrief-dialog, #worksheet-dialog { position: static; padding: 0; margin: 0; border: 0; max-width: 100%; max-height: none; overflow: visible; }
  #debrief-dialog::backdrop, #worksheet-dialog::backdrop { display: none; }
  #print-area { border: 0; padding: 0; }
  #worksheet-sheet { margin: 0; padding: .22in .15in; border: 0; }
  .worksheet-sheet h2 { font-size: 24pt; }
  .worksheet-questions { margin-block: .8in .3in; }
  .worksheet-questions li { min-height: 1.72in; }
}
