:root {
  --bg: #f7f4ee;
  --card: #ffffff;
  --ink: #1f2a24;
  --muted: #6b746e;
  --line: #e4ded3;
  --brand: #2f6b4f;
  --brand-ink: #ffffff;
  --yes: #2f6b4f;
  --yes-soft: #e3f0e8;
  --no: #a8432f;
  --no-soft: #f7e4df;
  --chosen: #f2c14e;
  --radius: 16px;
  --tap: 56px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141815;
    --card: #1e2420;
    --ink: #eef1ec;
    --muted: #9aa49d;
    --line: #2f3731;
    --brand: #5fae86;
    --brand-ink: #0d1510;
    --yes: #5fae86;
    --yes-soft: #1f3529;
    --no: #e08a76;
    --no-soft: #3a2420;
    --chosen: #d9a93a;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 18px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 22px; margin: 0; }
#who { color: var(--muted); font-size: 15px; }

main { max-width: 640px; margin: 0 auto; padding: 12px 16px 24px; }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs[hidden] { display: none; }
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 64px; text-decoration: none; color: var(--muted); font-size: 14px; font-weight: 600;
}
.tabs a .ico { font-size: 24px; line-height: 1.1; }
.tabs a.on { color: var(--brand); }

h2 { font-size: 22px; margin: 28px 0 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
h2 small { font-size: 15px; color: var(--muted); font-weight: 500; }
h3 { font-size: 19px; margin: 0 0 4px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.pad { padding: 24px 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 10px 0;
}
.card.chosen { border: 3px solid var(--chosen); }
.badge {
  display: inline-block; font-size: 13px; font-weight: 700; padding: 3px 10px; border-radius: 99px;
  background: var(--chosen); color: #2b2205;
}
.badge.todo { background: var(--line); color: var(--muted); }
.meta { color: var(--muted); font-size: 15px; margin: 4px 0 0; }
.title-link { color: inherit; text-decoration: none; }
.title-link:after { content: " ›"; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 20px;
  border: 2px solid var(--line); border-radius: 14px;
  background: var(--card); font-weight: 700; font-size: 18px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.wide { width: 100%; }
.btn.small { min-height: 44px; font-size: 16px; padding: 0 14px; }
.btn[disabled] { opacity: 0.6; }

.vote { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.vote .yes.on { background: var(--yes); border-color: var(--yes); color: var(--brand-ink); }
.vote .no.on { background: var(--no); border-color: var(--no); color: #fff; }
.voters { font-size: 15px; margin-top: 8px; color: var(--muted); }
.voters b.y { color: var(--yes); }
.voters b.n { color: var(--no); }

.comments { margin-top: 10px; font-size: 16px; }
.comments p { margin: 6px 0; padding: 8px 12px; background: var(--bg); border-radius: 10px; }
.comment-form { display: none; margin-top: 10px; gap: 8px; }
.comment-form.open { display: grid; }
textarea, input[type="email"], input[type="text"] {
  width: 100%; min-height: var(--tap); padding: 12px 14px;
  border: 2px solid var(--line); border-radius: 14px; background: var(--card);
}
textarea { min-height: 88px; resize: vertical; }
.link-btn { background: none; border: none; color: var(--brand); font-weight: 600; padding: 10px 0 0; cursor: pointer; font-size: 16px; }

.progress { font-size: 17px; margin: 6px 0 0; }
.spinner { width: 44px; height: 44px; border: 5px solid var(--line); border-top-color: var(--brand); border-radius: 50%; margin: 24px auto; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Login */
.login { max-width: 420px; margin: 8vh auto 0; display: grid; gap: 14px; }
.login h2 { justify-content: center; margin: 0; }
.code-input { text-align: center; font-size: 30px; letter-spacing: 10px; font-variant-numeric: tabular-nums; }
.error { color: var(--no); font-weight: 600; }

/* Shopping */
.shop-item {
  display: flex; align-items: center; gap: 14px; width: 100%;
  min-height: var(--tap); padding: 10px 4px; border: none; border-bottom: 1px solid var(--line);
  background: none; text-align: left; cursor: pointer;
}
.shop-item:last-child { border-bottom: none; }
.box { flex: 0 0 30px; height: 30px; border: 2px solid var(--muted); border-radius: 8px; display: grid; place-items: center; font-weight: 800; color: var(--brand-ink); }
.shop-item.done .box { background: var(--brand); border-color: var(--brand); }
.shop-item.done .what { text-decoration: line-through; color: var(--muted); }
.what { flex: 1; }
.what .name { font-weight: 600; }
.what .for { display: block; font-size: 14px; color: var(--muted); }
.amount { font-weight: 700; white-space: nowrap; }

/* Cooking view */
.recipe-head { margin-top: 8px; }
.facts { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.fact { background: var(--card); border: 1px solid var(--line); border-radius: 99px; padding: 4px 12px; font-size: 15px; }
.steps { list-style: none; padding: 0; margin: 0; counter-reset: step; }
.steps li {
  counter-increment: step; position: relative; padding: 14px 14px 14px 58px; margin: 10px 0;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); font-size: 20px; cursor: pointer;
}
.steps li:before {
  content: counter(step); position: absolute; left: 14px; top: 12px;
  width: 32px; height: 32px; border-radius: 50%; background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; font-weight: 800; font-size: 17px;
}
.steps li.done { opacity: 0.45; }
.note { background: var(--yes-soft); border-radius: var(--radius); padding: 12px 14px; margin: 10px 0; }
.back { display: inline-block; margin-top: 8px; font-weight: 600; text-decoration: none; font-size: 17px; }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 9;
  background: var(--ink); color: var(--bg); padding: 14px 16px; border-radius: 14px; text-align: center; font-weight: 600;
}

/* PIN pad */
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 8px 0; }
.pin-dots span { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots span.on { background: var(--brand); border-color: var(--brand); }
.pinpad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.pinpad .btn { min-height: 68px; font-size: 26px; }
.pinpad [data-other] { font-size: 14px; }

/* Kitchen */
.snap { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0; }
.snap label { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 96px; font-size: 17px; }
.snap label .ico { font-size: 34px; }
.snap input { display: none; }
.thumbs { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0; }
.thumbs figure { margin: 0; flex: 0 0 auto; text-align: center; font-size: 13px; color: var(--muted); }
.thumbs img { width: 76px; height: 76px; object-fit: cover; border-radius: 10px; display: block; border: 1px solid var(--line); }
.onhand-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.onhand-row:last-child { border-bottom: none; }
.onhand-row .what { flex: 1; }
.onhand-row.gone .name { text-decoration: line-through; color: var(--muted); }
.maybe { font-size: 13px; color: var(--muted); font-weight: 600; }
.add-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 10px; }
.seg { display: flex; gap: 6px; margin-top: 8px; }
.seg button { flex: 1; }
.seg button.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.at-home { display: block; font-size: 14px; color: var(--yes); font-weight: 600; }
