:root {
  --cream: #F6F1E7;
  --cream-soft: #EFE8D8;
  --basil: #2F4A3C;
  --basil-dark: #203127;
  --basil-tint: #E7EDE7;
  --saffron: #D6A24A;
  --saffron-tint: #F6E7CC;
  --charcoal: #24211C;
  --charcoal-soft: #6B6558;
  --line: #E4DCC8;
  --brick: #B5533C;
  --white: #FFFDF9;

  --font-display: "Fraunces", serif;
  --font-body: "Public Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "IBM Plex Mono", monospace;

  --radius-l: 20px;
  --radius-m: 14px;
  --radius-s: 9px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--cream);
  color: var(--charcoal);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3 { font-family: var(--font-display); margin: 0; }

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
}

.hidden { display: none !important; }

.mono { font-family: var(--font-mono); font-weight: 600; }

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ===== TOPBAR ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 10px;
  position: sticky;
  top: 0;
  background: var(--cream);
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--basil); }
.brand h1 { font-size: 26px; font-weight: 600; letter-spacing: 0.2px; color: var(--charcoal); }
.brand-mark { color: var(--saffron); display: inline-flex; }

.icon-btn {
  border: none;
  background: transparent;
  color: var(--basil);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  cursor: pointer;
}
.icon-btn:active { background: var(--basil-tint); }

.search-bar { padding: 0 20px 10px; }
.search-bar input {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius-m);
  border: 1.5px solid var(--line);
  background: var(--white);
  font-size: 15px;
}

/* ===== VIEW ===== */
.view {
  flex: 1;
  padding: 4px 20px 100px;
  animation: fadein 0.18s ease;
}
@keyframes fadein { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; transform: none; } }

.view-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0 18px;
  position: relative;
}
.view-header h2 { font-size: 21px; font-weight: 600; }
.back-btn {
  border: none; background: var(--basil-tint); color: var(--basil);
  width: 36px; height: 36px; border-radius: 50%;
  font-size: 17px; cursor: pointer;
}
.view-header-actions { margin-left: auto; display: flex; gap: 4px; }

/* ===== FILTER ROW / CHIPS ===== */
.filter-row { display: flex; flex-direction: column; gap: 10px; padding: 6px 0 14px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.chip {
  flex: none;
  border: 1.5px solid var(--line);
  background: var(--white);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--charcoal-soft);
  cursor: pointer;
  white-space: nowrap;
}
.chip.is-active { background: var(--basil); border-color: var(--basil); color: var(--cream); }
.time-select {
  align-self: flex-start;
  border: 1.5px solid var(--line);
  background: var(--white);
  border-radius: var(--radius-s);
  padding: 7px 10px;
  font-size: 13.5px;
  font-weight: 600;
}

/* ===== RECIPE CARDS (index-card motif) ===== */
.recipe-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.recipe-card {
  background: var(--white);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-m);
  padding: 12px 12px 14px;
  cursor: pointer;
  position: relative;
  transition: transform 0.12s ease;
}
.recipe-card:active { transform: scale(0.98); }
.recipe-card::before {
  content: "";
  position: absolute;
  top: 12px; left: 12px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--cream);
  border: 1.5px solid var(--line);
}
.recipe-thumb {
  width: 100%; aspect-ratio: 4/3;
  border-radius: var(--radius-s);
  object-fit: cover;
  background: var(--basil-tint);
  margin-bottom: 9px;
}
.recipe-thumb-fallback {
  width: 100%; aspect-ratio: 4/3;
  border-radius: var(--radius-s);
  background: var(--basil-tint);
  color: var(--basil);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 9px;
}
.recipe-card h3 {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.25;
  margin-bottom: 6px;
  min-height: 2.5em;
}
.recipe-card-meta { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--charcoal-soft); }
.recipe-fav-mark { color: var(--saffron); font-size: 14px; }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--charcoal-soft);
  font-size: 14.5px;
  line-height: 1.6;
}
.empty-mark { color: var(--saffron); display: inline-flex; margin-bottom: 14px; }

