:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --text: #1c1b18;
  --muted: #6b675e;
  --line: #e2dfd6;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #d8efe9;
  --warn: #b45309;
  --warn-soft: #fdf0dc;
  --danger: #b42318;
  --ok: #15803d;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 18, 12, .06), 0 4px 16px rgba(20, 18, 12, .06);
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1412;
    --surface: #131d1b;
    --surface-2: #1b2825;
    --text: #ecebe6;
    --muted: #9aa39f;
    --line: #26332f;
    --accent: #2dd4bf;
    --accent-ink: #062320;
    --accent-soft: #123a35;
    --warn: #fbbf24;
    --warn-soft: #3a2b0c;
    --danger: #f87171;
    --ok: #4ade80;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
}
body.no-tabbar { padding-bottom: calc(var(--safe-b) + 24px); }
img { max-width: 100%; display: block; }
a { color: var(--accent); }
h2 { font-size: 1.15rem; margin: 0 0 8px; }
h3 { font-size: 1rem; margin: 0 0 6px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }
[hidden] { display: none !important; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 6px;
  padding: calc(var(--safe-t) + 10px) 12px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.1rem; margin: 0 0 0 4px; font-weight: 700; letter-spacing: -.01em; }
.topbar-spacer { flex: 1; }
.icon-btn {
  border: 0; background: transparent; color: var(--text); width: 40px; height: 40px;
  display: grid; place-items: center; border-radius: 10px; cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }

main { max-width: 640px; margin: 0 auto; padding: 16px; outline: none; }

/* tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600;
}
.tabbar a svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.tabbar a.active { color: var(--accent); }
.tabbar .snap-circle {
  width: 48px; height: 48px; border-radius: 50%; margin-top: -18px;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
  box-shadow: 0 4px 14px rgba(15, 118, 110, .35);
}
.tabbar .snap-circle svg { stroke: currentColor; }

/* cards, lists */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.list { display: grid; gap: 10px; }
.item-row {
  display: grid; grid-template-columns: 72px 1fr auto; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px; color: inherit; text-decoration: none;
}
.item-row .thumb, .thumb {
  width: 72px; height: 72px; border-radius: 10px; object-fit: cover; background: var(--surface-2);
}
.thumb.placeholder { display: grid; place-items: center; color: var(--muted); font-size: .7rem; text-align: center; }
.item-row .title { font-weight: 650; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item-row .meta { font-size: .82rem; color: var(--muted); margin-top: 2px; }
.price { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

.chip {
  display: inline-block; font-size: .72rem; font-weight: 650; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); text-transform: capitalize;
}
.chip.listed { background: var(--accent-soft); color: var(--accent); }
.chip.sold, .chip.traded { background: #e7f6ec; color: var(--ok); }
.chip.match { background: var(--warn-soft); color: var(--warn); }
@media (prefers-color-scheme: dark) { .chip.sold, .chip.traded { background: #12301d; } }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty svg { width: 56px; height: 56px; stroke: currentColor; fill: none; stroke-width: 1.5; margin: 0 auto 10px; display: block; }

/* buttons */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 650; padding: 12px 16px; border-radius: 12px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
  min-height: 48px; touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.big { min-height: 56px; font-size: 1.05rem; }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* forms */
label.field { display: block; }
label.field > span, .field-label { display: block; font-size: .85rem; font-weight: 650; margin-bottom: 6px; }
.req::after { content: " *"; color: var(--danger); }
input[type=text], input[type=email], input[type=tel], input[type=number], input[type=search], select, textarea {
  width: 100%; font: inherit; font-size: 16px; /* 16px stops iOS zoom */
  color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px; min-height: 46px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.money { position: relative; }
.money::before { content: "$"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.money input { padding-left: 24px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg.wrap { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.seg button {
  font: inherit; font-weight: 650; font-size: .92rem; padding: 10px 6px; min-height: 46px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer;
}
.seg button[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* capture */
.capture-zone {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 28px 16px; text-align: center;
  background: var(--surface);
}
.capture-zone svg { width: 48px; height: 48px; stroke: var(--accent); fill: none; stroke-width: 1.6; margin: 0 auto 8px; display: block; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.preview { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; }
.preview img { width: 100%; max-height: 52vh; object-fit: contain; margin: 0 auto; }
.preview .badge {
  position: absolute; left: 8px; bottom: 8px; background: rgba(0,0,0,.62); color: #fff;
  font-size: .75rem; padding: 4px 8px; border-radius: 8px;
}
.privacy-note { display: flex; gap: 8px; font-size: .82rem; color: var(--muted); align-items: flex-start; }
.privacy-note svg { flex: none; width: 18px; height: 18px; stroke: var(--accent); fill: none; stroke-width: 2; margin-top: 1px; }

/* analyzing */
.analyzing { text-align: center; padding-top: 12px; }
.analyzing .photo-wrap { position: relative; border-radius: var(--radius); overflow: hidden; max-width: 360px; margin: 0 auto 20px; }
.analyzing .photo-wrap img { width: 100%; filter: saturate(.8); }
.scanline {
  position: absolute; left: 0; right: 0; height: 3px; background: var(--accent);
  box-shadow: 0 0 18px 4px var(--accent); animation: scan 1.8s ease-in-out infinite alternate;
}
@keyframes scan { from { top: 4%; } to { top: 94%; } }
.spinner {
  width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite; margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .scanline, .spinner { animation: none; } }

/* valuation */
.value-hero { text-align: center; padding: 18px 12px; }
.value-hero .mid { font-size: 2.4rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.value-hero .range { color: var(--muted); font-variant-numeric: tabular-nums; }
.conf { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin: 10px auto 4px; max-width: 220px; }
.conf > i { display: block; height: 100%; background: var(--accent); }
.conf.low > i { background: var(--warn); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
details.card summary { cursor: pointer; font-weight: 650; }

.detail-photo { border-radius: var(--radius); overflow: hidden; background: var(--surface-2); }
.detail-photo img { width: 100%; max-height: 60vh; object-fit: contain; }
.listing-copy { white-space: pre-wrap; font-size: .9rem; background: var(--surface-2); border-radius: 10px; padding: 12px; }

.search-row { display: flex; gap: 8px; }
.cats { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.cats::-webkit-scrollbar { display: none; }
.cats button {
  flex: none; font: inherit; font-size: .85rem; font-weight: 600; padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer;
}
.cats button[aria-pressed=true] { background: var(--text); color: var(--bg); border-color: var(--text); }

.banner { border-radius: 12px; padding: 12px 14px; font-size: .9rem; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.info { background: var(--accent-soft); color: var(--accent); }
.error-text { color: var(--danger); font-size: .9rem; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .9rem;
  max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.2);
}

.brand-hero { text-align: center; padding: 24px 0 8px; }
.brand-hero img { width: 72px; height: 72px; border-radius: 18px; margin: 0 auto 12px; }
.brand-hero h2 { font-size: 1.5rem; }
