:root {
  --bg: #faf8f4;
  --card: #ffffff;
  --ink: #1f2a24;
  --muted: #66716b;
  --line: #e6e2d9;
  --accent: #1f7a4d;
  --accent-ink: #ffffff;
  --offer: #ffe480;
  --offer-ink: #3d3000;
  --warn: #a3341f;
  --heart: #c2334d;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141a17;
    --card: #1d2521;
    --ink: #e9efe9;
    --muted: #9aa69f;
    --line: #2c3731;
    --accent: #4fbf87;
    --accent-ink: #0c1a13;
    --offer: #6b5a12;
    --offer-ink: #fff3c2;
    --warn: #ff9a85;
    --heart: #ff8499;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* or `display: flex` on a card would win */
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}
h1, h2, h3, p { margin: 0; }
button, input { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button:disabled { opacity: .45; cursor: default; }
button.quiet { border-color: transparent; background: none; color: var(--muted); text-decoration: underline; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---- sign in ---- */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card {
  width: min(360px, 100%);
  display: grid;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
}
.login-card label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.login-card input { padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); font-size: 16px; }
.error { color: var(--warn); }

/* ---- top ---- */
.top { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; }
.top h1 { font-size: 22px; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); }
.menu summary::-webkit-details-marker { display: none; }
.menu-items {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30;
  display: grid; gap: 6px; padding: 8px; width: 200px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 8px 24px rgb(0 0 0 / .15);
}
.menu-items button { width: 100%; text-align: left; }

.views { display: flex; gap: 4px; margin: 8px 16px 2px; padding: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.views button { flex: auto; min-width: 0; padding: 8px 4px; border: 0; border-radius: 8px; background: none; font-size: 14px; white-space: nowrap; }
.views button small { margin-left: 5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.views button[aria-pressed=true] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.views button[aria-pressed=true] small { color: inherit; opacity: .8; }
.views.muted { opacity: .45; }

.tools { display: flex; gap: 10px; align-items: center; padding: 8px 16px; }
.tools input[type=search] { flex: 1; min-width: 0; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); font-size: 16px; }
.toggle { display: flex; gap: 6px; align-items: center; white-space: nowrap; font-size: 14px; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

#chips {
  position: sticky; top: 0; z-index: 20;
  display: flex; gap: 8px; overflow-x: auto; padding: 8px 16px;
  background: var(--bg); border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
#chips::-webkit-scrollbar { display: none; }
#chips a {
  flex: none; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card);
  color: var(--ink); text-decoration: none; font-size: 14px;
}

/* ---- regulars ---- */
main { padding: 0 16px; }
section.department { scroll-margin-top: 56px; }
section.department > h2 { font-size: 19px; padding: 20px 0 2px; }
h3.aisle { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 14px 0 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.card {
  position: relative;
  display: flex; flex-direction: column; gap: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px;
}
.card.chosen { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.card img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #fff; border-radius: 8px; }
.card .title { font-size: 14px; line-height: 1.3; flex: 1; overflow-wrap: anywhere; }
.price { font-weight: 600; }
.offer { display: inline-block; font-size: 12px; font-weight: 600; background: var(--offer); color: var(--offer-ink); border-radius: 6px; padding: 2px 6px; }
.gone { font-size: 13px; color: var(--muted); }
.bought { font-size: 12px; color: var(--muted); }
.heart {
  position: absolute; top: 4px; right: 4px;
  display: grid; place-items: center; width: 44px; height: 44px; padding: 0;
  border: 0; border-radius: 50%; background: none; color: #8a8f8c;
}
.heart svg { fill: rgb(255 255 255 / .85); stroke: currentColor; stroke-width: 2; }
.heart[aria-pressed=true] { color: var(--heart); }
.heart[aria-pressed=true] svg { fill: currentColor; }
.card.unavailable img { opacity: .45; }

.qty { display: flex; align-items: center; gap: 6px; }
.qty button { min-width: 44px; min-height: 44px; padding: 0; font-size: 20px; line-height: 1; }
.qty .add { flex: 1; font-size: 15px; font-weight: 600; color: var(--accent); }
.qty output { flex: 1; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }

.empty { padding: 48px 0; text-align: center; color: var(--muted); display: grid; gap: 14px; justify-items: center; }

/* ---- bottom bar ---- */
#bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}
#summary { font-weight: 600; font-variant-numeric: tabular-nums; }
#summary small { display: block; font-weight: 400; color: var(--muted); font-size: 13px; }

/* ---- review sheet ---- */
dialog#sheet {
  width: min(560px, 100%); max-width: 100%; max-height: 92dvh;
  margin: auto auto 0; padding: 0; border: 0; border-radius: 18px 18px 0 0;
  background: var(--bg); color: var(--ink);
}
@media (min-width: 620px) { dialog#sheet { margin: auto; border-radius: 18px; } }
dialog#sheet::backdrop { background: rgb(0 0 0 / .45); }
.sheet-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: 19px; }
#sheet-body { padding: 8px 16px 20px; display: grid; gap: 4px; }
.row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.row .title { font-size: 15px; overflow-wrap: anywhere; }
.row .line-price { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.row .qty { grid-row: span 2; width: 132px; }
.total { display: flex; justify-content: space-between; padding: 14px 0 4px; font-weight: 600; font-size: 17px; }
.note { color: var(--muted); font-size: 14px; }
.actions { display: grid; gap: 10px; padding-top: 14px; }
.actions .primary { padding: 14px; font-size: 17px; }
.copy-box { width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); font: inherit; font-size: 14px; }
.result h3 { font-size: 20px; padding: 10px 0 6px; }
.result ul { margin: 6px 0 0; padding-left: 20px; }
.result .problem { margin-top: 14px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.result .problem strong { color: var(--warn); }

#toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 40; max-width: calc(100% - 32px);
  background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
#toast.show { opacity: 1; }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
@media (max-width: 359px) { .views button { font-size: 12.5px; } .views button small { margin-left: 3px; } }
