/* HKUGAC History Essay Grader. Calm paper-and-ink look; mobile first. */
:root {
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans TC", "PingFang HK", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --bg: #f6f4ef; --surface: #fff; --surface-2: #f1eee6; --line: #e1dccf; --line-strong: #c7bfac;
  --ink: #1d1f2b; --ink-2: #3b3e4d; --ink-3: #5e6170;
  --brand: #1f4fa8; --brand-hover: #173e86; --brand-soft: #e5ecfa;
  --ok: #17663d; --ok-soft: #dff2e6; --warn: #8a4b00; --warn-soft: #fdf0d9; --danger: #b3261e; --danger-soft: #fbe5e3;
  --mark: #ffe58a;
  --r: .6rem; --shadow: 0 1px 2px rgba(29, 31, 43, .06), 0 2px 8px rgba(29, 31, 43, .05);
  --ring: 0 0 0 3px #fff, 0 0 0 5px var(--brand);
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font); }
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: 1.5rem; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
a { color: var(--brand); }
[hidden] { display: none !important; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-3); }
.small { font-size: .875rem; }
.tiny { font-size: .78rem; }
.num { font-variant-numeric: tabular-nums; }
.warn-text { color: var(--warn); }
.stack { display: flex; flex-direction: column; gap: var(--gap, 1rem); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.row.gap { gap: .75rem; }
.spread { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; }
.grow { flex: 1; min-width: 0; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }

/* App bar */
.skip { position: absolute; left: -999px; top: .5rem; background: var(--surface); padding: .5rem 1rem; z-index: 20; }
.skip:focus { left: .5rem; }
.appbar { position: sticky; top: 0; z-index: 10; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: .6rem; color: var(--ink); text-decoration: none; font-weight: 700; }
.brand img { height: 2rem; width: auto; }
.appbar nav { display: flex; flex-wrap: wrap; gap: .25rem; }
.appbar nav a { padding: .45rem .7rem; border-radius: .45rem; color: var(--ink-2); text-decoration: none; font-weight: 600; font-size: .92rem; }
.appbar nav a:hover { background: var(--surface-2); }
.appbar nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand); }
.appbar .who { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
main { max-width: 72rem; margin: 0 auto; padding: 1.25rem 1rem 4rem; }
main.narrow { max-width: 44rem; }
.page-title { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }

/* Surfaces */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 1rem; min-width: 0; }
.card > h2:first-child, .card > h3:first-child { margin-bottom: .6rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr)); }
.cols-2 { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 900px) { .cols-2 { grid-template-columns: 1fr 1fr; } }
.cols-3 { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 1100px) { .cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.empty { color: var(--ink-3); padding: 1.5rem; text-align: center; border: 1px dashed var(--line-strong); border-radius: var(--r); }
.callout { border-left: 4px solid var(--brand); background: var(--brand-soft); padding: .75rem 1rem; border-radius: .4rem; }
.callout.warn { border-color: var(--warn); background: var(--warn-soft); }
.callout.ok { border-color: var(--ok); background: var(--ok-soft); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 2.6rem; padding: .5rem 1rem; border-radius: .5rem; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); font: 600 .95rem/1.2 var(--font); cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { min-height: 2.1rem; padding: .3rem .7rem; font-size: .85rem; }
.btn.lg { min-height: 3rem; padding: .6rem 1.4rem; font-size: 1.05rem; }

/* Forms */
.field { display: flex; flex-direction: column; gap: .3rem; }
.field > label, .label { font-weight: 600; font-size: .9rem; color: var(--ink-2); }
.hint { font-size: .82rem; color: var(--ink-3); }
input[type="text"], input[type="password"], input[type="number"], input[type="datetime-local"], input[type="search"], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--line-strong); border-radius: .45rem; background: #fff; color: var(--ink); font: inherit; }
textarea { min-height: 8rem; resize: vertical; line-height: 1.55; }
textarea.answer { font: 1.02rem/1.7 var(--serif); min-height: 24rem; }
input[type="number"] { max-width: 7rem; }
.check { display: inline-flex; align-items: center; gap: .45rem; font-weight: 600; cursor: pointer; }
.check input { width: 1.15rem; height: 1.15rem; }
fieldset { border: 1px solid var(--line); border-radius: var(--r); padding: .75rem 1rem 1rem; margin: 0; min-width: 0; }
legend { font-weight: 700; padding: 0 .3rem; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--surface-2); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #faf8f3; }

