:root {
  color-scheme: light;
  --bg: #f8f5ed;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --text: #1e2a2f;
  --muted: #667178;
  --line: #ded8cb;
  --accent: #2f7d68;
  --accent-strong: #215c4d;
  --berry: #c94f5f;
  --amber: #d9912e;
  --blue: #315d88;
  --shadow: 0 18px 46px rgba(30, 42, 47, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15191c;
  --surface: #20262a;
  --surface-strong: #273036;
  --text: #f8f2e7;
  --muted: #b9c1c6;
  --line: #3a444b;
  --accent: #70c5a6;
  --accent-strong: #9de0c7;
  --berry: #f08a98;
  --amber: #f0ba63;
  --blue: #8db4da;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(47, 125, 104, 0.12), transparent 260px),
    var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 880px);
  min-width: 0;
  margin: 0 auto;
  padding: 0 16px 28px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 4;
  min-width: 0;
  margin: 0 -16px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 12px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 68%, transparent);
}

.brand-row {
  display: grid;
  grid-template-columns: 48px 1fr 44px;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  box-shadow: 0 8px 18px rgba(30, 42, 47, 0.16);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  font-size: 24px;
  line-height: 1.1;
  letter-spacing: 0;
}

h3 {
  font-size: 15px;
  line-height: 1.25;
  letter-spacing: 0;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.icon-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 22px;
}

.search-wrap {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 44px;
  align-items: center;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  box-shadow: 0 8px 20px rgba(30, 42, 47, 0.08);
}

.search-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

#searchInput {
  min-width: 0;
  height: 52px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px 0 0 8px;
  background: transparent;
  color: var(--text);
  outline: 0;
}

#clearSearch {
  width: 44px;
  height: 44px;
  margin-right: 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
}

.quick-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
  margin-top: 12px;
}

.stat {
  min-width: 0;
  min-height: 50px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
}

.stat strong {
  display: block;
  font-size: 18px;
  line-height: 1;
}

.stat span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.15;
}

main {
  padding-top: 14px;
}

.controls {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.tabbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  min-width: 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.tab {
  min-width: 0;
  min-height: 40px;
  padding: 0 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.tab.is-active {
  background: var(--text);
  color: var(--bg);
}

.category-strip {
  display: flex;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  padding: 2px 0 8px;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
}

.category-strip::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  white-space: nowrap;
  scroll-snap-align: start;
}

.chip.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.result-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 12px 0 10px;
  color: var(--muted);
}

.result-summary strong {
  color: var(--text);
}

.ghost-button,
.secondary-button,
.primary-button {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 8px;
  font-weight: 750;
}

.ghost-button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
}

.primary-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.recipe-list {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.recipe-card {
  display: grid;
  gap: 9px;
  width: 100%;
  min-height: 118px;
  padding: 14px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--text);
  box-shadow: 0 10px 24px rgba(30, 42, 47, 0.08);
}

.recipe-card:focus-visible,
.icon-button:focus-visible,
.chip:focus-visible,
.tab:focus-visible,
.primary-button:focus-visible,
.secondary-button:focus-visible,
.ghost-button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.recipe-name {
  font-size: 18px;
  line-height: 1.18;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.favorite-dot {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  background: color-mix(in srgb, var(--amber) 18%, transparent);
  color: var(--amber);
  font-weight: 900;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  max-width: 100%;
  padding: 0 8px;
  border-radius: 7px;
  background: color-mix(in srgb, var(--line) 45%, transparent);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.pill.accent {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent-strong);
}

.pill.berry {
  background: color-mix(in srgb, var(--berry) 16%, transparent);
  color: var(--berry);
}

.preview {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.empty-state {
  padding: 42px 12px;
  text-align: center;
  color: var(--muted);
}

.empty-state h2 {
  margin-bottom: 8px;
  color: var(--text);
  font-size: 20px;
}

.recipe-dialog {
  width: min(100%, 760px);
  max-width: 100%;
  max-height: 100dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
}

.recipe-dialog::backdrop {
  background: rgba(12, 16, 19, 0.48);
  backdrop-filter: blur(4px);
}

.dialog-shell {
  display: grid;
  gap: 18px;
  max-height: calc(100dvh - env(safe-area-inset-top));
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  overflow: auto;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 14px 14px 0 0;
  background: var(--surface-strong);
  box-shadow: var(--shadow);
}

.dialog-header {
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 10px;
  align-items: start;
}

.dialog-header h2 {
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.dialog-meta,
.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.detail-section {
  display: grid;
  gap: 10px;
}

.detail-section h3 {
  color: var(--muted);
  text-transform: uppercase;
}

.ingredient-list {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.ingredient-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 11px 12px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.ingredient-row:first-child {
  border-top: 0;
}

.ingredient-name {
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.ingredient-note {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.ingredient-amount {
  color: var(--accent-strong);
  font-weight: 850;
  white-space: nowrap;
}

.detail-section p,
.detail-section li {
  color: var(--text);
  line-height: 1.48;
}

.detail-section ul {
  margin: 0;
  padding-left: 18px;
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 8;
  min-height: 44px;
  display: grid;
  place-items: center;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (min-width: 720px) {
  .app-shell {
    padding-left: 22px;
    padding-right: 22px;
  }

  .topbar {
    margin-left: -22px;
    margin-right: -22px;
    padding-left: 22px;
    padding-right: 22px;
  }

  .recipe-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .recipe-dialog {
    margin: auto;
  }

  .dialog-shell {
    border-bottom: 1px solid var(--line);
    border-radius: 10px;
    max-height: min(820px, 88dvh);
    padding: 22px;
  }
}
