:root {
  --bg: #faf7f2;
  --surface: #fff;
  --text: #1f1a17;
  --muted: #6b625b;
  --border: #e3dcd2;
  --accent: #c8102e;
  --accent-text: #fff;
  --chip: #efe8dd;
  --protein: #1a5aa8;
  --fat: #9a4a00;
  --carbs: #2c6e2f;
  --focus: #1a5fd0;
  --action-w: 112px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161311;
    --surface: #221e1b;
    --text: #f3ede6;
    --muted: #a89f96;
    --border: #3a332e;
    --accent: #ff5a70;
    --accent-text: #1a0508;
    --chip: #2f2925;
    --protein: #8cbcff;
    --fat: #f2b36b;
    --carbs: #8fd493;
    --focus: #7fb0ff;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.35;
  padding-bottom: calc(var(--bar-h, 0px) + 1rem);
}

h1, h2 { margin: 0; }
h1 { font-size: 1.15rem; }
h2 { font-size: 1rem; margin: 1rem 0 .5rem; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.muted { color: var(--muted); }
.status { padding: .75rem; border: 1px solid var(--accent); border-radius: .5rem; }

.top {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg);
  padding: .75rem 1rem .5rem;
  border-bottom: 1px solid var(--border);
}

.title-bar { display: flex; align-items: center; gap: .5rem; }
.title-bar h1 { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  width: 100%;
  min-height: 72px;
  padding: 0 1rem;
  font: inherit;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .75rem;
}

.card:disabled { color: var(--muted); }
.card small { font-size: .8rem; font-weight: 400; }

.search-row { display: flex; gap: .5rem; margin-top: .5rem; }
.search { flex: 1; min-width: 0; }

.search input, .sort select {
  min-height: 44px;
  padding: 0 .75rem;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .5rem;
}

.search input { width: 100%; }

.chips {
  display: flex;
  gap: .5rem;
  margin-top: .5rem;
  padding-bottom: .25rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  min-height: 44px;
  padding: 0 1rem;
  font: inherit;
  color: var(--text);
  background: var(--chip);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.chip:disabled { opacity: .4; }

.chip[aria-pressed="true"] {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
}

main { padding: 0 1rem; }

.list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: .75rem; }

.row {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  padding: .875rem;
  line-height: 1.45;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .5rem;
}

.name { display: block; font-weight: 600; overflow-wrap: anywhere; }
.facts { display: grid; gap: .3rem; margin-top: .3rem; font-size: .85rem; font-variant-numeric: tabular-nums; }
.energy { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 .5rem; }
.macro-row { display: flex; flex-wrap: wrap; gap: .25rem; }

.fact-cal { font-size: .95rem; color: var(--text); }
.fact-kj { color: var(--muted); }
.protein { --macro: var(--protein); }
.fat { --macro: var(--fat); }
.carbs { --macro: var(--carbs); }

.macro {
  padding: 0 .25rem;
  font-size: .75rem;
  font-weight: 600;
  color: var(--macro);
  background: color-mix(in srgb, var(--macro) 14%, var(--surface));
  border-radius: .25rem;
}

.nutrition th:is(.protein, .fat, .carbs) { font-weight: 600; color: var(--macro); }

.stepper {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  border: 1.5px solid var(--accent);
  border-radius: 999px;
}

.stepper output { min-width: 2rem; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }

.step { width: 44px; height: 44px; font: inherit; font-size: 1.25rem; color: var(--accent); background: none; border: 0; border-radius: 999px; }
.step:hover, .step:active { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.step:disabled { opacity: .4; background: none; }

.remove { min-height: 44px; padding: 0 .25rem; font: inherit; font-size: .85rem; color: var(--muted); background: none; border: 0; }

.extra-row { display: grid; grid-template-columns: minmax(0, 1fr) var(--action-w); align-items: center; gap: .5rem; padding: .25rem 0; border-bottom: 1px solid var(--border); }

.totals {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  padding: .25rem 1rem calc(.25rem + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 2px solid var(--accent);
}

.totals-main {
  display: flex;
  align-items: stretch;
  gap: .4rem;
  white-space: nowrap;
  width: 100%;
  min-height: 44px;
  padding: .25rem 0;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: none;
  border: 0;
}

.totals-main:disabled { color: var(--text); cursor: default; }

.totals-main > * { display: flex; align-items: center; }
.cal { font-size: 1.1rem; align-items: baseline; gap: .25rem; }
.cal strong { font-size: 1.5rem; }
#cb-kj { font-size: .8rem; }
.macros .macro { padding: 0 .2rem; font-size: .7rem; }

.badge {
  display: grid;
  place-items: center;
  align-self: center;
  min-width: 2rem;
  height: 2rem;
  padding: 0 .3rem;
  font-size: .85rem;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent);
  border-radius: 999px;
}

.macros { gap: .2rem; margin-left: auto; font-variant-numeric: tabular-nums; }

@media (max-width: 379.98px) { #cb-kj { display: none; } }

.extra-cal { display: block; font-size: .8rem; color: var(--muted); }
.extra-list { list-style: none; margin: .5rem 0 0; padding: 0; }

.empty { text-align: center; padding: 2rem 0; }

dialog {
  width: min(32rem, calc(100vw - 1rem));
  max-height: calc(100vh - 2rem);
  padding: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .75rem;
}

dialog::backdrop { background: rgb(0 0 0 / .5); }

.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .5rem; }
.sheet-head h2 { margin: 0; overflow-wrap: anywhere; }

.icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
  font-size: 1.5rem;
  color: var(--text);
  background: var(--chip);
  border: 1px solid var(--border);
  border-radius: .5rem;
}

.nutrition { width: 100%; border-collapse: collapse; margin: .75rem 0; font-variant-numeric: tabular-nums; }
.nutrition th, .nutrition td { padding: .25rem 0; border-bottom: 1px solid var(--border); }
.nutrition th { text-align: left; font-weight: 400; }
.nutrition td { text-align: right; }

.minor { margin: .5rem 0 0; font-size: .8rem; color: var(--muted); }
.minor a { color: inherit; }

.axis-label { margin: .75rem 0 0; font-size: .85rem; font-weight: 600; color: var(--muted); }
.options { flex-wrap: wrap; overflow-x: visible; }
.option:disabled { opacity: .4; }

.add-btn {
  width: 100%;
  min-height: 44px;
  margin-top: .5rem;
  font: inherit;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent);
  border: 0;
  border-radius: .5rem;
}

.plain-btn {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .5rem;
  width: 100%;
  min-height: 44px;
  margin-top: .75rem;
  padding: .5rem .75rem;
  font: inherit;
  font-weight: 600;
  text-align: left;
  color: var(--accent);
  background: none;
  border: 1.5px solid var(--accent);
  border-radius: .5rem;
}

.meal-head { margin: 1rem 0 0; font-size: 1rem; }

.menu-card, .line-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--action-w);
  align-items: center;
  position: relative;
  gap: .5rem;
}

.card-body { display: grid; grid-template-rows: repeat(4, 1.35rem); row-gap: .25rem; align-items: center; min-width: 0; }
.meal-card .card-body { grid-template-rows: repeat(5, 1.35rem); }
.card-body .facts { display: contents; }
.card-body .energy { flex-wrap: nowrap; }
.menu-card .macro-row, .line-card .macro-row { flex-wrap: nowrap; overflow: hidden; }
.menu-card .name, .line-card .name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.serving { overflow: hidden; font-size: .85rem; color: var(--muted); white-space: nowrap; text-overflow: ellipsis; }

.summary {
  display: block;
  max-width: 100%;
  margin: -12px 0;
  padding: 12px 0;
  overflow: hidden;
  font: inherit;
  font-size: .85rem;
  text-align: left;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--accent);
  background: none;
  border: 0;
}

