:root {
  --ink: #14201a; --muted: #5f6f66; --paper: #edf1ec; --card: #fff; --line: #e3e9e3;
  --green: #16a34a; --amber: #d99a00; --red: #ef4444;
  --kcal: #ff7a2f; --prot: #16a34a; --carb: #3b82f6; --fat: #ec4899; --fibre: #d99a00; --weight: #8b5cf6;
  --bar-h: 72px;
  --sel: #14201a; --on-sel: #fff; --send: #14201a;
  --ok-bg: #dcfce7; --ok-fg: #166534; --warn-bg: #fef3c7; --warn-fg: #92400e; --bad-bg: #fee2e2; --bad-fg: #991b1b;
  --info-bg: #e8f1ff; --info-fg: #1e3a8a; --banner-bg: #fff7e6; --banner-fg: #92400e;
  --green-t: #15803d; --red-t: #b91c1c; --amber-t: #b45309; --future: #b4bac4; --faint: #8b95a5; --sel-track: rgba(255,255,255,.35);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --ink: #eef3ef; --muted: #9aa8a0; --paper: #0f1512; --card: #18201b; --line: #26302a;
  --sel: #eef3ef; --on-sel: #14201a; --send: #34423a;
  --ok-bg: #14532d; --ok-fg: #bbf7d0; --warn-bg: #713f12; --warn-fg: #fde68a; --bad-bg: #7f1d1d; --bad-fg: #fecaca;
  --info-bg: #17284a; --info-fg: #bfd6ff; --banner-bg: #3a2a0c; --banner-fg: #fde68a;
  --green-t: #4ade80; --red-t: #f87171; --amber-t: #fbbf24; --future: #5a6372; --faint: #7c8696; --sel-track: rgba(0,0,0,.25);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --ink: #eef3ef; --muted: #9aa8a0; --paper: #0f1512; --card: #18201b; --line: #26302a;
    --sel: #eef3ef; --on-sel: #14201a; --send: #34423a;
    --ok-bg: #14532d; --ok-fg: #bbf7d0; --warn-bg: #713f12; --warn-fg: #fde68a; --bad-bg: #7f1d1d; --bad-fg: #fecaca;
    --info-bg: #17284a; --info-fg: #bfd6ff; --banner-bg: #3a2a0c; --banner-fg: #fde68a;
    --green-t: #4ade80; --red-t: #f87171; --amber-t: #fbbf24; --future: #5a6372; --faint: #7c8696; --sel-track: rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--paper); color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
body { padding-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom) + 24px); }
#app { max-width: 560px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 10px) 16px 16px; }
#top { display: flex; align-items: center; justify-content: space-between; padding: 6px 4px 2px; }
#top h1 { margin: 0; font-size: 26px; font-weight: 700; }
button { font: inherit; color: inherit; cursor: pointer; }
#gear { background: none; border: 0; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 22px; color: var(--ink); }

h3.sec { margin: 20px 6px 0; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.card { background: var(--card); border-radius: 20px; padding: 14px 16px; margin-top: 8px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .bold { font-weight: 700; }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 6px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 0; background: var(--paper); color: var(--ink); padding: 8px 14px; border-radius: 18px; font-size: 13px; }
.chip.on { background: var(--sel); color: var(--on-sel); }
.btn { width: 100%; margin-top: 8px; padding: 12px; border: 0; border-radius: 12px; background: var(--paper); font-size: 15px; }
.btn.primary { background: var(--sel); color: var(--on-sel); }
.field { display: block; margin-top: 10px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=search], input[type=number], input[type=password], textarea { width: 100%; font: inherit; padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); }

.banner { background: var(--banner-bg); color: var(--banner-fg); border-radius: 16px; padding: 12px 14px; margin-top: 10px; font-size: 13px; }
.banner.info { background: var(--info-bg); color: var(--info-fg); }

