:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --text: #2b2420;
  --muted: #7a6e66;
  --line: #e8e0d6;
  --accent: #b5532d;
  --accent-text: #ffffff;
  --chip: #f1e8de;
  --danger: #b3261e;
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1816;
    --surface: #26221f;
    --text: #f2ece6;
    --muted: #a99d93;
    --line: #3a342f;
    --accent: #e07a4f;
    --accent-text: #1b1816;
    --chip: #342d28;
    --danger: #f2827a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

#app {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px calc(32px + env(safe-area-inset-bottom));
}

h1, h2, h3 { line-height: 1.25; margin: 0; }
h2 { font-size: 1.15rem; margin: 28px 0 8px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.pad { padding: 16px 0; }

/* top bar */
.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(12px + env(safe-area-inset-top)) 0 12px;
  background: var(--bg);
}
.bar h1 { font-size: 1.6rem; flex: 1; }
.bar h1.center { font-size: 1.05rem; text-align: center; }
.spacer { flex: 1; }

/* buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); padding: 0 8px; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }

/* search + chips */
.search input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 0; scrollbar-width: none; }
.chips.static { flex-wrap: wrap; overflow: visible; padding: 8px 0 0; }
.chip {
  flex: none;
  padding: 6px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--chip);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.chip.on { background: var(--accent); color: var(--accent-text); }

/* grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
  padding-top: 4px;
}
.card {
  display: block;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  text-decoration: none;
}
.card img, .card .ph { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.card .ph {
  display: grid;
  place-items: center;
  background: var(--chip);
  color: var(--accent);
  font-size: 2.5rem;
  font-weight: 700;
}
.card-body { padding: 10px 12px 12px; }
.card-body h3 { font-size: 1rem; }
.card-body p { margin: 2px 0 0; font-size: 0.85rem; }

.empty { text-align: center; padding: 80px 0; }

/* recipe view */
.hero {
  display: block;
  width: 100%;
  max-height: 420px;
  object-fit: cover;
  border-radius: var(--radius);
}
.recipe h1 { font-size: 1.8rem; margin-top: 16px; }
.recipe > .muted { margin: 6px 0 0; }
.scaler { display: flex; align-items: center; gap: 12px; margin-top: 20px; font-weight: 600; }
.scaler output { min-width: 2ch; text-align: center; font-size: 1.2rem; }
.round {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
}
.ingredients { padding-left: 20px; margin: 0; }
.ingredients li { padding: 4px 0; }
.steps { padding-left: 22px; margin: 0; }
.steps li { padding: 8px 0; cursor: pointer; }
.steps li.done { color: var(--muted); text-decoration: line-through; }
.notes { white-space: pre-wrap; margin: 0; }

/* what can I cook? */
.cook-cta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}
.cook-cta span { font-size: 0.9rem; }
.cook { display: flex; flex-direction: column; gap: 12px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.have-bar { display: flex; align-items: center; justify-content: space-between; }
.chips.wrap { flex-wrap: wrap; overflow: visible; padding: 0; max-height: 240px; overflow-y: auto; }
.chip.add { background: transparent; border: 1px dashed var(--accent); color: var(--accent); }
.matches { display: flex; flex-direction: column; gap: 10px; }
.match {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}
.missing { color: var(--danger); font-size: 0.9rem; }
.have-all { color: var(--accent); font-size: 0.9rem; font-weight: 600; }

/* ingredient rows in the editor */
.field { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-weight: 600; }
.items { display: flex; flex-direction: column; gap: 10px; }
.item {
  display: grid;
  grid-template-columns: 64px 84px 1fr auto;
  grid-template-areas: "name name name del" "qty unit note opt";
  align-items: center;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.item input {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.i-name { grid-area: name; font-weight: 600; }
.i-del { grid-area: del; align-self: center; }
.i-qty { grid-area: qty; }
.i-unit { grid-area: unit; }
.i-note { grid-area: note; }
.i-opt {
  grid-area: opt;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--muted);
  white-space: nowrap;
}
.form label.i-opt { flex-direction: row; gap: 6px; font-weight: 400; }
@media (max-width: 520px) {
  .item { grid-template-areas: "name name name del" "qty unit opt opt" "note note note note"; }
}
.item .i-opt input.i-optional { width: 18px; height: 18px; margin: 0; padding: 0; accent-color: var(--accent); }
.i-del { justify-self: end; }
.add-item { align-self: flex-start; }

.save-error {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--danger);
  border-radius: 10px;
  color: var(--danger);
  font-weight: 600;
}

/* form */
.form { display: flex; flex-direction: column; gap: 16px; padding-top: 8px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.form label.btn { flex-direction: row; }
.form input, .form textarea, .form select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 400;
}
.form textarea { resize: vertical; }
.row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.photo-field { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.photo-preview {
  display: grid;
  place-items: center;
  width: 120px;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 1px dashed var(--line);
  border-radius: 10px;
  font-size: 0.85rem;
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
