:root {
  --bg: #f6f3ee; --card: #ffffff; --ink: #2a2622; --muted: #756d65; --line: #e6e0d8;
  --accent: #3f8f6b; --accent-ink: #ffffff;
  --small: #f0b64a; --large: #e8795a; --healthy: #5fb283; --on-btn: #2a1d0c;
  --over: #8a79d6; --track: #ebe5dc;
  --shadow: 0 1px 2px rgba(60, 40, 20, .08), 0 4px 14px rgba(60, 40, 20, .06);
  --radius: 18px;
  --nav-h: 58px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14110f; --card: #211d1a; --ink: #f1ebe3; --muted: #a39a90; --line: #35302b;
    --accent: #5cb88f; --accent-ink: #0d1f17;
    --small: #d9a23a; --large: #d9694a; --healthy: #4ea173; --on-btn: #1b1208;
    --over: #a597ee; --track: #302b27;
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; -webkit-text-size-adjust: 100%; }
body { overscroll-behavior: none; }
#app { height: 100%; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }
.screen { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px 18px; display: flex; flex-direction: column; gap: 12px; -webkit-overflow-scrolling: touch; }
h1 { font-size: 22px; margin: 4px 0 0; }
h2 { font-size: 15px; margin: 0 0 8px; letter-spacing: .01em; }
p { margin: 0 0 8px; } .muted { color: var(--muted); } .small { font-size: 13px; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); border: 1px solid var(--line); }
button { font: inherit; color: inherit; cursor: pointer; }

/* Nav */
nav { display: flex; background: var(--card); border-top: 1px solid var(--line); height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); }
nav button { flex: 1; background: none; border: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 11px; }
nav button[aria-current="page"] { color: var(--accent); font-weight: 600; }
nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Log */
.status { display: flex; flex-direction: column; gap: 6px; }
.status .row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.status .big { font-size: 26px; font-weight: 700; }
.bar { height: 12px; border-radius: 99px; background: var(--track); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.bar.over > i { background: var(--over); }
.snack-buttons { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.snack-row { flex: 1; min-height: 84px; display: flex; gap: 8px; }
.snack { flex: 1; min-height: 84px; border: 0; border-radius: 22px; color: var(--on-btn); display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px; text-align: left; box-shadow: var(--shadow); transition: transform .08s; touch-action: manipulation; }
.minus { width: 56px; border-radius: 22px; border: 1px solid var(--line); background: var(--card); font-size: 28px; color: var(--muted); touch-action: manipulation; }
.minus:disabled { opacity: .35; }
.snack:active { transform: scale(.98); }
.snack .name { font-size: 28px; font-weight: 700; display: block; }
.snack .eg { font-size: 14px; opacity: .8; }
.snack .pts { font-size: 22px; font-weight: 700; background: rgba(255,255,255,.4); border-radius: 99px; padding: 6px 14px; }
.snack.small { background: var(--small); } .snack.large { background: var(--large); } .snack.healthy { background: var(--healthy); }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; text-align: center; }
.stats div { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 8px 4px; }
.stats b { display: block; font-size: 20px; } .stats span { font-size: 12px; color: var(--muted); }

/* Buttons and links */
.btn { display: block; width: 100%; padding: 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); font-weight: 600; text-align: center; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.red { color: #c0392b; }
.link { background: none; border: 0; color: var(--accent); padding: 10px; font-size: 15px; text-align: center; }
.link.red { color: #c0392b; }
.stack { display: flex; flex-direction: column; gap: 8px; }

/* Toast */
#toast { position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 10px); z-index: 20; pointer-events: none; }
.toast { pointer-events: auto; background: var(--ink); color: var(--bg); border-radius: 16px; padding: 10px 12px; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.toast .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.toast .top button { background: none; border: 0; color: var(--bg); font-weight: 700; text-decoration: underline; padding: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.toast .chips { flex-wrap: nowrap; gap: 5px; }
.chip { border: 1px solid currentColor; background: none; border-radius: 99px; padding: 6px 12px; font-size: 14px; opacity: .85; }
.toast .chip { padding: 6px 9px; font-size: 13px; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; opacity: 1; font-weight: 600; }
.sheet .chip { color: var(--ink); } .sheet .chip[aria-pressed="true"] { color: var(--accent-ink); }

/* History */
.day { font-size: 13px; color: var(--muted); font-weight: 600; margin: 8px 0 4px; display: flex; justify-content: space-between; }
.entry { width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 6px; text-align: left; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.dot.small { background: var(--small); } .dot.large { background: var(--large); } .dot.healthy { background: var(--healthy); }
.entry .grow { flex: 1; min-width: 0; } .entry .t { font-weight: 600; }
.tag { font-size: 12px; background: var(--track); border-radius: 99px; padding: 2px 8px; color: var(--muted); }

/* Sheet */
#sheet:empty { display: none; }
#sheet { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; }
.sheet { background: var(--bg); width: 100%; max-height: 92%; overflow-y: auto; border-radius: 22px 22px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg button { border: 2px solid transparent; border-radius: 14px; padding: 12px 4px; font-weight: 600; color: var(--on-btn); }
.seg button.small { background: var(--small); } .seg button.large { background: var(--large); } .seg button.healthy { background: var(--healthy); }
.seg button:not([aria-pressed="true"]) { opacity: .45; } .seg button[aria-pressed="true"] { border-color: var(--ink); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
input { font: inherit; font-size: 16px; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); width: 100%; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

/* Charts */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 10px; font-family: inherit; }
.chart .bar-fill { fill: var(--accent); } .chart .bar-fill.peak { fill: var(--large); }
.chart .target { stroke: var(--over); stroke-width: 1.5; stroke-dasharray: 4 3; }
.chart .line { fill: none; stroke: var(--large); stroke-width: 2; } .chart .pt { fill: var(--large); }
.chart .axis { stroke: var(--line); }
.hbar { display: grid; grid-template-columns: 70px 1fr 56px; gap: 8px; align-items: center; font-size: 14px; margin: 4px 0; }
.hbar .b { height: 10px; background: var(--track); border-radius: 99px; overflow: hidden; } .hbar .b i { display: block; height: 100%; background: var(--accent); }
.hbar span:last-child { text-align: right; color: var(--muted); }
.banner { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 14px; padding: 12px; font-weight: 600; width: 100%; }
.settings-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 0; }
.settings-row input { width: 90px; text-align: right; }
.toggle { width: 22px; height: 22px; accent-color: var(--accent); }

.footer { text-align: center; font-size: 11px; line-height: 1.3; color: var(--muted); padding: 4px 0 2px; flex: none; }
