:root {
  --bg: #f4f6f1; --card: #fff; --ink: #17261c; --muted: #5b6b60; --line: #dfe5da;
  --accent: #1f7a4d; --accent-ink: #fff; --ok: #1f9d5c; --warn: #e69a00; --bad: #d63a2f;
  --soft: #e8efe6; --shadow: 0 1px 3px rgba(0,0,0,.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101612; --card: #1a231d; --ink: #eef3ee; --muted: #9fb0a4; --line: #2b372f;
    --accent: #3fb079; --accent-ink: #06150d; --soft: #243028; --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 18px; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; line-height: 1.35;
  padding-bottom: env(safe-area-inset-bottom);
}
body.locked { overflow: hidden; }
[hidden] { display: none !important; }
h1 { font-size: 1.6rem; margin: 0 0 .3rem; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.error { color: var(--bad); min-height: 1.3em; margin: .5rem 0 0; font-weight: 600; }

#view { max-width: 560px; margin: 0 auto; padding: 14px 14px 100px; }
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5;
}
#tabs button {
  flex: 1; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 700;
  padding: 16px 4px; font-size: 1rem;
}
#tabs button.on { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }

.card { background: var(--card); border-radius: 18px; padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); border: 1px solid var(--line); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem; border: 2px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-weight: 700; padding: 15px 18px;
  border-radius: 16px; min-height: 56px; width: 100%; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 44px; padding: 8px 14px; width: auto; font-size: .9rem; border-radius: 12px; }
.btn:disabled { opacity: .55; }
.btn svg { width: 26px; height: 26px; fill: currentColor; flex: none; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--bg); border: 2px solid var(--line);
  border-radius: 12px; padding: 12px; width: 100%; min-height: 50px;
}
input:focus, select:focus, textarea:focus { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
textarea { min-height: 120px; resize: vertical; }
label { display: block; font-size: .8rem; color: var(--muted); font-weight: 700; margin: 0 0 4px; }

#login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
#loginForm { width: 100%; max-width: 380px; display: grid; gap: 14px; }

/* day nav */
.daynav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.daynav button { width: 52px; min-height: 52px; font-size: 1.5rem; border-radius: 14px; border: 2px solid var(--line); background: var(--card); color: var(--ink); }
.daynav .title { flex: 1; text-align: center; font-weight: 800; font-size: 1.15rem; position: relative; }
.daynav .title input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; }

/* calories */
.big { font-size: 3rem; font-weight: 900; line-height: 1; letter-spacing: -1px; }
.big small { font-size: 1.1rem; font-weight: 700; color: var(--muted); letter-spacing: 0; }
.bar { height: 22px; background: var(--soft); border-radius: 12px; overflow: hidden; margin: 12px 0 6px; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 12px; transition: width .4s, background .3s; }
.bar.near > i { background: var(--warn); }
.bar.over > i { background: var(--bad); }
.over-txt { color: var(--bad); } .near-txt { color: var(--warn); }
.between { display: flex; justify-content: space-between; gap: 8px; }

/* mic */
.micwrap { display: flex; flex-direction: column; align-items: center; margin: 18px 0 14px; }
.mic {
  width: 168px; height: 168px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center; box-shadow: 0 8px 24px rgba(31,122,77,.35);
}
.mic svg { width: 84px; height: 84px; fill: currentColor; }
.mic:active { transform: scale(.97); }
.mic.live { animation: pulse 1.2s infinite; background: var(--bad); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(214,58,47,.5); } 100% { box-shadow: 0 0 0 28px rgba(214,58,47,0); } }
.micwrap p { margin: 10px 0 0; font-weight: 800; font-size: 1.1rem; }

.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; text-align: center; }
.macros div { background: var(--soft); border-radius: 14px; padding: 10px 4px; }
.macros b { display: block; font-size: 1.35rem; }
.macros span { font-size: .78rem; color: var(--muted); font-weight: 700; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin: 0 -2px; }
.chip {
  flex: none; border: 2px solid var(--line); background: var(--card); color: var(--ink); border-radius: 14px;
  padding: 10px 14px; font: inherit; font-size: .88rem; font-weight: 700; text-align: left; min-height: 56px; max-width: 200px;
}
.chip small { display: block; color: var(--muted); font-weight: 600; }

.entry { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 12px 0; border-top: 1px solid var(--line); }
.entry:first-child { border-top: 0; }
.entry .nm { font-weight: 800; font-size: 1.15rem; }
.entry .kc { font-weight: 900; font-size: 1.4rem; text-align: right; }
.entry .meta { font-size: 1rem; line-height: 1.5; color: var(--muted); }
.entry .acts { grid-column: 1 / -1; display: flex; gap: 8px; }
.tag { display: inline-block; font-size: .85rem; font-weight: 800; text-transform: uppercase; padding: 2px 8px; border-radius: 20px; background: var(--soft); color: var(--accent); margin-right: 6px; }
.conf-low { background: #fde7d9; color: #a1430c; } .conf-medium { background: #fdf3cf; color: #7a5b00; } .conf-high { background: #dcf3e5; color: #17663f; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--soft); border-radius: 14px; padding: 12px; }
.stat b { display: block; font-size: 1.7rem; font-weight: 900; }
.stat span { font-size: .78rem; color: var(--muted); font-weight: 700; text-transform: uppercase; }
svg.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 10px; }

