:root {
  --bg: #fbf8f4;
  --surface: #ffffff;
  --ink: #1d1a17;
  --muted: #6d6660;
  --line: #ebe4dc;
  --brand: #e8502f;
  --brand-ink: #ffffff;
  --brand-soft: #fde9e3;
  --good: #15803d;
  --good-soft: #e3f4e8;
  --shadow: 0 1px 2px rgba(29, 26, 23, .05), 0 6px 24px rgba(29, 26, 23, .06);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151311;
    --surface: #1f1c19;
    --ink: #f3eee8;
    --muted: #a59d95;
    --line: #34302b;
    --brand: #ff6a45;
    --brand-soft: #3a2119;
    --good: #4ade80;
    --good-soft: #17301f;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 24px rgba(0,0,0,.25);
  }
}
:root[data-theme="dark"] {
    --bg: #151311;
    --surface: #1f1c19;
    --ink: #f3eee8;
    --muted: #a59d95;
    --line: #34302b;
    --brand: #ff6a45;
    --brand-soft: #3a2119;
    --good: #4ade80;
    --good-soft: #17301f;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 24px rgba(0,0,0,.25);
  }
:root { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { color-scheme: dark; } }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }

/* header */
.top { border-bottom: 1px solid var(--line); background: var(--surface); }
.top-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 19px; text-decoration: none; letter-spacing: -.01em; }
.logo { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--brand); color: var(--brand-ink); font-weight: 800; font-size: 13px; letter-spacing: -.02em; }
.tag { color: var(--muted); font-size: 14px; }
@media (max-width: 520px) { .tag { display: none; } }

/* hero */
.hero { padding: 48px 0 28px; }
.hero h1 { font-size: clamp(28px, 5vw, 44px); line-height: 1.1; margin: 0 0 10px; letter-spacing: -.025em; text-wrap: balance; }
.sub { color: var(--muted); margin: 0 0 24px; font-size: 17px; }

