:root {
  --bg: #f3f6f2;
  --glow: rgba(31, 157, 99, .13);
  --card: #ffffff;
  --card2: #f7faf6;
  --ink: #15201a;
  --muted: #627069;
  --line: #e4e9e2;
  --accent: #178a56;
  --accent2: #22a96b;
  --accent-ink: #ffffff;
  --accent-soft: #e2f3e9;
  --warn: #c4531c;
  --warn-soft: #fbece3;
  --p: #3b7fb8;
  --c: #d39a2a;
  --f: #cc6358;
  --shadow: 0 1px 2px rgba(20, 40, 28, .05), 0 8px 24px rgba(20, 40, 28, .06);
  --shadow-lg: 0 -10px 40px rgba(10, 30, 20, .18);
  --ease: cubic-bezier(.22, .9, .3, 1);
  --spring: cubic-bezier(.34, 1.4, .5, 1);
  --nav-h: 66px;
}
/* Dark is the default. Settings can switch to Light or follow the phone (data-theme on <html>). */
:root[data-theme="dark"] {
    --bg: #0e1210; --glow: rgba(79, 208, 142, .10); --card: #171c19; --card2: #1c221e; --ink: #edf1ec; --muted: #93a099; --line: #262d28;
    --accent: #4fd08e; --accent2: #7be3ae; --accent-ink: #05190f; --accent-soft: #1a2d22; --warn: #ee9462; --warn-soft: #36251b;
    --p: #6aa6d8; --c: #e6b75e; --f: #e5948a;
    --shadow: 0 1px 2px rgba(0,0,0,.45), 0 8px 24px rgba(0,0,0,.28);
    --shadow-lg: 0 -10px 40px rgba(0,0,0,.55);
    color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #0e1210; --glow: rgba(79, 208, 142, .10); --card: #171c19; --card2: #1c221e; --ink: #edf1ec; --muted: #93a099; --line: #262d28;
    --accent: #4fd08e; --accent2: #7be3ae; --accent-ink: #05190f; --accent-soft: #1a2d22; --warn: #ee9462; --warn-soft: #36251b;
    --p: #6aa6d8; --c: #e6b75e; --f: #e5948a;
    --shadow: 0 1px 2px rgba(0,0,0,.45), 0 8px 24px rgba(0,0,0,.28);
    --shadow-lg: 0 -10px 40px rgba(0,0,0,.55);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
html, body { margin: 0; color: var(--ink); }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-top: env(safe-area-inset-top);
  overscroll-behavior-y: none;
}
/* page glow: a fixed layer instead of background-attachment:fixed, which repaints the whole screen on phones */
body::before { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none; background: radial-gradient(900px 380px at 50% -120px, var(--glow), transparent 70%); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 10px; }
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* press feel on everything tappable */
.iconbtn, .addbtn, .entry, .tile, .chip, .btn, .res, .tab, .fab, .x, .daylist .d, .torch {
  transition: transform .18s var(--ease), background-color .18s, box-shadow .25s, filter .18s, border-color .18s, color .18s;
}
.iconbtn:active, .addbtn:active, .chip:active, .x:active, .torch:active { transform: scale(.92); }
.entry:active, .res:active, .tile:active, .daylist .d:active { transform: scale(.985); }
.btn:active { transform: scale(.975); }

#app { max-width: 560px; margin: 0 auto; padding: 8px 16px calc(var(--nav-h) + 40px + env(safe-area-inset-bottom)); }
#app.enter > * { animation: up .22s var(--ease) both; animation-delay: calc(min(var(--i, 0), 3) * 20ms); }
@keyframes up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; padding: 8px 0 12px; }
.top h1 { font-size: 24px; margin: 0; font-weight: 750; letter-spacing: -.02em; }
.topr { display: flex; align-items: center; gap: 6px; }
.streak { white-space: nowrap; flex: none; font-size: 13px; font-weight: 700; padding: 5px 10px; border-radius: 99px; background: var(--warn-soft); color: var(--warn); display: inline-flex; gap: 4px; align-items: center; animation: pop .5s var(--spring) both; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
.iconbtn { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; color: var(--ink); }
.iconbtn:active { background: var(--line); }
.datebar { display: flex; align-items: center; gap: 2px; }
.datebar .label { min-width: 112px; text-align: center; font-weight: 750; font-size: 19px; letter-spacing: -.015em; }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 18px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 12px; font-weight: 700; }

