:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --line: #dde1e7;
  --text: #15181d;
  --muted: #5d6673;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --ok: #1a7f37;
  --warn: #b35900;
  --bad: #cf222e;
  --ok-bg: #e7f6ec;
  --warn-bg: #fff3e0;
  --bad-bg: #fdecee;
  --star: #e8a400;
  --s-wmi: #2f6fde;
  --s-vds: #8250df;
  --s-chk: #cf222e;
  --s-yr: #1a7f37;
  --s-plt: #b35900;
  --s-ser: #57606a;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 2px 8px rgb(0 0 0 / .04);
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1f232b;
    --line: #2b313b;
    --text: #e8ebf0;
    --muted: #97a0ad;
    --accent: #4c8dff;
    --ok: #3fb950;
    --warn: #e3a03a;
    --bad: #f47067;
    --ok-bg: #12261a;
    --warn-bg: #2b2112;
    --bad-bg: #2d1517;
    --s-wmi: #5a92ff;
    --s-vds: #a77bf3;
    --s-chk: #f47067;
    --s-yr: #3fb950;
    --s-plt: #e3a03a;
    --s-ser: #8b949e;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
.wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 16px; }
[hidden] { display: none !important; }

/* ---------- header / search */
.top {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.top-inner { display: flex; align-items: center; gap: 16px; padding-top: 10px; padding-bottom: 6px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 650; white-space: nowrap; }
.brand svg { width: 26px; height: 26px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.search { flex: 1; display: flex; gap: 8px; min-width: 0; }
.field { position: relative; flex: 1; min-width: 0; }
.field input {
  width: 100%; height: 46px; padding: 0 64px 0 14px;
  font: 600 17px/1 var(--mono); letter-spacing: .06em; text-transform: uppercase;
  color: var(--text); background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 12px; outline: none;
}
.field input::placeholder { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; font-weight: 400; letter-spacing: 0; text-transform: none; color: var(--muted); }
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.field input.ok { border-color: var(--ok); }
.field input.bad { border-color: var(--warn); }
.count { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font: 12px var(--mono); color: var(--muted); pointer-events: none; }
.count.full { color: var(--ok); }
.icon-btn { flex: none; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.primary { flex: none; height: 46px; padding: 0 20px; border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.primary:disabled { opacity: .55; cursor: default; }
.secondary { height: 42px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 550; display: inline-flex; align-items: center; }
.link { background: none; border: 0; color: var(--accent); padding: 0; }
.hint { margin: 0; min-height: 22px; padding-bottom: 6px; font-size: 13.5px; color: var(--muted); }
.hint.ok { color: var(--ok); }
.hint.warn { color: var(--warn); }
.hint.bad { color: var(--bad); }

@media (max-width: 640px) {
  .top-inner { flex-wrap: wrap; gap: 8px; }
  .brand span { font-size: 15px; }
  .search { flex-basis: 100%; }
  .primary { padding: 0 14px; }
  .field input { font-size: 15.5px; letter-spacing: .01em; padding: 0 10px; }
  .count { display: none; }
}

/* ---------- home */
main { flex: 1; padding-top: 20px; padding-bottom: 32px; }
.home h1 { font-size: clamp(26px, 4vw, 36px); letter-spacing: -.01em; margin-top: 12px; }
.lede { color: var(--muted); max-width: 60ch; font-size: 17px; }
.home h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; }
.where, .recent, .samples { margin-top: 28px; }
.where ul { margin: 0; padding-left: 20px; color: var(--text); }
.where li { margin: 4px 0; }
.recent-head { display: flex; justify-content: space-between; align-items: baseline; }
.recent ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.recent li button {
  width: 100%; text-align: left; padding: 12px 14px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.recent li button:hover { border-color: var(--accent); }
.recent .r-title { display: block; font-weight: 600; }
.recent .r-vin { display: block; font: 13px var(--mono); color: var(--muted); letter-spacing: .04em; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; }
.chip:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- result header */
.r-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.r-title h1 { font-size: clamp(24px, 4.2vw, 38px); letter-spacing: -.015em; }
.r-sub { color: var(--muted); margin-top: 4px; }
.r-actions { display: flex; gap: 8px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 550; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }

/* VIN strip */
.vinstrip { display: grid; grid-template-columns: repeat(17, minmax(0, 1fr)); gap: 3px; margin: 4px 0 6px; }
.vinstrip .c {
  font: 700 clamp(13px, 2.6vw, 22px)/1 var(--mono); text-align: center;
  padding: 10px 0 8px; border-radius: 6px; background: var(--surface);
  border-bottom: 3px solid var(--sc); color: var(--text); cursor: help;
}
.vinstrip .c.bad { background: var(--bad-bg); color: var(--bad); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--muted); margin-bottom: 20px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--sc); margin-right: 6px; vertical-align: -1px; }

/* ---------- tabs */
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; padding: 10px 14px; border: 0; background: none; color: var(--muted); font-weight: 550; border-bottom: 2.5px solid transparent; margin-bottom: -1px; display: flex; align-items: center; gap: 6px; }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tab .n { font-size: 12px; font-weight: 650; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.tab .n.hot { background: var(--bad-bg); color: var(--bad); }
.tab .spin { width: 12px; height: 12px; }

/* ---------- cards */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); align-items: start; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.card h2 { font-size: 15px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.card h2 small { font-weight: 450; color: var(--muted); font-size: 13px; }
.card.wide { grid-column: 1 / -1; }
.kv { display: grid; grid-template-columns: minmax(110px, 40%) 1fr; margin: 0; }
.kv dt, .kv dd { padding: 7px 0; border-top: 1px solid var(--line); margin: 0; font-size: 14.5px; }
.kv dt { color: var(--muted); padding-right: 12px; }
.kv dd { font-weight: 520; overflow-wrap: anywhere; }
.kv dt:first-of-type, .kv dt:first-of-type + dd { border-top: 0; }
.empty { color: var(--muted); font-size: 14.5px; margin: 0; }
.note { font-size: 13.5px; color: var(--muted); margin: 10px 0 0; }
.note.box { background: var(--surface-2); padding: 10px 12px; border-radius: 10px; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; }
.stat b { display: block; font-size: 26px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--muted); }
.stat.bad b { color: var(--bad); }

/* bars */
.bars { display: grid; gap: 6px; }
.bar { display: grid; grid-template-columns: minmax(120px, 34%) 1fr 48px; align-items: center; gap: 10px; font-size: 13.5px; }
.bar .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .track { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--accent); border-radius: 5px; }
.bar .v { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

/* list items (recalls, complaints) */
.items { display: grid; gap: 10px; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.item > summary { list-style: none; cursor: pointer; padding: 14px 16px; display: grid; gap: 4px; }
.item > summary::-webkit-details-marker { display: none; }
.item .i-top { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: 13px; color: var(--muted); }
.item .i-title { font-weight: 600; font-size: 15px; }
.item .i-body { padding: 0 16px 14px; font-size: 14.5px; }
.item .i-body h4 { margin: 12px 0 2px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.item .i-body p { margin: 0; }
.item[open] > summary .i-title { color: var(--accent); }
.flag { font-size: 12px; font-weight: 650; padding: 2px 8px; border-radius: 999px; background: var(--bad-bg); color: var(--bad); }
.flag.warn { background: var(--warn-bg); color: var(--warn); }
.flag.info { background: var(--surface-2); color: var(--muted); }
.more { margin-top: 12px; }

/* ratings */
.stars { color: var(--star); letter-spacing: 1px; font-size: 17px; white-space: nowrap; }
.stars .off { color: var(--line); }
.stars-row { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-top: 1px solid var(--line); font-size: 14.5px; gap: 10px; }
.stars-row:first-of-type { border-top: 0; }
.stars-row .na { color: var(--muted); font-size: 13.5px; }
.overall { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.overall .big { font-size: 40px; font-weight: 700; line-height: 1; }
.crash-pics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.crash-pics a { display: grid; gap: 4px; font-size: 12px; color: var(--muted); text-decoration: none; }
.crash-pics img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; background: var(--surface-2); }
.variant-pick { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.variant-pick button { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 13.5px; }
.variant-pick button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }

/* mpg */
.mpg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; text-align: center; }
.mpg div { background: var(--surface-2); border-radius: 12px; padding: 12px 6px; }
.mpg b { display: block; font-size: 30px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.mpg span { font-size: 12.5px; color: var(--muted); }
.mpg .comb { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
select { font: inherit; font-size: 14px; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; width: 100%; }

/* all fields */
.filter { width: 100%; height: 40px; padding: 0 12px; font: inherit; font-size: 14.5px; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; outline: none; }
.filter:focus { border-color: var(--accent); }


/* loading */
.spin { display: inline-block; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 20px 0; }
.skel { height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; margin: 10px 0; }
@keyframes shimmer { to { background-position: -200% 0; } }
.error { background: var(--bad-bg); color: var(--bad); border-radius: 12px; padding: 14px 16px; }
.error button { margin-top: 8px; }

/* footer */
.foot { color: var(--muted); font-size: 12.5px; padding-top: 16px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }

/* scanner */
.scanner { padding: 0; border: 0; border-radius: 18px; background: #000; color: #fff; width: min(560px, 94vw); max-height: 92vh; overflow: hidden; }
.scanner::backdrop { background: rgb(0 0 0 / .7); }
.scan-view { position: relative; width: 100%; height: min(74vh, calc(min(560px, 94vw) * 4 / 3)); background: #000; }
.scan-view video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-view:not([data-mode="live"]) .scan-frame { display: none; }
.scan-view[data-target="text"] .scan-frame { left: 4%; right: 4%; top: 43%; height: 14%; border-radius: 6px; transition: all .2s; }
.scan-target { display: flex; gap: 4px; padding: 8px; background: #111; }
.scan-target button { flex: 1; height: 36px; border-radius: 9px; border: 0; background: #222; color: #bbb; font-weight: 600; font-size: 14px; }
.scan-target button[aria-pressed="true"] { background: #fff; color: #000; }
.scan-view img { width: 100%; height: 100%; object-fit: contain; display: block; }
.scan-frame { position: absolute; left: 8%; right: 8%; top: 38%; height: 24%; border: 2.5px solid rgb(255 255 255 / .9); border-radius: 12px; box-shadow: 0 0 0 9999px rgb(0 0 0 / .35); }
.scan-status { position: absolute; left: 0; right: 0; bottom: 12px; text-align: center; margin: 0; font-size: 14px; text-shadow: 0 1px 3px #000; padding: 0 12px; }
.scan-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; padding: 12px; background: #111; }
.scan-actions #scan-use { background: #fff; color: #000; margin-right: auto; }
.scan-actions .secondary { background: #222; border-color: #333; color: #fff; cursor: pointer; }

@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; }
  .card { padding: 14px; }
  .r-actions .secondary { height: 38px; padding: 0 12px; font-size: 14px; }
  .bar { grid-template-columns: minmax(90px, 38%) 1fr 40px; }
}
@media print {
  .top, .foot, .tabs, .r-actions { display: none !important; }
  .tabpanel[hidden] { display: block !important; }
  .card, .item { box-shadow: none; break-inside: avoid; }
}
