/* ─── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #faf9f6;
  --surface:      #ffffff;
  --border:       #e5e2dc;
  --accent:       #c0392b;
  --accent-light: #f9eae8;
  --text:         #1a1a1a;
  --muted:        #6b6560;
  --radius:       12px;
  --shadow:       0 2px 12px rgba(0,0,0,.08);
  --max-width:    780px;
  --font:         -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100dvh;
}

img { display: block; max-width: 100%; }
a   { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Site Header ───────────────────────────────────────────────────── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.site-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: .65rem;
}

.back-link {
  font-size: .95rem;
  font-weight: 600;
  color: var(--accent);
}

/* ─── Search Bar ────────────────────────────────────────────────────── */
.search-bar-wrapper { width: 100%; }

.search-bar {
  width: 100%;
  padding: .6rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  font-size: 1rem;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
  -webkit-appearance: none;
}
.search-bar:focus { border-color: var(--accent); }

/* ─── Recipe Grid (Homepage) ────────────────────────────────────────── */
main { padding: 1.25rem; }

.recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  gap: 1.1rem;
  margin-top: .25rem;
}

.recipe-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  transition: transform .15s, box-shadow .15s;
}
.recipe-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,.12); text-decoration: none; }

.card-img-wrap { aspect-ratio: 4/3; overflow: hidden; background: #ede9e4; }
.card-img-wrap img { width: 100%; height: 100%; object-fit: cover; }

.card-body { padding: 1rem; flex: 1; display: flex; flex-direction: column; gap: .35rem; }
.card-title { font-size: 1.1rem; font-weight: 700; }
.card-desc  { font-size: .9rem; color: var(--muted); flex: 1; }
.card-meta  { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: .25rem; }
.card-meta span { font-size: .8rem; color: var(--muted); }
.card-meta .tag { background: var(--accent-light); color: var(--accent); border-radius: 999px; padding: .15rem .6rem; font-weight: 600; }

.card-tags { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .25rem; }
.card-tag {
  background: hsl(var(--tag-hue), 65%, 90%);
  color: hsl(var(--tag-hue), 55%, 30%);
  border-radius: 999px;
  padding: .15rem .6rem;
  font-size: .75rem;
  font-weight: 600;
}

.no-results { text-align: center; color: var(--muted); padding: 3rem 1rem; font-size: 1rem; }
.hidden { display: none !important; }

/* ─── Recipe Page ───────────────────────────────────────────────────── */
#recipe-root { max-width: var(--max-width); margin: 0 auto; padding: 1.25rem; }

.recipe-title { font-size: 1.8rem; font-weight: 800; line-height: 1.2; margin-bottom: .5rem; }
.recipe-desc  { font-size: 1rem; color: var(--muted); margin-bottom: 1rem; }

.recipe-meta {
  display: flex; flex-wrap: wrap; gap: .6rem;
  margin-bottom: 1rem;
}
.meta-pill {
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 999px;
  padding: .3rem .85rem;
  font-size: .85rem;
  font-weight: 600;
}

/* ─── Recipe Hero (full-bleed top banner) ───────────────────────────── */
.recipe-hero { border-radius: var(--radius); overflow: hidden; margin-bottom: 1.5rem; aspect-ratio: 16/9; background: #ede9e4; }
.recipe-hero img { width: 100%; height: 100%; object-fit: cover; }

/* ─── Recipe Image (between meta and portioning) ────────────────────── */
.recipe-img-wrap {
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1.5rem;
  aspect-ratio: 4/3;
  background: #ede9e4;
}
.recipe-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ─── Portioning Control ────────────────────────────────────────────── */
.portioning {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.portioning-label { font-size: .9rem; font-weight: 600; color: var(--muted); }
.portion-btn {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: .3rem .85rem;
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .12s, border-color .12s;
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}
.portion-btn:hover,
.portion-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ─── Sections ──────────────────────────────────────────────────────── */
.recipe-section { margin-bottom: 2rem; }
.recipe-section h2 {
  font-size: 1.15rem;
  font-weight: 700;
  border-bottom: 2px solid var(--accent);
  padding-bottom: .3rem;
  margin-bottom: .9rem;
  color: var(--accent);
}

/* ─── Video (optional, embedded YouTube) ───────────────────────────── */
.recipe-video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
}
.recipe-video-wrap iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* ─── Ingredient Groups ─────────────────────────────────────────────── */
.ingredient-group { margin-bottom: 1.25rem; }
.ingredient-group-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: .5rem;
}

.ingredient-list { list-style: none; }
.ingredient-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: .45rem 0;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
  font-size: .97rem;
}
.ingredient-list li:last-child { border-bottom: none; }
.ingredient-amount { font-weight: 600; white-space: nowrap; }
.ingredient-note   { font-size: .82rem; color: var(--muted); font-style: italic; }

