/* FridgeChef UI. Warm terracotta + fresh green on cream, rounded display type, one icon style.
   Semantic tokens only in components; the dark theme re-maps the same tokens. */

:root {
  --bg: #fffbeb;
  --surface: #ffffff;
  --surface-2: #fff7ed;
  --text: #1c1917;
  --muted: #57534e;
  --border: #f0e3dc;
  --border-strong: #e2cfc4;

  --primary: #9a3412;
  --primary-hover: #7c2d12;
  --on-primary: #ffffff;
  --accent-text: #9a3412;
  --ring: #c2410c;

  --green-ink: #065f46;
  --green-soft: #d1fae5;
  --green: #047857;
  --amber-ink: #92400e;
  --amber-soft: #fef3c7;
  --danger-ink: #991b1b;
  --danger-soft: #fee2e2;

  --r-sm: 10px;
  --r-md: 16px;
  --r-xl: 24px;
  --shadow-1: 0 1px 2px rgba(60, 30, 10, 0.06), 0 4px 14px rgba(60, 30, 10, 0.06);
  --shadow-2: 0 2px 4px rgba(60, 30, 10, 0.08), 0 12px 32px rgba(60, 30, 10, 0.12);

  --font-display: "Varela Round", "Nunito Sans", system-ui, sans-serif;
  --font-body: "Nunito Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1411;
    --surface: #251d19;
    --surface-2: #2e241f;
    --text: #f5ede8;
    --muted: #cdbdb4;
    --border: #3a2e27;
    --border-strong: #4d3d34;

    --primary: #c2410c;
    --primary-hover: #a3360a;
    --accent-text: #fdba74;
    --ring: #fdba74;

    --green-ink: #a7f3d0;
    --green-soft: #064e3b;
    --green: #34d399;
    --amber-ink: #fde68a;
    --amber-soft: #422006;
    --danger-ink: #fecaca;
    --danger-soft: #450a0a;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.3);
    --shadow-2: 0 2px 4px rgba(0, 0, 0, 0.5), 0 12px 32px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-padding-top: 5rem; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 400; line-height: 1.2; margin: 0; }
p { margin: 0; }
a { color: var(--accent-text); }
img { max-width: 100%; display: block; }
ul, ol { margin: 0; padding: 0; list-style: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }

.hidden, [hidden] { display: none !important; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; border-radius: 6px; }
[tabindex="-1"]:focus { outline: none; }

.icon {
  width: 1.25rem;
  height: 1.25rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -4rem;
  z-index: 100;
  background: var(--primary);
  color: var(--on-primary);
  padding: 0.6rem 1rem;
  border-radius: var(--r-sm);
  transition: top 160ms var(--ease);
}
.skip-link:focus { top: 0.75rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0 1.15rem;
  border-radius: 999px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
  transition: background-color 180ms var(--ease), border-color 180ms var(--ease), transform 120ms var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: var(--primary); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent-text); }
.btn.ghost:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn.lg { min-height: 52px; padding: 0 1.5rem; font-size: 1.05rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.link-btn { background: none; border: 0; padding: 0.25rem 0.1rem; color: var(--accent-text); font-weight: 700; text-decoration: underline; min-height: 44px; }

.back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
  background: none;
  border: 0;
  padding: 0 0.25rem;
  color: var(--accent-text);
  font-weight: 700;
}
.back:hover { text-decoration: underline; }

/* ---------- Top bar + stepper ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem clamp(1rem, 4vw, 2rem);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: 0.6rem; text-decoration: none; color: var(--text); min-height: 44px; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; background: var(--primary); color: var(--on-primary); }
.brand-name { font-family: var(--font-display); font-size: 1.3rem; }

.steps { display: flex; align-items: center; gap: 0.35rem; }
.steps li { display: flex; align-items: center; gap: 0.45rem; padding: 0.25rem 0.6rem 0.25rem 0.3rem; border-radius: 999px; color: var(--muted); font-weight: 700; font-size: 0.9rem; }
.steps .num { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; border: 1.5px solid var(--border-strong); background: var(--surface); font-size: 0.85rem; }
.steps .num .icon { width: 1rem; height: 1rem; }
.steps li.active { color: var(--text); background: var(--surface-2); }
.steps li.active .num { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.steps li.done { color: var(--green-ink); }
.steps li.done .num { background: var(--green-soft); border-color: var(--green); color: var(--green-ink); }

@media (max-width: 560px) {
  .steps li:not(.active) .lbl { display: none; }
  .brand-name { display: none; }
}

/* ---------- Layout ---------- */
main { max-width: 1120px; margin: 0 auto; padding: clamp(1.25rem, 4vw, 2.5rem) clamp(1rem, 4vw, 2rem) 3rem; }
.state { animation: enter 320ms var(--ease) both; }

