:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0efea;
  --ink: #1b1c1e;
  --muted: #62666d;
  --faint: #8c9097;
  --line: #e3e1da;
  --focus: #2458b8;
  --buy: #1c7547;
  --buy-bg: #e3f3ea;
  --offer: #2254b0;
  --offer-bg: #e5edfb;
  --auction: #6a3db5;
  --auction-bg: #efe8fb;
  --check: #8f5300;
  --check-bg: #fbf0dc;
  --bad: #b3261e;
  --bad-bg: #fbe6e4;
  --good: #1c7547;
  --pass: #62666d;
  --pass-bg: #eeede8;
  --shadow: 0 1px 2px rgba(20, 20, 20, 0.04), 0 4px 16px rgba(20, 20, 20, 0.04);
  --radius: 14px;
  --gutter: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16171a;
    --surface: #1f2024;
    --surface-2: #26282d;
    --ink: #ecebe7;
    --muted: #a3a7ae;
    --faint: #7d8189;
    --line: #2f3137;
    --focus: #7aa7ff;
    --buy: #5fd09a;
    --buy-bg: #173326;
    --offer: #8db3ff;
    --offer-bg: #1a2640;
    --auction: #bb9cff;
    --auction-bg: #2a2140;
    --check: #f2b866;
    --check-bg: #36290f;
    --bad: #ff8f86;
    --bad-bg: #3a1c1a;
    --good: #5fd09a;
    --pass: #a3a7ae;
    --pass-bg: #2a2c31;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- top bar */
.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-row {
  max-width: 1180px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  padding: 12px var(--gutter) 8px;
}
.brand { flex: 1; min-width: 0; }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: -0.01em; }
.status { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.ok { background: var(--buy); box-shadow: 0 0 0 3px color-mix(in srgb, var(--buy) 22%, transparent); }
.dot.warn { background: var(--check); }
.dot.bad { background: var(--bad); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; cursor: pointer; flex: none;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.tabs {
  max-width: 1180px; margin: 0 auto;
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  padding: 0 var(--gutter) 10px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 6px 12px; font-size: 14px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; color: var(--muted); text-decoration: none;
}
.tab b { font-weight: 600; color: var(--ink); }
.tab .count { font-size: 12px; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--surface-2); text-align: center; }
.tab[aria-current="page"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.tab[aria-current="page"] b { color: var(--bg); }
.tab[aria-current="page"] .count { background: color-mix(in srgb, var(--bg) 22%, transparent); }

/* ---------- page */
main { max-width: 1180px; margin: 0 auto; padding: 14px var(--gutter) 40px; }
.banner {
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px;
  background: var(--check-bg); color: var(--check); font-size: 14px;
  display: flex; gap: 10px; align-items: flex-start;
}
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner.info { background: var(--offer-bg); color: var(--offer); }
.banner b { color: inherit; }
.banner .grow { flex: 1; }
.banner button { flex: none; }

.market { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 calc(-1 * var(--gutter)) 14px; padding: 0 var(--gutter); }
.market::-webkit-scrollbar { display: none; }
.mk { flex: none; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: 12.5px; color: var(--muted); }
.mk b { display: block; color: var(--ink); font-size: 13.5px; }

.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr)); }

