:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --ink: #1c1917;
  --muted: #6b635b;
  --line: #e7e0d6;
  --accent: #c2410c;
  --accent-ink: #ffffff;
  --accent-soft: #fff1e8;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --warn: #a16207;
  --warn-soft: #fdf6e3;
  --ok: #15803d;
  --ok-soft: #e9f7ee;
  --info-soft: #eef2f7;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(28 25 23 / 6%), 0 4px 16px rgb(28 25 23 / 5%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14110f;
    --surface: #1e1a17;
    --ink: #f3eee8;
    --muted: #a99f95;
    --line: #342d28;
    --accent: #fb7a3c;
    --accent-ink: #1c0e05;
    --accent-soft: #3a1f12;
    --danger: #f87171;
    --danger-soft: #3b1717;
    --warn: #facc15;
    --warn-soft: #33290d;
    --ok: #4ade80;
    --ok-soft: #10301c;
    --info-soft: #232a33;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14110f;
  --surface: #1e1a17;
  --ink: #f3eee8;
  --muted: #a99f95;
  --line: #342d28;
  --accent: #fb7a3c;
  --accent-ink: #1c0e05;
  --accent-soft: #3a1f12;
  --danger: #f87171;
  --danger-soft: #3b1717;
  --warn: #facc15;
  --warn-soft: #33290d;
  --ok: #4ade80;
  --ok-soft: #10301c;
  --info-soft: #232a33;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