/* day summary */
.rings { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.rings.small3 { grid-template-columns: repeat(3, 1fr); margin-top: 6px; }
.ring { text-align: center; }
.ring svg { width: 100%; max-width: 150px; height: auto; display: block; margin: 0 auto; }
.rings.small3 .ring svg { max-width: 100px; }
.ring .lbl { font-weight: 700; font-size: 14px; margin-top: 2px; }
.ring .left { font-size: 12px; color: var(--muted); }
.ring .left.over { color: var(--red); }
.barline { margin: 8px 0 4px; }
.barline .top { display: flex; justify-content: space-between; font-size: 13px; }
.bar { height: 9px; border-radius: 5px; background: var(--line); margin-top: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 5px; }

/* calendar */
.calnav { display: flex; align-items: center; justify-content: space-between; }
.calnav button { background: none; border: 0; font-size: 26px; padding: 0 12px; }
.calnav b { font-size: 16px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); margin-top: 6px; }
.cal .wd { text-align: center; font-size: 11px; color: var(--muted); padding: 4px 0; }
.cal .day { position: relative; height: 52px; border: 0; background: none; border-radius: 12px; text-align: center; padding-top: 5px; }
.cal .day .n { font-size: 14px; }
.cal .day.today { box-shadow: inset 0 0 0 1.5px var(--ink); font-weight: 700; }
.cal .day.sel { background: var(--sel); color: var(--on-sel); }
.cal .day.future .n { color: var(--future); }
.cal .dot { width: 6px; height: 6px; border-radius: 3px; margin: 3px auto 0; }
.cal .pb { width: 50%; height: 3px; border-radius: 2px; background: var(--line); margin: 3px auto 0; overflow: hidden; }
.cal .day.sel .pb { background: var(--sel-track); }
.cal .pb > i { display: block; height: 100%; background: var(--faint); }
.cal .day.sel .pb > i { background: var(--on-sel); }
.cal .pb > i.hit { background: var(--green) !important; }

.entry { border-top: 1px solid var(--line); padding: 8px 0 2px; margin-top: 8px; }
.entry .meal { font-size: 11px; font-weight: 700; color: var(--muted); }

canvas.chart { width: 100%; height: 200px; display: block; margin-top: 10px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 10px; }
.stats b { display: block; font-size: 15px; } .stats span { font-size: 10.5px; color: var(--muted); }

.item { border-bottom: 1px solid var(--line); padding: 10px 0 6px; }
.badge { padding: 3px 10px; border-radius: 10px; font-weight: 700; font-size: 12.5px; }

.bubbles { display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 85%; padding: 8px 12px; border-radius: 16px; font-size: 14px; background: var(--paper); align-self: flex-start; white-space: pre-wrap; }
.bubble.me { background: var(--ok-bg); color: var(--ok-fg); align-self: flex-end; }
.bubble.err { background: var(--bad-bg); color: var(--bad-fg); }

