:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --card: var(--tg-theme-section-bg-color, var(--bg));
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --soft: color-mix(in srgb, var(--hint) 12%, transparent);
  --p: #3b82f6; --f: #f59e0b; --c: #10b981;
  --radius: 16px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --spring: cubic-bezier(.34, 1.4, .64, 1);
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #1c1c1e; --bg2: #000000; --card: #1c1c1e; --text: #f2f2f7; --hint: #8e8e93; --accent: #4f9cf0;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg2); color: var(--text); overscroll-behavior-y: none;
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.center { text-align: center; }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* ---------- top bar */
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg2) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px); padding: 6px 12px; }
.datebar { display: flex; align-items: center; justify-content: space-between; max-width: 640px; margin: 0 auto; }
.view-title { margin: 0 auto; max-width: 640px; font-size: 20px; padding: 10px 4px; }
.icon-btn { width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--card); display: grid; place-items: center;
  transition: transform .15s var(--ease), opacity .2s; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:active { transform: scale(.88); }
.icon-btn:disabled { opacity: .3; }
.date-label { border: 0; background: none; display: flex; flex-direction: column; align-items: center; padding: 2px 12px; min-width: 150px; }
.date-label span { font-weight: 700; font-size: 17px; }
.date-label small { color: var(--hint); font-size: 12px; min-height: 16px; }