main, .top, .foot { max-width: 720px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
a { color: var(--accent); }
img { max-width: 100%; }

.top { display: flex; align-items: center; justify-content: space-between; padding-top: 14px; padding-bottom: 6px; gap: 12px; }
.brand { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.15rem; letter-spacing: -0.01em; }
.freshness { font-size: 0.8rem; color: var(--muted); text-align: right; }

.hero h1 { font-size: clamp(1.6rem, 6vw, 2.2rem); line-height: 1.15; margin: 14px 0 8px; letter-spacing: -0.02em; text-wrap: balance; }
.hero p { margin: 0 0 18px; color: var(--muted); }
.hero strong { color: var(--accent); }

.tabs {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px;
  position: sticky; top: calc(8px + env(safe-area-inset-top, 0px)); z-index: 5; box-shadow: var(--shadow);
}
.tabs button {
  border: 0; background: none; color: var(--muted); font: inherit; font-size: 0.9rem; font-weight: 600;
  padding: 9px 2px; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
.count { display: inline-block; min-width: 1.3em; padding: 0 5px; border-radius: 999px; background: var(--line); color: var(--ink); font-size: 0.75rem; }
.count.warn { background: var(--danger); color: #fff; }

.panel { padding: 18px 0 8px; }
.hint { color: var(--muted); font-size: 0.92rem; margin: 0 0 12px; }

.searchbar { display: flex; gap: 8px; margin-bottom: 12px; }
input, textarea, select {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; width: 100%; min-width: 0;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
textarea { resize: vertical; }

.btn {
  font: inherit; font-weight: 650; border-radius: 12px; padding: 11px 16px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-align: center;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.small { padding: 8px 12px; font-size: 0.88rem; border-radius: 10px; }
.btn:active { transform: translateY(1px); }
.row { display: flex; gap: 8px; margin-top: 10px; }
.row.wrap { flex-wrap: wrap; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 0.85rem; color: var(--muted); margin-bottom: 14px; }
.chips button { font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 5px 11px; cursor: pointer; }

.results { display: grid; gap: 12px; }
.summary { margin: 4px 0 0; font-weight: 650; }
.summary.danger { color: var(--danger); }
.summary.ok { color: var(--ok); }
.loading { color: var(--muted); }
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 18px; }
.empty p { margin: 0 0 4px; color: var(--muted); }
.empty .ok { color: var(--ok); font-weight: 650; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); overflow-wrap: anywhere;
}
.card.exact, .card.strong, .card.recalled { border-left-color: var(--danger); }
.card.likely { border-left-color: var(--accent); }
.card.possible { border-left-color: var(--warn); }
.card.resolved { border-left-color: var(--ok); }
.card h3 { font-size: 1rem; line-height: 1.35; margin: 6px 0 4px; }
.card p { margin: 4px 0; font-size: 0.92rem; }
.card .product { color: var(--muted); }
.card .models { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.82rem; }
.card .context { font-size: 0.85rem; color: var(--muted); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 0.8rem; color: var(--muted); }
.card-more { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 10px; }
.card-more img { max-height: 200px; border-radius: 10px; display: block; margin-bottom: 8px; background: #fff; }

.chip { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding: 3px 8px; border-radius: 999px; }
.chip.exact, .chip.strong { background: var(--danger-soft); color: var(--danger); }
.chip.likely { background: var(--accent-soft); color: var(--accent); }
.chip.possible { background: var(--warn-soft); color: var(--warn); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.watch { background: var(--info-soft); color: var(--muted); }

.alert { background: var(--danger-soft); border: 1px solid var(--danger); color: var(--ink); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
.alert strong { color: var(--danger); }
.alert p { margin: 4px 0 0; font-size: 0.9rem; }

.clear { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.clear summary { cursor: pointer; color: var(--ok); font-weight: 650; }
.clear ul { padding-left: 18px; color: var(--muted); font-size: 0.9rem; }

.scanner { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 4 / 3; margin-bottom: 12px; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.reticle { position: absolute; inset: 30% 12%; border: 3px solid rgb(255 255 255 / 85%); border-radius: 12px; box-shadow: 0 0 0 999px rgb(0 0 0 / 35%); pointer-events: none; }
.scan-start { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }

.sheet { border: 0; padding: 0; border-radius: 18px; width: min(680px, calc(100vw - 16px)); max-height: calc(100dvh - 24px); background: var(--surface); color: var(--ink); }
.sheet::backdrop { background: rgb(0 0 0 / 50%); }
.wiz { padding: 18px 18px 22px; }
.wiz header { display: flex; justify-content: space-between; align-items: center; }
.wiz h2 { margin: 0; font-size: 1.3rem; }
.wiz .close { font-size: 1.6rem; line-height: 1; background: none; border: 0; color: var(--muted); cursor: pointer; padding: 4px 8px; }
.wiz-title { color: var(--muted); font-size: 0.9rem; margin: 6px 0 12px; }
.steps { padding-left: 22px; margin: 0; display: grid; gap: 14px; }
.steps li::marker { font-weight: 800; color: var(--accent); }
.steps h4 { margin: 0 0 4px; font-size: 1rem; }
.steps p { margin: 4px 0; font-size: 0.92rem; }
.steps img { max-height: 160px; border-radius: 10px; display: block; margin: 6px 0; background: #fff; }
.hazard { background: var(--danger-soft); border-radius: 10px; padding: 8px 10px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin: 10px 0; }
.grid label, .status { display: grid; gap: 4px; font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.grid input { padding: 9px 11px; font-size: 0.92rem; }
.subject { margin-bottom: 8px; font-weight: 600; font-size: 0.92rem; }
.wiz textarea { font-size: 0.88rem; line-height: 1.45; }
.fine { color: var(--muted); font-size: 0.8rem !important; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 0.9rem; z-index: 50;
  max-width: calc(100vw - 32px); box-shadow: var(--shadow);
}

.foot { color: var(--muted); font-size: 0.8rem; padding-top: 24px; padding-bottom: 32px; }
.foot p { margin: 4px 0; }

@media (max-width: 380px) {
  .tabs button { font-size: 0.78rem; }
  .searchbar .btn { padding-left: 12px; padding-right: 12px; }
}

/* ---- v2 components ---- */
.muted { color: var(--muted); }
.wide { width: 100%; }
.linkish { all: unset; cursor: pointer; }
.linkish:hover { text-decoration: underline; text-underline-offset: 3px; }
.linkish:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.feed { margin-top: 22px; display: grid; gap: 12px; }
.feed-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.feed-head h2 { font-size: 1.15rem; margin: 0; letter-spacing: -0.01em; }
.feed-head .muted { font-size: 0.85rem; }
.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filter {
  flex: none; font: inherit; font-size: 0.85rem; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 6px 12px; display: inline-flex; gap: 6px; align-items: center;
}
.filter .n { font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.filter[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.filter[aria-pressed="true"] .n { color: var(--bg); opacity: 0.75; }

.card.feed { border-left-color: var(--line); }
.chip.src { background: var(--info-soft); color: var(--muted); text-transform: none; letter-spacing: 0; font-size: 0.75rem; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0 2px; }
.tag { font-size: 0.72rem; font-weight: 650; padding: 2px 8px; border-radius: 6px; background: var(--danger-soft); color: var(--danger); text-transform: capitalize; }
.card .note { font-size: 0.85rem; color: var(--warn); }

.sheet .wiz h2 { font-size: 1.2rem; line-height: 1.3; margin: 10px 0 6px; text-wrap: balance; }
.sheet .wiz header h2 { margin: 0; }
.sheet section { margin-top: 12px; }
.sheet section h4 { margin: 0 0 4px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.sheet section p { margin: 0 0 4px; font-size: 0.95rem; }
.sheet .hazard { padding: 10px 12px; }
.sheet .hazard h4 { color: var(--danger); }
.hero-img { display: block; max-height: 220px; margin: 10px 0; border-radius: 12px; background: #fff; }
.codes { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.8rem !important; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--info-soft); padding: 8px 10px; border-radius: 8px; }

.or { text-align: center; color: var(--muted); font-size: 0.85rem; margin: 4px 0 10px; }
.ymm { display: grid; grid-template-columns: 1fr 1.4fr 1.4fr auto; gap: 8px; margin-bottom: 12px; }
@media (max-width: 520px) { .ymm { grid-template-columns: 1fr 1fr; } }
.howto { margin-top: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; font-size: 0.92rem; }
.howto summary { cursor: pointer; font-weight: 650; }
.howto ol { padding-left: 20px; display: grid; gap: 8px; }
.bm { cursor: grab; border-style: dashed; }
.backup { margin-top: 16px; }
.alert .row { margin-top: 8px; }
.searchbar .btn { white-space: nowrap; }
.card-head { min-width: 0; }
.card-head .chip { min-width: 0; overflow-wrap: anywhere; }
