:root {
  --bg: #f1f5f9; --fg: #0f172a; --card: #ffffff; --muted: #64748b; --line: #e2e8f0;
  --primary: #2563eb; --primary-fg: #fff; --ok: #16a34a; --ok-bg: #dcfce7;
  --warn: #b45309; --warn-bg: #fef3c7; --none: #475569; --none-bg: #e2e8f0;
  --danger: #dc2626; --plate: #facc15;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a; --fg: #e2e8f0; --card: #1e293b; --muted: #94a3b8; --line: #334155;
    --ok-bg: #14532d; --ok: #4ade80; --warn-bg: #451a03; --warn: #fbbf24;
    --none-bg: #1e293b; --none: #cbd5e1;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.top { display: flex; align-items: baseline; justify-content: space-between; padding: 12px 16px; background: #1e293b; color: #fff; }
.top h1 { margin: 0; font-size: 20px; }
.top .muted { color: #94a3b8; }
main { padding: 16px; max-width: 640px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }
.row { display: flex; gap: 8px; align-items: center; margin: 12px 0; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.mono, .plate-input { font-family: ui-monospace, "Roboto Mono", Menlo, monospace; }

input, textarea {
  font: inherit; color: inherit; background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px; width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; }
.plate-input {
  font-size: 36px; font-weight: 700; letter-spacing: 4px; text-align: center; text-transform: uppercase;
  background: var(--plate); color: #111; border: 3px solid #111; padding: 14px 8px;
}
.plate-input::placeholder { color: #0006; letter-spacing: 2px; font-size: 24px; }

.btn {
  font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--card); color: var(--fg);
  border-radius: 10px; padding: 10px 16px; min-height: 44px; cursor: pointer;
}
.btn.primary { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.big { flex: 1; min-height: 56px; font-size: 17px; }
.btn:active { transform: scale(.98); }

.result { margin-top: 8px; }
.banner { border-radius: 14px; padding: 16px; margin-bottom: 12px; }
.banner h2 { margin: 0 0 4px; font-size: 26px; letter-spacing: 1px; }
.banner.match { background: var(--ok-bg); color: var(--ok); border: 2px solid var(--ok); }
.banner.possible { background: var(--warn-bg); color: var(--warn); border: 2px solid var(--warn); }
.banner.none { background: var(--none-bg); color: var(--none); border: 2px dashed var(--none); }
.vcard { background: var(--card); color: var(--fg); border-radius: 12px; padding: 12px 14px; margin-top: 8px; border: 1px solid var(--line); }
.vcard .plate { font-family: ui-monospace, monospace; font-weight: 700; background: var(--plate); color: #111; padding: 2px 8px; border-radius: 4px; }
.vcard .nick { font-weight: 700; font-size: 18px; margin-left: 6px; }
.vcard .reason { font-size: 13px; color: var(--warn); }
.vcard dl { margin: 8px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 15px; }
.vcard dt { color: var(--muted); }
.vcard dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.ocr-info { display: flex; gap: 10px; align-items: center; font-size: 14px; color: var(--muted); }
.ocr-info img { height: 40px; max-width: 55%; border: 1px solid var(--line); border-radius: 4px; background: #fff; }

.vlist { list-style: none; padding: 0; margin: 0; }
.vlist li { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; cursor: pointer; }
.vlist .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin-bottom: 14px; }
.card h2 { margin: 0 0 6px; font-size: 17px; }
.radio { display: flex; gap: 6px; align-items: center; margin-right: 12px; }
.radio input { width: auto; }
.danger-zone { border-color: var(--danger); }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; border: 0; background: none; color: var(--muted); font: inherit; font-size: 22px;
  padding: 8px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tabs button span { font-size: 12px; font-weight: 600; }
.tabs button.active { color: var(--primary); }

dialog { border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 24px)); background: var(--card); color: var(--fg); }
dialog::backdrop { background: #0008; }
dialog form { padding: 18px; }
dialog h2 { margin-top: 0; }
dialog label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 10px; }
dialog label input, dialog label textarea { margin-top: 4px; color: var(--fg); }
.error { color: var(--danger); min-height: 1em; margin: 0; }

.overlay { position: fixed; inset: 0; background: #000; z-index: 20; display: flex; flex-direction: column; }
.overlay[hidden] { display: none; }
.overlay video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.guide {
  position: absolute; left: 7.5%; width: 85%; top: 35%; aspect-ratio: 2 / 1;
  border: 3px solid var(--plate); border-radius: 12px; box-shadow: 0 0 0 100vmax #0009;
}
.guide span { position: absolute; top: -32px; left: 0; right: 0; text-align: center; color: #fff; font-weight: 600; }
.scan-status { position: absolute; left: 0; right: 0; bottom: 130px; text-align: center; color: #fff; font-weight: 600; text-shadow: 0 1px 3px #000; }
.scan-status.static { position: static; color: var(--fg); text-shadow: none; min-height: 1.4em; }
.scanner-bar {
  position: absolute; bottom: 0; left: 0; right: 0; display: flex; justify-content: space-around; align-items: center;
  padding: 20px 20px calc(24px + env(safe-area-inset-bottom));
}
.scanner-bar .btn { width: 56px; height: 56px; border-radius: 50%; font-size: 22px; background: #0008; color: #fff; border-color: #fff6; }
.scanner-bar .btn.on { background: var(--plate); color: #111; }
.shutter { width: 76px; height: 76px; border-radius: 50%; border: 5px solid #fff; background: #fff4; }
.shutter:active { background: #fff; }
.shutter:disabled { opacity: .4; }

.overlay.light { background: var(--bg); color: var(--fg); padding: 16px; overflow: auto; }
.crop-wrap { position: relative; align-self: center; touch-action: none; user-select: none; }
.crop-wrap img { display: block; max-width: 100%; max-height: 60vh; }
.crop-box { position: absolute; border: 3px solid var(--plate); box-shadow: 0 0 0 100vmax #0007; cursor: move; touch-action: none; }
.crop-box .handle { position: absolute; right: -14px; bottom: -14px; width: 28px; height: 28px; background: var(--plate); border-radius: 50%; border: 2px solid #111; }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 15;
  background: #111; color: #fff; padding: 10px 16px; border-radius: 20px; max-width: 90vw;
}

.thumbs { display: flex; gap: 8px; overflow-x: auto; margin-top: 10px; }
.thumbs img { height: 88px; width: auto; max-width: 140px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); flex: none; cursor: zoom-in; }
.thumbs.edit { margin: 4px 0 8px; min-height: 0; }
.thumbs .t { position: relative; flex: none; }
.thumbs .t img { height: 72px; }
.thumbs .t button { position: absolute; top: -6px; right: -6px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: var(--danger); color: #fff; font-weight: 700; }
.field-label { font-size: 14px; color: var(--muted); }
.vlist li { display: flex; gap: 12px; align-items: center; }
.vlist .lthumb { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; flex: none; }
.vlist .lbody { min-width: 0; }
.viewer { align-items: center; justify-content: center; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
