:root {
  --paper: #f3ead8;
  --ink: #211b16;
  --muted: #756c60;
  --card: rgba(255, 251, 241, 0.84);
  --line: rgba(75, 55, 36, 0.16);
  --green: #386641;
  --gold: #bc7c2f;
  --red: #9f3b2f;
  --shadow: 0 20px 70px rgba(55, 35, 10, 0.18);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: ui-rounded, "Avenir Next", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 0%, rgba(255, 221, 150, 0.7), transparent 32rem),
    radial-gradient(circle at 90% 18%, rgba(121, 150, 107, 0.28), transparent 28rem),
    linear-gradient(150deg, #f6eddc 0%, #efe0c5 58%, #dcc2a0 100%);
  min-height: 100svh;
}

button, input { font: inherit; }

.app-shell {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
}

.hero {
  padding: 20px 4px 12px;
}

.brand-lockup {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-lockup > div {
  min-width: 0;
}

.brand-refresh {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  cursor: pointer;
  flex: 0 0 auto;
  order: 2;
  line-height: 0;
  -webkit-tap-highlight-color: transparent;
}

.brand-refresh:active .brand-mark {
  transform: scale(0.96);
}

.brand-mark {
  width: clamp(118px, 21vw, 176px);
  height: clamp(118px, 21vw, 176px);
  border-radius: 22px;
  box-shadow: 0 14px 38px rgba(55, 35, 10, 0.18);
  object-fit: cover;
  display: block;
  transition: transform 120ms ease;
}

.build-stamp {
  margin: 10px 0 0;
  color: rgba(92, 68, 38, 0.72);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1, h2 { margin: 0; letter-spacing: -0.06em; }

h1 {
  font-size: clamp(3.1rem, 16vw, 6.5rem);
  line-height: 0.84;
}

.brand-lockup h1 {
  font-size: clamp(2.7rem, 14vw, 5.4rem);
}

h2 {
  font-size: 1.6rem;
  line-height: 1;
}

.hero-copy {
  max-width: 28rem;
  margin: 10px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.brand-lockup .hero-copy {
  max-width: 22rem;
}

.quick-actions {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0 10px;
  scrollbar-width: none;
}

.chip, .ghost {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 251, 241, 0.72);
  color: var(--ink);
  padding: 10px 14px;
  font-weight: 900;
  white-space: nowrap;
}

.chip.active {
  background: var(--green);
  color: #fff6e8;
  border-color: transparent;
}

.search-row {
  margin: 0 0 10px;
}

.search-shell {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 251, 241, 0.82);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.search-label {
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 950;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.search-shell input {
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
  font-size: 1rem;
  font-weight: 850;
}

.search-shell input::placeholder {
  color: var(--muted);
}

.panel {
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--card);
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 10px 0;
  backdrop-filter: blur(18px);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 10px;
}

.shopping-heading-main {
  min-width: 0;
  flex: 1 1 auto;
}

.heading-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  flex-wrap: wrap;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.ghost {
  padding: 8px 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.36);
}

.danger-ghost {
  color: var(--red);
  border-color: rgba(159, 59, 47, 0.22);
  background: rgba(159, 59, 47, 0.06);
}

.checked-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid rgba(75, 55, 36, 0.14);
  border-radius: 999px;
  background: rgba(33, 27, 22, 0.06);
  color: var(--muted);
  padding: 7px 10px;
  font-size: 0.78rem;
  font-weight: 900;
  white-space: nowrap;
}

.checked-pill #checked-count {
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 950;
  line-height: 1;
}

.muted-pill {
  color: var(--muted);
  background: transparent;
}

.need-pill {
  background: rgba(159, 59, 47, 0.12);
  color: var(--red);
}

.need-pill #need-count {
  color: var(--red);
}

.helper {
  margin: -4px 0 14px;
  color: var(--muted);
  font-weight: 700;
}

.need-list {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.section-stack {
  display: grid;
  gap: 12px;
}

.group-section {
  border: 1px solid rgba(75, 55, 36, 0.12);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.26);
  padding: 8px;
}

.group-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 0;
  border-radius: 16px;
  background: transparent;
  color: inherit;
  padding: 8px;
  text-align: left;
}

.group-toggle span {
  display: grid;
  gap: 3px;
}

.group-toggle strong {
  font-size: 1.02rem;
}

.group-toggle small {
  color: var(--muted);
  font-weight: 800;
}

.group-chevron {
  display: inline-grid !important;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: rgba(33, 27, 22, 0.08);
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 950;
  flex: 0 0 auto;
}

.group-content {
  padding-top: 6px;
}

.group-section.collapsed .group-content {
  display: none;
}

.protein-board {
  display: grid;
  gap: 14px;
}

.protein-card-grid {
  display: grid;
  gap: 10px;
}

.protein-card {
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.5);
}

