:root {
  --bg: var(--tg-theme-secondary-bg-color, #f4f1ea);
  --panel: var(--tg-theme-bg-color, #ffffff);
  --ink: var(--tg-theme-text-color, #1f2421);
  --muted: var(--tg-theme-hint-color, #6b716c);
  --line: color-mix(in srgb, var(--ink) 12%, transparent);
  --accent: var(--tg-theme-button-color, #2f7d4f);
  --accent-ink: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2f7d4f);
  --warn: #b5541c;
  --warn-soft: color-mix(in srgb, #e3833f 16%, var(--panel));
  --good-soft: color-mix(in srgb, var(--accent) 14%, var(--panel));
  --bad: #c23b3b;
  --r: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--tg-theme-secondary-bg-color, #121513);
    --panel: var(--tg-theme-bg-color, #1c201d);
    --ink: var(--tg-theme-text-color, #ecefe9);
    --muted: var(--tg-theme-hint-color, #9aa39c);
    --accent: var(--tg-theme-button-color, #4fae78);
    --accent-ink: var(--tg-theme-button-text-color, #0c1a12);
    --link: var(--tg-theme-link-color, #6cc08d);
    --warn: #f0a46c;
    --bad: #ef7474;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; }
p { margin: 0; }

#app { max-width: 760px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); }
.top h1 { font-size: 20px; font-weight: 750; }
.me { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 5px 12px; font-size: 13px; max-width: 50%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
main { flex: 1; padding: 4px 16px calc(96px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 14px; outline: none; }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--panel); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px)); max-width: 760px; margin: 0 auto; }
.tabs button { background: none; border: 0; display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 11px; color: var(--muted); padding: 4px 0; position: relative; }
.tabs button .ic { font-size: 20px; line-height: 1.1; filter: grayscale(1); opacity: .7; }
.tabs button.on { color: var(--accent); font-weight: 600; }
.tabs button.on .ic { filter: none; opacity: 1; }
.tabs b { position: absolute; top: 0; left: calc(50% + 8px); background: var(--accent); color: var(--accent-ink); border-radius: 999px; font-size: 10px; min-width: 17px; height: 17px; line-height: 17px; padding: 0 4px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel { background: var(--panel); border-radius: var(--r); padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.panel h2 { font-size: 17px; }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; display: flex; flex-direction: column; gap: 12px; align-items: center; }

.search { width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 10px 14px; font-size: 16px; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 12px; font-size: 13px; white-space: nowrap; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.cards { display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--panel); border-radius: var(--r); padding: 12px 14px; display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: start; border: 1px solid transparent; }
.card.in { border-color: var(--accent); }
.card .open { all: unset; cursor: pointer; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.card .open:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 6px; }
.card h3 { font-size: 16px; font-weight: 650; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.badges { display: flex; flex-wrap: wrap; gap: 4px; }
.badge { font-size: 11.5px; border-radius: 999px; padding: 1px 8px; background: var(--bg); }
.badge.warn { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.badge.good { background: var(--good-soft); color: var(--accent); font-weight: 600; }
.badge.bad { background: color-mix(in srgb, var(--bad) 14%, var(--panel)); color: var(--bad); font-weight: 600; }
.add { border: 1px solid var(--accent); color: var(--accent); background: transparent; border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.add.on { background: var(--accent); color: var(--accent-ink); }

.btn { border: 0; background: var(--accent); color: var(--accent-ink); border-radius: 12px; padding: 12px 16px; font-weight: 650; font-size: 15px; text-align: center; text-decoration: none; display: inline-flex; justify-content: center; align-items: center; gap: 8px; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn.quiet { background: var(--bg); color: var(--ink); }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .55; cursor: default; }
.link { background: none; border: 0; color: var(--link); padding: 0; font-size: 13px; }

.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.stepper button { border: 0; background: none; width: 34px; height: 30px; font-size: 18px; }
.stepper span { min-width: 64px; text-align: center; font-size: 13px; font-variant-numeric: tabular-nums; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }

.lines { display: flex; flex-direction: column; }
.line { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 9px 0; border-top: 1px solid var(--line); }
.line:first-child { border-top: 0; }
.line .nm { font-weight: 550; }
.line .sub { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12.5px; color: var(--muted); align-items: center; }
.line .pr { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.line.home .nm, .line.home .pr { color: var(--muted); }
.dept-h { font-size: 12px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); font-weight: 650; }
.total { position: sticky; bottom: calc(68px + env(safe-area-inset-bottom, 0px)); background: var(--panel); border-radius: var(--r); padding: 10px 12px 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; box-shadow: 0 -6px 20px color-mix(in srgb, var(--ink) 10%, transparent); }
.total .tsum { display: flex; flex-direction: column; line-height: 1.15; }
.total .sum { font-size: 21px; font-weight: 750; font-variant-numeric: tabular-nums; }

.sheet { border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 760px; max-height: 92vh; border-radius: 18px 18px 0 0; background: var(--panel); color: var(--ink); }
.sheet::backdrop { background: rgb(0 0 0 / .45); }
.sheet[open] { animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(24px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .sheet[open] { animation: none; } }
#sheet-body { padding: 18px 16px calc(20px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 16px; overflow-y: auto; max-height: 92vh; }
.sheet h2 { font-size: 21px; }
.close { position: sticky; top: 0; align-self: flex-end; margin-bottom: -38px; border: 0; background: var(--bg); border-radius: 999px; width: 34px; height: 34px; font-size: 18px; z-index: 1; }
.ings { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.ings li { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; padding: 7px 0; border-top: 1px solid var(--line); }
.ings li:first-child { border-top: 0; }
.ings .q { color: var(--muted); font-size: 13px; white-space: nowrap; }
.ings li.avoided .n { color: var(--warn); font-weight: 600; }
.noeat { border: 1px solid var(--line); background: none; border-radius: 999px; font-size: 11.5px; padding: 3px 9px; color: var(--muted); white-space: nowrap; }
.noeat.on { border-color: var(--warn); color: var(--warn); background: var(--warn-soft); font-weight: 600; }
.steps { margin: 0; padding-left: 1.3em; display: flex; flex-direction: column; gap: 6px; }
.addon { background: var(--bg); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; }
.verdicts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.verdicts button { border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 9px 8px; font-size: 13.5px; }
.verdicts button.on { border-color: var(--accent); background: var(--good-soft); color: var(--accent); font-weight: 650; }
.verdicts button[data-v="never"].on, .verdicts button[data-v="dislike"].on { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, var(--panel)); color: var(--bad); }
textarea { width: 100%; min-height: 72px; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px 12px; resize: vertical; font-size: 15px; }
.fb { display: flex; flex-direction: column; gap: 3px; padding: 10px 0; border-top: 1px solid var(--line); }
.fb:first-child { border-top: 0; }
.fb .who { font-weight: 600; font-size: 13.5px; }
.fb .txt { white-space: pre-wrap; overflow-wrap: anywhere; }
.toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--panel); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 50; max-width: calc(100% - 32px); }
.names { display: flex; flex-wrap: wrap; gap: 8px; }
.input { width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px 12px; font-size: 16px; }
