:root {
  --bg: #f4f5f7;
  --fg: #1d2330;
  --muted: #6b7385;
  --card: #ffffff;
  --line: #dde1e8;
  --accent: #2357d8;
  --accent-fg: #ffffff;
  --accent-soft: #e6edff;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #f59e0b;
  --warn-soft: #fff4d6;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --empty: #94a3b8;
  --box-checked: #16a34a;
  --box-unsure: #f59e0b;
  --box-empty: #94a3b8;
  --box-num: #2357d8;
  --box-sel: #db2777;
  --quad: #22c55e;
  --quad-bad: #f59e0b;
  --radius: 10px;
  --radius-big: 16px;
  --gap: 12px;
  --pad: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --shadow: 0 1px 3px rgba(20, 30, 50, .12);
  --tap: 52px;
  --maxw: 1200px;
  --flash: rgba(255, 255, 255, .85);
  --overlay: rgba(10, 14, 22, .55);
  --hint-bg: rgba(10, 14, 22, .72);
  --hint-fg: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c;
    --fg: #e8ebf2;
    --muted: #98a1b3;
    --card: #1b2029;
    --line: #2c3340;
    --accent: #6d95ff;
    --accent-fg: #0b1020;
    --accent-soft: #1f2a45;
    --ok-soft: #12321f;
    --warn-soft: #3a2c0c;
    --bad-soft: #3d1414;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

.teatime {
  --bg: #fbf3e6;
  --card: #fffaf2;
  --accent: #8b4513;
  --accent-soft: #f3e2cc;
  --line: #e8d5bb;
  --fg: #3b2716;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 var(--gap); }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 var(--gap); }
small, .muted { color: var(--muted); }
code, .mono { font-family: var(--mono); font-size: .9em; }
[hidden], .hidden { display: none !important; }
.hidden-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px var(--pad);
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.logo { font-weight: 800; letter-spacing: -.02em; cursor: default; user-select: none; }
.by { color: var(--muted); font-size: .8rem; }
.spacer { flex: 1; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .78rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--fg);
  white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); }
.badge.warn { background: var(--warn-soft); }
.badge.bad { background: var(--bad-soft); }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: var(--pad); }
.narrow { max-width: 560px; margin: 0 auto; padding: var(--pad); }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-big);
  padding: var(--pad);
  box-shadow: var(--shadow);
  margin-bottom: var(--gap);
}
.row { display: flex; gap: var(--gap); align-items: center; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: var(--gap); }
.grid2 { display: grid; grid-template-columns: 1fr; gap: var(--gap); }
@media (min-width: 900px) { .grid2 { grid-template-columns: 340px 1fr; } }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 20px var(--pad) 30px; }

button, .btn, .bigbtn {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
}
button:disabled { opacity: .5; cursor: default; }
button.primary, .btn.primary, .bigbtn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.danger, .btn.danger { background: var(--bad); color: #fff; border-color: var(--bad); }
button.ghost, .bigbtn.ghost { background: transparent; }
button.small { min-height: 30px; padding: 3px 10px; font-size: .85rem; }
.bigbtn {
  width: 100%;
  min-height: var(--tap);
  font-size: 1.1rem;
  font-weight: 600;
  border-radius: var(--radius-big);
  margin-bottom: 10px;
}
.bigbtn.huge { min-height: 84px; font-size: 1.3rem; }

input[type=text], input[type=password], input[type=number], input:not([type]), select, textarea {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--fg);
}
input[type=range] { width: 100%; }
.field { margin-bottom: var(--gap); }
.field label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.check input { width: 22px; height: 22px; }

progress {
  width: 100%;
  height: 10px;
  appearance: none;
  -webkit-appearance: none;
  border: none;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
}
progress::-webkit-progress-bar { background: var(--line); border-radius: 99px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 99px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 99px; }
progress.bar { height: 16px; }
progress.bar.top::-webkit-progress-value { background: var(--ok); }
progress.bar.top::-moz-progress-bar { background: var(--ok); }

.engine { font-size: .9rem; color: var(--muted); margin-bottom: var(--gap); }
.engine.ready { color: var(--ok); }
.engine.fail { color: var(--bad); }
.tips { font-size: .9rem; color: var(--muted); }
.tips li { margin-bottom: 4px; }
.msg { padding: 10px 12px; border-radius: var(--radius); background: var(--accent-soft); margin-bottom: var(--gap); }
.msg.ok { background: var(--ok-soft); }
.msg.warn { background: var(--warn-soft); }
.msg.bad { background: var(--bad-soft); }

