:root {
  --bg: #faf7f5;
  --surface: #ffffff;
  --text: #221a1c;
  --muted: #6e6265;
  --line: #e8e0e2;
  --accent: #6d1a36;
  --accent-soft: #f4e6eb;
  --red: #8c1c3a;
  --white: #e3d48a;
  --rose: #ef9bb0;
  --card: #1f5fa8;
  --card-soft: #e5eef9;
  --maybe: #8a5a00;
  --maybe-soft: #fbf0d9;
  --down: #1d7a45;
  --up: #b3261e;
  --warn-soft: #fdf1e3;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141011;
    --surface: #1e1819;
    --text: #f1eaec;
    --muted: #a99ca0;
    --line: #342b2d;
    --accent: #e48aa6;
    --accent-soft: #3a2029;
    --white: #d8c66d;
    --card: #8ab8f0;
    --card-soft: #1c2a3d;
    --maybe: #e9c46a;
    --maybe-soft: #3a2f16;
    --down: #6fcf97;
    --up: #f28b82;
    --warn-soft: #3b2c18;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141011; --surface: #1e1819; --text: #f1eaec; --muted: #a99ca0; --line: #342b2d;
  --accent: #e48aa6; --accent-soft: #3a2029; --white: #d8c66d; --card: #8ab8f0; --card-soft: #1c2a3d;
  --maybe: #e9c46a; --maybe-soft: #3a2f16; --down: #6fcf97; --up: #f28b82; --warn-soft: #3b2c18;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0 auto;
  max-width: 760px;
  padding: 0 16px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.top { padding: calc(20px + env(safe-area-inset-top)) 0 8px; }
.top h1 { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 1.6rem; letter-spacing: -0.01em; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 0.95rem; }

.filters { display: grid; gap: 10px; padding: 12px 0; position: sticky; top: 0; z-index: 1; background: var(--bg); border-bottom: 1px solid var(--line); }
.filters fieldset { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; border: 0; }
.filters legend { float: left; width: 3.6em; padding-top: 5px; color: var(--muted); font-size: 0.85rem; }
.chip input, .toggle input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--muted); font-size: 0.9rem; cursor: pointer; user-select: none;
}
.chip input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.chip input:focus-visible + span, .toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip-red span::before, .chip-white span::before, .chip-rose span::before { content: ""; width: 10px; height: 10px; border-radius: 50%; }
.chip-red span::before { background: var(--red); }
.chip-white span::before { background: var(--white); }
.chip-rose span::before { background: var(--rose); }

.toggles { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.toggle { display: inline-flex; align-items: center; cursor: pointer; font-size: 0.9rem; color: var(--muted); }
.toggle span::before {
  content: ""; display: inline-block; vertical-align: middle; margin-right: 8px;
  width: 34px; height: 20px; border-radius: 999px; background: var(--line);
  box-shadow: inset 0 0 0 2px var(--line); transition: background 0.15s;
  background-image: radial-gradient(circle at 10px 10px, var(--surface) 7px, transparent 7.5px);
}
.toggle input:checked + span::before {
  background-color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--accent);
  background-image: radial-gradient(circle at 24px 10px, var(--surface) 7px, transparent 7.5px);
}

.notice { margin: 12px 0 0; padding: 8px 12px; border-radius: 8px; background: var(--warn-soft); font-size: 0.9rem; }
.count { margin: 14px 0 6px; color: var(--muted); font-size: 0.85rem; }

.feed { list-style: none; margin: 0; padding: 0; }
.wine + .wine { border-top: 1px solid var(--line); }
.wine a {
  display: grid; align-items: center; gap: 12px;
  /* Named areas, so a row whose image is missing or fails keeps its columns. */
  grid-template-columns: 6px 44px minmax(0, 1fr) auto;
  grid-template-areas: "swatch thumb body prices";
  padding: 12px 4px; color: inherit; text-decoration: none;
}
.wine a:hover .name { text-decoration: underline; }
.swatch { grid-area: swatch; width: 6px; align-self: stretch; border-radius: 3px; }
.swatch-red { background: var(--red); }
.swatch-white { background: var(--white); }
.swatch-rose { background: var(--rose); }
.thumb { grid-area: thumb; width: 44px; height: 56px; object-fit: contain; border-radius: 6px; background: #fff; }
.body { grid-area: body; min-width: 0; display: grid; gap: 3px; }
.name { font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 0.85rem; color: var(--muted); }
.store { font-weight: 600; color: var(--text); }
.offer { color: var(--muted); }

.prices { grid-area: prices; display: grid; justify-items: end; gap: 2px; text-align: right; }
.price { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.aside { font-size: 0.8rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.move.down { color: var(--down); }
.move.up { color: var(--up); }
.badge { font-size: 0.75rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; white-space: nowrap; }
.badge-card { background: var(--card-soft); color: var(--card); }
.badge-maybe { background: var(--maybe-soft); color: var(--maybe); }

/* Loyalty prices on: show the card price and its badges; off: the shelf price. */
body:not(.no-loyalty) .shelf-price { display: none; }
body.no-loyalty .card-price { display: none; }

.empty { padding: 32px 0; text-align: center; color: var(--muted); }

footer { margin-top: 24px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.85rem; }
footer summary { cursor: pointer; }
footer table { width: 100%; margin-top: 8px; border-collapse: collapse; font-variant-numeric: tabular-nums; }
footer th, footer td { padding: 4px 6px; text-align: left; border-bottom: 1px solid var(--line); }
footer tr.bad td { color: var(--up); }

@media (max-width: 420px) {
  .thumb { display: none; }
  .wine a { grid-template-columns: 6px minmax(0, 1fr) auto; grid-template-areas: "swatch body prices"; gap: 10px; }
  .price { font-size: 1.1rem; }
}
