/* Layout: sticky top bar with area filter; single centered column of sections; detail views open as pages (hash routes) or a modal. */
:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #18212b;
  --muted: #5b6672;
  --line: #dfe3dc;
  --cheap: #0e6b5f;
  --cheap-soft: #d7ece7;
  --dear: #b2412b;
  --dear-soft: #f6ded8;
  --tag: #f1c84b;
  --tag-ink: #3a2d00;
  --bar: #9aa5ae;
  --shadow: 0 10px 30px rgba(20, 30, 40, .14);
  --display: "Fraunces", Georgia, "Times New Roman", serif;
  --body: "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --r: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12171c; --panel: #1a2128; --ink: #e8ecef; --muted: #9aa6b1; --line: #2b343d;
    --cheap: #5cc2b0; --cheap-soft: #173a35; --dear: #f08a72; --dear-soft: #43241d;
    --tag: #e6bd44; --tag-ink: #241c00; --bar: #6c7782; --shadow: 0 10px 30px rgba(0,0,0,.45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12171c; --panel: #1a2128; --ink: #e8ecef; --muted: #9aa6b1; --line: #2b343d;
  --cheap: #5cc2b0; --cheap-soft: #173a35; --dear: #f08a72; --dear-soft: #43241d;
  --tag: #e6bd44; --tag-ink: #241c00; --bar: #6c7782; --shadow: 0 10px 30px rgba(0,0,0,.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.55 var(--body); }
a { color: inherit; }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--cheap); outline-offset: 2px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 8px; background: var(--panel); padding: 6px 10px; z-index: 50; }

.wrap { max-width: 72rem; margin-inline: auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }

/* Top bar */
.top { position: sticky; top: 0; z-index: 20; background: var(--panel); border-bottom: 1px solid var(--line); }
.top-inner { max-width: 72rem; margin-inline: auto; padding-block: 10px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font-family: var(--display); font-weight: 600; font-size: 1.15rem; }
.brand-mark { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 6px; background: var(--tag); color: var(--tag-ink); font-family: var(--body); font-weight: 600; }
.nav { display: flex; flex-wrap: wrap; gap: 2px; flex: 1 1 auto; }
.nav a { text-decoration: none; padding: 6px 10px; border-radius: 6px; color: var(--muted); font-weight: 500; }
.nav a:hover { color: var(--ink); background: var(--bg); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--bg); }
.area-pick { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); }
.area-pick select { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }

main { padding-block: 28px 48px; }
main:focus { outline: none; }

/* Type */
h1, h2, h3 { text-wrap: balance; margin: 0; }
h1 { font-family: var(--display); font-weight: 400; font-size: clamp(1.8rem, 3.4vw, 2.6rem); line-height: 1.15; }
h2 { font-family: var(--display); font-weight: 400; font-size: 1.5rem; }
h3 { font-size: 1rem; font-weight: 600; }
.lede { color: var(--muted); max-width: 44rem; margin: 8px 0 0; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .72rem; color: var(--muted); font-weight: 600; }
.small { font-size: .85rem; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

.stack { display: grid; gap: 28px; }
.sec { display: grid; gap: 14px; }
.sec-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; }
.grid2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; min-width: 0; display: grid; gap: 10px; align-content: start; }
.card > p { margin: 0; }

/* Headline answer */
.answer { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); }
.ans { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: grid; gap: 4px; cursor: pointer; text-align: left; font: inherit; color: inherit; }
.ans:hover { border-color: var(--muted); }
.ans .big { font-family: var(--display); font-size: 1.6rem; line-height: 1.2; }
.ans .idx { font-variant-numeric: tabular-nums; }

/* Index chip */
.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font-variant-numeric: tabular-nums; font-weight: 600; font-size: .85rem; }
.chip.lo { background: var(--cheap-soft); color: var(--cheap); }
.chip.hi { background: var(--dear-soft); color: var(--dear); }
.chip.mid { background: var(--bg); color: var(--muted); }
.tag { display: inline-block; padding: 0 6px; border-radius: 4px; background: var(--tag); color: var(--tag-ink); font-size: .75rem; font-weight: 600; }
.flag { display: inline-block; padding: 0 6px; border-radius: 4px; background: var(--dear-soft); color: var(--dear); font-size: .75rem; font-weight: 600; }
.match { font-size: .75rem; color: var(--muted); }

/* Bar rows (rankings) */
.bars { display: grid; gap: 4px; }
.bar-row { display: grid; grid-template-columns: minmax(7rem, 11rem) 1fr 3rem; align-items: center; gap: 10px; padding: 4px 6px; border-radius: 6px; cursor: pointer; border: 0; background: none; font: inherit; color: inherit; text-align: left; width: 100%; }
.bar-row:hover, .bar-row:focus-visible { background: var(--bg); }
.bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { position: relative; height: 14px; }
.bar-track .mid { position: absolute; top: -3px; bottom: -3px; width: 0; border-left: 1px dashed var(--muted); }
.bar-fill { position: absolute; top: 2px; height: 10px; border-radius: 5px; }
.bar-fill.lo { background: var(--cheap); }
.bar-fill.hi { background: var(--dear); }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