/* ---------- views */
.views { position: relative; max-width: 640px; margin: 0 auto; padding: 4px 14px calc(var(--tabbar-h) + var(--safe-b) + 92px); overflow-x: clip; }
.view[hidden] { display: none; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin: 10px 0; border: 0; display: block; width: 100%; text-align: left; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.pressable { transition: transform .18s var(--ease), filter .18s; }
.pressable:active { transform: scale(.97); filter: brightness(.96); }

/* summary ring */
.summary { display: grid; grid-template-columns: 124px 1fr; gap: 16px; align-items: center; }
.ring-wrap { position: relative; width: 124px; height: 124px; }
.ring { width: 124px; height: 124px; transform: rotate(-90deg); }
.ring circle { stroke-width: 10; fill: none; }
.ring-bg { stroke: var(--soft); }
.ring-fg { stroke: var(--accent); stroke-dasharray: 326.73; stroke-dashoffset: 326.73; transition: stroke-dashoffset .9s var(--ease), stroke .3s; }
.ring-fg.over { stroke: var(--danger); }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-center b { font-size: 26px; font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.ring-center span { font-size: 12px; color: var(--hint); text-align: center; padding: 0 10px; }
.macros { display: flex; flex-direction: column; gap: 8px; }
.macro { display: flex; align-items: center; gap: 10px; }
.mring { width: 34px; height: 34px; flex: none; transform: rotate(-90deg); }
.mring circle { fill: none; stroke-width: 5; }
.mbg { stroke: var(--soft); }
.mfg { stroke-dasharray: 100.53; stroke-dashoffset: 100.53; stroke-linecap: round; transition: stroke-dashoffset .9s var(--ease), stroke .3s; }
.p .mfg { stroke: var(--p); } .f .mfg { stroke: var(--f); } .c .mfg { stroke: var(--c); }
.mfg.over { stroke: var(--danger) !important; }
.mtext { display: flex; flex-direction: column; line-height: 1.2; }
.mtext span { font-size: 12px; color: var(--hint); }
.mtext b { font-variant-numeric: tabular-nums; font-size: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid3 label { margin: 0 0 4px; font-size: 13px; }
.seg-plain .seg-btn { color: var(--text); }
.seg-plain .seg-btn.active { background: var(--accent); color: var(--accent-text); }
.seg-plain { background: var(--bg2); }
.tdee-big { font-size: 30px; font-weight: 800; letter-spacing: -.5px; }
.tdee-row { display: flex; gap: 8px; margin-top: 12px; }
.tdee-row button { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 10px 4px; border-radius: 12px; border: 0;
  background: var(--soft); transition: transform .15s var(--spring); }
.tdee-row button:active { transform: scale(.94); }
.tdee-row button b { font-size: 16px; }
.tdee-row button span { font-size: 11px; color: var(--hint); }
.tdee-row button.current { outline: 2px solid var(--accent); }
.macro-head { display: flex; justify-content: space-between; font-size: 13px; }
.macro-head span { color: var(--hint); }
.macro-head b { font-variant-numeric: tabular-nums; }
.mbar { height: 6px; border-radius: 3px; background: var(--soft); overflow: hidden; margin-top: 4px; }
.mbar i { display: block; height: 100%; width: 0; border-radius: 3px; transition: width .8s var(--ease); }
.p .mbar i { background: var(--p); } .f .mbar i { background: var(--f); } .c .mbar i { background: var(--c); }

/* weight card */
.weight-card { display: flex; align-items: center; gap: 12px; }
.weight-icon { font-size: 24px; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: var(--soft); }
.weight-text { flex: 1; display: flex; flex-direction: column; }
.weight-text small { color: var(--hint); }
.chev { color: var(--hint); font-size: 24px; }

/* entries */
.entry-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; }
.entry-head .muted { font-size: 13px; }
.item { display: flex; justify-content: space-between; gap: 8px; padding: 10px 6px; margin: 0 -6px; border: 0; border-radius: 10px;
  border-top: 1px solid var(--line); width: calc(100% + 12px); background: none; text-align: left; transition: background .15s; }
.item:first-of-type { border-top: 0; }
.item:active { background: var(--soft); }
.item .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.item .kcal { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.entry-actions { display: flex; gap: 4px; margin-top: 4px; }
.chip { border: 0; background: var(--soft); color: var(--text); border-radius: 999px; padding: 6px 12px; font-size: 13px; transition: transform .15s var(--ease); }
.chip:active { transform: scale(.94); }
.chip.danger { color: var(--danger); }
.pending { border-left: 4px solid var(--danger); }
.pending.clarify { border-left-color: var(--accent); }
.pending p { margin: 4px 0; overflow-wrap: anywhere; }
.empty { text-align: center; padding: 30px 12px; color: var(--hint); }
.empty .big-emoji { font-size: 40px; display: block; margin-bottom: 6px; }
.skeleton { height: 74px; border-radius: var(--radius); margin: 10px 0;
  background: linear-gradient(90deg, var(--card) 0%, var(--soft) 50%, var(--card) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* floating add button */
.fab { position: fixed; right: max(18px, calc(50% - 320px + 18px)); bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); z-index: 9;
  width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 45%, transparent);
  transition: transform .25s var(--spring), opacity .2s; }
.fab svg { width: 26px; height: 26px; stroke-width: 2.5; }
.fab:active { transform: scale(.9); }
.fab.hidden { transform: scale(0); opacity: 0; pointer-events: none; }

/* bottom tab bar */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; padding: 6px 10px calc(6px + var(--safe-b));
  background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border-top: 1px solid var(--line); }
.tab { position: relative; z-index: 1; flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; color: var(--hint); font-size: 11px; font-weight: 600; transition: color .25s; }
.tab svg { width: 24px; height: 24px; transition: transform .35s var(--spring); }
.tab.active { color: var(--accent); }
.tab.active svg { transform: translateY(-1px) scale(1.08); }
.tab:active svg { transform: scale(.86); }
.tab-pill { position: absolute; top: 6px; height: 50px; border-radius: 14px; background: color-mix(in srgb, var(--accent) 13%, transparent);
  transition: transform .42s var(--spring), width .42s var(--spring); }

/* segmented control */
.seg { position: relative; display: flex; background: var(--card); border-radius: 12px; padding: 3px; margin-top: 6px; }
.seg-btn { position: relative; z-index: 1; flex: 1; border: 0; background: none; padding: 8px; border-radius: 9px; font-weight: 600; font-size: 14px; transition: color .25s; }
.seg-btn.active { color: var(--accent-text); }
.seg-pill { position: absolute; top: 3px; bottom: 3px; border-radius: 9px; background: var(--accent); transition: transform .4s var(--spring), width .4s var(--spring); }

/* charts */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 170px; padding-top: 8px; position: relative; }
.chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; min-width: 0; }
.chart .b { width: 100%; max-width: 34px; background: var(--accent); border-radius: 6px 6px 2px 2px; min-height: 3px; transform-origin: bottom; }
.chart .b.over { background: var(--danger); }
.chart .b.zero { background: var(--soft); }
.chart .lbl { font-size: 10px; color: var(--hint); margin-top: 5px; white-space: nowrap; height: 13px; }
.chart .goal { position: absolute; left: 0; right: 0; border-top: 1.5px dashed var(--hint); opacity: .6; }
.chart .goal span { position: absolute; right: 0; top: -16px; font-size: 10px; color: var(--hint); }
.wchart svg { width: 100%; height: 170px; overflow: visible; }
.wchart .line { stroke: var(--accent); stroke-width: 2.5; fill: none; }
.wchart .area { fill: color-mix(in srgb, var(--accent) 14%, transparent); stroke: none; }
.wchart .dot { fill: var(--card); stroke: var(--accent); stroke-width: 2; }
.wchart text { font-size: 10px; fill: var(--hint); stroke: none; }
.wchart .grid { stroke: var(--line); stroke-width: 1; }

