:root {
  color-scheme: light dark;
  font: 16px/1.45 system-ui, sans-serif;
  --page: var(--tg-theme-secondary-bg-color, #f0f4f0);
  --surface: var(--tg-theme-bg-color, #fff);
  --ink: var(--tg-theme-text-color, #192923);
  --muted: var(--tg-theme-hint-color, #54665d);
  --accent: var(--tg-theme-button-color, #21654b);
  --accent-ink: var(--tg-theme-button-text-color, #fff);
  --line: color-mix(in srgb, var(--ink) 13%, transparent);
  --soft: color-mix(in srgb, var(--accent) 9%, var(--surface));
  background: var(--page);
  color: var(--ink);
}

:root[data-theme="dark"] {
  --page: var(--tg-theme-secondary-bg-color, #151c19);
  --surface: var(--tg-theme-bg-color, #202b25);
  --ink: var(--tg-theme-text-color, #eef4ee);
  --muted: var(--tg-theme-hint-color, #adbbb1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --page: var(--tg-theme-secondary-bg-color, #151c19);
    --surface: var(--tg-theme-bg-color, #202b25);
    --ink: var(--tg-theme-text-color, #eef4ee);
    --muted: var(--tg-theme-hint-color, #adbbb1);
  }
}

body { margin: 0; overflow-x: clip; }

main {
  max-width: 55rem;
  margin: 0 auto;
  padding: max(1.5rem, var(--tg-content-safe-area-inset-top, 0px)) 1rem 2rem;
}

h1, h2, h3, h4, p { margin: 0; }
h1 { margin: .65rem 0 .35rem; font-size: clamp(2rem, 7vw, 3.1rem); letter-spacing: -.045em; line-height: 1.05; }
h2 { font-size: 1.2rem; letter-spacing: -.02em; }
.hint, .store-address, .store-metro, .product-unit { color: var(--muted); }

.hero {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  margin-bottom: 1rem;
  padding: clamp(1.25rem, 5vw, 2.5rem);
  border-radius: 1.5rem;
  background: linear-gradient(125deg, #164734, #24634c);
  color: #fff;
}

.hero::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset: -5rem -4rem auto auto;
  width: 18rem;
  aspect-ratio: 1;
  border-radius: 50%;
  background: repeating-radial-gradient(circle, transparent 0 18px, rgb(255 255 255 / 12%) 19px 20px);
}

.city {
  display: inline-block;
  padding: .25rem .6rem;
  border-radius: 999px;
  background: rgb(255 255 255 / 16%);
  font-size: .78rem;
  font-weight: 650;
}

.hero-description { max-width: 30ch; color: #e4f0e8; }
.panel, .catalog-product, .catalog-group {
  border: 1px solid var(--line);
  border-radius: 1.125rem;
  background: var(--surface);
}
.panel { padding: 1rem; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .75rem; }
.count { min-width: 1.5rem; padding: .125rem .35rem; border-radius: 999px; background: var(--soft); text-align: center; font-size: .8rem; font-weight: 700; }

ul { margin: 0; padding: 0; list-style: none; }

.store, .empty {
  margin-bottom: .75rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: .875rem;
  background: var(--soft);
}

.empty { color: var(--muted); border-style: dashed; }

.store {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}

.store-address { margin-top: .25rem; }
.store-metro { font-size: .875rem; }

button {
  min-height: 44px;
  padding: .5rem .875rem;
  border: 1px solid transparent;
  border-radius: .625rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

:is(button, summary, input, a):focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.primary {
  width: 100%;
  background: var(--accent);
  color: var(--accent-ink);
}

.secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}

.add-store { width: 100%; }
.add-store span { margin-right: .2rem; font-size: 1.2em; }

dialog {
  box-sizing: border-box;
  width: calc(100dvw - 2rem);
  max-width: 30rem;
  padding: 1rem;
  border: 0;
  border-radius: 1rem;
  background: var(--surface);
  color: var(--ink);
}

dialog::backdrop { background: rgb(0 0 0 / 50%); }
dialog form { margin-top: .75rem; }
dialog h2 { margin-bottom: .75rem; }

input[type="search"] {
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  margin: .25rem 0 .75rem;
  padding: .5rem .75rem;
  border: 1px solid var(--line);
  border-radius: .625rem;
  background: var(--page);
  color: var(--ink);
  font: inherit;
}

#available {
  max-height: 48dvh;
  overflow-y: auto;
}

.catalog { margin-top: 1.5rem; }
.catalog h2 { margin-bottom: .65rem; }
.search-panel { padding: .65rem; }
#catalog-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .5rem; }
.search-field { position: relative; }
.search-field svg { position: absolute; top: .7rem; left: .65rem; width: 1.4rem; color: var(--muted); pointer-events: none; }
.search-field input { margin: 0; padding-left: 2.3rem; }
#catalog-status { margin-top: .75rem; }
.catalog-group { margin-top: 1rem; padding: .85rem; background: var(--soft); }
.catalog-group h3 { font-size: 1.05rem; margin-bottom: .25rem; }
.catalog-group h4 { margin: .9rem 0 .45rem; font-size: .8rem; letter-spacing: .025em; }
.product-grid { display: grid; gap: .6rem; }
.catalog-product { display: grid; grid-template-columns: 5.25rem minmax(0, 1fr); gap: .75rem; padding: .65rem; align-items: start; }
.product-content { min-width: 0; overflow-wrap: anywhere; }
.product-content strong { display: block; font-size: .93rem; line-height: 1.3; }
.product-content a { color: inherit; text-decoration-color: var(--line); text-underline-offset: .15em; }
.product-price { margin-top: .3rem; font-weight: 780; font-size: 1.25rem; letter-spacing: -.025em; }
.product-unit { font-size: .8rem; }
.product-badge { display: inline-block; margin: .25rem .25rem 0 0; padding: .15rem .4rem; border-radius: .35rem; background: var(--soft); font-size: .73rem; font-weight: 650; }
.product-photo { position: relative; display: grid; place-items: center; aspect-ratio: 1; overflow: hidden; border-radius: .7rem; background: var(--soft); color: var(--muted); font-size: .72rem; }
.product-photo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #fff; opacity: 0; }
.product-photo img.loaded { opacity: 1; }
.product-details { grid-column: 1 / -1; border-top: 1px solid var(--line); font-size: .85rem; }
.product-details summary { padding: .65rem .25rem .25rem; cursor: pointer; font-weight: 650; }
.nutrition { margin: .25rem 0 .4rem; padding: .5rem; border-radius: .5rem; background: var(--soft); white-space: pre-line; }

@media (min-width: 44rem) {
  .product-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Meal planner */
.app-hero { margin-bottom: 1.25rem; }
.city-button { display: inline-flex; align-items: center; gap: .35rem; border: 0; color: inherit; cursor: pointer; }
.profile-summary { margin-top: 1rem; max-width: 42ch; color: #e4f0e8; font-size: .88rem; }
.eyebrow { margin-bottom: .15rem; color: var(--muted); font-size: .73rem; font-weight: 750; letter-spacing: .06em; text-transform: uppercase; }
.hero .eyebrow { color: #c8e1d1; }
.text-button { min-height: auto; padding: .25rem 0; border: 0; background: none; color: var(--accent); font-size: .88rem; }

.planner { margin-bottom: 1.5rem; }
.meal-form { display: grid; gap: 1rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
.serving-field { grid-column: 1 / -1; }
.field-label, .range-label > span { display: flex; justify-content: space-between; gap: .5rem; margin-bottom: .35rem; font-size: .82rem; font-weight: 700; }
select, input[type="text"] {
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  padding: .5rem .65rem;
  border: 1px solid var(--line);
  border-radius: .625rem;
  background: var(--page);
  color: var(--ink);
  font: inherit;
}
.range-label { display: block; }
.range-label output { color: var(--accent); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; margin: .1rem 0 0; accent-color: var(--accent); }
.range-hint { display: block; margin-top: .15rem; color: var(--muted); font-size: .72rem; }

.results-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: .7rem; }
.results-heading .hint { max-width: 16rem; text-align: right; font-size: .78rem; }
.meal-cards { display: grid; gap: .75rem; }
.meal-card {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 1.125rem;
  background: var(--surface);
  box-shadow: 0 8px 22px rgb(28 59 41 / 5%);
}
.meal-card-top { display: flex; gap: .75rem; align-items: flex-start; }
.meal-card-content { min-width: 0; }
.meal-card h3 { font-size: 1.05rem; line-height: 1.2; }
.meal-emoji { display: grid; flex: none; width: 2.5rem; aspect-ratio: 1; place-items: center; border-radius: .75rem; background: var(--soft); font-size: 1.45rem; }
.meal-description { margin-top: .25rem; color: var(--muted); font-size: .9rem; }
.meal-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: .35rem; margin: .85rem 0 .65rem; }
.meal-metrics li { padding: .45rem; border-radius: .6rem; background: var(--soft); }
.meal-metrics strong, .meal-metrics span { display: block; }
.meal-metrics strong { font-size: .85rem; white-space: nowrap; }
.meal-metrics span { margin-top: .05rem; color: var(--muted); font-size: .68rem; }
.match-note { margin-bottom: .65rem; color: var(--accent); font-size: .8rem; font-weight: 650; }
.replacement-note { margin: -.2rem 0 .65rem; padding: .45rem .55rem; border-radius: .55rem; background: var(--soft); color: var(--accent); font-size: .78rem; font-weight: 650; }
.meal-details { margin-bottom: .8rem; border-top: 1px solid var(--line); }
.meal-details summary { padding: .65rem 0 .15rem; cursor: pointer; font-size: .86rem; font-weight: 650; }
.ingredient-list, .swap-list, .basket-items { display: grid; gap: .3rem; margin: .45rem 0; padding-left: 1rem; list-style: disc; color: var(--muted); font-size: .84rem; }
.replaced-ingredient s { color: var(--muted); }
.replaced-ingredient strong { color: var(--accent); }
.swap-list { color: var(--accent); }
.meal-card .secondary { width: 100%; }

.basket { margin: 1.25rem 0; }
.basket-title { margin-bottom: .55rem; font-weight: 750; }
.basket-total { margin: .75rem 0; color: var(--accent); font-size: 1.1rem; font-weight: 800; }
.basket-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.basket-actions > :first-child { grid-column: 1 / -1; }
.basket-note { margin-top: .6rem; color: var(--muted); font-size: .76rem; }

.workspace { margin-top: 1.75rem; }
.workspace > summary { display: flex; align-items: center; justify-content: space-between; gap: .6rem; padding: .35rem 0; cursor: pointer; font-weight: 750; list-style: none; }
.workspace > summary::-webkit-details-marker { display: none; }
.workspace > summary::after { content: "⌄"; margin-left: .1rem; color: var(--muted); }
.workspace[open] > summary::after { transform: rotate(180deg); }
.workspace .count { margin-left: auto; }
.workspace-content { padding-top: .75rem; }

.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.icon-button { display: grid; min-width: 36px; min-height: 36px; padding: 0; place-items: center; border-color: var(--line); background: var(--surface); color: var(--ink); font-size: 1.45rem; line-height: 1; }
dialog { max-height: calc(100dvh - 2rem); overflow-x: hidden; overflow-y: auto; }
dialog fieldset { margin: 1rem 0; padding: 0; border: 0; }
dialog legend { margin-bottom: .5rem; font-size: .9rem; font-weight: 750; }
.fieldset-hint { margin: -.2rem 0 .65rem; color: var(--muted); font-size: .78rem; }
.choice-grid { display: grid; width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .45rem; }
.choice { position: relative; display: grid; min-width: 0; min-height: 42px; place-items: center; padding: 0 .45rem; border: 1px solid var(--line); border-radius: .65rem; background: var(--surface); overflow-wrap: anywhere; text-align: center; font-size: .82rem; font-weight: 650; cursor: pointer; }
.choice input { position: absolute; opacity: 0; }
.choice > span { max-width: 100%; overflow-wrap: anywhere; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--soft); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.choice:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.exclusion-grid { display: flex; flex-wrap: wrap; gap: .5rem; }
.choice-pill { display: inline-grid; flex: 0 0 auto; min-height: 38px; padding: 0 .85rem; border-radius: 999px; }
.choice-pill:has(input:checked)::after { content: "×"; margin-left: .35rem; font-size: 1rem; font-weight: 800; }
.choice-pill:has(input:checked) span { text-decoration: line-through; text-decoration-thickness: 1.5px; }
.custom-exclusions { margin-top: 1rem; padding-top: .85rem; border-top: 1px dashed var(--line); color: var(--muted); font-size: .82rem; }
.custom-exclusions label { display: block; margin-bottom: .35rem; color: var(--ink); font-weight: 700; }
.custom-exclusions p { margin-top: .25rem; font-size: .74rem; }
.profile-edit-note { margin: .5rem 0 1rem; color: var(--muted); font-size: .76rem; }
.safety-note { margin: 1rem 0; padding: .65rem .75rem; border-radius: .65rem; background: var(--soft); color: var(--muted); font-size: .78rem; }

.city-list { display: grid; gap: .55rem; margin: 1rem 0; }
.city-row { display: flex; align-items: center; gap: .55rem; }
.city-row button { flex: 1; text-align: left; }
.city-row button[aria-pressed="true"] { border-color: var(--accent); background: var(--soft); color: var(--accent); }
.city-row button:disabled { opacity: .55; cursor: not-allowed; }
.soon, .available { flex: none; font-size: .72rem; font-weight: 700; }
.soon { color: var(--muted); }
.available { color: var(--accent); }
.location-button { width: 100%; }
#location-status { margin-top: .65rem; }

@media (min-width: 44rem) {
  .meal-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .serving-field { grid-column: auto; }
  .meal-card { display: flex; flex-direction: column; }
  .meal-card > .secondary { margin-top: auto; }
}

@media (max-width: 22rem) {
  .form-grid { grid-template-columns: 1fr; }
  .results-heading { align-items: flex-start; flex-direction: column; }
  .results-heading .hint { text-align: left; }
}
