* {
  box-sizing: border-box;
}

:root {
  --bg: #f4f9ff;
  --surface: #ffffff;
  --surface-alt: #eef7ff;
  --text: #12324d;
  --muted: #5b7490;
  --border: #cfe2f4;
  --accent: #1f6ed4;
  --accent-dark: #1452a3;
  --accent-soft: #dceeff;
  --accent-contrast: #ffffff;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

html[data-theme="dark"] body {
  background: #07111f;
  color: #f5fbff;
}

button,
select,
input {
  font: inherit;
}

button,
select,
input,
a {
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

button {
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  background: var(--accent);
  color: var(--accent-contrast);
  cursor: pointer;
  font-weight: 700;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(31, 110, 212, 0.2);
}

button.secondary {
  background: var(--surface);
  color: var(--accent);
}

html[data-theme="dark"] button.secondary {
  border-color: #6fa8ff;
  background: #172a3f;
  color: #dceeff;
}

.hidden {
  display: none !important;
}

.hero {
  display: flex;
  align-items: end;
  min-height: 320px;
  padding: 2rem;
  background:
    linear-gradient(110deg, rgba(6, 30, 58, 0.9), rgba(6, 30, 58, 0.35)),
    url("https://images.unsplash.com/photo-1502301103665-0b95cc738daf?auto=format&fit=crop&w=1600&q=80");
  background-position: center;
  background-size: cover;
  color: #fff;
}

.hero > div {
  max-width: 720px;
}

.eyebrow {
  margin: 0 0 0.45rem;
  color: var(--accent-dark);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero .eyebrow {
  color: #dceeff;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  max-width: 12ch;
  margin: 0;
  font-size: clamp(2.5rem, 8vw, 5.8rem);
  line-height: 0.94;
  letter-spacing: 0;
}

.intro {
  max-width: 580px;
  margin: 1rem 0 0;
  color: #fff6e7;
  font-size: 1.08rem;
  line-height: 1.55;
}

main {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.5rem 0 3rem;
}

.toolbar,
.search-panel,
.results-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.search-panel {
  align-items: stretch;
  padding: 1rem 0 0;
}

.search-form {
  flex: 1;
}

.toolbar {
  align-items: center;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.search-form label,
.toolbar label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 800;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 0.75rem;
}

.control-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.toggle-control {
  display: inline-flex;
  align-items: center;
  min-height: 2.9rem;
  gap: 0.45rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.8rem;
  background: var(--surface-alt);
  color: var(--text);
  font-weight: 800;
  white-space: nowrap;
}

.toggle-control input {
  width: 1rem;
  min-width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: #1f5f5b;
}

select,
input {
  min-width: 220px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.72rem 0.9rem;
  background: var(--surface);
  color: var(--text);
}

html[data-theme="dark"] select,
html[data-theme="dark"] input,
html[data-theme="dark"] .toggle-control {
  border-color: #52615e;
  background: #172321;
  color: #f4efe6;
}

select:focus,
input:focus,
button:focus,
a:focus {
  outline: none;
  box-shadow: 0 0 0 4px rgba(31, 110, 212, 0.2);
}

.quick-searches {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 0.5rem;
  max-width: 420px;
}

.quick-searches button {
  border-color: var(--border);
  padding: 0.55rem 0.7rem;
  background: var(--surface-alt);
  color: var(--accent-dark);
  font-size: 0.9rem;
}

#surprise-me {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
}

html[data-theme="dark"] .quick-searches button {
  border-color: #665342;
  background: #241f19;
  color: #f7c889;
}

html[data-theme="dark"] #surprise-me {
  border-color: #e08a62;
  background: #8c3f29;
  color: #fff7ee;
}

#status {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 1.6rem;
  margin: 0.5rem 0;
  color: var(--muted);
  font-style: italic;
}

#status.loading::before {
  width: 0.9rem;
  height: 0.9rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  content: "";
  animation: spin 700ms linear infinite;
}

html[data-theme="dark"] #status {
  color: #b4c1bd;
}

html[data-theme="dark"] #status.loading::before {
  border-color: #52615e;
  border-top-color: #7fb7a7;
}

.stats-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 0.75rem 0 1.25rem;
}

.stats-panel > div {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.8rem;
  background: var(--surface);
}

.stats-panel span {
  display: block;
  font-size: 1.45rem;
  font-weight: 900;
  line-height: 1;
}

.stats-panel p {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.progress-stat {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.progress-track {
  overflow: hidden;
  height: 0.5rem;
  margin-top: 0.65rem;
  border-radius: 999px;
  background: var(--accent-soft);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 220ms ease;
}

html[data-theme="dark"] .stats-panel > div {
  border-color: #2d3d39;
  background: #172321;
}

html[data-theme="dark"] .stats-panel p {
  color: #b4c1bd;
}

html[data-theme="dark"] .progress-track {
  background: #2d3d39;
}

.results-header {
  margin-top: 0.5rem;
}

.results-header h2 {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2.2rem);
}

.meal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 1rem;
}

