:root {
  --bg: #0d0f12;
  --fg: #f2f4f7;
  --muted: #9aa3ad;
  --panel: #171a1f;
  --line: #2a2f37;
  --accent: #3b82f6;
  --high: #22c55e;
  --medium: #f59e0b;
  --low: #ef4444;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

button, input, select { font: inherit; color: inherit; }
button { touch-action: manipulation; cursor: pointer; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.error { color: var(--low); }
.warn {
  background: #3a2a06; border: 1px solid var(--medium); border-radius: 8px;
  padding: 10px 12px;
}

/* ---- setup and results panels ---- */
.panel { max-width: 560px; margin: 0 auto; padding: calc(16px + var(--safe-top)) 16px 32px; }
.panel h1 { font-size: 22px; margin: 0 0 4px; }
.panel h2 { font-size: 17px; margin: 24px 0 8px; }
form label { display: block; margin: 14px 0; color: var(--muted); }
form input, form select {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
}
button {
  padding: 12px 18px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel);
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button:disabled { opacity: 0.5; cursor: default; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot.high { background: var(--high); }
.dot.medium { background: var(--medium); }
.dot.low { background: var(--low); }
#truth input { width: 64px; padding: 6px 8px; text-align: right; background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; }
/* Check-the-list rows: photo of where the item was found, name, count, Not there. */
.check { display: grid; grid-template-columns: 96px 1fr auto; gap: 10px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--line); }
.check .thumb { position: relative; width: 96px; height: 72px; border-radius: 6px; overflow: hidden;
  background: var(--panel); }
.check .thumb img { width: 100%; height: 100%; object-fit: fill; display: block; }
.check .thumb .box { position: absolute; border: 2px solid var(--accent); border-radius: 2px; }
.check .name { min-width: 0; overflow-wrap: anywhere; }
.check .ctl { display: flex; gap: 8px; align-items: center; }
.check button { padding: 8px 10px; font-size: 13px; }
.check.gone .name { text-decoration: line-through; color: var(--muted); }
.check.gone .thumb { opacity: 0.35; }
.check.gone input { opacity: 0.35; }
.check.gone button.not-there { border-color: var(--low); color: var(--low); }
#save-note { margin-top: 10px; }
@media (max-width: 420px) {
  .check { grid-template-columns: 72px 1fr; }
  .check .thumb { width: 72px; height: 54px; }
  .check .ctl { grid-column: 1 / -1; justify-content: flex-end; }
}

/* ---- scan view ---- */
#scan { position: fixed; inset: 0; overflow: hidden; background: #000; }
#video, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
#video { object-fit: cover; }
#overlay { pointer-events: none; }

#hud-top {
  position: absolute; top: 0; left: 0; right: 0;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: linear-gradient(rgba(0, 0, 0, 0.6), transparent);
  font-variant-numeric: tabular-nums;
}
#stats { font-weight: 600; }
#ring {
  position: absolute; right: 12px; top: calc(56px + var(--safe-top));
  width: 96px; height: 96px; pointer-events: none;
}
#hint {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%);
  padding: 10px 18px; border-radius: 999px; background: rgba(0, 0, 0, 0.7);
  font-size: 18px; font-weight: 600; white-space: nowrap; pointer-events: none;
}
#hint.bad { color: #fecaca; border: 1px solid var(--low); }
#hint.soft { color: #fde68a; border: 1px solid var(--medium); }

#hud-bottom {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 10px 16px calc(12px + var(--safe-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75) 30%);
  display: flex; flex-direction: column; gap: 10px;
}
#tray {
  list-style: none; margin: 0; padding: 0; max-height: 34vh; overflow-y: auto;
  display: flex; flex-wrap: wrap; gap: 6px; align-content: flex-end;
}
#tray li {
  max-width: 100%; padding: 6px 10px; border-radius: 10px; font-size: 14px;
  background: rgba(23, 26, 31, 0.85); border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
}
#tray li.high { border-left-color: var(--high); }
#tray li.medium { border-left-color: var(--medium); }
#tray li.low { border-left-color: var(--low); }
#tray li.new { animation: pop 0.8s ease-out; }
#tray .count { color: var(--muted); margin-left: 4px; }
#tray .ask { display: block; font-size: 12px; color: #fde68a; overflow-wrap: anywhere; }
#tray .tag { font-size: 11px; color: var(--muted); margin-left: 4px; }
#tray li { cursor: pointer; user-select: none; -webkit-user-select: none; }
#tray li.armed { border-color: var(--low); background: rgba(127, 29, 29, 0.85); }
#tray .confirm { display: block; font-size: 12px; font-weight: 600; color: #fecaca; }
#undo {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 6px 6px 12px; border-radius: 10px; font-size: 14px;
  background: rgba(23, 26, 31, 0.92); border: 1px solid var(--line);
}
#undo button { padding: 6px 12px; font-size: 14px; color: var(--accent); }
#done { align-self: stretch; }

@keyframes pop {
  from { transform: scale(1.15); background: rgba(59, 130, 246, 0.6); }
  to { transform: scale(1); }
}