/* forms */
.form label { display: block; margin-bottom: 14px; font-weight: 600; font-size: 14px; }
input[type=text], input[type=number], input[type=search], input[type=date] {
  width: 100%; margin-top: 6px; padding: 12px 14px; border-radius: 12px; border: 1px solid transparent; background: var(--bg2);
  font-weight: 400; font-size: 16px; transition: border-color .2s, box-shadow .2s; -webkit-appearance: none; appearance: none; }
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.primary { background: var(--accent); color: var(--accent-text); border: 0; border-radius: 12px; padding: 14px 16px; font-weight: 700; }
.primary:disabled { opacity: .5; }
.secondary { background: var(--soft); border: 0; border-radius: 12px; padding: 14px 16px; font-weight: 600; }
.secondary.danger { color: var(--danger); }
.wide { width: 100%; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 label { margin: 0; }
.actions { display: flex; gap: 10px; margin-top: 16px; }
.actions > * { flex: 1; }

/* bottom sheet */
.sheet-backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .45); }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; max-width: 640px; margin: 0 auto; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 22px 22px 0 0; padding: 0 16px calc(18px + var(--safe-b)); box-shadow: 0 -10px 40px rgba(0,0,0,.25); touch-action: pan-y; }
.sheet h3 { margin: 4px 0 14px; font-size: 19px; }
.sheet-handle { position: sticky; top: 0; display: flex; justify-content: center; padding: 10px 0 8px; background: var(--bg); z-index: 1; cursor: grab; touch-action: none; }
.sheet-handle span { width: 38px; height: 5px; border-radius: 3px; background: var(--line); }
.results { max-height: 36vh; overflow: auto; margin: 8px 0; }
.result { display: flex; justify-content: space-between; gap: 8px; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: none; padding: 12px 4px; transition: background .15s; }
.result:active { background: var(--soft); }
.result.sel { color: var(--accent); font-weight: 700; }

/* weight sheet */
.stepper { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 8px 0 4px; }
.stepper button { width: 54px; height: 54px; border-radius: 50%; border: 0; background: var(--soft); font-size: 26px; font-weight: 600;
  transition: transform .15s var(--spring); touch-action: manipulation; }
.stepper button:active { transform: scale(.86); }
.stepper input { width: 150px; text-align: center; font-size: 40px; font-weight: 800; padding: 6px; background: none; margin: 0; font-variant-numeric: tabular-nums; }
.stepper-unit { text-align: center; color: var(--hint); margin-bottom: 6px; }
.delta { text-align: center; font-size: 13px; color: var(--hint); min-height: 18px; }

/* toast */
#toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); z-index: 50; max-width: 560px; margin: 0 auto;
  background: color-mix(in srgb, var(--text) 88%, transparent); color: var(--bg); padding: 12px 16px; border-radius: 14px; text-align: center; font-weight: 600;
  transform: translateY(20px) scale(.96); opacity: 0; pointer-events: none; transition: transform .35s var(--spring), opacity .25s; }
#toast.show { transform: none; opacity: 1; }
#toast.error { background: var(--danger); color: #fff; }

/* ---------- cooking mode */
.tab { position: relative; }
.tab-badge { position: absolute; top: 2px; left: 50%; margin-left: 6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; text-align: center; font-weight: 700; z-index: 2; }
.cook-head { display: flex; gap: 8px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.cook-head .primary { flex: 1 1 100%; }
.cook-head .secondary { flex: 1; padding: 10px; }
.chip.on { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.section-h { font-size: 15px; margin: 18px 4px 4px; color: var(--hint); font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
.dish-card { display: block; }
.dish-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 4px; }
.live-dot { font-size: 12px; color: var(--c); font-weight: 700; display: inline-flex; align-items: center; gap: 6px; }
.live-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.7); } }
.left-bar { height: 8px; border-radius: 4px; background: var(--soft); overflow: hidden; margin: 6px 0; }
.left-bar i { display: block; height: 100%; width: 0; background: var(--c); border-radius: 4px; transition: width .9s var(--ease); }
.primary-chip { background: var(--accent); color: var(--accent-text); }
.recent-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.recent-row:first-child { border-top: 0; }
#cook-recent-card:has(#cook-recent:empty) { display: none; }
.linkish { border: 0; background: none; padding: 0; text-align: left; color: inherit; }
.linkish.small { color: var(--accent); font-size: 13px; }
#leftovers-strip { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.left-chip { display: flex; justify-content: space-between; align-items: center; gap: 8px; background: var(--card); border-radius: 14px; padding: 10px 12px;
  border-left: 4px solid var(--c); }