.error-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  padding: 0.75rem 1rem;
  border-radius: var(--r-md);
  background: var(--danger-soft);
  border: 1px solid var(--danger-ink);
  color: var(--danger-ink);
  font-weight: 600;
}
.error-bar .link-btn { color: var(--danger-ink); }

.demo-banner { background: var(--amber-soft); border-bottom: 1px solid var(--border-strong); color: var(--amber-ink); font-size: 0.85rem; padding: 0.5rem 1rem; text-align: center; }

/* ---------- Step 1: hero + upload ---------- */
.hero { display: grid; gap: 2rem; align-items: center; }
@media (min-width: 900px) { .hero { grid-template-columns: 1.15fr 0.85fr; gap: 3rem; } }

.eyebrow { color: var(--accent-text); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; font-size: 0.8rem; margin-bottom: 0.6rem; }
.hero h1 { font-size: clamp(2.1rem, 4.6vw, 2.8rem); letter-spacing: -0.01em; }
.hero h1 span { color: var(--accent-text); }
.lede { margin: 1rem 0 1.5rem; max-width: 34rem; color: var(--muted); font-size: 1.1rem; }

.hero-art { display: none; width: 100%; max-width: 340px; height: auto; justify-self: center; border-radius: var(--r-xl); box-shadow: var(--shadow-2); }
@media (min-width: 900px) { .hero-art { display: block; } }

.drop-zone {
  display: grid;
  justify-items: center;
  gap: 0.4rem;
  padding: 2rem 1.25rem;
  text-align: center;
  border: 2px dashed var(--border-strong);
  border-radius: var(--r-xl);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 180ms var(--ease), background-color 180ms var(--ease), transform 180ms var(--ease);
}
.drop-zone:hover, .drop-zone.dragging { border-color: var(--primary); background: var(--surface-2); }
.drop-zone.dragging { transform: scale(1.01); }
.drop-icon { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%; background: var(--surface-2); color: var(--accent-text); }
.drop-icon .icon { width: 1.6rem; height: 1.6rem; }
.drop-title { font-family: var(--font-display); font-size: 1.3rem; }
.drop-sub { color: var(--muted); font-size: 0.95rem; max-width: 26rem; }
.drop-actions { margin-top: 0.6rem; }
.sample { margin-top: 0.5rem; }

.preview { display: grid; gap: 1rem; }
.preview-frame { position: relative; overflow: hidden; border-radius: var(--r-xl); box-shadow: var(--shadow-1); background: var(--surface-2); }
.preview-frame img { width: 100%; max-height: 420px; object-fit: contain; }
.status { color: var(--muted); font-weight: 600; min-height: 1.6em; }
.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }

.scan { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.scan::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(52, 211, 153, 0) 55%, rgba(52, 211, 153, 0.35) 92%, rgba(52, 211, 153, 0.95) 100%);
  transform: translateY(-100%);
  animation: sweep 1.7s ease-in-out infinite;
}

.tips { margin-top: 1.5rem; display: grid; gap: 0.4rem; color: var(--muted); font-size: 0.95rem; }
.tips li { display: flex; align-items: center; gap: 0.5rem; }
.tips .icon { color: var(--green); width: 1.1rem; height: 1.1rem; }

.how { margin-top: clamp(2.5rem, 6vw, 4.5rem); }
.how h2 { font-size: 1.6rem; margin-bottom: 1.1rem; }
.how-grid { display: grid; gap: 1rem; }
@media (min-width: 700px) { .how-grid { grid-template-columns: repeat(3, 1fr); } }
.how-grid li { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); padding: 1.25rem; box-shadow: var(--shadow-1); }
.how-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; background: var(--surface-2); color: var(--accent-text); margin-bottom: 0.75rem; }
.how-grid h3 { font-size: 1.2rem; margin-bottom: 0.25rem; }
.how-grid p { color: var(--muted); font-size: 0.95rem; }

