:root {
  --bg: #fff; --surface: #f4f4f2; --line: #d9d9d4; --text: #1c1c1a; --muted: #6a6a64;
  --accent: #0b57d0; --accent-ink: #fff; --bad: #b3261e; --good: #1a7f37;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151614; --surface: #1d1f1c; --line: #34372f; --text: #e8e8e3; --muted: #9a9b93;
    --accent: #8ab4f8; --accent-ink: #0d1b33; --bad: #ff8a80; --good: #5fd07a; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); padding-bottom: 72px; }
.muted { color: var(--muted); font-size: 14px; }
.grow { flex: 1; }
header { display: flex; gap: 8px; align-items: center; padding: 8px 16px; border-bottom: 1px solid var(--line); min-height: 52px; }
main { padding: 0 16px; max-width: 720px; margin: 0 auto; }
h2 { font-size: 16px; margin: 24px 0 8px; }

button, .btn { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 10px 14px; min-height: 44px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
button:disabled, .btn.busy { opacity: .6; cursor: default; pointer-events: none; }
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
:focus-visible, .btn:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.spin::before { content: ""; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

footer { position: fixed; inset: auto 0 0 0; display: flex; gap: 8px; padding: 8px 16px; background: var(--bg); border-top: 1px solid var(--line); }
footer .primary { flex: 1; }

.shot { margin: 16px 0 24px; }
.stage { position: relative; line-height: 0; touch-action: pan-y; background: #000; }
.stage canvas { width: 100%; height: auto; display: block; }
.stage svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage polygon { fill: rgba(11, 87, 208, .12); stroke: #4d90fe; stroke-width: 2; vector-effect: non-scaling-stroke; }
.stage polygon.selected { stroke: #ffb300; stroke-width: 3; }
.stage text { fill: #fff; stroke: #000; stroke-width: 3px; paint-order: stroke; font-weight: 700; text-anchor: middle; dominant-baseline: middle; pointer-events: none; }
/* The grip is much bigger than its visible dot, for a fingertip. */
.stage .grip { fill: transparent; touch-action: none; cursor: grab; }
.stage .dot { fill: #fff; stroke: #0b57d0; stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: none; }
#loupe { position: fixed; z-index: 10; width: 176px; height: 176px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px #000; pointer-events: none; }
#loupe[hidden] { display: none; }
.job { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; overflow-wrap: anywhere; }
.job p { margin: 0; }
.job.failed p { color: var(--bad); }
.job p.spin { display: flex; flex-wrap: wrap; align-items: center; gap: 0 8px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.row button { padding: 8px 10px; font-size: 14px; }
#finish .row button { flex: 1; font-size: 16px; }
.warn { color: var(--bad); font-size: 14px; margin: 4px 0; }

#pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.page { min-width: 0; }
.page img { width: 100%; display: block; border: 1px solid var(--line); background: var(--surface); }
.page .thumb { padding: 0; border: 0; background: none; display: block; width: 100%; min-height: 0; }
.page .meta { font-size: 13px; color: var(--muted); margin: 4px 0; }
.page .row { margin-top: 0; flex-wrap: nowrap; }
.page .row button { flex: 1; padding: 6px 4px; font-size: 13px; }

fieldset { border: 0; padding: 0; margin: 16px 0; display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: center; }
fieldset legend { float: left; padding: 0; margin-right: 8px; }
fieldset label { padding: 8px 0; }
.field { display: block; margin: 8px 0; font-size: 14px; }
.field input { display: block; width: 100%; font: inherit; font-size: 16px; padding: 10px; margin-top: 4px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 4px; }
.check { display: block; padding: 8px 0; font-size: 14px; }
.name { font-weight: 600; overflow-wrap: anywhere; margin: 8px 0; }
#status { min-height: 24px; margin: 12px 0; overflow-wrap: anywhere; }
#status.error { color: var(--bad); }
#status.ok { color: var(--good); }
#status a { color: inherit; }

dialog.ask { padding: 16px; border: 1px solid var(--line); border-radius: 4px; background: var(--bg); color: var(--text); width: min(90vw, 360px); }
dialog.ask p { margin: 0 0 8px; }
dialog.ask button { flex: 1; }
.stack { display: grid; gap: 8px; margin-top: 8px; }
button.link { display: inline; min-height: 0; padding: 8px 4px; border: 0; background: none; color: inherit; text-decoration: underline; font-size: inherit; }
#zoom { padding: 0; border: 0; max-width: none; max-height: none; width: 100vw; height: 100dvh; background: #000; overflow: auto; }
dialog img { display: block; width: 200%; max-width: none; }
dialog form { position: fixed; top: 8px; right: 8px; }