.protein-card small {
  display: block;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 950;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.protein-card strong {
  display: block;
  margin-top: 4px;
  font-size: 1.02rem;
}

.protein-card span {
  display: inline-block;
  margin-top: 8px;
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 0.84rem;
  font-weight: 950;
}

.protein-card p {
  margin: 10px 0 0;
  color: var(--muted);
  font-weight: 780;
  line-height: 1.35;
}

.protein-card.best span {
  background: rgba(56, 102, 65, 0.14);
  color: var(--green);
}

.protein-card.lean span {
  background: rgba(87, 111, 163, 0.14);
  color: #37517b;
}

.protein-card.batch span {
  background: rgba(188, 124, 47, 0.16);
  color: #8d5a1f;
}

.protein-card.health span {
  background: rgba(159, 59, 47, 0.12);
  color: var(--red);
}

.protein-rank-list {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.42);
  padding: 12px;
}

.protein-rank-header {
  display: grid;
  gap: 4px;
  margin-bottom: 8px;
}

.protein-rank-header small {
  color: var(--muted);
  font-weight: 780;
}

.protein-rank-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid rgba(75, 55, 36, 0.08);
}

.protein-rank-row:first-of-type {
  border-top: 0;
}

.protein-rank-row div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.protein-rank-row small {
  color: var(--muted);
  font-weight: 780;
}

.protein-rank-number {
  border-radius: 999px;
  background: rgba(33, 27, 22, 0.08);
  color: var(--ink);
  padding: 6px 9px;
  font-size: 0.76rem;
  font-weight: 950;
}

.protein-rank-price {
  color: var(--green);
  font-size: 0.94rem;
  font-weight: 950;
  white-space: nowrap;
}