/* ---------- Step 2: ingredients ---------- */
.ing-grid { display: grid; gap: 1.5rem; margin-top: 0.5rem; }
@media (min-width: 860px) { .ing-grid { grid-template-columns: 0.8fr 1.2fr; align-items: start; gap: 2.5rem; } }
.photo-card { margin: 0; border-radius: var(--r-xl); overflow: hidden; box-shadow: var(--shadow-1); background: var(--surface-2); }
.photo-card img { width: 100%; max-height: 460px; object-fit: contain; }

.panel { display: grid; gap: 1rem; align-content: start; }
.panel h2 { font-size: clamp(1.7rem, 4vw, 2.2rem); }
.count { font-weight: 700; color: var(--muted); }
.count span:first-child { color: var(--accent-text); font-size: 1.1rem; }

.chip-list { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  min-height: 44px;
  padding: 0.2rem 0.3rem 0.2rem 1rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  font-weight: 700;
  text-transform: capitalize;
  animation: pop 260ms var(--ease) both;
  animation-delay: calc(min(var(--i, 0), 14) * 30ms);
}
.chip button { display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); transition: background-color 160ms var(--ease), color 160ms var(--ease); }
.chip button:hover { background: var(--danger-soft); color: var(--danger-ink); }
.chip button .icon { width: 1rem; height: 1rem; }
.chip.leaving { animation: out 160ms ease-in both; }

.empty { padding: 1rem; border: 1.5px dashed var(--border-strong); border-radius: var(--r-md); color: var(--muted); text-align: center; }

.add-row label { display: block; font-weight: 700; margin-bottom: 0.35rem; }
.add-field { display: flex; gap: 0.5rem; }
.add-field input {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 0 1rem;
  border-radius: 999px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  transition: border-color 160ms var(--ease);
}
.add-field input:hover { border-color: var(--primary); }
.add-field input::placeholder { color: var(--muted); opacity: 0.8; }

.pantry { display: grid; gap: 0.5rem; }
.pantry-list { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 44px;
  padding: 0 0.95rem;
  border-radius: 999px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  font-weight: 700;
  font-size: 0.92rem;
  transition: background-color 160ms var(--ease), border-color 160ms var(--ease);
}
.toggle:hover { border-color: var(--primary); }
.toggle[aria-pressed="true"] { background: var(--green-soft); border-color: var(--green); color: var(--green-ink); }
.toggle .icon { width: 1rem; height: 1rem; }

#btn-generate { justify-self: start; margin-top: 0.5rem; }

/* ---------- Step 3: recipes ---------- */
.rec-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.rec-head h2 { font-size: clamp(1.8rem, 4vw, 2.4rem); }
.rec-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.filters { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.25rem; }
.filters .toggle[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }

.recipe-grid { display: grid; gap: 1.25rem; align-items: start; }
@media (min-width: 720px) { .recipe-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1040px) { .recipe-grid { grid-template-columns: repeat(3, 1fr); } }

