:root {
  --bg: #f4f5f7; --card: #ffffff; --text: #15171c; --muted: #6b7280;
  --line: #e3e5ea; --accent: #2563eb; --accent-text: #fff; --ok: #16a34a; --bad: #dc2626;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --card: #181b21; --text: #e8eaee; --muted: #8b93a1;
    --line: #2a2f38; --accent: #4f8cff; --accent-text: #fff; --ok: #22c55e; --bad: #f87171;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --card: #181b21; --text: #e8eaee; --muted: #8b93a1;
  --line: #2a2f38; --accent: #4f8cff; --accent-text: #fff; --ok: #22c55e; --bad: #f87171;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}
header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 760px; margin: 0 auto; padding: 14px 16px 6px;
}
h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; }
main { max-width: 760px; margin: 0 auto; padding: 8px 16px 40px; }

.tabs { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.tabs button {
  border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600;
  padding: 7px 14px; border-radius: 8px; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-text); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px; margin-bottom: 14px;
}
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.center { text-align: center; }
.name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

button, select, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.primary, .secondary {
  border-radius: 10px; padding: 10px 16px; font-weight: 600; border: 1px solid transparent;
}
.primary { background: var(--accent); color: var(--accent-text); }
.secondary { background: transparent; border-color: var(--line); }
select, textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; width: 100%;
}
textarea { resize: vertical; margin: 10px 0; }
details summary { cursor: pointer; color: var(--muted); margin-top: 12px; }

.drop {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 2px dashed var(--line); border-radius: 12px; padding: 26px 12px; cursor: pointer; text-align: center;
}
.drop.over { border-color: var(--accent); }
.drop strong { color: var(--accent); font-size: 17px; }

.settings { display: grid; gap: 14px; }
.settings label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
.settings output { font-weight: 400; color: var(--muted); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.settings p { margin: 0; }

.qrwrap {
  background: #fff; border-radius: 10px; margin: 14px auto 6px; padding: 0;
  width: min(100%, 72vh); aspect-ratio: 1; cursor: zoom-in;
}
canvas#qr { width: 100%; height: 100%; display: block; image-rendering: pixelated; image-rendering: crisp-edges; }
.full {
  position: fixed; inset: 0; background: #fff; z-index: 10;
  display: flex; align-items: center; justify-content: center; cursor: zoom-out;
}
.full canvas#qr { width: min(100vw, 100vh); height: min(100vw, 100vh); }

.view { position: relative; margin-top: 14px; border-radius: 12px; overflow: hidden; background: #000; aspect-ratio: 1; }
.view video { width: 100%; height: 100%; object-fit: cover; display: block; }
.aim { position: absolute; inset: 0; box-shadow: inset 0 0 0 3px rgba(255,255,255,.35); border-radius: 12px; pointer-events: none; }
.view.hit .aim { box-shadow: inset 0 0 0 3px var(--ok); }
#camSel { width: auto; max-width: 45%; }

.stats { margin-top: 14px; display: grid; gap: 6px; }
.bar { height: 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 99px; overflow: hidden; }
.bar div { height: 100%; width: 0; background: var(--accent); transition: width .15s; }

.result .row { flex-wrap: wrap; }
.result img, .result video { max-width: 100%; border-radius: 8px; margin-top: 10px; display: block; }
.result pre {
  white-space: pre-wrap; word-break: break-word; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px; max-height: 300px; overflow: auto; margin: 10px 0 0;
}
.ok { color: var(--ok); } .bad { color: var(--bad); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