/* Spread rows */
.spread-row { display: grid; grid-template-columns: minmax(7rem, 11rem) 1fr; gap: 10px; align-items: center; padding: 6px; }
.spread-track { position: relative; height: 22px; }
.spread-line { position: absolute; top: 10px; height: 2px; background: var(--bar); border-radius: 2px; }
.dot { position: absolute; top: 4px; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; border: 2px solid var(--panel); cursor: pointer; padding: 0; }
.dot.lo { background: var(--cheap); }
.dot.hi { background: var(--dear); }
.dot:hover, .dot:focus-visible { transform: scale(1.3); }
.axis { display: grid; grid-template-columns: minmax(7rem, 11rem) 1fr; gap: 10px; padding: 0 6px; }
.axis-track { position: relative; height: 18px; font-size: .72rem; color: var(--muted); }
.axis-track span { position: absolute; transform: translateX(-50%); }

/* Tables */
.tbl-wrap { overflow-x: auto; }
.tbl-scroll { max-height: 34rem; overflow: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
.tbl th { position: sticky; top: 0; background: var(--panel); text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th button { all: unset; cursor: pointer; }
.tbl th button:focus-visible { outline: 2px solid var(--cheap); }
.tbl td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl td.n, .tbl th.n { text-align: right; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--bg); }
.tbl .sub { display: block; color: var(--muted); font-size: .8rem; }
.tbl tr.missing td { color: var(--muted); }
.cheaper { color: var(--cheap); }
.dearer { color: var(--dear); }

.tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.input { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; min-width: 0; max-width: 20rem; width: 100%; }
.btn { font: inherit; font-size: .85rem; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 6px; padding: 6px 10px; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.back { display: inline-flex; gap: 6px; align-items: center; text-decoration: none; color: var(--muted); font-size: .9rem; }

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr)); gap: 12px; }
.kv div { display: grid; gap: 2px; }
.kv b { font-family: var(--display); font-weight: 400; font-size: 1.5rem; font-variant-numeric: tabular-nums; }

.empty { padding: 24px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--r); }
.prose { max-width: 44rem; }
.prose p, .prose li { color: var(--ink); }

/* Tooltip */
.tip { position: fixed; z-index: 40; max-width: min(22rem, calc(100vw - 24px)); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 10px 12px; font-size: .82rem; pointer-events: none; }
.tip h4 { margin: 0 0 4px; font-size: .88rem; }
.tip .tl { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; }
.tip .tl span:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; }
.tip .hint { margin-top: 6px; color: var(--muted); font-size: .75rem; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: max(16px, env(safe-area-inset-top, 0px)) 16px 16px; }
.modal-back { position: absolute; inset: 0; background: rgba(10, 15, 20, .5); }
.modal-box { position: relative; background: var(--panel); border-radius: var(--r); box-shadow: var(--shadow); width: min(56rem, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 22px; display: grid; gap: 14px; }
.modal-x { position: absolute; top: 10px; right: 12px; font-size: 1.4rem; line-height: 1; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px 8px; }

.foot { border-top: 1px solid var(--line); padding-block: 18px; font-size: .8rem; color: var(--muted); }
.foot-inner { display: flex; flex-wrap: wrap; gap: 6px 24px; justify-content: space-between; }

@media (max-width: 40rem) {
  .hide-sm { display: none; }
  .bar-row, .spread-row, .axis { grid-template-columns: minmax(5.5rem, 8rem) 1fr; }
  .bar-row .bar-val { display: none; }
}
@media (prefers-reduced-motion: no-preference) {
  .dot { transition: transform .15s ease-out; }
}

/* search, receipts, review */
.sub { display: block; color: var(--muted); font-size: .8rem; }
.btn.primary { background: var(--ink); color: var(--panel); border-color: var(--ink); font-weight: 600; }
.btn.primary:hover { opacity: .9; }
.btn:disabled { opacity: .5; cursor: progress; }
.linkish { font: inherit; font-size: .8rem; background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; cursor: pointer; white-space: nowrap; }
.linkish:hover { color: var(--ink); }
.search-bar .big-input { max-width: 36rem; font-size: 1.05rem; padding: 10px 12px; }
.form { display: grid; gap: 12px; max-width: 34rem; }
.form label { display: grid; gap: 4px; }
.form .input { max-width: none; }
.receipt-preview img { max-height: 260px; max-width: 100%; border: 1px solid var(--line); border-radius: 6px; }
.product h3 { margin: 0; }
.offers { display: grid; }
.offer { display: grid; grid-template-columns: 1.6rem 1fr auto auto; gap: 4px 12px; align-items: center; padding: 9px 0; border-top: 1px solid var(--line); }
.offer:first-child { border-top: 0; }
.offer-rank { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.offer-store { min-width: 0; }
.offer-price { text-align: right; display: grid; justify-items: end; gap: 2px; font-variant-numeric: tabular-nums; }
.offer.stale { opacity: .5; }
.review { grid-template-columns: 1fr auto; align-items: center; }
@media (max-width: 40rem) {
  .offer { grid-template-columns: 1.4rem 1fr auto; }
  .offer .linkish { grid-column: 2 / -1; justify-self: start; }
  .review { grid-template-columns: 1fr; }
}
