:root {
  --bg: #faf6ef;
  --surface: #fffdf7;
  --ink: #2a241a;
  --muted: #7a6f5e;
  --accent: #b9512c;
  --line: #e8e0cf;
  --radius: 6px;
  --maxw: 760px;
  --font-serif: Georgia, 'Iowan Old Style', 'Source Serif Pro', serif;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
}

h1, h2, h3 {
  font-family: var(--font-serif);
  letter-spacing: 0.01em;
  font-weight: 600;
}
h1 { font-size: 2rem; margin: 0 0 0.4em; }
h2 { font-size: 1.35rem; margin: 1.6em 0 0.6em; }

a { color: var(--accent); }
a:hover { text-decoration: underline; }

.site-header {
  display: flex; align-items: center; gap: 1.5rem;
  padding: 0.9rem 1.4rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.site-header .brand {
  font-family: var(--font-serif); font-size: 1.25rem; font-weight: 700;
  color: var(--ink); text-decoration: none;
}
.site-header nav { display: flex; gap: 1rem; }
.site-header nav a { color: var(--ink); text-decoration: none; }
.site-header nav a:hover { color: var(--accent); }
.site-header .units { margin-left: auto; display: flex; gap: 0.25rem; }
.site-header .units a {
  padding: 0.25rem 0.6rem; border: 1px solid var(--line);
  border-radius: 999px; font-size: 0.85rem;
  text-decoration: none; color: var(--muted);
}
.site-header .units a.active {
  background: var(--ink); color: var(--bg); border-color: var(--ink);
}

main { max-width: var(--maxw); margin: 1.5rem auto; padding: 0 1.2rem; }

.flashes { list-style: none; padding: 0; max-width: var(--maxw); margin: 0.5rem auto; }
.flash {
  padding: 0.6rem 1rem; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  margin-bottom: 0.4rem;
}
.flash-error { background: #fbecec; border-color: #e9b8b8; }

.empty { color: var(--muted); font-style: italic; }

.search { display: flex; gap: 0.5rem; margin-bottom: 1.4rem; }
.search input {
  flex: 1; padding: 0.6rem 0.8rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); font: inherit;
}
.search button {
  padding: 0.6rem 1rem; border: 1px solid var(--ink);
  background: var(--ink); color: var(--bg);
  border-radius: var(--radius); cursor: pointer;
}

.recipe-grid {
  list-style: none; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}
.recipe-card a { display: block; text-decoration: none; color: var(--ink); }
.recipe-card img, .recipe-card-placeholder {
  width: 100%; aspect-ratio: 1 / 1; object-fit: cover;
  border-radius: var(--radius); background: var(--line);
  display: block;
}
.recipe-card-name { display: block; padding: 0.5rem 0.2rem 0; font-weight: 600; }

.recipe-header { margin-bottom: 1rem; }
.recipe-header .lead { color: var(--muted); margin-top: 0; }
.recipe-meta {
  display: flex; flex-wrap: wrap; gap: 0.6rem 1.2rem;
  color: var(--muted); font-size: 0.9rem;
}
.recipe-actions {
  margin-top: 0.7rem; display: flex; gap: 0.6rem; align-items: center;
}
.recipe-actions form { display: inline; }
.link-button {
  background: none; border: none; color: var(--accent);
  cursor: pointer; padding: 0; font: inherit;
}
.recipe-hero {
  width: 100%; max-height: 380px; object-fit: cover;
  border-radius: var(--radius); margin: 0.6rem 0 1rem;
}

.ingredients ul { list-style: none; padding: 0; }
.ingredients li {
  padding: 0.45rem 0; border-bottom: 1px dashed var(--line);
  display: flex; flex-wrap: wrap; gap: 0.4rem 0.8rem; align-items: baseline;
}
.ing-qty { color: var(--accent); font-weight: 600; min-width: 6ch; }
.ing-name { font-weight: 500; }
.ing-note { color: var(--muted); font-style: italic; font-size: 0.9rem; }
.ing-alts { font-size: 0.85rem; color: var(--muted); }
.ing-alts summary { cursor: pointer; }

.method ol { padding-left: 1.4rem; }
.method li { margin-bottom: 1rem; }
.ing-ref {
  white-space: nowrap;
  background: rgba(185, 81, 44, 0.08);
  border-radius: 4px; padding: 0 0.2rem;
}
.ing-amt { color: var(--accent); font-style: normal; font-weight: 600; }

.step-notes {
  list-style: none; padding: 0.3rem 0 0 0.7rem; margin: 0.3rem 0 0;
  border-left: 3px solid var(--line);
}
.step-notes li {
  font-size: 0.92rem; color: var(--muted); margin-bottom: 0.3rem;
}
.step-notes form { display: inline; }
.note-form { margin-top: 0.4rem; display: flex; gap: 0.4rem; }
.note-form input[type="text"] {
  flex: 1; padding: 0.35rem 0.5rem; border: 1px solid var(--line);
  border-radius: 4px; background: var(--surface); font: inherit; font-size: 0.9rem;
}
.note-form button {
  padding: 0.3rem 0.7rem; border: 1px solid var(--line);
  background: var(--surface); border-radius: 4px;
  cursor: pointer; font-size: 0.85rem;
}

.recipe-form { display: flex; flex-direction: column; gap: 1rem; }
.recipe-form label { display: flex; flex-direction: column; gap: 0.3rem; }
.recipe-form input, .recipe-form textarea {
  padding: 0.55rem 0.7rem; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface); font: inherit;
}
.recipe-form textarea { font-family: var(--font-sans); }
.recipe-form .row { display: flex; gap: 0.8rem; }
.recipe-form .row label { flex: 1; }
.recipe-thumb {
  max-width: 120px; border-radius: var(--radius);
  display: block; margin-bottom: 0.5rem;
}

