:root {
  --bg: #f4f4f7;
  --surface: #ffffff;
  --surface-2: #ececf1;
  --ink: #0b0b10;
  --ink-2: #5b5b68;
  --line: rgba(11, 11, 16, .08);
  --accent: #3b5bff;
  --accent-2: #8a5cff;
  --accent-ink: #ffffff;
  --good: #0f9d63;
  --good-bg: rgba(15, 157, 99, .12);
  --warn: #b26b00;
  --warn-bg: rgba(255, 166, 0, .16);
  --bad: #d92d3a;
  --bad-bg: rgba(217, 45, 58, .12);
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(20,20,40,.06);
  --r-lg: 28px;
  --r-md: 20px;
  --r-sm: 14px;
  --spring: cubic-bezier(.2, .9, .25, 1.15);
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0b10;
    --surface: #17171e;
    --surface-2: #22222b;
    --ink: #f5f5f8;
    --ink-2: #9a9aab;
    --line: rgba(255, 255, 255, .07);
    --good: #34d399;
    --good-bg: rgba(52, 211, 153, .13);
    --warn: #fbbf24;
    --warn-bg: rgba(251, 191, 36, .13);
    --bad: #fb7185;
    --bad-bg: rgba(251, 113, 133, .13);
    --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 10px 30px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0b10; --surface: #17171e; --surface-2: #22222b; --ink: #f5f5f8; --ink-2: #9a9aab;
  --line: rgba(255,255,255,.07); --good: #34d399; --good-bg: rgba(52,211,153,.13);
  --warn: #fbbf24; --warn-bg: rgba(251,191,36,.13); --bad: #fb7185; --bad-bg: rgba(251,113,133,.13);
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 10px 30px rgba(0,0,0,.35); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 Inter, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  min-height: 100dvh; overflow-x: hidden;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 12px; }

.app {
  max-width: 520px; margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}

/* top bar */
.top { display: flex; align-items: center; justify-content: space-between; height: 48px; }
.brand { display: flex; align-items: center; gap: 10px; font: 700 19px/1 "Inter Tight", sans-serif; letter-spacing: -.02em; }
.logo {
  width: 32px; height: 32px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-weight: 800; font-size: 17px;
}
.pill-mt { font-size: 13px; font-weight: 600; padding: 7px 12px; border-radius: 99px; background: var(--surface); box-shadow: var(--shadow); }

/* hero */
.hero { padding: 22px 2px 18px; transition: opacity .35s var(--ease), transform .35s var(--ease), max-height .4s var(--ease); max-height: 200px; }
.hello { margin: 0 0 6px; color: var(--ink-2); font-weight: 500; }
h1 { margin: 0; font: 800 clamp(34px, 9.5vw, 44px)/1.02 "Inter Tight", sans-serif; letter-spacing: -.035em; }
.app.searched .hero { opacity: 0; transform: translateY(-12px); max-height: 0; padding: 0; overflow: hidden; }
.app.searched .how, .app.searched .chips, .app.searched .recent { display: none; }

/* search pill */
.search {
  position: sticky; top: max(8px, env(safe-area-inset-top)); z-index: 5;
  display: flex; align-items: center; gap: 6px; padding: 6px 6px 6px 18px;
  background: var(--surface); border-radius: 99px; box-shadow: var(--shadow);
  border: 1px solid var(--line); transition: box-shadow .2s, transform .2s var(--spring);
}
.search:focus-within { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent), var(--shadow); }
.search input[type="search"] {
  flex: 1; min-width: 0; height: 44px; border: 0; outline: 0; background: none; color: var(--ink);
  font: 500 16px/1 Inter, sans-serif;
}
.search input::placeholder { color: var(--ink-2); }
.search input::-webkit-search-cancel-button { display: none; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex: none; transition: transform .15s var(--spring), background .2s; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:active { transform: scale(.9); }
.cam { background: var(--surface-2); }
.go { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-ink); }
.photo-chip { position: relative; flex: none; margin-left: -10px; }
.photo-chip img { width: 38px; height: 38px; border-radius: 12px; object-fit: cover; display: block; }
.photo-chip .x {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--ink); color: var(--bg); font-size: 10px; display: grid; place-items: center;
}

/* chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 16px 2px 4px; margin: 0 -16px; padding-inline: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: none; padding: 10px 14px; border-radius: 99px; background: var(--surface); font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow); transition: transform .15s var(--spring);
}
.chips button:active { transform: scale(.94); }

/* recent + how */
.sec-head { display: flex; justify-content: space-between; align-items: baseline; margin: 22px 4px 8px; }
h2 { margin: 0; font: 700 17px/1.2 "Inter Tight", sans-serif; letter-spacing: -.01em; }
.link { color: var(--accent); font-weight: 600; font-size: 14px; }
.recent ul { list-style: none; margin: 0; padding: 4px; background: var(--surface); border-radius: var(--r-md); box-shadow: var(--shadow); }
.recent li button { width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 14px; text-align: left; }
.recent li button:active { background: var(--surface-2); }
.recent .ic { width: 36px; height: 36px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; }
.how-card { margin-top: 24px; padding: 6px 18px; background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow); }
.how-row { display: flex; gap: 14px; align-items: flex-start; padding: 14px 0; }
.how-row + .how-row { border-top: 1px solid var(--line); }
.how-row p { margin: 0; color: var(--ink-2); font-size: 15px; }
.how-row b { color: var(--ink); font-weight: 600; }
.dot { flex: none; width: 28px; height: 28px; border-radius: 10px; display: grid; place-items: center; font: 700 14px "Inter Tight"; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }

/* results */
.results { margin-top: 18px; }
.understood { display: flex; align-items: center; gap: 10px; margin: 4px 4px 14px; color: var(--ink-2); font-size: 15px; }
.understood b { color: var(--ink); }
.card {
  position: relative; display: flex; gap: 14px; width: 100%; text-align: left; padding: 16px;
  background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow); margin-bottom: 10px;
  opacity: 0; transform: translateY(18px) scale(.98);
  animation: rise .55s var(--spring) forwards; animation-delay: calc(var(--i) * 70ms);
  transition: transform .15s var(--spring);
}
.card:active { transform: scale(.98); }
@keyframes rise { to { opacity: 1; transform: none; } }
.emoji { flex: none; width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center; font-size: 30px; background: var(--surface-2); }
.card-main { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; }
.tier { display: inline-block; line-height: 1.3; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; padding: 3px 8px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); margin-bottom: 6px; }
.tier.lead { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.card h3 { margin: 0 0 3px; font: 700 17px/1.25 "Inter Tight", sans-serif; letter-spacing: -.01em; }
.card p { margin: 0; color: var(--ink-2); font-size: 14px; }
.best-line { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 13px; font-weight: 600; color: var(--good); }
.chev { align-self: center; color: var(--ink-2); font-size: 22px; }

/* skeleton */
.skel { height: 106px; border-radius: var(--r-lg); margin-bottom: 10px; background: var(--surface); position: relative; overflow: hidden; }
.skel::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--ink) 6%, transparent), transparent); animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }
.scanning { display: flex; align-items: center; gap: 12px; margin: 4px 4px 14px; color: var(--ink-2); font-size: 15px; }
.scanning img { width: 44px; height: 44px; border-radius: 14px; object-fit: cover; }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite var(--ease); }
@keyframes pulse { 50% { transform: scale(1.6); opacity: .4; } }
.empty { text-align: center; padding: 40px 20px; color: var(--ink-2); }
.retry { margin-top: 14px; padding: 12px 20px; border-radius: 99px; background: var(--surface); box-shadow: var(--shadow); font-weight: 600; }

/* sheet */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); opacity: 0; transition: opacity .3s var(--ease); z-index: 20; }
.scrim.on { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-width: 520px; margin: 0 auto;
  max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 30px 30px 0 0; padding: 8px 16px calc(24px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .45s var(--spring);
}
.sheet.on { transform: translateY(0); }
.sheet.dragging { transition: none; }
.grab { width: 40px; height: 5px; border-radius: 9px; background: color-mix(in srgb, var(--ink) 22%, transparent); margin: 6px auto 14px; touch-action: none; }
.s-head { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.s-head .emoji { width: 64px; height: 64px; font-size: 34px; background: var(--surface); box-shadow: var(--shadow); }
.s-head h2 { font-size: 22px; letter-spacing: -.02em; }
.s-head p { margin: 4px 0 0; color: var(--ink-2); font-size: 14px; }
.best {
  padding: 18px; border-radius: var(--r-lg); color: #fff;
  background: radial-gradient(120% 140% at 0% 0%, var(--accent-2) 0%, var(--accent) 55%, #2238c9 100%);
  box-shadow: 0 14px 34px color-mix(in srgb, var(--accent) 35%, transparent);
}
.best .lbl { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; opacity: .85; }
.best .store { display: flex; align-items: center; gap: 10px; margin: 6px 0 12px; font: 800 26px/1.1 "Inter Tight", sans-serif; letter-spacing: -.02em; }
.best .notes .note { background: rgba(255,255,255,.16); color: #fff; }
.cta {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; margin-top: 14px; height: 54px;
  border-radius: 99px; background: #fff; color: #10123a; font: 700 16px "Inter Tight", sans-serif; text-decoration: none;
  transition: transform .15s var(--spring);
}
.cta:active { transform: scale(.97); }
.notes { display: flex; flex-wrap: wrap; gap: 6px; }
.note { font-size: 12.5px; font-weight: 600; padding: 5px 9px; border-radius: 99px; }
.note.good { background: var(--good-bg); color: var(--good); }
.note.warn { background: var(--warn-bg); color: var(--warn); }
.note.bad { background: var(--bad-bg); color: var(--bad); }
.others { margin-top: 18px; background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 4px 16px; }
.other { display: flex; align-items: flex-start; gap: 12px; padding: 14px 0; color: inherit; text-decoration: none; }
.other + .other { border-top: 1px solid var(--line); }
.other .flag { font-size: 24px; line-height: 1; margin-top: 2px; }
.other .nm { font-weight: 600; margin-bottom: 6px; }
.other .open { margin-left: auto; align-self: center; color: var(--accent); font-weight: 600; font-size: 14px; white-space: nowrap; }
.fine { color: var(--ink-2); font-size: 12.5px; margin: 16px 4px 0; }
.admin-tag { font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px; margin-left: 6px; }
.admin-tag.y { background: var(--good-bg); color: var(--good); }
.admin-tag.n { background: var(--bad-bg); color: var(--bad); }
.best .admin-tag { background: #fff; color: #10123a; font-family: Inter, sans-serif; }

/* toast + footer */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0;
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 99px; font-weight: 600; font-size: 14px;
  transition: opacity .25s, transform .35s var(--spring); z-index: 30; max-width: calc(100% - 32px);
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.foot p { color: var(--ink-2); font-size: 12px; margin: 34px 6px 0; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; }
  .card { opacity: 1; transform: none; }
}
