:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f3eee6;
  --text: #2a2420;
  --muted: #7a6f66;
  --line: #e6dfd4;
  --accent: #c2410c;
  --accent-text: #ffffff;
  --accent-soft: #fde7da;
  --good: #15803d;
  --good-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 2px 8px rgba(60, 40, 20, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171412;
    --surface: #221e1b;
    --surface-2: #2c2723;
    --text: #f2ece6;
    --muted: #a99d93;
    --line: #3a332e;
    --accent: #f97316;
    --accent-text: #1a0f08;
    --accent-soft: #3d2416;
    --good: #4ade80;
    --good-soft: #14301f;
    --warn: #fbbf24;
    --warn-soft: #3a2d0f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
body.locked { overflow: hidden; }
a { color: var(--accent); }
[hidden] { display: none !important; }

.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: calc(12px + env(safe-area-inset-top)) 16px 8px;
  border-bottom: 1px solid var(--line);
}
.top h1 { margin: 0; font-size: 20px; letter-spacing: -.01em; }
main { max-width: 720px; margin: 0 auto; padding: 16px; }

input, textarea, select {
  font: inherit; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; width: 100%; min-width: 0;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
label { display: block; }
.form label { margin: 0 0 14px; font-weight: 600; font-size: 14px; }
.form label input, .form label textarea { margin-top: 6px; font-weight: 400; }
.form small { font-weight: 400; color: var(--muted); }

.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 10px 16px; white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.big { display: block; width: 100%; padding: 14px; font-size: 17px; margin: 12px 0; }
.btn.danger { color: #b91c1c; }
.btn:disabled { opacity: .6; }
.link { background: none; border: 0; color: var(--accent); font: inherit; padding: 4px 0; cursor: pointer; }

.add-row { display: flex; gap: 8px; margin-bottom: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--accent-soft); color: var(--text);
  border-radius: 999px; padding: 6px 6px 6px 12px; font-size: 15px;
}
.chip button {
  border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1;
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
}
.hint { color: var(--muted); font-size: 14px; margin: 4px 0; }

.toggles { margin: 16px 0 4px; display: grid; gap: 10px; }
.grocy-box {
  margin-top: 14px; padding: 12px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); display: grid; gap: 10px;
}
.grocy-status {
  text-align: left; font: inherit; font-size: 14px; color: var(--muted); background: none;
  border: 0; padding: 0; cursor: pointer;
}
.grocy-status b { color: var(--text); font-weight: 600; }
.grocy-status .due { color: var(--warn); font-weight: 600; }
.grocy-status u { color: var(--accent); text-decoration: none; font-weight: 600; margin-left: 12px; white-space: nowrap; }
.uses { margin: 4px 0 0; font-size: 13px; color: var(--warn); }
.ings .box { font-size: 12px; color: var(--muted); margin-left: 6px; white-space: nowrap; }
.stock-list { list-style: none; padding: 0; margin: 8px 0 0; }
.stock-list li { display: flex; justify-content: space-between; gap: 10px; padding: 9px 2px; border-bottom: 1px solid var(--line); }
.stock-list .when { color: var(--muted); font-size: 14px; white-space: nowrap; }
.stock-list li.due .when { color: var(--warn); font-weight: 600; }
.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; font-size: 15px; }
.switch small { display: block; color: var(--muted); font-size: 13px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch > span {
  flex: none; width: 44px; height: 26px; border-radius: 999px; background: var(--line);
  position: relative; transition: background .15s;
}
.switch > span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.warning { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 4px; }
.filters select {
  appearance: none; -webkit-appearance: none; padding-right: 32px; font-size: 15px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 52%, calc(100% - 12px) 52%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.filters select.set { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.time-row { display: flex; align-items: center; gap: 8px; margin: 4px 0 12px; font-size: 15px; }
.time-row input { width: 90px; }
.results-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 8px 0; color: var(--muted); font-size: 14px; }
.check { display: flex; align-items: center; gap: 6px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.list { display: grid; gap: 10px; }
@media (min-width: 640px) { .list { grid-template-columns: 1fr 1fr; } }
.card {
  display: flex; gap: 12px; align-items: stretch; text-align: left; width: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px; box-shadow: var(--shadow); color: inherit; font: inherit; cursor: pointer;
}
.card img, .card .noimg {
  flex: none; width: 88px; height: 88px; border-radius: 10px; object-fit: cover; background: var(--surface-2);
}
.noimg { display: grid; place-items: center; font-size: 34px; }
.card-body { min-width: 0; padding: 2px 4px 2px 0; }
.card h3 { margin: 0 0 2px; font-size: 16px; line-height: 1.25; }
.meta { margin: 0; color: var(--muted); font-size: 13px; }
.match { margin: 6px 0 0; font-size: 13px; color: var(--warn); }
.match.ready { color: var(--good); font-weight: 600; }
.badge {
  display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 1px 6px; margin-left: 4px;
}
.stars-small { color: var(--accent); font-size: 13px; letter-spacing: 1px; }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; }
.spinner { text-align: center; color: var(--muted); padding: 28px 0; }
.spinner::before {
  content: ""; display: block; margin: 0 auto 10px; width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.section-title { font-size: 16px; margin: 20px 0 8px; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.pill {
  font: inherit; font-size: 14px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 6px 12px; cursor: pointer;
}
.pill.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  border: 0; background: none; color: var(--muted); font: inherit; font-size: 12px; font-weight: 600;
  padding: 8px 0 10px; display: grid; justify-items: center; gap: 2px; cursor: pointer;
}
.tabbar button span { font-size: 20px; line-height: 1.2; }
.tabbar button.active { color: var(--accent); }

/* Full-screen recipe sheet */
.sheet {
  position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.sheet-close {
  position: fixed; z-index: 21; top: calc(10px + env(safe-area-inset-top)); left: 10px;
  width: 40px; height: 40px; border-radius: 50%; border: 0; font-size: 20px; cursor: pointer;
  background: rgba(0,0,0,.55); color: #fff;
}
#sheet-content { max-width: 720px; margin: 0 auto; padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
.hero { width: 100%; aspect-ratio: 4 / 3; max-height: 46vh; object-fit: cover; display: block; background: var(--surface-2); }
.sheet-body { padding: 16px; }
.sheet-body.pad-top { padding-top: calc(64px + env(safe-area-inset-top)); }
.sheet-body h2 { margin: 0 0 4px; font-size: 24px; line-height: 1.2; }
.sheet-body h3 { margin: 22px 0 8px; font-size: 18px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 4px; }
.actions .btn { text-decoration: none; display: inline-flex; align-items: center; }
.summary { border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-top: 12px; background: var(--warn-soft); color: var(--warn); }
.summary.ready { background: var(--good-soft); color: var(--good); font-weight: 600; }

.ings { list-style: none; padding: 0; margin: 0; }
.ings li {
  display: flex; gap: 10px; padding: 9px 2px; border-bottom: 1px solid var(--line); align-items: baseline;
}
.ings li::before { content: "•"; color: var(--muted); width: 14px; flex: none; text-align: center; }
.ings li.have::before { content: "✓"; color: var(--good); font-weight: 700; }
.ings li.missing::before { content: "✗"; color: var(--warn); font-weight: 700; }
.ings li.missing .name { color: var(--warn); }
.ings li.staple { color: var(--muted); }
.ings .measure { color: var(--muted); min-width: 0; margin-left: auto; text-align: right; font-size: 14px; padding-left: 8px; }
.legend { color: var(--muted); font-size: 13px; margin: 0 0 4px; }

.steps { padding-left: 0; margin: 0; list-style: none; counter-reset: step; }
.steps li { counter-increment: step; position: relative; padding: 0 0 14px 40px; }
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: 0;
  width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
}

.stars { display: flex; gap: 4px; margin-bottom: 10px; }
.stars button { border: 0; background: none; font-size: 28px; line-height: 1; color: var(--line); cursor: pointer; padding: 2px; }
.stars button.on { color: var(--accent); }
.saved-note { color: var(--good); font-size: 13px; min-height: 18px; margin-top: 4px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(84px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  max-width: calc(100% - 32px); box-shadow: 0 4px 16px rgba(0,0,0,.2);
}

.status-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 12px; margin-bottom: 10px; }
.status-row { padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.status-row:last-child { border-bottom: 0; }
.status-row b { display: block; font-size: 15px; }
.status-row.ok b::before { content: "✓ "; color: var(--good); }
.status-row.bad b::before { content: "⚠ "; color: var(--warn); }
.status-row.bad span { color: var(--warn); }
.status-row code { font-size: 12px; color: var(--muted); word-break: break-all; }