/* ─── Instructions ──────────────────────────────────────────────────── */
.instruction-list { list-style: none; counter-reset: steps; }
.instruction-list li {
  counter-increment: steps;
  display: flex;
  gap: 1rem;
  padding: .75rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .97rem;
}
.instruction-list li:last-child { border-bottom: none; }
.instruction-list li::before {
  content: counter(steps);
  min-width: 1.8rem;
  height: 1.8rem;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .85rem;
  flex-shrink: 0;
  margin-top: .1rem;
}

/* ─── Substitutions ─────────────────────────────────────────────────── */
.sub-list { list-style: none; }
.sub-list li {
  padding: .5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .95rem;
}
.sub-list li:last-child { border-bottom: none; }
.sub-original { font-weight: 600; }
.sub-arrow    { color: var(--muted); margin: 0 .4rem; }
.sub-for      { color: var(--muted); }

/* ─── Notes ─────────────────────────────────────────────────────────── */
.notes-box {
  background: var(--accent-light);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: .8rem;
}
.notes-list {
  list-style: none;
  display: grid;
  gap: .65rem;
}
.notes-list li {
  display: grid;
  grid-template-columns: 1.65rem 1fr;
  gap: .65rem;
  align-items: start;
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--accent) 24%, var(--border));
  border-radius: 10px;
  padding: .75rem .85rem;
  font-size: .95rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.04);
}
.note-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.65rem;
  height: 1.65rem;
  background: var(--accent-light);
  border-radius: 50%;
  line-height: 1;
}

/* ─── Footer ─────────────────────────────────────────────────────────── */
footer {
  text-align: center;
  width: 100%;
  display: block;
  font-size: .6rem;
  color: var(--muted);
}

/* ─── Loading ────────────────────────────────────────────────────────── */
.loading { color: var(--muted); text-align: center; padding: 3rem; }

/* ─── Desktop tweaks ─────────────────────────────────────────────────── */
@media (min-width: 640px) {
  .site-header { display: flex; align-items: center; gap: 1.5rem; padding: 1rem 2rem; }
  .site-title  { margin-bottom: 0; white-space: nowrap; }
  main         { padding: 1.5rem 2rem; }
  #recipe-root { padding: 2rem; }
  .recipe-title { font-size: 2.2rem; }
}

/* ─── Dark Mode ──────────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #1a1917;
    --surface:      #242220;
    --border:       #3a3733;
    --accent:       #e05c4b;
    --accent-light: #2e1f1d;
    --text:         #f0ede8;
    --muted:        #9a948d;
    --shadow:       0 2px 12px rgba(0,0,0,.35);
  }

  .search-bar      { background: var(--surface); }
  .portion-btn     { color: var(--text); }
  .recipe-img-wrap { background: #2a2825; }
  .card-img-wrap   { background: #2a2825; }
  .recipe-hero     { background: #2a2825; }
  .card-tag        { background: hsl(var(--tag-hue), 45%, 22%); color: hsl(var(--tag-hue), 65%, 82%); }
}