:root {
  --tomato: #e0533d;
  --tomato-dark: #c23f2c;
  --tomato-soft: #f6cabf;
  --cream: #fdf6ee;
  --cream-2: #f7ece0;
  --ink: #2c2420;
  --ink-soft: #6b5f57;
  --line: #e7d9ca;
  --card: #ffffff;
  --card-2: #fffaf4;
  --good: #3f9d6b;
  --good-soft: #def0e5;
  --warn: #c98a2e;
  --shadow: 0 6px 22px rgba(120, 70, 50, 0.12);
  --shadow-lg: 0 16px 44px rgba(90, 50, 35, 0.22);
  --radius: 16px;
  --radius-sm: 11px;
  --tap: 44px;
}

[data-theme="dark"] {
  --tomato: #f06b54;
  --tomato-dark: #d8503b;
  --tomato-soft: #5a2a22;
  --cream: #1b1714;
  --cream-2: #241d18;
  --ink: #f3e9df;
  --ink-soft: #b9a99c;
  --line: #3a2f28;
  --card: #261e18;
  --card-2: #2d241d;
  --good: #5bbd85;
  --good-soft: #1f3a2b;
  --warn: #e0a851;
  --shadow: 0 6px 22px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 44px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--cream);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-wrap: break-word;
  word-break: break-word;
}

h1, h2, h3, p { margin: 0; }

button { font-family: inherit; cursor: pointer; }

.hidden { display: none !important; }

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--tomato);
  color: #fff;
  padding: 10px 14px;
  border-radius: 0 0 10px 0;
  z-index: 100;
}
.skip-link:focus { left: 0; }

:focus-visible {
  outline: 3px solid var(--tomato);
  outline-offset: 2px;
  border-radius: 6px;
}

/* HEADER */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: linear-gradient(135deg, var(--tomato), var(--tomato-dark));
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px; height: 42px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  flex-shrink: 0;
}
.brand-text { min-width: 0; }
.brand-text h1 { font-size: 1.2rem; font-weight: 800; letter-spacing: -0.01em; }
.tagline { font-size: 0.74rem; opacity: 0.9; }
.header-actions { display: flex; gap: 6px; flex-shrink: 0; }

.icon-btn {
  display: grid;
  place-items: center;
  width: var(--tap); height: var(--tap);
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  border-radius: 12px;
  transition: background 0.18s ease, transform 0.12s ease;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.28); }
.icon-btn:active { transform: scale(0.94); }

.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* MAIN */
main {
  flex: 1;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px 28px;
}

.tabs {
  display: flex;
  gap: 8px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 5px;
  margin-bottom: 16px;
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.92rem;
  font-weight: 700;
  padding: 11px 8px;
  border-radius: 10px;
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background 0.18s ease, color 0.18s ease;
}
.tab.is-active {
  background: var(--tomato);
  color: #fff;
  box-shadow: 0 4px 12px rgba(224, 83, 61, 0.35);
}
.badge {
  background: rgba(255, 255, 255, 0.28);
  color: inherit;
  font-size: 0.72rem;
  font-weight: 800;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  display: inline-grid;
  place-items: center;
}
.tab:not(.is-active) .badge { background: var(--line); color: var(--ink-soft); }

/* CARDS */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.field-label {
  display: block;
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 10px;
}
.ing-input-row { display: flex; gap: 8px; }
#ingInput {
  flex: 1;
  min-width: 0;
  border: 2px solid var(--line);
  background: var(--card-2);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 1rem;
  min-height: var(--tap);
  transition: border-color 0.18s ease;
}
#ingInput:focus { outline: none; border-color: var(--tomato); }
#ingInput::placeholder { color: var(--ink-soft); opacity: 0.7; }

.btn {
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.95rem;
  padding: 12px 16px;
  min-height: var(--tap);
  transition: transform 0.12s ease, background 0.18s ease, color 0.18s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--tomato); color: #fff; }