/* history */
.dayrow { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; width: 100%; border: 0; border-top: 1px solid var(--line); background: none; color: var(--ink); font: inherit; padding: 12px 0; text-align: left; }
.dayrow:first-child { border-top: 0; }
.dayrow .mini { grid-column: 1 / -1; height: 8px; background: var(--soft); border-radius: 6px; overflow: hidden; }
.dayrow .mini i { display: block; height: 100%; background: var(--ok); }
.dayrow.near .mini i { background: var(--warn); } .dayrow.over .mini i { background: var(--bad); }
.wk { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 10px; }

/* sheets */
.sheet { position: fixed; inset: 0; background: var(--bg); z-index: 20; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet .inner { max-width: 560px; margin: 0 auto; padding: 14px 14px 140px; }
.sheet header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.sheet header h1 { margin: 0; font-size: 1.3rem; }
.x { border: 0; background: var(--soft); color: var(--ink); width: 48px; height: 48px; border-radius: 50%; font-size: 1.4rem; }
.foot { position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line); padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); z-index: 21; }
.foot .in { max-width: 560px; margin: 0 auto; display: grid; gap: 10px; }
.banner { background: #fdf3cf; color: #5c4400; border-radius: 12px; padding: 12px; font-weight: 600; margin-bottom: 12px; }
@media (prefers-color-scheme: dark) { .banner { background: #3b3210; color: #f5dc8a; } }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.item { margin-bottom: 14px; }
.item .top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.item > div + div, .item > .grid2, .item > .grid4 { margin-top: 10px; }
.spinner { width: 54px; height: 54px; border: 6px solid var(--soft); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin: 40px auto 16px; }
@keyframes spin { to { transform: rotate(360deg); } }
.center { text-align: center; }
.stack { display: grid; gap: 10px; }
.photo-prev { width: 100%; max-height: 260px; object-fit: cover; border-radius: 14px; margin-bottom: 8px; }
#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); background: #17261c; color: #fff; padding: 12px 20px; border-radius: 30px; font-weight: 700; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }

.photogrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.ph { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 16px; padding: 0; overflow: hidden; text-align: left; font: inherit; }
.ph img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--soft); }
.ph span { display: block; padding: 8px 10px 10px; font-size: .8rem; color: var(--muted); }
.ph b { color: var(--ink); }
.photo-big { width: 100%; max-height: 60vh; object-fit: contain; border-radius: 14px; background: #000; margin-bottom: 12px; }
#tabs button { font-size: .92rem; padding-left: 0; padding-right: 0; }
.dayhead { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.dayhead h2 { margin: 0; }
.dayhead small { font-weight: 700; }
.t-ok { color: var(--ok); } .t-over { color: var(--bad); } .t-low { color: var(--warn); }
.pm { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.pm:first-of-type { border-top: 0; }
.pm .nm { font-weight: 800; } .pm .meta { font-size: .95rem; color: var(--muted); line-height: 1.45; }
.pm .kc { font-weight: 900; font-size: 1.2rem; text-align: right; }
.pm .acts { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.pm.done { opacity: .6; }
.shop h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 14px 0 4px; }
.shop label { display: flex; gap: 12px; align-items: center; color: var(--ink); font-size: 1.05rem; font-weight: 600; margin: 0; padding: 10px 0; border-top: 1px solid var(--line); }
.shop label input { width: 26px; min-height: 26px; flex: none; }
.shop label.got span { text-decoration: line-through; color: var(--muted); }
.recipe h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 0 6px; }
.recipe ol { margin: 0; padding-left: 1.4rem; } .recipe ol li { margin-bottom: 12px; font-size: 1.05rem; line-height: 1.45; }
.recipe ul { margin: 0; padding-left: 1.2rem; } .recipe ul li { margin-bottom: 4px; }
.recipe .times { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 0; }
/* forecast, protein, coach */
.row .btn { padding-left: 8px; padding-right: 8px; }
.bar.slim { height: 12px; margin: 8px 0 4px; }
.bar.prot > i { background: #3b82f6; }
.st-ahead, .st-on_track { background: #dcf3e5; color: #17663f; } .st-behind { background: #fde7d9; color: #a1430c; } .st-tracking, .st-nodata { background: var(--soft); color: var(--muted); }
@media (prefers-color-scheme: dark) { .st-ahead, .st-on_track { background: #1d3a2a; color: #8be0ae; } .st-behind { background: #43261a; color: #f5b48f; } .conf-low { background: #43261a; color: #f5b48f; } .conf-medium { background: #3b3210; color: #f5dc8a; } .conf-high { background: #1d3a2a; color: #8be0ae; } }
.coach h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 14px 0 4px; }
.coach ul { margin: 0; padding-left: 1.2rem; } .coach li { margin-bottom: 6px; }
.coach .head { font-size: 1.15rem; font-weight: 800; margin: 0; }
.answer { border-top: 1px solid var(--line); padding: 12px 0; } .answer:first-child { border-top: 0; }
.answer .q { font-weight: 800; margin-bottom: 4px; }
.pill { display: inline-block; margin-top: 6px; }
.suggest { display: flex; flex-wrap: wrap; gap: 8px; }
.suggest button { border: 2px solid var(--line); background: var(--card); color: var(--ink); border-radius: 20px; padding: 8px 14px; font: inherit; font-size: .85rem; font-weight: 700; min-height: 44px; }
