:root {
  --bg: #EEE4D6;
  --hi: #FFF8EE;
  --lo: #D3C2AA;
  --ink: #3B2F24;
  --muted: #7A6753;
  --terra: #C2643A;
  --terra-ink: #A24F2A;
  --sage: #7F9465;
  --cactus: #4F7346;
  --gold: #D9A441;
  --sky: #8DB0C6;
  --low: #D9A441;
  --out: #C2643A;
  --raised: 6px 6px 14px var(--lo), -6px -6px 14px var(--hi);
  --raised-sm: 3px 3px 7px var(--lo), -3px -3px 7px var(--hi);
  --inset: inset 4px 4px 9px var(--lo), inset -4px -4px 9px var(--hi);
  --radius: 20px;
  --font: "Nunito", system-ui, -apple-system, sans-serif;
  --display: "Rye", Georgia, serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--font);
  min-height: 100vh;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--terra-ink); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-family: var(--display); font-weight: 400; font-size: 1.7rem; letter-spacing: .5px; }
h2 { font-size: 1.1rem; font-weight: 800; }
h3 { font-size: 1rem; font-weight: 800; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

/* ---- top bar & tabs ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand img { border-radius: 10px; box-shadow: var(--raised-sm); }
.brand span { font-family: var(--display); font-size: 1.25rem; }
.tabs {
  position: fixed; left: 12px; right: 12px; bottom: calc(10px + env(safe-area-inset-bottom));
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  padding: 8px; border-radius: 24px; background: var(--bg); box-shadow: var(--raised);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px; border-radius: 16px; text-decoration: none; color: var(--muted);
  font-size: .72rem; font-weight: 700;
}
.tabs a .ico { font-size: 1.3rem; line-height: 1; }
.tabs a.active { color: var(--terra-ink); box-shadow: var(--inset); }

@media (min-width: 860px) {
  body { padding-bottom: 40px; }
  .tabs { position: static; display: flex; box-shadow: var(--raised-sm); padding: 6px; }
  .tabs a { flex-direction: row; gap: 8px; padding: 8px 16px; font-size: .9rem; }
  .tabs a .ico { font-size: 1.05rem; }
}

main { max-width: 960px; margin: 0 auto; padding: 8px 16px 24px; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 0 16px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }

/* ---- surfaces ---- */
.card { background: var(--bg); border-radius: var(--radius); box-shadow: var(--raised); padding: 16px; margin-bottom: 18px; }
.well { border-radius: 16px; box-shadow: var(--inset); padding: 12px; }
.grid { display: grid; gap: 18px; }
@media (min-width: 700px) { .grid.two { grid-template-columns: 1fr 1fr; } .grid.three { grid-template-columns: repeat(3, 1fr); } }

/* ---- controls ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 16px; padding: 11px 18px; cursor: pointer;
  background: var(--bg); box-shadow: var(--raised-sm); font-weight: 800; color: var(--ink);
  min-height: 44px;
}
.btn:active { box-shadow: var(--inset); }
.btn.primary { background: var(--terra); color: #FFF8EE; box-shadow: 4px 4px 10px var(--lo), -4px -4px 10px var(--hi); }
.btn.primary:active { background: var(--terra-ink); }
.btn.green { background: var(--cactus); color: #FFF8EE; }
.btn.small { padding: 7px 12px; min-height: 36px; font-size: .88rem; border-radius: 12px; }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .55; cursor: default; }
.icon-btn { border: 0; background: var(--bg); box-shadow: var(--raised-sm); width: 36px; height: 36px; border-radius: 12px; cursor: pointer; color: var(--muted); flex: none; }
.icon-btn:active { box-shadow: var(--inset); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.stack > * + * { margin-top: 12px; }

input[type=text], input[type=search], input[type=password], input[type=number], select, textarea {
  width: 100%; border: 0; border-radius: 14px; padding: 12px 14px; background: var(--bg); box-shadow: var(--inset);
  outline: none; min-height: 44px;
}
textarea { resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus { box-shadow: var(--inset), 0 0 0 2px var(--sage); }
label.field { display: block; font-weight: 700; font-size: .85rem; color: var(--muted); }
label.field > span { display: block; margin-bottom: 6px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 0; border-radius: 999px; padding: 8px 14px; cursor: pointer; background: var(--bg);
  box-shadow: var(--raised-sm); font-weight: 700; font-size: .88rem; color: var(--muted); min-height: 38px;
}
.chip.on { box-shadow: var(--inset); color: var(--terra-ink); }

.toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 700; }
.toggle input { appearance: none; width: 50px; height: 28px; border-radius: 999px; box-shadow: var(--inset); position: relative; margin: 0; cursor: pointer; flex: none; }
.toggle input::after { content: ""; position: absolute; top: 4px; left: 4px; width: 20px; height: 20px; border-radius: 50%; background: var(--bg); box-shadow: var(--raised-sm); transition: left .15s; }
.toggle input:checked { background: var(--sage); }
.toggle input:checked::after { left: 26px; }

.stepper { display: inline-flex; align-items: center; gap: 10px; }
.stepper output { min-width: 2ch; text-align: center; font-weight: 800; font-size: 1.1rem; }

/* ---- pantry ---- */
.cat-head { display: flex; align-items: center; gap: 8px; margin: 18px 4px 8px; font-weight: 800; color: var(--muted); text-transform: uppercase; font-size: .78rem; letter-spacing: .08em; }
.items { list-style: none; margin: 0; padding: 0; }
.item { display: flex; align-items: center; gap: 10px; padding: 10px 6px; border-bottom: 1px solid rgba(122,103,83,.14); }
.item:last-child { border-bottom: 0; }
.item .name { flex: 1; min-width: 0; }
.item .name b { display: block; font-weight: 700; overflow-wrap: anywhere; }
.item .name small { color: var(--muted); }
.seg { display: inline-flex; border-radius: 12px; box-shadow: var(--inset); padding: 3px; flex: none; }
.seg button { border: 0; background: transparent; border-radius: 9px; padding: 5px 9px; font-size: .78rem; font-weight: 800; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--bg); box-shadow: var(--raised-sm); }
.seg button.on[data-v=plenty] { color: var(--cactus); }
.seg button.on[data-v=low] { color: #A97A1E; }
.seg button.on[data-v=out] { color: var(--terra-ink); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.dot.plenty { background: var(--sage); } .dot.low { background: var(--low); } .dot.out { background: var(--out); }
.preview .item { gap: 8px; flex-wrap: wrap; }
.preview .item input[type=text] { flex: 2 1 120px; min-height: 38px; padding: 8px 10px; }
.preview .item select { flex: 1 1 110px; min-height: 38px; padding: 8px 10px; }

/* ---- empty states ---- */
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }
.empty svg { width: 92px; height: 92px; display: block; margin: 0 auto 10px; }

/* ---- recipes ---- */
.recipe-card { cursor: pointer; display: flex; flex-direction: column; gap: 8px; text-align: left; border: 0; width: 100%; }
.recipe-card .emoji { font-size: 2rem; width: 56px; height: 56px; display: grid; place-items: center; border-radius: 18px; box-shadow: var(--inset); }
.meta { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: .76rem; font-weight: 800; padding: 3px 10px; border-radius: 999px; background: rgba(127,148,101,.18); color: var(--cactus); }
.tag.warn { background: rgba(194,100,58,.14); color: var(--terra-ink); }
.nutri { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.nutri div { text-align: center; padding: 10px 4px; border-radius: 14px; box-shadow: var(--inset); }
.nutri b { display: block; font-size: 1.05rem; }
.nutri small { color: var(--muted); font-size: .72rem; font-weight: 700; }
.ings { list-style: none; padding: 0; margin: 0; }
.ings li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px dashed rgba(122,103,83,.22); }
.ings li:last-child { border-bottom: 0; }
.ings .amt { flex: none; width: 92px; font-weight: 800; color: var(--terra-ink); }
.ings .sub { display: block; font-size: .82rem; color: var(--cactus); font-weight: 700; }
.ings .missing b::after { content: " · need"; color: var(--terra-ink); font-size: .78rem; font-weight: 800; }
.steps { padding-left: 0; margin: 0; list-style: none; counter-reset: s; }
.steps li { counter-increment: s; display: flex; gap: 12px; padding: 8px 0; }
.steps li::before { content: counter(s); flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: var(--terra-ink); box-shadow: var(--raised-sm); }

.stars { display: inline-flex; gap: 4px; }
.stars button { border: 0; background: none; font-size: 1.7rem; cursor: pointer; padding: 2px; filter: grayscale(1) opacity(.45); }
.stars button.on { filter: none; }
.stars.small button { font-size: 1.1rem; }

/* ---- loading ---- */
.loading { text-align: center; padding: 40px 12px; color: var(--muted); font-weight: 700; }
.tumble { font-size: 2.6rem; display: inline-block; animation: roll 1.4s linear infinite; }
@keyframes roll { 0% { transform: translateX(-60px) rotate(0); } 50% { transform: translateX(60px) rotate(360deg); } 100% { transform: translateX(-60px) rotate(720deg); } }
@media (prefers-reduced-motion: reduce) { .tumble { animation: none; } }

/* ---- sheet ---- */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(59,47,36,.35); }
.sheet-panel {
  position: relative; width: 100%; max-width: 720px; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 26px 26px 0 0; padding: 22px 18px calc(24px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 30px rgba(59,47,36,.2);
}
@media (min-width: 760px) { .sheet { align-items: center; } .sheet-panel { border-radius: 26px; max-height: 88vh; } }
.sheet-close { position: sticky; top: 0; float: right; z-index: 2; }

.toast {
  position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--hi); padding: 10px 18px; border-radius: 14px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: all .2s; z-index: 60; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.bar { height: 10px; border-radius: 999px; box-shadow: var(--inset); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--sage); border-radius: 999px; }
.prompt-box { font-family: ui-monospace, Menlo, monospace; font-size: .82rem; min-height: 220px; }
.banner { padding: 10px 14px; border-radius: 14px; background: rgba(217,164,65,.18); color: #7A5A17; font-weight: 700; font-size: .88rem; margin-bottom: 14px; }
.shop-item { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid rgba(122,103,83,.14); }
.shop-item.done b { text-decoration: line-through; color: var(--muted); }
.shop-item .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.check { appearance: none; width: 26px; height: 26px; border-radius: 9px; box-shadow: var(--raised-sm); cursor: pointer; flex: none; margin: 0; display: grid; place-items: center; }
.check:checked { box-shadow: var(--inset); }
.check:checked::after { content: "✓"; color: var(--cactus); font-weight: 900; }