/* bottom bar */
#voicebar { position: fixed; left: 0; right: 0; bottom: calc(var(--bar-h) + env(safe-area-inset-bottom)); background: var(--card); padding: 8px 20px; font-size: 13px; font-weight: 700; border-top: 1px solid var(--line); z-index: 5; }
#bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--card); padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); display: flex; gap: 8px; align-items: flex-end; border-top: 1px solid var(--line); }
#bar textarea { flex: 1; resize: none; border-radius: 22px; background: var(--paper); border: 0; max-height: 110px; padding: 11px 16px; font-size: 16px; }
.round { width: 46px; height: 46px; border-radius: 50%; border: 0; display: grid; place-items: center; flex: none; }
.round.green { background: var(--green); } .round.ink { background: var(--send); } .round.red { background: var(--red); } .round.amber { background: #f59e0b; }

/* settings panel */
#scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; }
#panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(92vw, 400px); background: var(--paper); z-index: 21; transform: translateX(100%); transition: transform .22s ease; display: flex; flex-direction: column; border-radius: 24px 0 0 24px; padding-top: env(safe-area-inset-top); }
#panel.open { transform: none; }
#panelhead { display: flex; align-items: center; gap: 4px; padding: 14px 8px 8px; }
#panelhead h2 { flex: 1; margin: 0; font-size: 20px; }
#panelhead button { background: none; border: 0; font-size: 22px; padding: 6px 14px; }
#panelback { font-size: 30px !important; padding-bottom: 2px !important; }
#panelbody { flex: 1; overflow-y: auto; padding: 0 14px calc(24px + env(safe-area-inset-bottom)); }
.menurow { display: flex; align-items: center; padding: 12px 0; border: 0; background: none; width: 100%; text-align: left; border-bottom: 1px solid var(--line); }
.menurow:last-child { border-bottom: 0; }
.menurow .t { font-size: 16px; } .menurow .s { font-size: 12px; color: var(--muted); } .menurow .c { font-size: 24px; color: var(--muted); }

/* profile picker */
.pick { display: block; width: 100%; text-align: left; font-size: 18px; font-weight: 700; padding: 16px 18px; border: 0; border-radius: 16px; background: var(--card); margin-top: 8px; }
#toast { position: fixed; left: 50%; bottom: calc(var(--bar-h) + env(safe-area-inset-bottom) + 30px); transform: translateX(-50%); background: var(--sel); color: var(--on-sel); padding: 10px 16px; border-radius: 20px; font-size: 14px; z-index: 40; max-width: 90vw; text-align: center; }
[hidden] { display: none !important; }

.entry.tap { cursor: pointer; border-radius: 10px; }
.entry.tap:active, .entry.tap:focus-visible { background: var(--paper); outline: none; }
:focus-visible { outline: 2px solid var(--carb); outline-offset: 2px; }

/* sheet: entry menu and edit form */
#sheet { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheetcard { background: var(--card); width: min(100%, 520px); border-radius: 24px 24px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 88vh; overflow-y: auto; }
.sheettitle { font-weight: 700; font-size: 16px; margin: 0 4px 8px; word-break: break-word; }
.menuitem { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 14px 6px; font-size: 16px; border-top: 1px solid var(--line); }
.menuitem.danger { color: var(--red-t); }

/* photo bubble, day explorer, analytics */
.round.soft { background: var(--paper); color: var(--ink); }
body.noscroll { overflow: hidden; }
#daypage { position: fixed; inset: 0; z-index: 30; background: var(--paper); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.dphead { position: sticky; top: 0; z-index: 2; background: var(--paper); display: flex; align-items: center; gap: 6px; padding: calc(env(safe-area-inset-top) + 8px) 12px 8px; border-bottom: 1px solid var(--line); }
.dphead .grow { min-width: 0; } .dphead b { font-size: 16px; }
.dpbtn { border: 0; background: var(--card); color: var(--ink); width: 40px; height: 40px; border-radius: 20px; font-size: 20px; flex: none; }
.dpbtn:disabled { opacity: .35; }
.dpbody { max-width: 560px; margin: 0 auto; padding: 4px 16px calc(40px + env(safe-area-inset-bottom)); }
.cmp { display: flex; align-items: baseline; gap: 8px; padding: 7px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.cmp:first-of-type { border-top: 0; } .cmp .muted { flex: 1 1 110px; } .cmp b { flex: none; }
.delta { font-size: 12px; color: var(--muted); } .delta.good { color: var(--green-t); font-weight: 700; } .delta.bad { color: var(--red-t); font-weight: 700; }
.stack { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--line); }
.stack i { display: block; height: 100%; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; } .legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.bar.thin { height: 5px; margin-top: 6px; }
.hl { padding: 6px 0; border-top: 1px solid var(--line); font-size: 14px; } .hl:first-child { border-top: 0; }
.msg { padding: 6px 0; border-top: 1px solid var(--line); } .msg:first-child { border-top: 0; } .msg.bot { color: var(--muted); }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--paper); border-radius: 14px; padding: 10px 12px; } .tile b { display: block; font-size: 20px; margin: 2px 0; }
.squares { display: flex; flex-wrap: wrap; gap: 4px; }
.sq { width: 14px; height: 14px; border: 0; border-radius: 4px; padding: 0; }
.vbars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: end; }
.vb { text-align: center; } .vbc { position: relative; height: 90px; background: var(--paper); border-radius: 8px; overflow: hidden; display: flex; align-items: flex-end; }
.vbc i { display: block; width: 100%; } .vbc u { position: absolute; left: 0; right: 0; height: 0; border-top: 2px dashed var(--ink); opacity: .5; text-decoration: none; }
.vbv { font-size: 10px; min-height: 14px; } .vbl { color: var(--muted); }

/* day header, two rings and three bars, quick add, meals */
.dayhead { display: flex; align-items: center; gap: 4px; margin-top: 12px; }
.dayhead .arrow { width: 48px; height: 48px; border: 0; background: none; font-size: 32px; line-height: 1; color: var(--ink); border-radius: 24px; }
.dayhead .arrow:disabled { color: var(--future); }
.dayhead .daytitle { flex: 1; border: 0; background: none; font-weight: 700; font-size: 16px; text-align: center; padding: 10px 0; color: var(--ink); }
.rings2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 4px; }
.ring2 { text-align: center; }
.ring2 svg { width: 100%; max-width: 150px; height: auto; display: block; margin: 0 auto; }
.ringcap { font-size: 12px; color: var(--muted); margin-top: 2px; }
.bl { margin-top: 12px; }
.bl .top { display: flex; justify-content: space-between; font-size: 13px; }
.bl .bar { height: 8px; }
.cap { font-size: 12px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin-bottom: 4px; }
.banner.info { background: #e3efe6; color: #1f5133; }
:root[data-theme="dark"] .banner.info { background: #1f3b2e; color: #bbf7d0; }
