:root {
  --bg: #f7f7f5;
  --card: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b7280;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --line: #e5e7eb;
  --done: #9ca3af;
  --danger: #b91c1c;
  --hover: rgba(15, 118, 110, 0.05);
  --radius: 12px;
  color-scheme: light dark;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 20px -8px rgba(16, 24, 40, 0.10);
  --sk-base: #e8e8e6;
  --sk-shine: #f5f5f3;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  max-width: 640px; margin: 0 auto;
  padding-top: 0;
  padding-right: max(16px, env(safe-area-inset-right));
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: max(16px, env(safe-area-inset-left));
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
}

.topbar { padding: calc(28px + env(safe-area-inset-top)) 4px 12px; }
.topbar h1 { margin: 0; font-size: 1.8rem; letter-spacing: -0.02em; }
.topbar h1 .q { color: var(--accent); }
.tagline { margin: 4px 0 0; color: var(--muted); font-size: 0.95rem; }

/* ask form */
.ask { display: flex; gap: 8px; margin-top: 12px; }
.ask input {
  flex: 1; min-width: 0; padding: 13px 14px; font-size: 1rem;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card);
}
.ask input:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.ask button {
  position: relative;
  padding: 13px 20px; font-size: 1rem; font-weight: 600; cursor: pointer;
  color: var(--accent-ink); background: var(--accent); border: 0; border-radius: var(--radius);
  transition: filter .15s ease, opacity .15s ease, transform .06s ease;
}
.ask button:hover:not(:disabled) { filter: brightness(0.93); }
.ask button:active:not(:disabled) { transform: translateY(1px); }
.ask button:disabled { opacity: 0.55; cursor: default; }
.ask button.loading { color: transparent; opacity: 1; }
.ask button.loading::after {
  content: ""; position: absolute; top: 50%; left: 50%;
  width: 16px; height: 16px; margin: -8px 0 0 -8px;
  border: 2px solid var(--accent-ink); border-right-color: transparent;
  border-radius: 50%; animation: wdin-spin 0.6s linear infinite;
}
@keyframes wdin-spin { to { transform: rotate(360deg); } }

/* Mic (voice input) button — a light icon button, distinct from the solid Ask button. Higher
   specificity than `.ask button` so the teal fill is overridden. */
.ask .mic {
  flex: 0 0 auto;
  width: 48px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--accent); background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}
.ask .mic:hover { border-color: var(--accent); }
.ask .mic.listening {
  color: var(--accent-ink); background: var(--accent); border-color: var(--accent);
  animation: mic-pulse 1.2s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(15, 118, 110, 0.45); }
  50% { box-shadow: 0 0 0 7px rgba(15, 118, 110, 0); }
}
@media (prefers-reduced-motion: reduce) { .ask .mic.listening { animation: none; } }