.actions { display: grid; justify-items: center; gap: .15rem; }
.in-cart { font-size: .75rem; color: var(--muted); }
.score { font-size: .75rem; color: var(--protein); white-space: nowrap; }

.add {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: none;
  border: 0;
}

.add span {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--accent);
  border: 1.5px solid var(--accent);
  border-radius: 50%;
}

.add:hover span, .add:active span { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.add:disabled span { opacity: .4; background: none; }

.info {
  display: grid;
  flex: none;
  place-items: center;
  align-self: center;
  width: 44px;
  height: 44px;
  margin: -12px -12px -12px -6px;
  padding: 0;
  background: none;
  border: 0;
}

.info span {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  font-size: .7rem;
  font-weight: 600;
  line-height: 1;
  color: var(--muted);
  border: 1.5px solid var(--muted);
  border-radius: 50%;
}

.info:hover span, .info:active span { background: color-mix(in srgb, var(--muted) 12%, transparent); }

.actions .stepper { width: var(--action-w); }
.actions .stepper output { min-width: 0; }

.link-btn {
  padding: .25rem 0;
  font: inherit;
  color: var(--accent);
  text-decoration: underline;
  background: none;
  border: 0;
}

.back-btn { margin-top: .5rem; }
.source-list { margin: .25rem 0 0; padding: 0; list-style: none; }
.source-list li { margin-top: .5rem; overflow-wrap: anywhere; }
.source-list a { color: var(--accent); }

.confirm-actions { display: flex; gap: .5rem; }
.confirm-actions > * { flex: 1; }
.confirm-actions .add-btn { margin-top: 0; }

#picker-h { margin: 1.5rem 0 1rem; }

#sheet .sheet-head { margin-bottom: .25rem; }
#sheet-body { display: flex; flex-direction: column; gap: 1rem; margin-top: 1rem; }
#sheet-body > * { margin: 0; }
#sheet .axis-label { margin: 0 0 .5rem; }
#sheet-body > .axis-label { margin-bottom: -.5rem; }
#sheet-body > .back-btn { align-self: flex-start; }
#sheet-body > .meal-head { margin-top: .5rem; padding-top: 1rem; border-top: 1px solid var(--border); }
#sheet-body > .meal-head:first-child { margin-top: 0; padding-top: 0; border-top: 0; }

.cart-head { display: none; }

@media (min-width: 1024px) {
  body { padding-bottom: 1rem; }

  .top {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-inline: max(1rem, calc((100% - 1440px) / 2 + 1rem));
  }

  .title-bar { flex: none; max-width: 40%; }
  #menu-controls { flex: 1; min-width: 0; }
  .search-row { margin-top: 0; }

  main {
    display: grid;
    grid-template-columns: 200px minmax(0, 1fr) 360px;
    gap: 1.5rem;
    align-items: start;
    max-width: 1440px;
    margin-inline: auto;
    padding-top: 1rem;
  }

  #picker-h { margin-top: .5rem; }
  .cart-head h2 { margin: 0; }

  #results-h {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  #status, #picker { grid-column: 1 / -1; }
  #sidebar { grid-column: 1; }
  #menu { grid-column: 2; }
  #cart { grid-column: 3; }

  #chains { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
  #results { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }

  .sidebar, #cart {
    position: sticky;
    top: calc(var(--top-h, 0px) + 1rem);
    max-height: calc(100vh - var(--top-h, 0px) - 2rem);
    overflow-y: auto;
  }

  .sidebar .chips {
    flex-direction: column;
    margin-top: 0;
    padding-bottom: 0;
    overflow-x: visible;
  }

  .sidebar .chip { width: 100%; text-align: left; border-radius: .5rem; }

  #cart {
    padding: 1rem 1rem 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: .75rem;
  }

  .cart-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .75rem; }
  #browse { display: none; }
  #cart-lines { margin-bottom: 1rem; }

  #cart-summary {
    position: sticky;
    bottom: 0;
    margin: 0 -1rem;
    padding: 0 1rem 1rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
  }
}
