:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #16202e;
  --muted: #64748b;
  --line: #dfe5ee;
  --brand: #2f6bd8;
  --brand-dark: #24549f;
  --ok: #157f47;
  --ok-bg: #e6f6ec;
  --warn: #9a6206;
  --warn-bg: #fdf3e0;
  --bad: #b3261e;
  --bad-bg: #fdeceb;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

main { max-width: 1080px; margin: 0 auto; padding: 0 20px 64px; }

.page-head {
  max-width: 1080px;
  margin: 0 auto;
  padding: 40px 20px 8px;
}
.page-head h1 { margin: 0; font-size: 30px; letter-spacing: -0.02em; }
.sub { margin: 8px 0 24px; color: var(--muted); max-width: 62ch; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 20px;
}
.card h2 { margin: 0 0 16px; font-size: 17px; display: flex; align-items: center; gap: 10px; }

.step {
  display: inline-grid; place-items: center;
  width: 24px; height: 24px; flex: none;
  background: var(--brand); color: #fff;
  border-radius: 50%; font-size: 13px; font-weight: 700;
}

.muted { color: var(--muted); font-weight: 400; }
.hint { margin: 12px 0 0; color: var(--muted); font-size: 13.5px; }

/* ---- answer key ---- */
.keygrid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.keyfield label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.keyfield textarea {
  width: 100%; resize: vertical;
  font: 14px/1.7 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.14em;
  padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px;
  background: #fbfcfe; color: var(--ink);
}
.keyfield textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
.keystatus { margin: 6px 0 0; font-size: 13px; font-weight: 600; min-height: 20px; }
.keystatus.ok { color: var(--ok); }
.keystatus.bad { color: var(--bad); }
.keystatus.idle { color: var(--muted); font-weight: 400; }

/* ---- drop zone ---- */
.drop {
  border: 2px dashed #c3cede;
  border-radius: var(--radius);
  background: #fbfcfe;
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.drop:hover, .drop:focus-visible { border-color: var(--brand); background: #f2f6fd; outline: none; }
.drop.over { border-color: var(--brand); background: #e8f0fd; }
.drop.disabled { opacity: .5; pointer-events: none; }
.dropicon {
  width: 34px; height: 34px; margin-bottom: 8px;
  fill: none; stroke: var(--brand); stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
.dropmain { margin: 0; font-size: 17px; font-weight: 600; }
.dropsub { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.link { color: var(--brand); text-decoration: underline; }

/* ---- progress ---- */
.bar { height: 8px; background: #e7ecf4; border-radius: 99px; overflow: hidden; }
.barfill { height: 100%; width: 0; background: var(--brand); transition: width .18s ease; }
.progresstext { margin: 10px 0 0; color: var(--muted); font-size: 14px; }

/* ---- results ---- */
.resulthead { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.resulthead h2 { margin: 0; }
.actions { display: flex; gap: 8px; }

.btn {
  font: inherit; font-size: 14px; font-weight: 600;
  padding: 9px 16px; border-radius: 8px;
  border: 1px solid var(--brand); background: var(--brand); color: #fff;
  cursor: pointer;
}
.btn:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: #f1f4f9; }
.btn.tiny { padding: 5px 11px; font-size: 13px; }

.summary { display: flex; gap: 28px; flex-wrap: wrap; margin: 18px 0 4px; }
.stat .n { font-size: 25px; font-weight: 700; letter-spacing: -0.02em; }
.stat .l { display: block; font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 14px; border-radius: 9px; margin-top: 14px; font-size: 14px;
}
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.bad { background: var(--bad-bg); color: var(--bad); }

.tablewrap { margin-top: 18px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr.row-error { background: var(--bad-bg); }
tbody tr.row-review { background: var(--warn-bg); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
/* Wide enough to actually read the handwriting — a thumbnail too small to read
   is the same as no thumbnail at all. */
.namecrop { width: 176px; height: auto; display: block; border-radius: 4px; background: #fff; }
.score-big { font-weight: 700; }
.errmsg { color: var(--bad); font-size: 13.5px; }
.notes { max-width: 340px; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 99px;
  font-size: 12px; font-weight: 600; margin: 1px 3px 1px 0; white-space: nowrap;
}
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }

/* ---- detail modal ---- */
.modal {
  position: fixed; inset: 0; background: rgba(16,24,38,.55);
  display: grid; place-items: center; padding: 20px; z-index: 20;
}
/* `display` here beats the hidden attribute's built-in `display:none`, so
   without this the invisible overlay covers the page and eats every click. */
[hidden] { display: none !important; }
.modalbox {
  background: #fff; border-radius: var(--radius);
  width: min(1000px, 100%); max-height: 92vh; display: flex; flex-direction: column;
}
.modalhead {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.modalhead h3 { margin: 0; font-size: 16px; }
.modalbody { padding: 18px 20px 22px; overflow: auto; }

.legend { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 14px; }
.detailgrid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(74px, 1fr));
  gap: 5px; margin-bottom: 18px;
}
.qcell {
  border-radius: 6px; padding: 5px 6px; font-size: 12.5px; line-height: 1.35;
  border: 1px solid transparent;
}
.qcell .qn { color: var(--muted); font-size: 11px; }
.qcell.correct { background: var(--ok-bg); color: var(--ok); }
.qcell.wrong { background: var(--bad-bg); color: var(--bad); }
.qcell.blank { background: var(--warn-bg); color: var(--warn); }
.detailsheet canvas { width: 100%; height: auto; border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; }

.page-foot {
  max-width: 1080px; margin: 0 auto; padding: 0 20px 40px;
  color: var(--muted); font-size: 13px;
}

@media (max-width: 720px) {
  .keygrid { grid-template-columns: 1fr; }
  .page-head { padding-top: 26px; }
  .page-head h1 { font-size: 24px; }
  .card { padding: 18px 16px; }
}