.meal-card {
  display: flex;
  min-height: 100%;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 12px 30px rgba(31, 110, 212, 0.08);
  animation: card-in 220ms ease both;
}

.meal-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 16px 34px rgba(31, 110, 212, 0.14);
}

html[data-theme="dark"] .meal-card {
  border-color: #2d3d39;
  background: #172321;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
}

.meal-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
}

.card-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  padding: 0.9rem;
}

.card-body p {
  margin: 0 0 0.35rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.card-body h3 {
  flex: 1;
  margin: 0 0 0.9rem;
  font-size: 1.05rem;
  line-height: 1.25;
}

.card-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
}

.card-actions button {
  width: 100%;
  padding: 0.65rem 0.75rem;
}

.load-more-wrap {
  display: flex;
  justify-content: center;
  padding: 1.25rem 0 0;
}

.detail-facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
  margin: 0.25rem 0 1rem;
}

.detail-facts div {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem;
  background: var(--surface-alt);
}

.detail-facts dt {
  color: #5d6670;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.detail-facts dd {
  margin: 0.3rem 0 0;
  font-weight: 900;
}

html[data-theme="dark"] .detail-facts div {
  border-color: #2d3d39;
  background: #111817;
}

html[data-theme="dark"] .detail-facts dt {
  color: #b4c1bd;
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.empty-state {
  grid-column: 1 / -1;
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 2rem;
  background: var(--surface);
  color: var(--muted);
  text-align: center;
}

.empty-state p {
  margin: 0;
}

.empty-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.empty-actions button {
  border-color: var(--accent);
  padding: 0.55rem 0.7rem;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 0.9rem;
}

html[data-theme="dark"] .empty-state {
  border-color: #52615e;
  background: #172321;
  color: #c8d5d1;
}

dialog {
  width: min(900px, calc(100% - 1rem));
  max-height: calc(100vh - 2rem);
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 30px 80px rgba(8, 28, 58, 0.16);
}

html[data-theme="dark"] dialog {
  background: #172321;
  color: #f4efe6;
}

dialog::backdrop {
  background: rgba(16, 24, 28, 0.62);
}

.recipe-detail {
  position: relative;
  display: grid;
  grid-template-columns: minmax(240px, 0.85fr) 1.15fr;
  max-height: calc(100vh - 2rem);
  overflow: auto;
}

.recipe-detail > img {
  width: 100%;
  height: 100%;
  min-height: 360px;
  object-fit: cover;
}

.detail-body {
  padding: 2rem;
}

.detail-body h2 {
  margin: 0 0 1rem;
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  line-height: 1;
}

.detail-body h3 {
  margin: 1.5rem 0 0.6rem;
}

.detail-body ul {
  margin: 0;
  padding-left: 1.2rem;
}

.detail-body li {
  margin-bottom: 0.35rem;
}

#detail-instructions {
  white-space: pre-line;
  line-height: 1.65;
}

.video-link {
  display: inline-flex;
  margin-top: 1rem;
  color: var(--accent);
  font-weight: 800;
}

.ingredients-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.ingredients-header h3 {
  margin: 1.5rem 0 0.6rem;
}

#unit-toggle {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  padding: 0.4rem 0.75rem;
}

.drink-pairing {
  margin-top: 1.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid #e4ddcd;
}

html[data-theme="dark"] .drink-pairing {
  border-top-color: #364440;
}

.source-tag {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6c7a76;
  margin-left: 0.4rem;
}

#drink-content {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.drink-thumb {
  width: 72px;
  height: 72px;
  border-radius: 8px;
  object-fit: cover;
  animation: card-in 220ms ease both;
}

.drink-name {
  margin: 0 0 0.2rem;
  font-weight: 800;
}

.drink-meta {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: #6c7a76;
}

.drink-status {
  font-style: italic;
  color: #6c7a76;
}

.icon-button {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border-color: rgba(255, 255, 255, 0.75);
  background: rgba(29, 35, 40, 0.75);
}

@media (max-width: 720px) {
  .hero {
    min-height: 280px;
    padding: 1.25rem;
  }

  main {
    width: min(100% - 1rem, 1120px);
  }

  .toolbar,
  .search-panel,
  .results-header,
  .search-row,
  .control-row {
    align-items: stretch;
    flex-direction: column;
  }

  select,
  input,
  button {
    width: 100%;
  }

  .toggle-control {
    width: 100%;
  }

  .toggle-control input {
    width: 1rem;
    min-width: 1rem;
  }

  .quick-searches {
    max-width: none;
  }

  .search-row {
    grid-template-columns: 1fr;
  }

  .stats-panel,
  .detail-facts {
    grid-template-columns: 1fr;
  }

  .recipe-detail {
    grid-template-columns: 1fr;
  }

  .recipe-detail > img {
    min-height: 220px;
    max-height: 300px;
  }

  .detail-body {
    padding: 1.2rem;
  }
}

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