/* Badges */
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 700; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }

/* Steps */
.steps { display: flex; flex-wrap: wrap; gap: .4rem; list-style: none; padding: 0; margin: 0 0 1rem; counter-reset: s; }
.steps li { counter-increment: s; padding: .35rem .75rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: .85rem; color: var(--ink-3); }
.steps li::before { content: counter(s) ". "; }
.steps li[aria-current="step"] { background: var(--brand); color: #fff; border-color: var(--brand); }
.steps li.done { color: var(--ok); border-color: var(--ok); }

/* Page masking */
.pages { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr)); }
.page-card { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: .6rem; display: flex; flex-direction: column; gap: .5rem; }
.page-card.excluded .mask-canvas { opacity: .3; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.mask-canvas { width: 100%; height: auto; border: 1px solid var(--line); border-radius: .3rem; touch-action: none; cursor: crosshair; background: #fff; }
.thumbs { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .25rem; }
.thumbs img { height: 9rem; width: auto; border: 1px solid var(--line); border-radius: .3rem; background: #fff; }
.scan { width: 100%; height: auto; border: 1px solid var(--line); border-radius: .3rem; background: #fff; }

/* Check and audit */
.side-by-side { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 760px) { .side-by-side { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .side-by-side .sticky { position: sticky; top: 4.5rem; max-height: calc(100vh - 5.5rem); overflow: auto; } }
mark { background: var(--mark); color: inherit; padding: 0 .1em; border-radius: .15em; }
.diff { white-space: pre-wrap; font: .95rem/1.65 var(--serif); overflow-wrap: anywhere; }
.diff del { background: var(--danger-soft); color: var(--danger); }
.diff ins { background: var(--ok-soft); color: var(--ok); text-decoration: none; }
.audit-text { white-space: pre-wrap; font: .95rem/1.65 var(--serif); overflow-wrap: anywhere; max-height: 40rem; overflow: auto; }
.meter { height: .5rem; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--brand); }

/* Results */
.score { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.score .big { font: 700 2.4rem/1 var(--font); font-variant-numeric: tabular-nums; }
.part { border-top: 1px solid var(--line); padding-top: .75rem; margin-top: .75rem; }
blockquote { margin: .3rem 0; padding: .3rem .8rem; border-left: 3px solid var(--line-strong); color: var(--ink-2); font: .95rem/1.55 var(--serif); }
ul.tight { margin: .25rem 0; padding-left: 1.2rem; }
ul.tight li + li { margin-top: .2rem; }

/* Tabs */
.tabs { display: flex; flex-wrap: wrap; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
.tabs button { border: 0; background: transparent; padding: .6rem .9rem; font: 600 .95rem var(--font); color: var(--ink-3); border-bottom: 3px solid transparent; cursor: pointer; }
.tabs button[aria-selected="true"] { color: var(--brand); border-color: var(--brand); }

/* Toasts and dialogs */
.toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: .5rem; z-index: 50; width: min(92vw, 30rem); }
.toast { background: var(--ink); color: #fff; padding: .7rem 1rem; border-radius: .5rem; box-shadow: var(--shadow); }
.toast.error { background: var(--danger); }
dialog.modal { border: 0; border-radius: .8rem; padding: 1.25rem; width: min(94vw, 32rem); box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
dialog.modal.wide { width: min(96vw, 60rem); }
dialog.modal::backdrop { background: rgba(20, 22, 30, .45); }
.modal-body { margin: .75rem 0 1rem; display: flex; flex-direction: column; gap: .75rem; max-height: 70vh; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: .5rem; flex-wrap: wrap; }

/* Sign-in */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.signin .card { width: min(100%, 24rem); padding: 1.5rem; }
.signin img { height: 3.2rem; width: auto; margin-bottom: .5rem; }
.progress { display: flex; align-items: center; gap: .6rem; color: var(--ink-2); }
.spinner { width: 1.1rem; height: 1.1rem; border: 2px solid var(--line-strong); border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
@media print { .appbar, .no-print { display: none !important; } body { background: #fff; } .card { box-shadow: none; } }