.dish-head h3 { margin-bottom: 2px; }
.dish-totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); gap: 6px; margin: 10px 0; }
.dish-totals div { background: var(--soft); border-radius: 12px; padding: 8px; display: flex; flex-direction: column; align-items: center; }
.dish-totals b { font-size: 17px; font-variant-numeric: tabular-nums; }
.dish-totals span { font-size: 11px; color: var(--hint); }
.ing-list { margin: 6px 0 10px; }
.ing-row { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: baseline; width: 100%; border: 0; background: none;
  text-align: left; padding: 9px 4px; border-top: 1px solid var(--line); border-radius: 8px; }
.ing-row:first-child { border-top: 0; }
.ing-row:active { background: var(--soft); }
.ing-row .g { font-weight: 700; font-variant-numeric: tabular-nums; }
.add-box { background: var(--bg2); border-radius: 14px; padding: 10px; }
.add-box input[type=search] { margin-top: 0; background: var(--card); }
.row-right { display: flex; justify-content: flex-end; gap: 6px; margin: 6px 0; flex-wrap: wrap; }
.picked { margin-top: 8px; }
.picked-name { display: flex; justify-content: space-between; align-items: baseline; }
.big-input { font-size: 30px !important; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; }
.quick { display: flex; gap: 6px; justify-content: center; margin: 8px 0; }
.result-row { display: flex; align-items: stretch; border-bottom: 1px solid var(--line); }
.result-row .result { border-bottom: 0; flex: 1; }
.info-btn { border: 0; background: none; color: var(--accent); font-size: 20px; width: 44px; flex: none; }
.pot-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 12px; }
.chip.sel { background: var(--accent); color: var(--accent-text); }
.field-label { font-weight: 600; font-size: 14px; }
.switch-row { display: flex !important; gap: 10px; align-items: flex-start; font-weight: 400 !important; margin: 10px 0; }
.switch-row input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.pot-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.celebrate { position: fixed; left: 50%; bottom: 140px; z-index: 60; pointer-events: none; }
.celebrate span { position: absolute; font-size: 28px; }
textarea { width: 100%; margin-top: 6px; padding: 10px 12px; border-radius: 10px; border: 1px solid transparent; background: var(--bg2);
  font: inherit; font-size: 15px; resize: vertical; }
textarea:focus { outline: none; border-color: var(--accent); }

/* ---------- labels */
.brand { color: var(--hint); font-weight: 500; font-size: 15px; }
.item-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 4px; }
.kbzhu { margin: 10px 0; }
.kbzhu-title { margin-bottom: 4px; }
.kbzhu-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.kb { border-radius: 12px; padding: 8px 4px; display: flex; flex-direction: column; align-items: center; background: var(--soft); }
.kb b { font-size: 18px; font-variant-numeric: tabular-nums; }
.kb span { font-size: 11px; color: var(--hint); }
.kb.p { box-shadow: inset 0 -3px 0 var(--p); } .kb.f { box-shadow: inset 0 -3px 0 var(--f); } .kb.c { box-shadow: inset 0 -3px 0 var(--c); }
.kb.kcal { box-shadow: inset 0 -3px 0 var(--accent); }
.split { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--soft); margin: 8px 0 4px; }
.split i { display: block; height: 100%; width: 0; transition: width .8s var(--ease); }
.split .p { background: var(--p); } .split .f { background: var(--f); } .split .c { background: var(--c); }
.section-title { font-weight: 700; margin: 14px 0 6px; }
.ing-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ing-chip { background: var(--soft); border-radius: 10px; padding: 5px 9px; font-size: 13px; line-height: 1.3; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.badge { font-size: 12px; padding: 4px 9px; border-radius: 999px; background: var(--soft); }
.badge.warn { background: color-mix(in srgb, var(--f) 22%, transparent); }
.badge.allergen { background: color-mix(in srgb, var(--danger) 18%, transparent); }
.badge.ok { background: color-mix(in srgb, var(--c) 20%, transparent); }
.badge.muted-badge { color: var(--hint); }
.grid4 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.barcode-row { display: flex; gap: 8px; align-items: flex-end; }
.barcode-row input { flex: 1; font-size: 20px; letter-spacing: 1px; font-variant-numeric: tabular-nums; }
.barcode-row .primary { margin-bottom: 1px; }
.scan-video { width: 100%; border-radius: 14px; background: #000; max-height: 260px; object-fit: cover; margin: 6px 0; }
.chip.danger { color: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
}