/* summary */
.summary { display: grid; grid-template-columns: 136px 1fr; gap: 18px; align-items: center; background: linear-gradient(160deg, var(--card) 40%, var(--card2)); }
.ringwrap { position: relative; width: 136px; height: 136px; }
.ring { width: 136px; height: 136px; display: block; filter: drop-shadow(0 4px 10px color-mix(in srgb, var(--accent) 22%, transparent)); }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 11; }
.ring-fg { fill: none; stroke: url(#rg); stroke-width: 11; stroke-linecap: round; transition: stroke-dashoffset 1s var(--ease); }
.ring-fg.over { stroke: var(--warn); }
.ringtxt { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ringtxt b { font-size: 30px; line-height: 1; font-weight: 780; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.ringtxt span { font-size: 12px; color: var(--muted); margin-top: 5px; font-weight: 560; }
.ringtxt.over b { color: var(--warn); }
.macros { display: grid; gap: 12px; }
.macro .row { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 5px; font-weight: 560; }
.macro .row b { color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 99px; transition: width .9s var(--ease); background-image: linear-gradient(90deg, rgba(255,255,255,.0), rgba(255,255,255,.28)); }
.eaten { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 14px; justify-content: space-between; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 12px; font-weight: 560; }
.eaten b { color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; }

/* meals */
.card.meal { padding: 12px 18px 8px; }
.mealhead { display: flex; align-items: center; justify-content: space-between; padding: 4px 0 8px; }
.mealhead h3 { margin: 0; font-size: 17px; font-weight: 720; letter-spacing: -.01em; display: flex; align-items: baseline; }
.mealhead small { color: var(--muted); font-size: 13px; margin-left: 8px; font-weight: 560; font-variant-numeric: tabular-nums; }
.addbtn { color: var(--accent); font-weight: 700; font-size: 14px; padding: 7px 12px; border-radius: 12px; display: flex; align-items: center; gap: 4px; background: var(--accent-soft); }
.addbtn:active { background: color-mix(in srgb, var(--accent) 22%, var(--accent-soft)); }
.addbtn .ic { width: 16px; height: 16px; stroke-width: 2.6; }
.entry { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 11px 0; border-top: 1px solid var(--line); border-radius: 0; }
.entry:first-of-type { border-top: 0; }
.entry.fresh { animation: fresh 1.6s var(--ease); }
@keyframes fresh { 0% { background: var(--accent-soft); transform: translateX(10px); opacity: .2; } 25% { transform: none; opacity: 1; } 100% { background: transparent; } }
.thumb { width: 46px; height: 46px; border-radius: 14px; background: var(--accent-soft); object-fit: cover; flex: none; display: grid; place-items: center; color: var(--accent); font-weight: 700; }
.thumb.emoji { font-size: 24px; line-height: 1; }
.entry .meta { flex: 1; min-width: 0; }
.entry .nm { font-weight: 620; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .kc { font-weight: 720; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); font-size: 14px; padding: 4px 0 14px; }

/* bottom nav */
#nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 96%, transparent); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: 1fr 1fr 88px 1fr 1fr; align-items: center; max-width: 560px; margin: 0 auto; border-radius: 22px 22px 0 0; }
.tab { display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--muted); font-size: 12px; font-weight: 640; height: var(--nav-h); justify-content: center; position: relative; }
.tab .ic { transition: transform .35s var(--spring); }
.tab.on { color: var(--accent); }
.tab.on .ic { transform: translateY(-2px) scale(1.12); }
.tab::after { content: ""; position: absolute; bottom: 7px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); transform: scale(0); transition: transform .35s var(--spring); }
.tab.on::after { transform: scale(1); }
.fab { width: 60px; height: 60px; border-radius: 50%; background: linear-gradient(145deg, var(--accent2), var(--accent)); color: var(--accent-ink); display: grid; place-items: center; margin: -26px auto 0;
  box-shadow: 0 10px 24px color-mix(in srgb, var(--accent) 45%, transparent), inset 0 1px 0 rgba(255,255,255,.35); }
.fab .ic { width: 28px; height: 28px; stroke-width: 2.6; transition: transform .35s var(--spring); }
.fab:hover .ic { transform: rotate(90deg); }
.fab:active { transform: scale(.9); }
.fab:active .ic { transform: rotate(90deg) scale(.9); }

/* sheets */
.backdrop { position: fixed; inset: 0; background: rgba(8, 14, 10, .5); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); z-index: 40; animation: fade .25s ease; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-width: 560px; margin: 0 auto; background: var(--bg); border-radius: 28px 28px 0 0; box-shadow: var(--shadow-lg);
  max-height: 94vh; max-height: 94dvh; display: flex; flex-direction: column; animation: rise .42s var(--spring); padding-bottom: env(safe-area-inset-bottom); }
.sheet::before { content: ""; width: 40px; height: 5px; border-radius: 99px; background: var(--line); margin: 8px auto 0; flex: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px 6px 22px; }
.sheet-head h2 { margin: 0; font-size: 20px; font-weight: 750; letter-spacing: -.015em; }
.sheet-body { overflow-y: auto; padding: 4px 16px 22px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
#sheet-root.closing .sheet { animation: sink .22s ease-in forwards; }
#sheet-root.closing .backdrop { animation: fadeout .22s ease forwards; }
@keyframes rise { from { transform: translateY(70px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes sink { to { transform: translateY(60px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeout { to { opacity: 0; } }
.sheet-body > * { animation: up .45s var(--ease) both; }
.sheet-body > *:nth-child(2) { animation-delay: 40ms; } .sheet-body > *:nth-child(3) { animation-delay: 80ms; } .sheet-body > *:nth-child(4) { animation-delay: 120ms; } .sheet-body > *:nth-child(n+5) { animation-delay: 150ms; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 16px 14px; text-align: left; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); }
.tile .ic { width: 42px; height: 42px; padding: 10px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); stroke-width: 2.1; }
.tile b { font-weight: 720; letter-spacing: -.01em; }
.tile span { font-size: 12.5px; color: var(--muted); margin-top: -8px; }
.tile:active { background: var(--accent-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 9px 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); font-size: 14px; font-weight: 560; }
.chip.on { background: linear-gradient(145deg, var(--accent2), var(--accent)); border-color: transparent; color: var(--accent-ink); box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 30%, transparent); }
.chip:active { background: var(--accent-soft); }
.chip.on:active { background: var(--accent); }
.sec { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; margin: 18px 2px 9px; }

/* forms */
label.f { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.in, select.in, textarea.in { width: 100%; padding: 13px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); outline: none; font-size: 16px; transition: border-color .2s, box-shadow .25s; }
.in:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.field { margin-bottom: 12px; }
.btn { width: 100%; padding: 15px; border-radius: 16px; background: linear-gradient(145deg, var(--accent2), var(--accent)); color: var(--accent-ink); font-weight: 720; font-size: 16px; letter-spacing: -.005em; display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 8px 18px color-mix(in srgb, var(--accent) 28%, transparent), inset 0 1px 0 rgba(255,255,255,.3); }
.btn:active { filter: brightness(.94); box-shadow: 0 3px 8px color-mix(in srgb, var(--accent) 25%, transparent); }
.btn[disabled] { opacity: .5; box-shadow: none; }
.btn.ghost { background: var(--card); color: var(--ink); border: 1px solid var(--line); box-shadow: none; }
.btn.danger { background: var(--warn-soft); color: var(--warn); box-shadow: none; }
.btn.small { width: auto; padding: 10px 15px; font-size: 14px; border-radius: 13px; }
.note { font-size: 13px; color: var(--muted); }
.callout { background: var(--accent-soft); border-radius: 16px; padding: 13px 15px; font-size: 14px; margin-bottom: 12px; }
.callout.warn { background: var(--warn-soft); color: var(--ink); }
.callout ol { margin: 6px 0 0; padding-left: 20px; }
.callout li { margin: 3px 0; }
.callout a { color: var(--accent); font-weight: 650; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 3px solid color-mix(in srgb, currentColor 25%, transparent); border-top-color: currentColor; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.thinking { display: flex; gap: 12px; align-items: center; justify-content: center; padding: 16px; color: var(--muted); text-align: center; font-weight: 560; }

/* photo */
.preview { width: 100%; max-height: 260px; object-fit: cover; border-radius: 20px; display: block; margin-bottom: 12px; background: var(--line); box-shadow: var(--shadow); }
.item { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow); animation: up .4s var(--ease) both; }
.item .top2 { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.item .top2 .in { font-weight: 650; }
.x { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; color: var(--muted); flex: none; }
.x:active { background: var(--line); }
.conf { font-size: 11.5px; padding: 3px 9px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 700; margin-left: 6px; }
.conf.low { background: var(--warn-soft); color: var(--warn); }
.item .portion { font-size: 13px; color: var(--muted); margin: 0 2px 8px; }
.mini { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.mini label { font-size: 11.5px; color: var(--muted); display: block; margin-bottom: 3px; font-weight: 600; }
.mini .in { padding: 9px 6px; font-size: 16px; text-align: center; font-weight: 650; }
.scales { display: flex; flex-wrap: wrap; gap: 6px 5px; margin-top: 10px; align-items: center; }
.scales small { color: var(--muted); font-size: 12px; margin-right: 1px; font-weight: 600; }
.scales .chip { padding: 6px 9px; font-size: 12.5px; white-space: nowrap; }
.totalbar { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 4px 12px; }
.totalbar b { font-size: 26px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }

/* search results */
.res { display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; margin-bottom: 8px; box-shadow: 0 1px 2px rgba(20,40,28,.03); }
.res .em { font-size: 22px; flex: none; width: 34px; text-align: center; }
.res .rm { flex: 1; min-width: 0; }
.res .nm { font-weight: 620; overflow-wrap: anywhere; }
.res .sub { font-size: 12.5px; color: var(--muted); }
.res .kc { font-weight: 720; white-space: nowrap; font-variant-numeric: tabular-nums; text-align: right; }
.res .kc small { display: block; color: var(--muted); font-weight: 560; font-size: 11.5px; }
.res:active { background: var(--accent-soft); }

/* barcode scanner */
.scanbox { position: relative; border-radius: 22px; overflow: hidden; background: #000; aspect-ratio: 4 / 3; margin-bottom: 12px; box-shadow: var(--shadow); }
.scanbox video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanbox .guide { position: absolute; left: 10%; right: 10%; top: 28%; bottom: 28%; border-radius: 16px; box-shadow: 0 0 0 999px rgba(0,0,0,.42); transition: box-shadow .3s; }
.scanbox .guide i { position: absolute; width: 26px; height: 26px; border: 3.5px solid #fff; transition: border-color .2s; }
.scanbox .guide i:nth-child(1) { left: -2px; top: -2px; border-right: 0; border-bottom: 0; border-top-left-radius: 14px; }
.scanbox .guide i:nth-child(2) { right: -2px; top: -2px; border-left: 0; border-bottom: 0; border-top-right-radius: 14px; }
.scanbox .guide i:nth-child(3) { left: -2px; bottom: -2px; border-right: 0; border-top: 0; border-bottom-left-radius: 14px; }
.scanbox .guide i:nth-child(4) { right: -2px; bottom: -2px; border-left: 0; border-top: 0; border-bottom-right-radius: 14px; }
.scanbox .guide u { position: absolute; left: 6px; right: 6px; height: 2px; top: 0; border-radius: 2px; background: linear-gradient(90deg, transparent, var(--accent2), transparent); box-shadow: 0 0 14px var(--accent2); animation: sweep 2s ease-in-out infinite; text-decoration: none; }
@keyframes sweep { 0%, 100% { top: 6px; opacity: .2; } 50% { top: calc(100% - 8px); opacity: 1; } }
.scanbox.hit .guide i { border-color: var(--accent2); }
.scanbox.hit::after { content: ""; position: absolute; inset: 0; background: var(--accent2); opacity: 0; animation: flash .5s ease; pointer-events: none; }
@keyframes flash { 0% { opacity: .5; } 100% { opacity: 0; } }
.scanbox .msg { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: #fff; padding: 20px; font-size: 14px; background: rgba(0,0,0,.55); }
.torch { position: absolute; right: 12px; top: 12px; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: #fff; background: rgba(0,0,0,.45); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); z-index: 2; }
.torch.on { background: #ffd24a; color: #3b2c00; }
.scanbox .hint { position: absolute; left: 0; right: 0; bottom: 10px; text-align: center; font-size: 12.5px; color: rgba(255,255,255,.85); font-weight: 560; pointer-events: none; }

/* dialog */
.dlg { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 24px; }
.dlg .backdrop { z-index: 0; }
.dlg .box { position: relative; z-index: 1; background: var(--card); border-radius: 26px; padding: 22px 20px 18px; max-width: 340px; width: 100%; box-shadow: 0 30px 80px rgba(0,0,0,.4); animation: pop .4s var(--spring) both; text-align: center; }
.dlg h3 { margin: 0 0 6px; font-size: 19px; letter-spacing: -.01em; }
.dlg p { margin: 0 0 18px; color: var(--muted); font-size: 14.5px; }

/* history */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11.5px; font-weight: 600; }
.chart text.tod { fill: var(--ink); font-weight: 800; }
.chart .gl { stroke: var(--ink); stroke-width: 1.4; stroke-dasharray: 4 4; opacity: .55; pointer-events: none; }
.chart rect.b { fill: var(--accent); transform-origin: bottom; transform-box: fill-box; animation: grow .7s var(--ease) both; }
.chart rect.b.over { fill: var(--warn); }
.chart rect.b.none { fill: var(--line); }
.chart g { cursor: pointer; }
@keyframes grow { from { transform: scaleY(0); } to { transform: none; } }
.daylist .d { display: flex; justify-content: space-between; align-items: center; width: 100%; padding: 13px 0; border-top: 1px solid var(--line); text-align: left; border-radius: 0; }
.daylist .d:first-child { border-top: 0; }
.daylist .d b { font-variant-numeric: tabular-nums; }
.stat { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat span { font-size: 12px; color: var(--muted); font-weight: 560; }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); transform: translate(-50%, 24px) scale(.94); background: var(--ink); color: var(--bg);
  padding: 11px 18px; border-radius: 99px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .25s, transform .45s var(--spring); z-index: 90; max-width: 86vw; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.3); }
#toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
details.card summary { cursor: pointer; font-weight: 700; list-style: none; display: flex; justify-content: space-between; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary::after { content: "+"; color: var(--muted); transition: transform .3s var(--spring); }
details.card[open] summary::after { content: "–"; }
details.card[open] summary { margin-bottom: 12px; }
hr.s { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
@media (max-width: 360px) { .summary { grid-template-columns: 1fr; justify-items: center; } .macros { width: 100%; } }

/* extra nutrients (label / AI) */
.xline { margin-top: 8px; font-size: 12.5px; line-height: 1.5; color: var(--muted); }
.xcard h2 { margin-bottom: 10px; }
.xgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 14px 10px; }
.xgrid > div { display: flex; flex-direction: column; gap: 2px; }
.xgrid b { font-size: 18px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.xgrid b small { font-size: 12px; font-weight: 560; color: var(--muted); }
.xgrid span { font-size: 12.5px; color: var(--muted); font-weight: 560; }

@media (max-width: 360px) { .wem { display: none; } .datebar .label { min-width: 80px; font-size: 17px; } .top h1 { font-size: 22px; } .card { padding: 15px; } .summary { gap: 14px; } }
/* chart legend, macro averages */
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--muted); font-weight: 600; margin: -2px 0 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .dash { width: 18px; border-top: 2px dashed var(--ink); opacity: .6; }
.legend .sq { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); }
.legend .sq.over { background: var(--warn); }
.mavg { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 16px; margin-top: 14px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.mavg span { display: inline-flex; align-items: center; gap: 6px; }
.mavg i { width: 8px; height: 8px; border-radius: 50%; }
.mavg b { color: var(--ink); }
.wline { fill: none; stroke: var(--accent); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.wdot { fill: var(--card); stroke: var(--accent); stroke-width: 2.2; }
.wchart { margin-bottom: 10px; }
.wcard .daylist .d { padding: 11px 0; }

/* water card, copy button, toast undo */
.water { padding: 14px 18px 16px; }
.wrow { flex-wrap: wrap; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.wl { display: flex; align-items: center; gap: 12px; min-width: 0; }
.wem { font-size: 26px; width: 46px; height: 46px; border-radius: 14px; background: color-mix(in srgb, var(--p) 16%, var(--card)); display: grid; place-items: center; flex: none; }
.water h2 { margin: 0 0 2px; }
.wv { white-space: nowrap; font-size: 14px; color: var(--muted); font-weight: 560; font-variant-numeric: tabular-nums; }
.wv b { color: var(--ink); font-size: 17px; font-weight: 740; }
.wbtns { display: flex; gap: 8px; flex: none; }
.roundbtn { min-width: 44px; height: 44px; padding: 0 12px; border-radius: 14px; background: var(--card2); border: 1px solid var(--line); font-size: 22px; font-weight: 600; line-height: 1; display: inline-flex; align-items: center; justify-content: center; gap: 5px; transition: transform .18s var(--ease), background-color .18s, opacity .2s; }
.roundbtn small { font-size: 12px; font-weight: 700; }
.roundbtn.plus { background: color-mix(in srgb, var(--p) 18%, var(--card)); border-color: transparent; color: var(--p); }
.roundbtn:active { transform: scale(.92); }
.roundbtn[disabled] { opacity: .35; pointer-events: none; }
.linkbtn { color: var(--accent); font-weight: 700; font-size: 14px; padding: 6px 0 12px; display: block; text-align: left; }
.linkbtn:active { opacity: .6; }
.chip.fav { background: color-mix(in srgb, var(--c) 14%, var(--card)); border-color: color-mix(in srgb, var(--c) 35%, var(--line)); }
#toast.has-undo { pointer-events: auto; padding-right: 8px; }
#toast button { margin-left: 8px; padding: 6px 14px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); font-weight: 750; font-size: 13.5px; }
#toast button:active { transform: scale(.94); }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.torch[hidden] { display: none; }

.torch.zoom { right: auto; left: 12px; font-weight: 800; font-size: 14px; letter-spacing: -.02em; }
.torch.zoom.on { background: var(--accent2); color: #06200f; }

.welcome { background: linear-gradient(160deg, var(--accent-soft), var(--card)); }
.welcome h2 { margin-bottom: 8px; }
.welcome p { font-size: 14.5px; color: var(--ink); }
.welcome .note { color: var(--muted); }

/* ============ gym log ============ */
#nav { grid-template-columns: 1fr 1fr 88px 1fr 1fr; }
.gstart { margin-bottom: 14px; }
.gstart .ic { width: 20px; height: 20px; stroke-width: 2.6; }
.gactive { background: linear-gradient(160deg, var(--accent-soft), var(--card)); }
.gactive h2 { color: var(--accent); }
.gabig { font-size: 22px; font-weight: 760; letter-spacing: -.02em; }
.wdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.wd { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 650; }
.wd i { width: 30px; height: 30px; border-radius: 50%; background: var(--line); display: block; transition: background .3s, transform .4s var(--spring); }
.wd.on i { background: linear-gradient(145deg, var(--accent2), var(--accent)); transform: scale(1.05); box-shadow: 0 4px 10px color-mix(in srgb, var(--accent) 35%, transparent); }
.wd.today span { color: var(--ink); }
.wd.today:not(.on) i { box-shadow: inset 0 0 0 2px var(--accent); background: transparent; }
.mrow { display: grid; grid-template-columns: 84px 1fr 26px; gap: 10px; align-items: center; font-size: 13px; margin-bottom: 7px; color: var(--muted); font-weight: 600; }
.mrow b { color: var(--ink); text-align: right; font-variant-numeric: tabular-nums; }
.tpl { display: flex; align-items: center; gap: 4px; border-top: 1px solid var(--line); }
.tpl:first-of-type { border-top: 0; }
.tplmain { flex: 1; min-width: 0; text-align: left; padding: 12px 0; display: flex; align-items: center; gap: 10px; }
.tplt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.gostart { flex: none; font-size: 12.5px; font-weight: 750; color: var(--accent); background: var(--accent-soft); border-radius: 99px; padding: 6px 13px; }
.tplmain b { font-weight: 700; }
.tplmain small { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wcardrow { align-items: center !important; gap: 10px; }
.wcardrow .wlt { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0; flex: 1; text-align: left; }
.wcardrow small { color: var(--muted); font-size: 12.5px; font-weight: 560; }
.wcardrow .wn { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { color: var(--muted); font-size: 22px; flex: none; }

/* live workout screen */
.gym { position: fixed; left: 0; right: 0; top: 0; bottom: 0; z-index: 35; max-width: 560px; margin: 0 auto; background: var(--bg); display: flex; flex-direction: column; animation: up .35s var(--ease) both; }
.gh { display: flex; align-items: center; gap: 6px; padding: calc(8px + env(safe-area-inset-top)) 10px 8px 6px; background: var(--card); border-bottom: 1px solid var(--line); flex: none; }
.gtitle { flex: 1; min-width: 0; }
.gname { width: 100%; font-size: 18px; font-weight: 760; letter-spacing: -.015em; background: none; border: 0; outline: none; padding: 2px 0; color: var(--ink); }
.gsub { font-size: 12.5px; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.gfin { flex: none; padding: 10px 18px; }
.gbody { flex: 1; overflow-y: auto; padding: 12px 12px 20px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.gnotein { margin-bottom: 12px; font-size: 16px; }
.gex { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 12px 10px 10px; margin-bottom: 12px; box-shadow: var(--shadow); position: relative; }
.gex.ss { border-left: 4px solid hsl(var(--ssh) 65% 55%); border-radius: 8px 20px 20px 8px; }
.gex.ss.first { margin-bottom: 0; border-bottom-left-radius: 0; border-bottom-right-radius: 0; margin-top: 18px; }
.gex.ss.mid { margin-bottom: 0; border-radius: 0 0 0 0; border-top: 0; }
.gex.ss.last { border-top: 0; border-top-left-radius: 0; border-top-right-radius: 0; margin-bottom: 12px; }
.sstag { position: absolute; top: -20px; left: -4px; font-size: 11.5px; font-weight: 750; letter-spacing: .06em; text-transform: uppercase; color: hsl(var(--ssh) 65% 45%); }
.gexh { display: flex; align-items: center; justify-content: space-between; gap: 4px; padding: 0 4px; }
.gexn { text-align: left; font-weight: 740; font-size: 17px; letter-spacing: -.01em; color: var(--accent); padding: 4px 0; flex: 1; min-width: 0; }
.gexm { font-size: 12.5px; color: var(--muted); font-weight: 560; padding: 0 4px 8px; }
.vs { font-weight: 700; margin-left: 4px; }
.vs.up { color: var(--accent); } .vs.down { color: var(--warn); }
.gnote { margin: 0 4px 8px; padding: 8px 11px; border-radius: 12px; background: var(--card2); border: 1px solid var(--line); font-size: 13.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.gnote.pinned { background: color-mix(in srgb, #f2c94c 18%, var(--card)); border-color: color-mix(in srgb, #f2c94c 45%, var(--line)); }
.shead, .srow { display: grid; grid-template-columns: 34px minmax(44px, 1fr) repeat(var(--n), minmax(54px, 76px)) 40px; gap: 6px; align-items: center; }
.shead { font-size: 10.5px; font-weight: 750; letter-spacing: .06em; color: var(--muted); text-align: center; padding: 0 2px 4px; }
.srow { position: relative; padding: 4px 2px; border-radius: 14px; transition: background .3s; }
.srow.done { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.sn { width: 32px; height: 32px; border-radius: 10px; background: var(--card2); border: 1px solid var(--line); font-weight: 750; font-size: 14px; font-variant-numeric: tabular-nums; }
.sn:active { transform: scale(.92); }
.t-W .sn { background: #f2c94c33; color: #b8860b; border-color: #f2c94c66; }
.t-D .sn { background: #5b8def33; color: #3f6fd6; border-color: #5b8def66; }
.t-F .sn { background: #e0585833; color: #d04545; border-color: #e0585866; }
.sprev { font-size: 12.5px; color: var(--muted); text-align: center; font-weight: 560; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.sin { padding: 9px 2px; text-align: center; font-weight: 700; font-size: 16px; border-radius: 12px; min-width: 0; }
.sin::placeholder { color: var(--muted); opacity: .55; font-weight: 600; }
.sck { width: 38px; height: 38px; border-radius: 12px; background: var(--card2); border: 1px solid var(--line); color: var(--muted); display: grid; place-items: center; transition: transform .25s var(--spring), background .2s, color .2s; }
.sck .ic { width: 20px; height: 20px; stroke-width: 3; }
.sck.on { background: linear-gradient(145deg, var(--accent2), var(--accent)); color: var(--accent-ink); border-color: transparent; transform: scale(1.04); box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 35%, transparent); }
.sck:active { transform: scale(.9); }
.rpe, .prb { grid-column: 1 / -1; justify-self: start; font-size: 11.5px; font-weight: 750; border-radius: 99px; padding: 2px 9px; margin-left: 40px; }
.rpe { background: var(--card2); color: var(--muted); border: 1px solid var(--line); }
.prb { background: color-mix(in srgb, #f2c94c 25%, var(--card)); color: #9a6b00; }
.hsr .prb { margin-left: 0; }
.addset { width: 100%; margin-top: 6px; padding: 10px; border-radius: 12px; background: var(--card2); color: var(--accent); font-weight: 700; font-size: 14px; }
.addset:active { background: var(--accent-soft); }
.grest { display: none; flex: none; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.grest.on { display: block; animation: up .3s var(--ease) both; }
.rprog { height: 4px; background: var(--line); }
.rprog i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent2), var(--accent)); transition: width .5s linear; }
.rrow { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 10px 12px; }
.rt { text-align: center; min-width: 96px; }
.rt small { display: block; font-size: 11px; color: var(--muted); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.rt b { font-size: 30px; font-weight: 780; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.rb { padding: 11px 16px; border-radius: 14px; background: var(--card2); border: 1px solid var(--line); font-weight: 700; font-size: 15px; transition: transform .18s var(--ease); }
.rb:active { transform: scale(.92); }
.rb.skip { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.gbanner { position: fixed; left: 12px; right: 12px; max-width: 536px; margin: 0 auto; bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom)); z-index: 19; display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 18px; background: linear-gradient(145deg, var(--accent2), var(--accent)); color: var(--accent-ink); text-align: left; box-shadow: 0 10px 28px color-mix(in srgb, var(--accent) 40%, transparent); animation: up .4s var(--ease) both; }
.gbd { width: 10px; height: 10px; border-radius: 50%; background: var(--accent-ink); animation: pulse 1.6s ease-in-out infinite; flex: none; }
@keyframes pulse { 0%, 100% { opacity: .35; transform: scale(.8); } 50% { opacity: 1; transform: scale(1.1); } }
.gbt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.gbt b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gbt small { opacity: .8; font-weight: 600; font-variant-numeric: tabular-nums; }
.gbr { font-weight: 750; font-variant-numeric: tabular-nums; background: #0002; border-radius: 99px; padding: 3px 10px; }
.gbgo { font-weight: 750; flex: none; }

/* sheets inside the gym log */
.menurow { display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left; padding: 14px 16px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; margin-bottom: 8px; }
.menurow small { color: var(--muted); font-size: 12.5px; }
.menurow.danger { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.menurow:active { background: var(--accent-soft); }
.chk { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; color: var(--ink); line-height: 1.35; }
.chk input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; margin-top: 1px; }
.plout { margin: 14px 0; text-align: center; }
.bar-svg { width: 100%; max-width: 330px; height: auto; }
.plsum b { display: block; font-size: 24px; letter-spacing: -.01em; }
.plsum small { color: var(--muted); font-size: 13px; }
.hscroll { flex-wrap: nowrap !important; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.hscroll::-webkit-scrollbar { display: none; }
.hscroll .chip { flex: none; }
.res.pk .pkn { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-weight: 750; font-size: 13px; flex: none; color: var(--accent-ink); }
.res.pk.sel { border-color: var(--accent); background: var(--accent-soft); }
.res.pk.sel .pkn { background: var(--accent); border-color: var(--accent); }
.gpbar { position: sticky; bottom: -22px; padding: 10px 0 4px; display: grid; gap: 8px; background: linear-gradient(transparent, var(--bg) 24%); }
.gpbar:empty { display: none; }
.hsr { display: flex; align-items: center; gap: 10px; padding: 3px 0; font-size: 14.5px; font-variant-numeric: tabular-nums; }
.hn { width: 24px; height: 24px; border-radius: 8px; background: var(--card2); border: 1px solid var(--line); display: grid; place-items: center; font-size: 12px; font-weight: 750; color: var(--muted); flex: none; }
.rtable { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; margin-bottom: 10px; }
.rtable th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 6px 4px; }
.rtable td { padding: 7px 4px; border-top: 1px solid var(--line); }
.rtable td.pr2 { color: var(--accent); font-weight: 700; }
.prline { text-align: center; margin-top: 10px; font-weight: 750; color: #9a6b00; }
textarea.in { resize: vertical; min-height: 90px; }
@media (max-width: 360px) { .shead, .srow { grid-template-columns: 30px minmax(36px, 1fr) repeat(var(--n), minmax(48px, 70px)) 36px; gap: 4px; } .sck { width: 34px; height: 34px; } .sn { width: 30px; } .tab span { font-size: 11px; } }

body.hasbanner #app { padding-bottom: calc(var(--nav-h) + 100px + env(safe-area-inset-bottom)); }

/* backup / install nudges */
.nudge { background: linear-gradient(160deg, var(--accent-soft), var(--card)); }
.nudge.warn { background: linear-gradient(160deg, var(--warn-soft), var(--card)); }
.nudge h2 { margin-bottom: 8px; }
.nudge p { margin: 0 0 12px; font-size: 14.5px; line-height: 1.4; }
.bkline { margin: 0 0 12px; font-size: 14px; color: var(--muted); }
.bkline b { color: var(--ink); }

[hidden] { display: none !important; }