.recipe-card { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); overflow: hidden; box-shadow: var(--shadow-1); animation: rise 420ms var(--ease) both; animation-delay: calc(var(--i, 0) * 70ms); }
.card-band { position: relative; display: flex; align-items: flex-end; justify-content: space-between; padding: 0.9rem 1.1rem; min-height: 92px; color: #ffffff; overflow: hidden; }
.recipe-card:nth-child(3n + 1) .card-band { background: linear-gradient(135deg, #9a3412, #ea580c); }
.recipe-card:nth-child(3n + 2) .card-band { background: linear-gradient(135deg, #047857, #10b981); }
.recipe-card:nth-child(3n) .card-band { background: linear-gradient(135deg, #92400e, #d97706); }
.card-band .mark { position: absolute; right: -10px; top: -14px; width: 110px; height: 110px; opacity: 0.18; stroke-width: 1.5; }
.badge { position: relative; display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.2rem 0.7rem; border-radius: 999px; background: rgba(0, 0, 0, 0.28); font-weight: 700; font-size: 0.85rem; }
.badge.diff { text-transform: capitalize; }

.card-body { display: grid; gap: 0.85rem; padding: 1.1rem 1.25rem 1.25rem; }
.card-body h3 { font-size: 1.35rem; }
.card-body .desc { color: var(--muted); font-size: 0.96rem; }
.pills { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.pill { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.2rem 0.7rem; border-radius: 999px; background: var(--surface-2); font-weight: 700; font-size: 0.88rem; }
.pill .icon { width: 1rem; height: 1rem; color: var(--accent-text); }

.match { display: grid; gap: 0.35rem; }
.match-label { font-weight: 700; font-size: 0.9rem; }
.meter { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.meter > span { display: block; height: 100%; width: 100%; background: var(--green); transform-origin: left; transform: scaleX(var(--p, 0)); transition: transform 700ms var(--ease); border-radius: 999px; }

.section-title { font-family: var(--font-display); font-weight: 400; font-size: 1.05rem; margin: 0.25rem 0 -0.4rem; }
.ing-list { display: grid; gap: 0.3rem; }
.ing-list li { display: flex; align-items: flex-start; gap: 0.5rem; font-size: 0.95rem; }
.ing-list .icon { width: 1.05rem; height: 1.05rem; margin-top: 0.2rem; }
.ing-list .have .icon { color: var(--green); }
.ing-list .need .icon { color: var(--amber-ink); }
.ing-list .need .name { font-weight: 700; }
.ing-list .qty { color: var(--muted); }

details.steps-box { border-top: 1px solid var(--border); padding-top: 0.6rem; }
details.steps-box summary { display: flex; justify-content: space-between; align-items: center; min-height: 44px; cursor: pointer; font-family: var(--font-display); font-size: 1.05rem; list-style: none; }
details.steps-box summary::-webkit-details-marker { display: none; }
details.steps-box summary .prog { font-family: var(--font-body); font-size: 0.85rem; font-weight: 700; color: var(--muted); }
.steps-list { display: grid; gap: 0.15rem; counter-reset: step; }
.steps-list label { display: flex; gap: 0.7rem; align-items: flex-start; min-height: 44px; padding: 0.4rem 0; cursor: pointer; font-size: 0.96rem; }
.steps-list input { width: 22px; height: 22px; margin-top: 0.1rem; flex: none; accent-color: var(--primary); cursor: pointer; }
.steps-list input:checked + span { color: var(--muted); text-decoration: line-through; }

.card-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; padding-top: 0.25rem; }
.card-actions .btn { min-height: 44px; font-size: 0.9rem; padding: 0 0.95rem; }

/* skeletons while generating */
.skeleton { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); overflow: hidden; animation: pulse 1.4s ease-in-out infinite; }
.skeleton .sk-band { height: 92px; background: var(--surface-2); }
.skeleton .sk-body { display: grid; gap: 0.7rem; padding: 1.25rem; }
.skeleton .sk-line { height: 14px; border-radius: 7px; background: var(--surface-2); }
.skeleton .sk-line.w60 { width: 60%; } .skeleton .sk-line.w80 { width: 80%; } .skeleton .sk-line.w40 { width: 40%; }

/* ---------- Toast + footer ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  z-index: 50;
  transform: translate(-50%, 1rem);
  max-width: calc(100vw - 2rem);
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  background: #1c1917;
  color: #ffffff;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms var(--ease), transform 200ms var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.foot { max-width: 1120px; margin: 0 auto; padding: 1.5rem clamp(1rem, 4vw, 2rem) 2.5rem; color: var(--muted); font-size: 0.88rem; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.5rem 2rem; border-top: 1px solid var(--border); }

/* ---------- Motion ---------- */
@keyframes enter { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(0.85); } to { opacity: 1; transform: none; } }
@keyframes out { to { opacity: 0; transform: scale(0.85); } }
@keyframes sweep { from { transform: translateY(-100%); } to { transform: translateY(100%); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
  .scan::before { animation: none; transform: translateY(-40%); }
}

/* ---------- Print: just the recipes ---------- */
@media print {
  .topbar, .skip-link, .hero, .how, .rec-actions, .filters, .card-actions, .foot, .toast, .demo-banner, .back, .error-bar { display: none !important; }
  body { background: #ffffff; color: #000000; }
  .recipe-grid { display: block; }
  .recipe-card { break-inside: avoid; box-shadow: none; border: 1px solid #999999; margin-bottom: 1rem; }
  details.steps-box > :not(summary) { display: block !important; }
  .card-band { background: #eeeeee !important; color: #000000; }
}
