:root {
  --bg: #f4f1e8;
  --panel: #fffaf0;
  --panel-solid: #fffdf7;
  --ink: #1e2a26;
  --muted: #667169;
  --line: #d8d0bd;
  --field: #ffffff;
  --tile: #fffdf7;
  --texture-opacity-a: 0.88;
  --texture-opacity-b: 0.94;
  --green: #2f7d5f;
  --green-dark: #1f5d47;
  --gold: #b7832f;
  --red: #b94d45;
  --blue: #35749a;
  --shadow: 0 18px 45px rgba(42, 38, 27, 0.14);
}

[data-theme="dark"] {
  --bg: #121815;
  --panel: #1c2722;
  --panel-solid: #202c27;
  --ink: #eef5e9;
  --muted: #a9b8ad;
  --line: #39473f;
  --field: #111a16;
  --tile: #18231e;
  --texture-opacity-a: 0.93;
  --texture-opacity-b: 0.96;
  --green: #57a87d;
  --green-dark: #8bd0a5;
  --gold: #d0a24f;
  --red: #cf6d62;
  --blue: #6ba5c3;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(rgba(244, 241, 232, var(--texture-opacity-a)), rgba(244, 241, 232, var(--texture-opacity-b))),
    url("data:image/svg+xml,%3Csvg width='160' height='160' viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Crect width='160' height='160' fill='%23eee7d5'/%3E%3Cpath d='M0 75c28-15 49-16 74-2 21 12 40 12 66-3 8-5 14-7 20-8v18c-26 5-45 23-75 18-22-4-37-18-61-9-10 4-18 9-24 14V75z' fill='%23d9e3cc'/%3E%3Cpath d='M0 128c22-16 43-20 68-12 35 12 59 4 92-20v32c-30 16-58 21-88 11-31-10-51-1-72 17v-28z' fill='%23c7d5bd'/%3E%3Ccircle cx='124' cy='35' r='18' fill='%23d6b16a'/%3E%3Cpath d='M20 34h42M28 45h28M96 83h34M102 94h24' stroke='%23b7aa8c' stroke-width='4' stroke-linecap='round'/%3E%3C/svg%3E");
  background-size: cover, 320px 320px;
  background-color: var(--bg);
}

[data-theme="dark"] body {
  background:
    linear-gradient(rgba(18, 24, 21, var(--texture-opacity-a)), rgba(18, 24, 21, var(--texture-opacity-b))),
    url("data:image/svg+xml,%3Csvg width='160' height='160' viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Crect width='160' height='160' fill='%23202a25'/%3E%3Cpath d='M0 75c28-15 49-16 74-2 21 12 40 12 66-3 8-5 14-7 20-8v18c-26 5-45 23-75 18-22-4-37-18-61-9-10 4-18 9-24 14V75z' fill='%232b4034'/%3E%3Cpath d='M0 128c22-16 43-20 68-12 35 12 59 4 92-20v32c-30 16-58 21-88 11-31-10-51-1-72 17v-28z' fill='%2326372e'/%3E%3Ccircle cx='124' cy='35' r='18' fill='%235b4b2a'/%3E%3Cpath d='M20 34h42M28 45h28M96 83h34M102 94h24' stroke='%2347574e' stroke-width='4' stroke-linecap='round'/%3E%3C/svg%3E");
  background-color: var(--bg);
  background-size: cover, 320px 320px;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 28px clamp(16px, 4vw, 48px) 18px;
}

.kicker {
  margin: 0 0 4px;
  color: var(--green-dark);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 0.96;
}

h2 {
  margin-bottom: 6px;
  font-size: 1.15rem;
}

h3 {
  margin-bottom: 5px;
  font-size: 1.05rem;
}

.ghost-button,
.segment,
.ingredient {
  cursor: pointer;
}

.ghost-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: color-mix(in srgb, var(--panel-solid) 78%, transparent);
}

.top-actions {
  display: flex;
  gap: 10px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 0.92fr) minmax(380px, 1.08fr);
  gap: 20px;
  padding: 0 clamp(16px, 4vw, 48px) 36px;
}

.inventory-panel,
.results-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.panel-header p {
  margin-bottom: 0;
  color: var(--muted);
}

.inventory-count,
.stats-strip div {
  display: grid;
  justify-items: end;
  gap: 2px;
}

.inventory-count strong,
.stats-strip strong {
  font-size: 1.45rem;
  line-height: 1;
}

.inventory-count span,
.stats-strip span {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.filters {
  display: grid;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.search-box,
.sort-control {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.search-box input,
.sort-control select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--field);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.segment {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--tile);
  font-weight: 700;
}

.segment.active {
  border-color: var(--green);
  color: white;
  background: var(--green);
}

.ingredient-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
  max-height: calc(100vh - 315px);
  min-height: 280px;
  overflow: auto;
  padding: 18px;
}

.ingredient {
  position: relative;
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 68px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  text-align: left;
  color: var(--ink);
  background: var(--tile);
}

.ingredient.selected {
  border-color: var(--green);
  background: color-mix(in srgb, var(--green) 15%, var(--tile));
}

.ingredient-art,
.recipe-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: white;
  background: #26332f;
  font-size: 1.35rem;
  font-weight: 900;
  overflow: hidden;
}

.recipe-icon {
  width: 48px;
  height: 48px;
}

.ingredient-art img,
.recipe-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 0;
  transform: scale(1.05);
}

.recipe-icon img {
  padding: 0;
  transform: scale(1.25);
}

.ingredient-text {
  min-width: 0;
}

.ingredient-text strong,
.ingredient-text small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ingredient-text small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.75rem;
}

.checkmark {
  position: absolute;
  top: 6px;
  right: 7px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  color: white;
  background: var(--green);
  display: none;
  place-items: center;
  font-size: 0.78rem;
  font-weight: 900;
}

.ingredient.selected .checkmark {
  display: grid;
}

.results-header {
  align-items: end;
}

.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  border-bottom: 1px solid var(--line);
  background: var(--line);
}

.stats-strip div {
  padding: 14px 18px;
  background: var(--tile);
}

.recipe-list {
  display: grid;
  gap: 12px;
  max-height: calc(100vh - 266px);
  min-height: 360px;
  overflow: auto;
  padding: 18px;
}

.recipe-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--tile);
}

.recipe-card.available {
  border-color: rgba(47, 125, 95, 0.55);
}

.recipe-card.locked {
  opacity: 0.78;
}

.recipe-main {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 12px;
  align-items: start;
}

.recipe-description {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.recipe-meta,
.recipe-ingredients {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.pill {
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--ink);
  background: color-mix(in srgb, var(--muted) 20%, var(--tile));
  font-size: 0.78rem;
  font-weight: 800;
}

.pill.good {
  color: white;
  background: var(--green);
}

.pill.warn {
  color: white;
  background: var(--gold);
}

.pill.missing {
  color: white;
  background: var(--red);
}

.missing-line {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 260px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 26px;
  color: var(--muted);
  text-align: center;
  background: color-mix(in srgb, var(--tile) 42%, transparent);
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .ingredient-grid,
  .recipe-list {
    max-height: none;
  }
}

@media (max-width: 560px) {
  .topbar,
  .panel-header,
  .results-header {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .top-actions button,
  .sort-control {
    width: 100%;
  }

  .segmented {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats-strip {
    grid-template-columns: 1fr;
  }
}