/* ---------- deal card */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px; display: flex; flex-direction: column; gap: 10px;
  min-width: 0;
}
.card.fresh { border-color: color-mix(in srgb, var(--buy) 55%, var(--line)); }
.card-top { display: flex; gap: 12px; min-width: 0; }
.thumb {
  width: 92px; height: 92px; flex: none; border-radius: 10px; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--line); cursor: zoom-in; padding: 0; position: relative;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .n { position: absolute; right: 4px; bottom: 4px; font-size: 11px; background: rgba(0,0,0,.6); color: #fff; border-radius: 6px; padding: 0 5px; }
.card-main { flex: 1; min-width: 0; }
.meta { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.tier { font-size: 12px; font-weight: 650; border-radius: 6px; padding: 2px 7px; letter-spacing: 0.01em; }
.tier.buy { background: var(--buy-bg); color: var(--buy); }
.tier.offer { background: var(--offer-bg); color: var(--offer); }
.tier.auction { background: var(--auction-bg); color: var(--auction); }
.tier.check { background: var(--check-bg); color: var(--check); }
.tier.rejected { background: var(--bad-bg); color: var(--bad); }
.tier.pass, .tier.ignored { background: var(--pass-bg); color: var(--pass); }
.title { margin: 4px 0 0; font-size: 14.5px; font-weight: 500; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.price { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.price .each { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.price .each small { font-size: 13px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.price .total { font-size: 13px; color: var(--muted); }
.reason { font-size: 14px; font-weight: 550; }
.reason.buy { color: var(--buy); }
.reason.offer { color: var(--offer); }
.reason.auction { color: var(--auction); }
.reason.check { color: var(--check); }
.reason.rejected { color: var(--bad); }
.reason.pass, .reason.ignored { color: var(--muted); font-weight: 500; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12.5px; border-radius: 999px; padding: 2px 9px; background: var(--surface-2); color: var(--muted); }
.chip.good { background: var(--buy-bg); color: var(--good); }
.chip.warn { background: var(--check-bg); color: var(--check); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.quote { font-size: 13px; color: var(--muted); background: var(--surface-2); border-radius: 10px; padding: 8px 10px; margin: 0; overflow-wrap: anywhere; }
.quote b { color: var(--bad); font-weight: 600; }
.seller { font-size: 12.5px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 8px 12px; font-size: 14px; font-weight: 550; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; color: var(--ink);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.primary:hover { opacity: 0.9; }
.btn.buy { background: var(--buy); border-color: var(--buy); color: #fff; }
.btn.offer { background: var(--offer); border-color: var(--offer); color: #fff; }
.btn.auction { background: var(--auction); border-color: var(--auction); color: #fff; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn.buy, :root:not([data-theme="light"]) .btn.offer, :root:not([data-theme="light"]) .btn.auction { color: #111; }
}
.btn.grow { flex: 1 1 auto; }
.btn.quiet { border-color: transparent; background: transparent; color: var(--muted); padding-left: 8px; padding-right: 8px; }
.btn.quiet:hover { background: var(--surface-2); color: var(--ink); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn svg { width: 16px; height: 16px; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty h2 { color: var(--ink); font-size: 17px; margin: 0 0 6px; }
.empty p { margin: 0 auto; max-width: 420px; }

/* ---------- sign in */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px var(--gutter); }
.login form { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 24px; box-shadow: var(--shadow); }
.login h1 { font-size: 20px; margin: 0 0 4px; }
.login p { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.login .btn { width: 100%; }
.login .error { color: var(--bad); font-size: 13.5px; min-height: 20px; margin: 8px 0 0; }

/* ---------- forms / settings */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .lbl { font-size: 13px; font-weight: 600; color: var(--muted); }
input[type="text"], input[type="password"], input[type="number"], input[type="time"], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 9px 11px; min-height: 42px; font-size: 16px; /* 16px stops iOS zooming in */
}
textarea { min-height: 84px; resize: vertical; line-height: 1.4; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 18%, transparent); }

.settings { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.section > h2 { font-size: 16px; margin: 0 0 2px; letter-spacing: -0.01em; }
.section > .sub { color: var(--muted); font-size: 13.5px; margin: 0 0 14px; }
.rows { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); min-width: 0; }
.row:first-child { border-top: 0; padding-top: 0; }
.row .txt { flex: 1; min-width: 0; }
.row .txt b { display: block; font-weight: 550; font-size: 14.5px; }
.row .txt span { display: block; color: var(--muted); font-size: 12.5px; }
.row .ctl { flex: none; display: flex; align-items: center; gap: 6px; }
.money-in { position: relative; width: 104px; }
.money-in input { padding-left: 22px; text-align: right; }
.money-in::before { content: "$"; position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 15px; }
.pct-in { position: relative; width: 92px; }
.pct-in input { padding-right: 26px; text-align: right; }
.pct-in::after { content: "%"; position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.small-in { width: 84px; text-align: right; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.help { font-size: 13px; color: var(--muted); }
.help a { color: var(--focus); }
.steps { margin: 0; padding-left: 20px; font-size: 14px; display: flex; flex-direction: column; gap: 6px; }
.steps li::marker { color: var(--muted); font-weight: 600; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; background: var(--surface-2); border-radius: 8px; padding: 2px 6px; overflow-wrap: anywhere; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline > input { flex: 1 1 160px; min-width: 0; }
.ok-text { color: var(--good); font-size: 13.5px; font-weight: 550; }
.bad-text { color: var(--bad); font-size: 13.5px; }
.meter { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--buy); border-radius: 99px; }
.meter.warn > i { background: var(--check); }
.meter.bad > i { background: var(--bad); }

.search-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.search-row:first-child { border-top: 0; padding-top: 0; }
.search-row .opts { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.search-row .opts select { width: auto; min-height: 36px; padding: 5px 8px; font-size: 14px; }
.search-row .opts input { width: 64px; min-height: 36px; padding: 5px 8px; font-size: 14px; text-align: right; }

/* switch */
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + span { background: var(--buy); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

details.more > summary { cursor: pointer; font-weight: 600; font-size: 15px; list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::after { content: "Show"; font-size: 13px; font-weight: 500; color: var(--muted); }
details.more[open] > summary::after { content: "Hide"; }
details.more[open] > summary { margin-bottom: 12px; }

.savebar {
  position: sticky; bottom: 0; z-index: 5; margin: 0 calc(-1 * var(--gutter));
  padding: 12px var(--gutter) calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: center;
}
.savebar .msg { flex: 1; font-size: 13.5px; color: var(--muted); min-width: 0; }
.savebar .msg.bad { color: var(--bad); }

/* ---------- toast + photo viewer */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  z-index: 50; max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.viewer { position: fixed; inset: 0; z-index: 40; background: #0b0b0d; color: #fff; display: flex; flex-direction: column; }
.viewer-top { display: flex; align-items: center; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; }
.viewer-top .t { flex: 1; font-size: 13px; opacity: .8; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-top button, .viewer-nav button { background: rgba(255,255,255,.12); border: 0; color: #fff; border-radius: 10px; min-width: 40px; height: 40px; cursor: pointer; font-size: 15px; padding: 0 12px; }
.viewer-stage { flex: 1; overflow: auto; display: grid; place-items: center; touch-action: pan-x pan-y pinch-zoom; }
.viewer-stage img { max-width: 100%; max-height: 100%; object-fit: contain; cursor: zoom-in; }
.viewer-stage.zoomed { place-items: start; }
.viewer-stage.zoomed img { max-width: none; max-height: none; width: 220%; cursor: zoom-out; }
.viewer-nav { display: flex; justify-content: center; gap: 12px; align-items: center; padding: 10px 14px calc(14px + env(safe-area-inset-bottom)); font-size: 13px; }
.viewer-strip { display: flex; gap: 6px; overflow-x: auto; padding: 0 14px 10px; }
.viewer-strip button { flex: none; width: 54px; height: 54px; padding: 0; border-radius: 8px; overflow: hidden; border: 2px solid transparent; background: #222; cursor: pointer; }
.viewer-strip button[aria-current="true"] { border-color: #fff; }
.viewer-strip img { width: 100%; height: 100%; object-fit: cover; display: block; }

@media (min-width: 760px) {
  :root { --gutter: 24px; }
  .thumb { width: 108px; height: 108px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- sort, new-deals pill, clearing */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; border-radius: 8px; padding: 6px 12px; font-size: 13.5px; font-weight: 550; color: var(--muted); cursor: pointer; min-height: 34px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.new-pill {
  position: sticky; top: 120px; z-index: 6; margin-left: auto;
  border: 0; border-radius: 999px; padding: 8px 14px; background: var(--buy); color: #fff;
  font-size: 13.5px; font-weight: 650; cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,.15);
}
.card.seen { opacity: 0.55; }
.card.is-sample { border-style: dashed; }
.chip.sample { background: var(--auction-bg); color: var(--auction); font-weight: 600; }
.banner.sample { background: var(--auction-bg); color: var(--auction); flex-wrap: wrap; }
.banner-actions { display: flex; gap: 6px; flex: none; }
.caught { text-align: center; color: var(--muted); padding: 32px 16px 12px; }
.caught h2 { color: var(--ink); font-size: 17px; margin: 0 0 6px; }
.caught p { margin: 0 auto 14px; max-width: 420px; font-size: 14px; }
.inline.center { justify-content: center; }
.empty .inline.center { margin-top: 14px; }