.view { animation: fadein .15s ease-out; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.rescanvas, .refcanvas, .thumbcanvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fff;
  touch-action: manipulation;
}
.refcanvas { cursor: crosshair; touch-action: none; }
.refcanvas.z1 { width: 100%; }
.refcanvas.z2 { width: 150%; max-width: none; }
.refcanvas.z3 { width: 220%; max-width: none; }
.refcanvas.z4 { width: 320%; max-width: none; }
.resbar { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; font-weight: 600; }

.checklist, .reslist { list-style: none; margin: 0; padding: 0; }
.checklist li, .reslist li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  user-select: none;
  min-height: 46px;
}
.reslist li .st {
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 6px;
  border: 2px solid var(--box-empty);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
}
.reslist li.s1 .st { border-color: var(--box-checked); background: var(--box-checked); color: #fff; }
.reslist li.s2 .st { border-color: var(--box-unsure); background: var(--warn-soft); color: var(--box-unsure); }
.reslist li.s2 { background: var(--warn-soft); }
.reslist li .num { color: var(--muted); font-size: .8rem; min-width: 22px; }
.reslist li .dup { font-size: .75rem; color: var(--muted); }

.manual { display: grid; grid-template-columns: 1fr; gap: var(--gap); }
@media (min-width: 760px) { .manual { grid-template-columns: 1fr 1fr; } }
.manual .photo { max-height: 70vh; overflow: auto; border-radius: var(--radius); border: 1px solid var(--line); background: #000; }
.manual .photo img { display: block; width: 100%; height: auto; }
@media (max-width: 759px) { .manual .photo { position: sticky; top: 56px; max-height: 42vh; z-index: 5; } }

.live { position: relative; width: 100%; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 3 / 4; }
.live video, .live canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.live.flash::after { content: ""; position: absolute; inset: 0; background: var(--flash); animation: flash .35s ease-out forwards; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
.hint {
  margin: 10px 0;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--hint-bg);
  color: var(--hint-fg);
  font-size: 1.05rem;
  font-weight: 600;
  text-align: center;
  min-height: 52px;
}
.hint.good { background: var(--ok); }
.shutter { width: 74px; height: 74px; border-radius: 50%; background: #fff; border: 6px solid var(--accent); font-size: 0; }

.sent { font-size: 2.2rem; font-weight: 800; text-align: center; color: var(--ok); padding: 60px 0; }
.sent small { display: block; font-size: 1rem; color: var(--muted); font-weight: 400; margin-top: 10px; }

.toasts { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); }
.toast { background: var(--fg); color: var(--bg); padding: 10px 14px; border-radius: var(--radius); box-shadow: var(--shadow); font-size: .95rem; animation: fadein .2s; }
.toast.ok { background: var(--ok); color: #fff; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.warn { background: var(--warn); color: #1d1300; }

.modal { position: fixed; inset: 0; background: var(--overlay); z-index: 90; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal .card { width: min(520px, 100%); max-height: 90vh; overflow: auto; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: var(--gap); border-bottom: 1px solid var(--line); }
.tabs button { border: none; border-bottom: 3px solid transparent; border-radius: 0; background: transparent; padding: 10px 14px; }
.tabs button.on { border-bottom-color: var(--accent); font-weight: 700; }

.qrbox { text-align: center; }
.qrbox img { width: 100%; max-width: 260px; height: auto; image-rendering: pixelated; background: #fff; padding: 8px; border-radius: var(--radius); }
.qrbox .link { word-break: break-all; font-size: .75rem; }

.stats { display: flex; gap: var(--gap); flex-wrap: wrap; }
.stat { flex: 1; min-width: 120px; background: var(--accent-soft); border-radius: var(--radius); padding: 10px 12px; }
.stat b { display: block; font-size: 1.6rem; }
.stat.warn { background: var(--warn-soft); }

.scans { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--gap); }
.scan { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-big); padding: 10px; box-shadow: var(--shadow); }
.scan.unsure { border: 2px solid var(--warn); background: var(--warn-soft); }
.scan.fresh { animation: pop .8s ease-out; }
@keyframes pop { 0% { transform: scale(.96); box-shadow: 0 0 0 4px var(--accent); } 100% { transform: scale(1); } }
.scan .meta { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: .85rem; margin: 6px 0; }
.scan .who { width: 100%; padding: 5px 8px; font-size: .9rem; }
.scan .picked { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.scan .tools { display: flex; gap: 6px; justify-content: flex-end; margin-top: 6px; }

.totals { width: 100%; border-collapse: collapse; }
.totals th, .totals td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.totals td.n, .totals th.n { text-align: right; white-space: nowrap; }
.totals td.barcell { width: 38%; }
.totals tr.dup td:first-child::after { content: " ⧉"; color: var(--muted); }

.models { list-style: none; padding: 0; margin: 0; }
.models li { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 0; border-bottom: 1px solid var(--line); }
.models li.on { font-weight: 700; }
.models li .name { flex: 1; min-width: 160px; }

.editor { display: grid; grid-template-columns: 1fr; gap: var(--gap); }
@media (min-width: 980px) { .editor { grid-template-columns: 1.1fr 1fr; } }
.editor .canvaswrap { max-height: 80vh; overflow: auto; border-radius: var(--radius); }
.labels { list-style: none; padding: 0; margin: 0; max-height: 70vh; overflow: auto; }
.labels li { display: flex; gap: 6px; align-items: center; padding: 4px 0; }
.labels li .num { width: 30px; text-align: right; color: var(--box-num); font-weight: 700; flex: none; }
.labels li.sel { background: var(--accent-soft); border-radius: 6px; }
.labels li.dupe input { border-color: var(--warn); background: var(--warn-soft); }
.labels li input { padding: 6px 8px; }
.toolbar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: var(--gap); }
.toolbar button.on { background: var(--accent-soft); border-color: var(--accent); }

.testtable { width: 100%; border-collapse: collapse; font-size: .9rem; }
.testtable th, .testtable td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.testtable td.pass, .testtable .pass { color: var(--ok); font-weight: 700; }
.testtable td.fail, .testtable .fail { color: var(--bad); font-weight: 700; }
.testtable td.na { color: var(--muted); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.gallery figure { margin: 0; font-size: .75rem; }
.gallery canvas, .gallery img { width: 100%; height: auto; border-radius: 6px; border: 1px solid var(--line); background: #fff; }
.bigscore { font-size: 2.4rem; font-weight: 800; }
.log { font-family: var(--mono); font-size: .8rem; white-space: pre-wrap; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; max-height: 300px; overflow: auto; }

.henry {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-size: clamp(2rem, 9vw, 6rem);
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 4px 0 var(--card), 0 8px 24px rgba(0, 0, 0, .3);
  animation: henry 3.2s ease-in-out forwards;
  text-align: center;
}
@keyframes henry {
  0% { opacity: 0; transform: scale(.3) rotate(-12deg); }
  15% { opacity: 1; transform: scale(1.1) rotate(3deg); }
  30% { transform: scale(1) rotate(0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-40px); }
}
.confetti { position: fixed; inset: 0; z-index: 199; pointer-events: none; width: 100%; height: 100%; }
.wiggle { animation: wiggle .5s ease-in-out 2; }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-4deg); } 75% { transform: rotate(4deg); } }

.diag td:first-child { width: 45%; }
.kbd { font-family: var(--mono); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; font-size: .8rem; }
.center { text-align: center; }
.mt { margin-top: var(--gap); }
.mb0 { margin-bottom: 0; }
.right { text-align: right; }
.big404 { font-size: 5rem; font-weight: 900; text-align: center; margin: 40px 0 0; }

.page-install { padding: var(--pad); }
.install { max-width: 560px; margin: 30px auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-big); padding: 20px; box-shadow: var(--shadow); }
.install-title { font-size: 1.3rem; }
.install-msg { padding: 10px 12px; border-radius: var(--radius); }
.install-msg.is-ok { background: var(--ok-soft); }
.install-msg.is-bad, .install-note.is-bad { background: var(--bad-soft); padding: 10px 12px; border-radius: var(--radius); }
.install-checks { list-style: none; padding: 0; margin: 0 0 var(--gap); }
.install-check { padding: 8px 0; border-bottom: 1px solid var(--line); }
.install-check.is-ok .install-mark { color: var(--ok); font-weight: 800; }
.install-check.is-bad .install-mark { color: var(--bad); font-weight: 800; }
.install-hint { display: block; color: var(--muted); margin-left: 22px; }
.install-form { margin: var(--gap) 0; }
.install-foot { color: var(--muted); font-size: .8rem; text-align: center; margin-top: 20px; }
.btn-primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