/* ===== SEGMENTED CONTROL ===== */
.segmented { display: flex; background: var(--basil-tint); border-radius: var(--radius-m); padding: 4px; gap: 4px; margin-bottom: 20px; }
.seg-btn {
  flex: 1; border: none; background: transparent; padding: 9px 4px;
  border-radius: var(--radius-s); font-size: 12.5px; font-weight: 600;
  color: var(--basil); cursor: pointer;
}
.seg-btn.is-active { background: var(--white); box-shadow: 0 1px 3px rgba(36,33,28,0.12); }

/* ===== FORMS ===== */
.field-label { display: block; font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--basil); margin: 16px 0 6px; }
.label-hint { text-transform: none; font-weight: 500; color: var(--charcoal-soft); letter-spacing: 0; }
input[type="text"], input[type="url"], input[type="number"], input[type="file"], textarea, select {
  width: 100%;
  border: 1.5px solid var(--line);
  background: var(--white);
  border-radius: var(--radius-s);
  padding: 11px 13px;
  font-size: 15px;
}
textarea { resize: vertical; line-height: 1.5; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btn-primary, .btn-secondary, .btn-danger {
  border: none;
  border-radius: var(--radius-s);
  padding: 13px 18px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  margin-top: 14px;
}
.btn-primary { background: var(--basil); color: var(--cream); }
.btn-primary:active { background: var(--basil-dark); }
.btn-secondary { background: var(--saffron-tint); color: var(--basil-dark); }
.btn-danger { background: transparent; color: var(--brick); border: 1.5px solid var(--brick); }

.input-methods { display: flex; gap: 10px; margin-top: 14px; }
.input-methods .btn-secondary { margin-top: 0; }
.btn-secondary.is-dictating, .btn-secondary.is-busy { background: var(--brick); color: var(--white); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.75; } }

.hint { font-size: 13px; color: var(--charcoal-soft); line-height: 1.55; margin-top: 10px; }
.status-msg { font-size: 13px; margin-top: 8px; font-weight: 600; }
.status-msg.ok { color: var(--basil); }
.status-msg.err { color: var(--brick); }

.photo-picker { position: relative; }
.photo-preview { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: var(--radius-m); margin-bottom: 8px; }
input[type="file"] { padding: 9px; font-size: 13px; }

.form-actions { margin-top: 8px; }

/* ===== DETAIL ===== */
.detail-photo { width: 100%; aspect-ratio: 16/10; object-fit: cover; border-radius: var(--radius-l); margin-bottom: 14px; }
.detail-title { font-size: 25px; font-weight: 600; line-height: 1.2; margin-bottom: 10px; }
.detail-meta { display: flex; gap: 8px; margin-bottom: 18px; }
.meta-pill { background: var(--basil-tint); color: var(--basil); font-size: 12.5px; font-weight: 700; padding: 5px 11px; border-radius: 999px; }
.meta-pill-accent { background: var(--saffron-tint); color: #7A5117; }

.servings-control {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--white); border: 1.5px solid var(--line);
  border-radius: var(--radius-m); padding: 12px 16px; margin-bottom: 18px;
  font-weight: 600;
}
.stepper { display: flex; align-items: center; gap: 14px; }
.stepper button {
  width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid var(--basil);
  background: var(--white); color: var(--basil); font-size: 16px; font-weight: 700; cursor: pointer;
}
.stepper span { min-width: 20px; text-align: center; font-size: 16px; }

.detail-tabs { display: flex; gap: 22px; border-bottom: 1.5px solid var(--line); margin-bottom: 16px; }
.dtab { border: none; background: transparent; padding: 4px 0 12px; font-size: 14.5px; font-weight: 700; color: var(--charcoal-soft); cursor: pointer; border-bottom: 2.5px solid transparent; margin-bottom: -1.5px; }
.dtab.is-active { color: var(--basil); border-bottom-color: var(--saffron); }