/* Commerce hero — the result leads with buying the whole kit; the total is the anchor. */
.kit-hero {
  margin: 6px 0 16px;
  padding: 16px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  border-radius: var(--radius);
}
.kit-hero-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  margin-bottom: 12px;
}
.kit-count { color: #047857; font-weight: 600; font-size: 0.95rem; }
.kit-total { font-size: 2rem; font-weight: 800; color: var(--accent); letter-spacing: -0.02em; line-height: 1; }
.buy-all {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  width: 100%; padding: 15px 16px; min-height: 56px;
  background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: var(--radius); cursor: pointer;
  box-shadow: 0 2px 10px rgba(15, 118, 110, 0.3);
  transition: filter .15s ease, transform .06s ease, box-shadow .15s ease;
}
.buy-all:hover { filter: brightness(0.95); box-shadow: 0 4px 14px rgba(15, 118, 110, 0.35); }
.buy-all:active { transform: translateY(1px); }
.buy-all:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.buy-all-main { font-size: 1.2rem; font-weight: 700; letter-spacing: -0.01em; }
.buy-all-sub { font-size: 0.85rem; opacity: 0.92; }
.kit-alt { margin: 11px 0 0; text-align: center; color: #047857; font-size: 0.9rem; font-weight: 500; }

/* The hidden attribute must always win: author display rules (e.g. .buy-all's flex) otherwise
   override the UA's [hidden] { display: none } and a "hidden" control stays visible. */
[hidden] { display: none !important; }

/* Guided "shop the kit" — one item at a time with a progress bar; replaces the tab-wall. */
.kit-guide { margin-top: 2px; }
.kit-guide-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.kit-guide-title { color: #047857; font-weight: 700; font-size: 0.95rem; }
.kit-guide-count { color: #047857; font-weight: 600; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.kit-guide-bar { height: 8px; margin: 8px 0 10px; background: #a7f3d0; border-radius: 999px; overflow: hidden; }
.kit-guide-fill { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .25s ease; }
.kit-guide-item { font-weight: 600; margin-bottom: 10px; }
.kit-guide-next {
  display: block; width: 100%; padding: 13px 16px; min-height: 48px;
  background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: var(--radius); cursor: pointer;
  font-size: 1.05rem; font-weight: 700;
  transition: filter .15s ease, transform .06s ease;
}
.kit-guide-next:hover { filter: brightness(0.95); }
.kit-guide-next:active { transform: translateY(1px); }
.kit-guide-next:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .kit-guide-fill { transition: none; } }

/* Per-item Switch — best-pick alternatives; rendered only when the item carries PA-API data. */
.switch-pick {
  display: block; margin: 6px 0 0 auto; padding: 4px 10px;
  color: var(--accent); background: var(--card);
  border: 1px solid var(--line); border-radius: 999px; cursor: pointer;
  font-size: 0.78rem; font-weight: 600;
}
.switch-pick:hover { border-color: var(--accent); }
.switch-pick:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (prefers-color-scheme: dark) {
  .kit-hero { background: #06251f; border-color: #115e56; }
  .kit-count, .kit-alt, .kit-guide-title, .kit-guide-count { color: #6ee7b7; }
  .kit-guide-bar { background: #115e56; }
}

.ask button:focus-visible,
.buy:focus-visible,
.del:focus-visible,
.check:focus-visible,
.install-btn:focus-visible,
.demo-toggle input:focus-visible,
.saved-card summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.saved-card summary:focus-visible { border-radius: 6px; }
.item:focus-within { background-color: var(--hover); }
/* Headings focused programmatically (result heading after a query, Saved heading after a delete)
   are not tab-reachable, so hide the focus ring — but keep it if a browser treats the focus as keyboard-visible. */
.result-title:focus:not(:focus-visible),
#saved h2:focus:not(:focus-visible) { outline: none; }

.demo-toggle { display: flex; align-items: center; gap: 8px; min-height: 44px; margin: 4px 4px 0; color: var(--muted); font-size: 0.85rem; }

/* first-run example prompts */
.examples { margin: 14px 4px 0; }
.examples[hidden] { display: none; }
.examples-lead { margin: 0 0 10px; color: var(--muted); font-size: 0.9rem; line-height: 1.45; }
.examples-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.example {
  display: inline-flex; align-items: center; min-height: 44px;
  padding: 8px 14px; border-radius: 999px; cursor: pointer;
  font-size: 0.9rem; font-weight: 600; letter-spacing: 0.01em;
  color: var(--accent); background: #f0fdfa; border: 1px solid #99f6e4;
  transition: background .15s ease, transform .06s ease;
}
.example:hover { background: #ccfbf1; }
.example:active { transform: translateY(1px); }
.example:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.status { min-height: 1.2em; margin: 14px 4px; font-size: 0.95rem; }
.status.working { color: var(--accent); }
.status.error { color: var(--danger); }
.status-retry {
  display: inline-flex; align-items: center; min-height: 44px;
  margin-left: 10px; padding: 4px 14px; vertical-align: middle;
  font: inherit; font-size: 0.85rem; font-weight: 600; line-height: 1;
  color: var(--accent); background: var(--card);
  border: 1px solid var(--accent); border-radius: 999px; cursor: pointer;
  transition: background .15s ease, transform .06s ease;
}
.status-retry:hover { background: var(--hover); }
.status-retry:active { transform: translateY(1px); }
.status-retry:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.offline-banner {
  margin: 12px 4px 0; padding: 8px 12px; border-radius: 8px;
  background: #fef3c7; color: #92400e; border: 1px solid #fde68a;
  font-size: 0.85rem;
}

.muted { color: var(--muted); font-size: 0.9rem; }

/* results + saved cards */
.result { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-top: 8px; box-shadow: var(--shadow); }
.result-title { margin: 0 0 6px; font-size: 1.2rem; font-weight: 700; letter-spacing: -0.01em; line-height: 1.3; }
.result-title + .muted { margin: 3px 0 14px; font-variant-numeric: tabular-nums; }
@keyframes wdin-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.result:not([hidden]) { animation: wdin-rise .28s cubic-bezier(.22,.61,.36,1) both; }
.result .items + .muted { margin: 14px 0 0; }
.result .affiliate-note { font-size: 0.8rem; }
.result .affiliate-note + .muted { margin-top: 4px; }
.basket-total { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

.saved { margin: 28px 0 40px; }
.saved h2 { font-size: 0.78rem; color: var(--muted); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 10px; }
.saved-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; padding: 4px 14px; box-shadow: var(--shadow); }
.saved-card summary { display: flex; justify-content: space-between; align-items: center; cursor: pointer; padding: 10px 0; font-weight: 600; }
.saved-q { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 10px; }
.saved-prog { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 500; display: inline-block; }
.saved-prog.bump { animation: wdin-bump .3s ease; }
@keyframes wdin-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); color: var(--accent); }
  100% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .saved-prog.bump { animation: none; }
}
.saved-meta { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.saved-buy { color: var(--accent); font-weight: 600; font-size: 0.82rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* item rows */
.items { list-style: none; margin: 8px 0 0; padding: 0; }
.item { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: rgba(15, 118, 110, 0.08); }
.item .check { margin-top: 1px; width: 24px; height: 24px; accent-color: var(--accent); flex: 0 0 auto; }
.item-body { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; gap: 2px; }
.item-name { font-weight: 600; line-height: 1.35; transition: color .15s ease; }
.item-why { color: var(--muted); font-size: 0.85rem; transition: color .15s ease; }
.item-right { flex: 0 0 auto; margin-left: 8px; }
.item.done .item-name { text-decoration: line-through; color: var(--done); }
.item.done .item-why { color: var(--done); }
.item.done .buy,
.item.done .notbuyable { opacity: 0.45; }

/* Whole row is a click target — give pointer devices a hover affordance (touch keeps its tap-highlight). */
@media (hover: hover) and (pointer: fine) {
  .item { transition: background-color .12s ease; }
  .item:hover { background-color: var(--hover); }
}

.buy {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px;
  white-space: nowrap; padding: 6px 12px; border-radius: 999px;
  background: #d5faf2; color: var(--accent); text-decoration: none; font-size: 0.82rem; font-weight: 600;
  letter-spacing: 0.01em; font-variant-numeric: tabular-nums;
  border: 1px solid #5eead4;
  transition: background .15s ease, transform .06s ease, opacity .15s ease;
}
.buy:hover { background: #b6f5e9; }
.buy:active { transform: translateY(1px); }
.buy-price { font-weight: 700; }
.buy-label { font-weight: 600; }
.buy-price + .buy-label::before { content: "\00b7"; margin: 0 6px; opacity: 0.55; font-weight: 400; }
.buy-label::after { content: "\2197"; margin-left: 5px; font-weight: 400; opacity: 0.6; }
.notbuyable { color: var(--muted); font-size: 0.8rem; transition: opacity .15s ease; }

.del { margin: 4px 0 8px; background: none; border: 0; color: var(--danger); font-size: 0.85rem; cursor: pointer; padding: 10px 4px; min-height: 44px; }
.del:hover { text-decoration: underline; }

.clear-all {
  display: block; margin: 6px auto 0; padding: 10px 8px; min-height: 44px;
  background: none; border: 0; color: var(--muted); font-size: 0.8rem; cursor: pointer;
}
.clear-all:hover { color: var(--danger); text-decoration: underline; }
.clear-all[hidden] { display: none; }
.clear-all:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.foot { color: var(--muted); font-size: 0.78rem; text-align: center; padding: 0 0 28px; }
.foot span { display: block; }
.foot-privacy { margin-bottom: 6px; }
.foot a { color: var(--muted); }
.foot a:hover { color: var(--accent); }

/* legal pages (privacy.html) */
.legal { padding: 4px 4px 20px; }
.legal h2 { font-size: 1.05rem; margin: 22px 0 6px; }
.legal p, .legal ul { margin: 8px 0; font-size: 0.92rem; }
.legal ul { padding-left: 20px; }
.legal li { margin: 4px 0; }
.legal a { color: var(--accent); }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14151a; --card: #1e2027; --ink: #f3f4f6; --muted: #9ca3af; --line: #2c2f38;
    --accent: #2dd4bf; --accent-ink: #06251f;
    --hover: rgba(45, 212, 191, 0.08);
    --shadow: 0 1px 2px rgba(0,0,0,0.35), 0 8px 20px -8px rgba(0,0,0,0.55);
    --sk-base: #262931; --sk-shine: #333844;
  }
  .buy { background: #06251f; border-color: #115e56; }
  .buy:hover { background: #0a3a31; }
  .example { background: #06251f; border-color: #115e56; }
  .example:hover { background: #0a3a31; }
  .offline-banner { background: #3a2f12; color: #fde68a; border-color: #5b4a1a; }
}

/* PWA install button */
.install-btn {
  display: inline-flex; align-items: center; min-height: 44px; margin: 10px 4px 0; padding: 9px 14px; font-size: 0.9rem; font-weight: 600;
  cursor: pointer; color: var(--accent); background: var(--card);
  border: 1px solid var(--accent); border-radius: var(--radius);
}
.install-btn[hidden] { display: none; }   /* override the inline-block above when hidden */

/* Service-worker update toast */
.update-toast {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50;
  display: flex; align-items: center; gap: 12px; max-width: 92%;
  padding: 10px 14px; border-radius: var(--radius);
  background: var(--ink); color: var(--bg); font-size: 0.9rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}
.update-refresh {
  cursor: pointer; min-height: 44px; padding: 6px 12px; border: 0; border-radius: 8px; font-weight: 600;
  color: var(--accent-ink); background: var(--accent);
}
.update-refresh:disabled { opacity: 0.6; cursor: default; }
.update-dismiss {
  cursor: pointer; min-height: 44px; padding: 6px 10px; border: 0; border-radius: 8px;
  font-weight: 500; color: var(--bg); background: transparent; opacity: 0.7;
}
.update-dismiss:hover { opacity: 1; text-decoration: underline; }
.update-dismiss:focus-visible { outline: 2px solid var(--bg); outline-offset: 2px; }

/* loading skeleton — result busy state */
.skeleton { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-top: 8px; box-shadow: var(--shadow); }
.skeleton[hidden] { display: none; }
.sk-line, .sk-box, .sk-pill {
  background: linear-gradient(100deg, var(--sk-base) 40%, var(--sk-shine) 50%, var(--sk-base) 60%);
  background-size: 200% 100%; animation: wdin-shimmer 1.3s linear infinite; border-radius: 6px;
}
.sk-title { height: 20px; width: 62%; margin-bottom: 10px; }
.sk-sub { height: 13px; width: 42%; margin-bottom: 18px; }
.sk-row { display: flex; align-items: flex-start; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); }
.sk-box { width: 24px; height: 24px; flex: 0 0 auto; margin-top: 1px; }
.sk-body { display: flex; flex-direction: column; gap: 8px; flex: 1 1 auto; min-width: 0; }
.sk-name { height: 14px; width: 55%; }
.sk-why { height: 11px; width: 35%; }
.sk-pill { width: 64px; height: 30px; border-radius: 999px; flex: 0 0 auto; margin-left: 8px; }
@keyframes wdin-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