.need-card {
  display: grid;
  gap: 6px;
  border: 1px solid rgba(159, 59, 47, 0.18);
  border-radius: 18px;
  background: rgba(159, 59, 47, 0.06);
  padding: 12px;
  transition: background 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

.need-card.checked {
  background: rgba(56, 102, 65, 0.12);
  border-color: rgba(56, 102, 65, 0.28);
}

.need-main {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.need-toggle {
  min-width: 0;
  width: 100%;
  display: grid;
  gap: 6px;
  border: 0;
  padding: 0;
  text-align: left;
  color: inherit;
  background: transparent;
}

.need-card small,
.need-card p {
  color: var(--muted);
  font-weight: 800;
}

.need-card strong {
  display: block;
}

.need-card p {
  margin: 0 0 0 42px;
}

.need-price {
  width: fit-content;
  border-radius: 999px;
  background: rgba(56, 102, 65, 0.12);
  color: var(--green);
  padding: 6px 9px;
  font-size: 0.78rem;
  font-weight: 950;
}

.need-meta {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.empty-state {
  margin: 0 0 10px;
  border: 1px dashed var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.34);
  color: var(--muted);
  padding: 12px;
  font-weight: 750;
}

.item-list {
  display: grid;
  gap: 10px;
}

.item-card {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.48);
  padding: 14px;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.item-card.checked {
  background: rgba(56, 102, 65, 0.12);
  border-color: rgba(56, 102, 65, 0.32);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.check-target {
  flex: 0 0 auto;
}

.check-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.fake-check {
  width: 30px;
  height: 30px;
  border: 2px solid rgba(33, 27, 22, 0.32);
  border-radius: 10px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
}

.check-row input:checked + .fake-check {
  background: var(--green);
  border-color: var(--green);
}

.check-row input:checked + .fake-check::after {
  content: "✓";
  color: white;
  font-weight: 950;
}

.item-main {
  display: grid;
  gap: 2px;
}

.item-toggle {
  min-width: 0;
  width: 100%;
  display: grid;
  gap: 6px;
  border: 0;
  padding: 0;
  text-align: left;
  color: inherit;
  background: transparent;
}

.item-main strong, .pantry-item strong {
  font-size: 1rem;
}

.item-main small, .item-card p {
  color: var(--muted);
  font-weight: 750;
}

.price-snapshot {
  color: var(--green);
  font-size: 0.82rem;
  font-weight: 950;
}

.item-card p {
  margin: 8px 0 0 42px;
  line-height: 1.35;
}

.priority-badge {
  width: fit-content;
  margin: 8px 0 0 42px;
  border-radius: 999px;
  padding: 6px 9px;
  font-size: 0.74rem;
  font-weight: 950;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.priority-badge.need {
  background: rgba(159, 59, 47, 0.12);
  color: var(--red);
}

.priority-badge.stock {
  background: rgba(188, 124, 47, 0.16);
  color: #8d5a1f;
}

.sourcing-badge {
  width: fit-content;
  margin: 8px 0 0 42px;
  border-radius: 999px;
  padding: 6px 9px;
  font-size: 0.72rem;
  font-weight: 950;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sourcing-badge.always-fine,
.sourcing-badge.usually-fine {
  background: rgba(56, 102, 65, 0.12);
  color: var(--green);
}

.sourcing-badge.upgrade-if-close {
  background: rgba(188, 124, 47, 0.16);
  color: #8d5a1f;
}

.sourcing-badge.prefer-upgrade,
.sourcing-badge.strongly-prefer-upgrade {
  background: rgba(159, 59, 47, 0.12);
  color: var(--red);
}

.performance-badge {
  width: fit-content;
  margin: 8px 0 0 42px;
  border-radius: 999px;
  padding: 6px 9px;
  font-size: 0.72rem;
  font-weight: 950;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.performance-badge.best-bang {
  background: rgba(56, 102, 65, 0.16);
  color: var(--green);
}

.performance-badge.strong-value {
  background: rgba(188, 124, 47, 0.16);
  color: #8d5a1f;
}

.performance-badge.quality-upgrade,
.performance-badge.health-first {
  background: rgba(87, 111, 163, 0.14);
  color: #37517b;
}

.buy-hint {
  width: fit-content;
  margin: 8px 0 0 42px;
  border-radius: 999px;
  background: rgba(56, 102, 65, 0.1);
  color: var(--green);
  padding: 6px 9px;
  font-size: 0.78rem;
  font-weight: 950;
}

.price-history {
  display: grid;
  gap: 8px;
  margin: 12px 0 0 42px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.price-history strong {
  font-size: 0.88rem;
}

.history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 10px;
  align-items: baseline;
  color: var(--muted);
  font-weight: 800;
}

.history-row b {
  color: var(--ink);
}

.history-row small {
  grid-column: 1 / -1;
}

.price-list {
  display: grid;
  gap: 8px;
}

.deal-list {
  display: grid;
  gap: 10px;
}

.deal-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.46);
  padding: 12px;
}

.deal-card div {
  display: grid;
  gap: 3px;
}

.deal-card strong {
  font-size: 1rem;
}

.deal-card small,
.deal-card p {
  color: var(--muted);
  font-weight: 800;
}

.deal-card p {
  margin: 8px 0 0;
  line-height: 1.35;
}

.deal-signal {
  width: fit-content;
  border-radius: 999px;
  background: var(--green);
  color: #fff6e8;
  padding: 5px 8px;
  font-size: 0.68rem;
  font-weight: 950;
  text-transform: uppercase;
}

.price-card {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.42);
  padding: 12px;
}

.price-card div {
  display: grid;
  gap: 2px;
}

.price-card small {
  color: var(--muted);
  font-weight: 800;
}

.price-card span {
  border-radius: 999px;
  background: rgba(56, 102, 65, 0.12);
  color: var(--green);
  font-weight: 950;
  padding: 8px 10px;
  white-space: nowrap;
}

.pantry-item {
  display: grid;
  gap: 12px;
}

.pantry-item p { margin-left: 0; }

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 4px;
  border-radius: 16px;
  background: rgba(33, 27, 22, 0.08);
  gap: 4px;
}

.segmented button {
  border: 0;
  border-radius: 13px;
  padding: 9px 8px;
  font-weight: 950;
  color: var(--muted);
  background: transparent;
}

.segmented button.active {
  background: var(--ink);
  color: white;
}

.variant-toggle {
  margin: 8px 0 0 42px;
}

.sourcing-note {
  color: var(--muted);
  font-weight: 800;
}

.performance-note {
  color: var(--muted);
  font-weight: 800;
}

.segmented [data-status="need"].active { background: var(--red); }
.segmented [data-status="enough"].active { background: var(--green); }
.segmented [data-status="stock"].active { background: var(--gold); }

.custom-item-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.custom-item-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  padding: 11px 12px;
  font-weight: 800;
}

.custom-item-form input::placeholder {
  color: var(--muted);
}

.rules ul {
  margin: 14px 0 0;
  padding-left: 20px;
  color: var(--muted);
  font-weight: 750;
  line-height: 1.45;
}

@media (min-width: 680px) {
  .item-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pantry-panel .item-list { grid-template-columns: 1fr; }
  .protein-card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .hero {
    padding-top: 16px;
  }

  .brand-lockup {
    gap: 12px;
  }

  .brand-mark {
    width: 102px;
    height: 102px;
    border-radius: 20px;
  }

  .brand-lockup h1 {
    font-size: clamp(2.45rem, 12vw, 3.55rem);
    line-height: 0.9;
  }

  .shopping-heading {
    align-items: stretch;
    gap: 8px;
    flex-direction: column;
  }

  .shopping-heading .heading-actions {
    gap: 6px;
    width: 100%;
  }

  .shopping-actions .ghost {
    flex: 1 1 calc(33.333% - 6px);
    min-width: 0;
  }

  .checked-pill {
    padding: 7px 9px;
  }

  .panel {
    padding: 14px;
  }

  .chip {
    padding: 9px 13px;
  }

}