.ingredients-edit { border: 1px solid var(--line); border-radius: var(--radius); padding: 0.8rem 1rem; }
.ingredients-edit legend { padding: 0 0.4rem; color: var(--muted); }

#ing-table { width: 100%; border-collapse: collapse; }
#ing-table th, #ing-table td {
  padding: 0.3rem 0.25rem; border-bottom: 1px solid var(--line);
  text-align: left; font-weight: normal;
}
#ing-table input {
  width: 100%; padding: 0.35rem; border: 1px solid var(--line);
  border-radius: 4px; background: var(--surface); font: inherit;
}
#ing-table th { font-size: 0.85rem; color: var(--muted); }
.remove-row {
  background: none; border: 1px solid var(--line); color: var(--muted);
  padding: 0.25rem 0.5rem; border-radius: 4px; cursor: pointer;
}
#add-row {
  margin-top: 0.5rem; padding: 0.4rem 0.9rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 4px; cursor: pointer;
}

.actions {
  display: flex; gap: 0.8rem; align-items: center; margin-top: 0.5rem;
}
.actions button {
  padding: 0.6rem 1.2rem; background: var(--ink); color: var(--bg);
  border: none; border-radius: var(--radius); cursor: pointer; font: inherit;
}
.actions a { color: var(--muted); }

.hint { color: var(--muted); font-size: 0.88rem; margin: 0 0 0.4rem; }
.hint code {
  background: var(--surface); padding: 0.05rem 0.3rem; border-radius: 3px;
}

.shopping-pick .recipe-checks {
  list-style: none; padding: 0; columns: 2; column-gap: 1.4rem;
}
.shopping-pick .recipe-checks li { break-inside: avoid; padding: 0.2rem 0; }
.shopping-items { list-style: none; padding: 0; }
.shopping-items li {
  padding: 0.35rem 0; border-bottom: 1px dashed var(--line);
}
.shopping-items label {
  display: flex; gap: 0.6rem; align-items: baseline;
}
.item-qty { color: var(--accent); font-weight: 600; min-width: 6ch; }

@media (max-width: 540px) {
  .site-header { flex-wrap: wrap; gap: 0.8rem; }
  .site-header .units { margin-left: 0; }
  .recipe-form .row { flex-direction: column; }
  .shopping-pick .recipe-checks { columns: 1; }
}
