:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --ink: #14171a;
  --muted: #5d636b;
  --line: #dcd8d0;
  --accent: #14171a;
  --accent-ink: #ffffff;
  --good: #187a43;
  --good-bg: #e3f3e8;
  --warn: #9a5b00;
  --warn-bg: #fdf0d9;
  --bad: #b3261e;
  --bad-bg: #fbe4e2;
  --brand: #f2b705;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1113;
    --surface: #1a1d21;
    --ink: #f1efe9;
    --muted: #a0a6ad;
    --line: #2d3238;
    --accent: #f2b705;
    --accent-ink: #14171a;
    --good: #5fd18f;
    --good-bg: #13301f;
    --warn: #f3b75a;
    --warn-bg: #352610;
    --bad: #ff8a80;
    --bad-bg: #3a1714;
    --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.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); margin: 0; }
.fineprint { color: var(--muted); font-size: 13px; margin: 18px 2px 8px; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: #14171a; color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 30px; height: 30px; color: var(--brand); }
.brand h1 { font-size: 20px; letter-spacing: -.01em; }
.top-actions { display: flex; gap: 4px; }
.icon-btn { width: 44px; height: 44px; border: 0; background: transparent; color: #fff; border-radius: 10px; display: grid; place-items: center; }
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:active { background: rgba(255,255,255,.12); }

main { max-width: 720px; margin: 0 auto; padding: 16px; }

.banner { background: var(--warn-bg); color: var(--warn); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; font-size: 14px; }
.banner strong { display: block; margin-bottom: 2px; }

.capture { display: grid; gap: 10px; }
.row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.capture > * { min-width: 0; }
.big-btn {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; min-height: 72px; box-shadow: var(--shadow); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.big-btn:active { transform: scale(.985); }
.big-btn svg { width: 28px; height: 28px; flex: none; }
.big-btn span { display: grid; }
.big-btn small { color: var(--muted); font-size: 13px; }
.big-btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; min-height: 96px; }
.big-btn.primary small { color: inherit; opacity: .75; }
.big-btn.primary strong { font-size: 19px; }
.row2 .big-btn { flex-direction: column; align-items: flex-start; gap: 8px; }

.type-search { display: flex; gap: 8px; margin-top: 2px; }
.type-search input { flex: 1; min-width: 0; padding: 13px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.type-search button { padding: 0 18px; border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.progress { text-align: center; padding: 40px 0; }
.spinner { width: 36px; height: 36px; border: 4px solid var(--line); border-top-color: var(--brand); border-radius: 50%; margin: 0 auto 12px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.results-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin: 6px 0 12px; }
.results-head h2 { font-size: 22px; }
.head-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.solid { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 600; }
.note { background: var(--surface); border-left: 4px solid var(--brand); padding: 10px 12px; border-radius: 8px; font-size: 14px; }

.totals { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; box-shadow: var(--shadow); }
.totals-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.totals .k { color: var(--muted); font-size: 13px; display: block; }
.totals .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.totals .lot-verdict { margin-top: 12px; padding: 10px 12px; border-radius: 10px; font-weight: 600; }

.items { display: grid; gap: 12px; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.item-top { display: flex; gap: 12px; align-items: flex-start; }
.thumb { width: 56px; height: 56px; object-fit: contain; border-radius: 8px; background: #fff; flex: none; }
.item-name h3 { font-size: 17px; }
.sub { font-size: 13px; margin-top: 2px; }
.low-conf { color: var(--warn); }

.prices { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; margin-top: 12px; }
.prices > div { background: var(--bg); border-radius: 10px; padding: 10px; }
.label { display: block; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.range { font-variant-numeric: tabular-nums; }
.range .mid { font-size: 24px; font-weight: 700; display: block; }
.range .lh { font-size: 13px; color: var(--muted); }
.range .lh a { color: var(--ink); font-weight: 600; }
.range .state { font-size: 15px; color: var(--muted); }
.buy { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.buy-box.has { background: var(--good-bg); }
.buy-box.has .buy { color: var(--good); }

.verdict { margin-top: 10px; padding: 9px 12px; border-radius: 10px; font-size: 14px; font-weight: 600; }
.good { background: var(--good-bg); color: var(--good); }
.warn { background: var(--warn-bg); color: var(--warn); }
.bad { background: var(--bad-bg); color: var(--bad); }

.retail { margin-top: 10px; font-size: 14px; }
.retail ul { list-style: none; padding: 0; margin: 6px 0 0; display: grid; gap: 4px; }
.retail li { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px dashed var(--line); padding: 4px 0; }
.retail li a { color: inherit; }
.retail .p { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

.item-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; align-items: flex-start; }
.chip { background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 7px 12px; font-size: 14px; list-style: none; }
.chip:disabled { opacity: .5; }
details.links { width: 100%; }
details.links > summary { display: inline-block; cursor: pointer; }
details.links > summary::-webkit-details-marker { display: none; }
.link-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin-top: 8px; }
.link-grid a { display: block; text-align: center; padding: 9px; border-radius: 10px; background: var(--bg); color: inherit; text-decoration: none; font-size: 14px; }
.link-grid a.key { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.edit-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; margin-top: 10px; }
.edit-form input { grid-column: 1 / -1; min-width: 0; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 16px; }
.edit-form select { min-width: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); padding: 8px; font-size: 16px; }

dialog { border: 0; padding: 0; background: transparent; width: min(560px, 100%); max-height: 92vh; margin: auto auto 0; }
dialog::backdrop { background: rgba(0,0,0,.45); }
.sheet { background: var(--surface); color: var(--ink); border-radius: 18px 18px 0 0; padding: 20px 18px calc(18px + env(safe-area-inset-bottom)); display: grid; gap: 12px; max-height: 92vh; overflow: auto; }
.sheet label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.sheet input, .sheet select { padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); font-size: 16px; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.cost-summary { font-size: 14px; color: var(--ink); }
.cost-summary table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.cost-summary th, .cost-summary td { text-align: right; padding: 5px 4px; border-bottom: 1px solid var(--line); }
.cost-summary th:first-child, .cost-summary td:first-child { text-align: left; }
.cost-summary th { color: var(--muted); font-weight: 500; font-size: 12px; }
.paid-tag { font-style: normal; font-size: 11px; font-weight: 600; background: var(--brand); color: #14171a; border-radius: 6px; padding: 1px 6px; margin-left: 4px; }
.free-left { text-align: center; font-size: 14px; margin-top: 2px; }
.icon-btn.signed-in svg circle { fill: currentColor; }
.stack { display: grid; gap: 10px; margin-top: 10px; }
.err { color: var(--bad); font-size: 14px; margin: 8px 0 0; }
.linkish { background: none; border: 0; color: var(--muted); text-decoration: underline; font-size: 14px; padding: 4px; justify-self: center; }
#signinBox h2, #accountBox h2 { margin-bottom: 6px; }
.meter { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; font-size: 14px; margin: 10px 0; font-variant-numeric: tabular-nums; }
.meter i { grid-column: 1 / -1; display: block; height: 6px; border-radius: 3px; background: linear-gradient(90deg, var(--brand) var(--p), var(--line) var(--p)); }
.plans { display: grid; gap: 10px; margin: 12px 0; }
.plan { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 8px; }
.plan-head { display: flex; justify-content: space-between; align-items: baseline; }
.plan-head span { font-size: 20px; font-weight: 700; }
.plan-head small { font-size: 13px; font-weight: 400; color: var(--muted); }
.plan ul { margin: 0; padding-left: 18px; font-size: 14px; color: var(--muted); }
#accountBox > .ghost { width: 100%; margin-top: 8px; }
#historyList { display: grid; gap: 8px; }
.hist { text-align: left; width: 100%; background: var(--bg); border: 0; border-radius: 10px; padding: 10px 12px; }
.hist small { color: var(--muted); display: block; }

@media (min-width: 640px) {
  dialog { margin: auto; }
  .sheet { border-radius: 18px; }
  .totals-grid { grid-template-columns: repeat(4, 1fr); }
  .link-grid { grid-template-columns: repeat(4, 1fr); }
}
.fineprint a { color: inherit; }
.legal-links { text-align: center; }

.install-card { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; display: grid; gap: 8px; box-shadow: var(--shadow); }
.install-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.install-x { background: none; border: 0; color: var(--muted); font-size: 24px; line-height: 1; padding: 0 4px; cursor: pointer; }
.install-steps { margin: 0; padding-left: 20px; font-size: 15px; display: grid; gap: 4px; }

a.chip { color: inherit; text-decoration: none; display: inline-flex; align-items: center; }
.chip.sold-link { font-weight: 600; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: #14171a; color: #fff; padding: 10px 14px; border-radius: 10px; font-size: 14px; max-width: calc(100% - 32px); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- iPhone app (html.native) ---------- */
.native-only { display: none !important; }
html.native .native-only { display: flex !important; }
html.native .web-only, html.native .top-actions { display: none !important; }
html.native body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
html.native input, html.native textarea { -webkit-user-select: text; user-select: text; }
html.native .top { padding-top: calc(env(safe-area-inset-top) + 10px); }
html.native #liveScanBtn { width: 100%; text-align: left; margin-bottom: 10px; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: rgba(255,255,255,.94); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; }
.tabbar button { flex: 1; background: none; border: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 0; cursor: pointer; }
.tabbar button svg { width: 24px; height: 24px; }
.tabbar button.active { color: var(--ink); font-weight: 600; }
.offline-screen { position: fixed; inset: 0; z-index: 60; background: var(--bg); display: grid; place-items: center; padding: 24px; }
.offline-screen[hidden] { display: none; }
.offline-box { max-width: 360px; text-align: center; display: grid; gap: 12px; }
.offline-icon { font-size: 40px; }
.linkish.danger { color: #b42318; margin-top: 8px; }
html.native #liveScanBtn.hide-free { display: none !important; }
button.link { background: none; border: 0; padding: 6px 0; color: inherit; text-decoration: underline; font: inherit; width: auto; }
#guestBox { margin-bottom: 18px; padding-bottom: 14px; border-bottom: 1px solid rgba(0,0,0,.08); }