.btn-primary:hover { background: var(--tomato-dark); }
.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1.5px solid var(--line);
}
.btn-ghost:hover { color: var(--tomato); border-color: var(--tomato); }

.hint { font-size: 0.78rem; color: var(--ink-soft); margin-top: 8px; }

.suggest-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}
.suggest-pill {
  border: 1.5px dashed var(--line);
  background: transparent;
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 0.82rem;
  font-weight: 600;
  min-height: 36px;
}
.suggest-pill:hover { border-color: var(--tomato); color: var(--tomato); border-style: solid; }
.suggest-pill.is-on {
  background: var(--good-soft);
  color: var(--good);
  border-color: var(--good);
  border-style: solid;
}

.chips { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--tomato-soft);
  color: var(--tomato-dark);
  border-radius: 999px;
  padding: 7px 8px 7px 14px;
  font-size: 0.86rem;
  font-weight: 700;
  max-width: 100%;
}
[data-theme="dark"] .chip { color: var(--ink); }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-x {
  border: none;
  background: rgba(0, 0, 0, 0.12);
  color: inherit;
  width: 24px; height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  line-height: 1;
  flex-shrink: 0;
}
.chip-x:hover { background: rgba(0, 0, 0, 0.22); }

.ing-actions { margin-top: 14px; display: flex; }
.ing-actions .btn { width: 100%; }

/* FILTER */
.filter-card { padding: 0; overflow: hidden; }
.filter-head {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  font-size: 1rem;
  font-weight: 700;
  min-height: var(--tap);
}
.chev { transition: transform 0.22s ease; }
.filter-head[aria-expanded="true"] .chev { transform: rotate(180deg); }
.filter-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.25s ease;
}
.filter-body.is-open { grid-template-rows: 1fr; }
.filter-body > .filter-grid { overflow: hidden; }
.filter-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 0 16px;
}
.filter-body.is-open > .filter-grid { padding: 4px 16px 18px; }
.filter-item {
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink-soft);
  flex: 1 1 140px;
}
.filter-item select {
  border: 2px solid var(--line);
  background: var(--card-2);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.92rem;
  min-height: var(--tap);
}
.filter-item select:focus { outline: none; border-color: var(--tomato); }
.check-item {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  flex: 1 1 100%;
  cursor: pointer;
}
.check-item input {
  width: 22px; height: 22px;
  accent-color: var(--tomato);
  flex-shrink: 0;
}
.stepper {
  display: inline-flex;
  align-items: center;
  border: 2px solid var(--line);
  background: var(--card-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
  width: fit-content;
}
.step-btn {
  border: none;
  background: transparent;
  color: var(--tomato);
  font-size: 1.3rem;
  font-weight: 800;
  width: var(--tap); height: var(--tap);
  line-height: 1;
}
.step-btn:hover { background: var(--tomato-soft); }
#portOut {
  min-width: 36px;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--ink);
}

/* RESULTS */
.result-meta {
  font-size: 0.84rem;
  color: var(--ink-soft);
  font-weight: 600;
  margin: 6px 2px 12px;
  min-height: 1.2em;
}
.recipe-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }

.recipe {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px 14px;
  box-shadow: var(--shadow);
  position: relative;
  text-align: left;
  width: 100%;
  display: block;
  color: inherit;
  transition: transform 0.14s ease, border-color 0.18s ease;
}
.recipe:hover { border-color: var(--tomato-soft); transform: translateY(-2px); }
.recipe-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.recipe-title-btn {
  border: none;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 0;
  flex: 1;
  min-width: 0;
}
.recipe-name { font-size: 1.08rem; font-weight: 800; letter-spacing: -0.01em; }
.recipe-sub { font-size: 0.78rem; color: var(--ink-soft); margin-top: 3px; }
.fav-btn {
  border: none;
  background: var(--cream-2);
  color: var(--ink-soft);
  width: 40px; height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: color 0.18s ease, background 0.18s ease, transform 0.12s ease;
}
.fav-btn:active { transform: scale(0.9); }
.fav-btn.is-fav { color: #f0b429; background: #fff3d6; }
[data-theme="dark"] .fav-btn.is-fav { background: #3a2f12; }

.match-bar-wrap { margin-top: 12px; }
.match-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.match-pct { color: var(--good); }
.match-pct.partial { color: var(--warn); }
.match-track {
  height: 8px;
  background: var(--cream-2);
  border-radius: 999px;
  overflow: hidden;
}
.match-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--good), #6fc99a);
  border-radius: 999px;
  transition: width 0.4s ease;
}
.match-fill.partial { background: linear-gradient(90deg, var(--warn), #e0b35f); }

.missing-note {
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--ink-soft);
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
}
.missing-note.all-have { color: var(--good); font-weight: 700; }
.miss-tag {
  background: var(--cream-2);
  border-radius: 999px;
  padding: 3px 9px;
  font-weight: 600;
  font-size: 0.76rem;
}
.tag-row { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--tomato-dark);
  background: var(--tomato-soft);
  border-radius: 6px;
  padding: 3px 7px;
}
[data-theme="dark"] .tag { color: var(--ink); }
.tag.veg { color: var(--good); background: var(--good-soft); }

/* EMPTY */
.empty-state {
  text-align: center;
  color: var(--ink-soft);
  padding: 40px 20px;
  font-size: 0.95rem;
}
.empty-emoji { font-size: 2.6rem; margin-bottom: 8px; }

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
@media (min-width: 600px) { .modal { align-items: center; padding: 20px; } }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(40, 25, 18, 0.55);
  backdrop-filter: blur(2px);
}
.modal-card {
  position: relative;
  background: var(--card);
  width: 100%;
  max-width: 600px;
  max-height: 90dvh;
  border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: slideUp 0.28s ease;
  padding-bottom: calc(env(safe-area-inset-bottom) + 8px);
}
@media (min-width: 600px) { .modal-card { border-radius: 22px; animation: pop 0.22s ease; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes pop { from { transform: scale(0.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  background: var(--cream-2);
  color: var(--ink);
  z-index: 2;
}
.modal-close:hover { background: var(--tomato-soft); }
.modal-body { padding: 22px 20px 8px; }
.modal-body h2 { font-size: 1.45rem; font-weight: 800; padding-right: 44px; letter-spacing: -0.01em; }
.modal-meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; }
.meta-pill {
  background: var(--cream-2);
  border-radius: 10px;
  padding: 6px 11px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-soft);
}
.modal-section-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--tomato);
  font-weight: 800;
  margin: 22px 0 10px;
}
.port-control {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.port-control .stepper { border-color: var(--line); }
.port-control-label { font-size: 0.85rem; font-weight: 700; color: var(--ink-soft); }
.ing-list { list-style: none; margin: 0; padding: 0; }
.ing-list li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
}
.ing-list li:last-child { border-bottom: none; }
.ing-list .amt { font-weight: 800; color: var(--tomato); min-width: 70px; flex-shrink: 0; }
.ing-list li.have .ing-name::after { content: " ✓"; color: var(--good); font-weight: 800; }
.ing-list li.missing .ing-name { color: var(--ink-soft); }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: step; }
.steps li {
  position: relative;
  padding: 0 0 16px 42px;
  counter-increment: step;
  font-size: 0.95rem;
}
.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0; top: -2px;
  width: 30px; height: 30px;
  background: var(--tomato);
  color: #fff;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.9rem;
}
.steps li:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 14px; top: 30px;
  width: 2px;
  height: calc(100% - 30px);
  background: var(--line);
}
.modal-fav-btn {
  width: 100%;
  margin: 22px 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
}

/* TOAST */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 22px);
  transform: translateX(-50%) translateY(140%);
  background: var(--ink);
  color: var(--cream);
  padding: 13px 20px;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 80;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  max-width: calc(100vw - 40px);
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* FOOTER */
.app-footer {
  text-align: center;
  font-size: 0.74rem;
  color: var(--ink-soft);
  padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