.search {
  display: grid;
  grid-template-columns: 2fr 1.4fr 1fr auto;
  gap: 8px;
  background: var(--surface);
  padding: 8px;
  border-radius: 18px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.field { display: flex; flex-direction: column; padding: 6px 12px; border-radius: 12px; min-width: 0; }
.field:focus-within { background: var(--bg); }
.field span { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.field input, .field select {
  border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 16px; padding: 2px 0; outline: none; width: 100%;
}
.field select { cursor: pointer; }
.go {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; background: var(--brand); color: var(--brand-ink);
  font: inherit; font-weight: 700; font-size: 16px; padding: 0 22px; cursor: pointer; min-height: 52px;
}
.go:hover { filter: brightness(1.05); }
.go:disabled { opacity: .6; cursor: wait; }
@media (max-width: 800px) {
  .search { grid-template-columns: 1fr 1fr; }
  .field.item { grid-column: 1 / -1; }
  .go { grid-column: 1 / -1; }
}
@media (max-width: 440px) {
  .search { grid-template-columns: 1fr; }
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-size: 14px; padding: 6px 12px; border-radius: 999px; cursor: pointer;
}
.chip:hover { border-color: var(--brand); color: var(--brand); }

/* results */
#results-area { padding-bottom: 32px; }
.status { color: var(--muted); margin: 8px 0 16px; min-height: 24px; }
.status.err { color: var(--brand); }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

.summary { display: grid; grid-template-columns: 1.6fr 1fr 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat small { display: block; color: var(--muted); font-size: 13px; font-weight: 500; }
.stat strong { display: block; font-size: 22px; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.stat.best { background: var(--good-soft); border-color: transparent; }
.stat.best strong { color: var(--good); font-size: 28px; }
.stat .where { font-size: 14px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 720px) { .summary { grid-template-columns: 1fr 1fr; } .stat.best { grid-column: 1 / -1; } }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: end; margin-bottom: 14px; font-size: 14px; color: var(--muted); }
.toolbar label { display: flex; flex-direction: column; gap: 4px; }
.toolbar select, .toolbar input[type=number] {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; min-width: 120px;
}
.toolbar input[type=number] { width: 120px; }
.toolbar .check { flex-direction: row; align-items: center; gap: 6px; padding-bottom: 8px; cursor: pointer; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.offer {
  display: grid; grid-template-columns: 34px 76px 1fr auto; gap: 14px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px 12px 12px;
}
.offer.top1 { border-color: var(--good); box-shadow: 0 0 0 1px var(--good) inset; }
.rank { font-weight: 800; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.offer.top1 .rank { color: var(--good); }
.thumb { width: 76px; height: 76px; border-radius: 10px; background: #fff; object-fit: contain; border: 1px solid var(--line); }
.thumb.empty { display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.info { min-width: 0; }
.title { font-weight: 600; margin: 0 0 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; color: var(--muted); }
.meta .store { color: var(--ink); font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.meta .store img { width: 16px; height: 16px; border-radius: 4px; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); }
.badge.good { background: var(--good-soft); color: var(--good); }
.price { text-align: right; }
.price strong { display: block; font-size: 20px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.price s { color: var(--muted); font-size: 13px; }
.price a {
  display: inline-block; margin-top: 6px; font-size: 14px; font-weight: 600; text-decoration: none;
  color: var(--brand); border: 1px solid var(--brand); padding: 4px 12px; border-radius: 999px;
}
.price a:hover { background: var(--brand); color: var(--brand-ink); }
@media (max-width: 600px) {
  .offer { grid-template-columns: 60px 1fr; grid-template-areas: "thumb info" "thumb price"; gap: 8px 12px; padding: 12px; position: relative; }
  .rank { position: absolute; top: 6px; left: 6px; background: var(--surface); border-radius: 6px; padding: 0 5px; font-size: 12px; }
  .thumb { grid-area: thumb; width: 60px; height: 60px; }
  .info { grid-area: info; }
  .price { grid-area: price; text-align: left; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .price a { margin-top: 0; }
}

.empty-state { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--muted); }

.elsewhere { margin-top: 24px; }
.elsewhere h3 { font-size: 15px; margin: 0 0 10px; }
.links { display: flex; flex-wrap: wrap; gap: 8px; }
.links a {
  text-decoration: none; font-size: 14px; font-weight: 500; padding: 8px 14px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line);
}
.links a:hover { border-color: var(--brand); color: var(--brand); }

/* how it works */
.how { padding: 32px 16px 48px; }
.how-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.how-grid > div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.how-grid b { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--brand-soft); color: var(--brand); }
.how-grid h3 { margin: 10px 0 4px; font-size: 16px; }
.how-grid p { margin: 0; color: var(--muted); font-size: 14px; }
.fine { color: var(--muted); font-size: 13px; margin-top: 16px; }
@media (max-width: 720px) { .how-grid { grid-template-columns: 1fr; } }

.foot { border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; padding: 20px 0; }

.secondhand {
  display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid #1877f2;
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 20px;
}
.sh-text { flex: 1 1 360px; min-width: 0; }
.sh-text h3 { margin: 0 0 4px; font-size: 16px; }
.sh-text p { margin: 0; color: var(--muted); font-size: 14px; }
.sh-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sh-actions a {
  text-decoration: none; font-weight: 600; font-size: 14px; padding: 9px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg);
}
.sh-actions a.fb { background: #1877f2; border-color: #1877f2; color: #fff; }
.sh-actions a:hover { filter: brightness(1.05); }

.top-right { display: flex; align-items: center; gap: 14px; }
.theme { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); }
.theme button {
  display: grid; place-items: center; width: 32px; height: 28px; border: 0; border-radius: 999px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.theme button:hover { color: var(--ink); }
.theme button[aria-pressed="true"] { background: var(--surface); color: var(--brand); box-shadow: 0 1px 3px rgba(0,0,0,.15); }

/* price-alert waitlist */
#alert-card { margin-bottom: 16px; }
.alert {
  display: flex; flex-wrap: wrap; gap: 14px 20px; align-items: end; justify-content: space-between;
  background: var(--brand-soft); border-radius: var(--radius); padding: 16px 18px;
}
.alert-text { flex: 1 1 320px; min-width: 0; }
.alert-text h3 { margin: 4px 0 2px; font-size: 16px; }
.alert-text p { margin: 0; font-size: 14px; color: var(--muted); }
.soon { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--brand); }
.alert-fields { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.alert-fields label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.alert-fields input {
  font: inherit; font-size: 15px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; width: 150px;
}
.alert-fields input[type=email] { width: 220px; }
.alert-fields button {
  font: inherit; font-weight: 700; border: 0; border-radius: 10px; padding: 10px 16px;
  background: var(--brand); color: var(--brand-ink); cursor: pointer;
}
.alert-fields button:disabled { opacity: .6; cursor: wait; }
.alert-done { font-size: 15px; padding: 4px 0; }
@media (max-width: 520px) {
  .alert-fields, .alert-fields label, .alert-fields input, .alert-fields input[type=email], .alert-fields button { width: 100%; }
}