.ingredient-list { list-style: none; margin: 0; padding: 0; }
.ingredient-list li {
  display: flex; align-items: baseline; gap: 10px;
  padding: 10px 0; border-bottom: 1px dashed var(--line);
  font-size: 15px;
}
.ingredient-list li .qty { font-family: var(--font-mono); font-weight: 600; color: var(--basil); min-width: 60px; }
.ingredient-list li.checked { opacity: 0.4; text-decoration: line-through; }

.step-list { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.step-list li {
  counter-increment: step;
  padding: 12px 0 12px 38px;
  border-bottom: 1px dashed var(--line);
  position: relative;
  font-size: 15px;
  line-height: 1.5;
}
.step-list li::before {
  content: counter(step);
  position: absolute; left: 0; top: 10px;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--saffron); color: var(--basil-dark);
  font-family: var(--font-mono); font-weight: 700; font-size: 12.5px;
  display: flex; align-items: center; justify-content: center;
}

.source-link { margin-top: 22px; font-size: 12.5px; color: var(--charcoal-soft); }
.source-link a { color: var(--basil); }

/* ===== COOK MODE ===== */
.cook-overlay {
  position: fixed; inset: 0; background: var(--basil);
  color: var(--cream); z-index: 50;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top, 20px) 24px calc(env(safe-area-inset-bottom, 20px) + 20px);
}
.cook-top { display: flex; align-items: center; justify-content: space-between; padding-top: 12px; }
.cook-top .icon-btn { color: var(--cream); }
.cook-top .icon-btn:active { background: rgba(255,255,255,0.12); }
#cook-progress { color: var(--saffron); font-size: 13px; }
.cook-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 28px; }
.cook-step-text { font-family: var(--font-display); font-size: 26px; line-height: 1.35; }
.cook-timer-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.cook-timer { font-size: 34px; color: var(--saffron); }
.cook-nav { display: flex; gap: 12px; padding-top: 10px; }
.cook-nav button { margin-top: 0; }
.cook-overlay .btn-secondary { background: rgba(255,255,255,0.14); color: var(--cream); }
.cook-overlay .btn-primary { background: var(--saffron); color: var(--basil-dark); }

/* ===== SHOPPING LIST ===== */
.shopping-list { list-style: none; margin: 0; padding: 0; }
.shopping-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 4px; border-bottom: 1px dashed var(--line);
  font-size: 15.5px;
}
.shopping-list li .check {
  width: 22px; height: 22px; border-radius: 6px; border: 1.5px solid var(--basil);
  display: flex; align-items: center; justify-content: center; flex: none; cursor: pointer;
  color: var(--basil); font-size: 13px; font-weight: 700;
}
.shopping-list li.checked { opacity: 0.4; text-decoration: line-through; }
.shopping-list li .item-name { flex: 1; }
.shopping-list li .item-remove { border: none; background: none; color: var(--charcoal-soft); font-size: 15px; cursor: pointer; }

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 560px;
  background: var(--white);
  border-top: 1.5px solid var(--line);
  display: flex; align-items: center; justify-content: space-around;
  padding: 8px 20px calc(8px + env(safe-area-inset-bottom));
  z-index: 10;
}
.nav-btn {
  background: none; border: none; display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--charcoal-soft); font-size: 11px; font-weight: 600; cursor: pointer; padding: 4px 10px;
}
.nav-btn.is-active { color: var(--basil); }
.nav-add { margin-top: -26px; }
.nav-add-circle {
  width: 52px; height: 52px; border-radius: 50%; background: var(--saffron); color: var(--basil-dark);
  display: flex; align-items: center; justify-content: center; font-size: 28px; font-weight: 400;
  box-shadow: 0 4px 12px rgba(47,74,60,0.25);
}

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: 92px; left: 50%; transform: translateX(-50%);
  background: var(--charcoal); color: var(--cream);
  padding: 11px 20px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,0.2);
  animation: toastin 0.18s ease;
}
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px);} to { opacity: 1; transform: translate(-50%, 0);} }

@media (min-width: 600px) {
  .recipe-grid { grid-template-columns: 1fr 1fr 1fr; }
}
