:root {
  --bg: #f6f7f5; --surface: #ffffff; --surface2: #eef2ef; --text: #1b2421; --muted: #5d6b66; --line: #dde3e0;
  --brand: #0f766e; --brand-ink: #ffffff; --brand-soft: #d9f0ec;
  --good: #1f9d55; --warn: #d98a00; --bad: #d64545; --low: #b03a8f;
  --band: rgba(31, 157, 85, .10); --chart-line: #0f766e; --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1413; --surface: #182120; --surface2: #202b29; --text: #e8efec; --muted: #9db0aa; --line: #2c3a37;
    --brand: #2dd4bf; --brand-ink: #062a26; --brand-soft: #123b36; --good: #3ccf7a; --warn: #f0b13a; --bad: #ff6b6b; --low: #e57ad0;
    --band: rgba(60, 207, 122, .12); --chart-line: #2dd4bf; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; background: var(--bg); color: var(--text);
  padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
h1 { font-size: 1.5rem; margin: .4rem 0 .6rem; } h2 { font-size: 1.1rem; margin: 1.4rem 0 .5rem; } h3 { font-size: 1rem; margin: .2rem 0 .5rem; }
p { margin: .4rem 0; } a { color: var(--brand); } small { color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: .85rem; } .error { color: var(--bad); } .hint { display: block; margin-top: 4px; }
button, input, select, textarea { font: inherit; color: inherit; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; text-decoration: none; color: var(--text); font-size: 1.05rem; }
.avatar-btn, .avatar { width: 36px; height: 36px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--brand); color: var(--brand-ink); font-weight: 700; border: 0; flex: none; }
.avatar.big { width: 52px; height: 52px; font-size: 1.3rem; }
main { max-width: 760px; margin: 0 auto; padding: 8px 16px 24px; outline: none; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { display: flex; flex-direction: column; align-items: center; padding: 8px 0 10px; font-size: .75rem; text-decoration: none; color: var(--muted); min-height: 56px; }
.tabbar a span { font-size: 1.3rem; line-height: 1.3; } .tabbar a.on { color: var(--brand); font-weight: 600; }
.fab { position: fixed; z-index: 21; left: 50%; transform: translateX(-50%); bottom: calc(18px + env(safe-area-inset-bottom)); width: 64px; height: 64px; border-radius: 50%; border: 4px solid var(--bg);
  background: var(--brand); color: var(--brand-ink); font-size: 2rem; line-height: 1; box-shadow: 0 4px 14px rgba(0,0,0,.25); cursor: pointer; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 10px 0; box-shadow: var(--shadow); }
.card.cta { border-color: var(--brand); background: var(--brand-soft); } .card.note, p.note { background: color-mix(in srgb, var(--warn) 14%, var(--surface)); border-radius: 10px; padding: 10px 12px; }
.card.coach { border-left: 4px solid var(--brand); }
.row { display: flex; align-items: center; } .gap { gap: 10px; } .wrap { flex-wrap: wrap; } .grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 10px 16px; border-radius: 12px; cursor: pointer; min-height: 44px; text-decoration: none; text-align: center; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.btn.ghost { background: transparent; } .btn.big { width: 100%; padding: 14px; font-size: 1.05rem; min-height: 52px; } .btn.small { padding: 6px 12px; min-height: 36px; font-size: .9rem; }
.btn.danger { background: var(--bad); color: #fff; border-color: var(--bad); } .danger-text { color: var(--bad); }
.btn:disabled { opacity: .55; }
.icon-btn { border: 0; background: transparent; font-size: 1.5rem; width: 44px; height: 44px; border-radius: 50%; cursor: pointer; }
.icon-btn:disabled { opacity: .3; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; } .chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px; min-height: 40px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }

.form { display: flex; flex-direction: column; gap: 14px; }
.form label, .field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .92rem; }
.form label.check { flex-direction: row; align-items: center; font-weight: 400; gap: 8px; } .check input { width: 22px; height: 22px; }
input, select, textarea { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 12px; min-height: 44px; font-weight: 400; width: 100%; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 2px; }
input.pin { font-size: 2rem; text-align: center; letter-spacing: .5em; }
.search { margin: 6px 0; }
details { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; } details[open] { padding-bottom: 14px; } details > * + * { margin-top: 12px; }
summary { cursor: pointer; font-weight: 600; color: var(--brand); }

.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); }
.stepper input { width: 70px; border: 0; text-align: center; border-radius: 0; min-height: 42px; padding: 6px; }
.stepper .step { width: 44px; height: 44px; border: 0; background: var(--surface2); font-size: 1.3rem; cursor: pointer; }
.stepper .suffix { padding-right: 6px; color: var(--muted); }

/* sheets */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0,0,0,.4); opacity: 0; transition: opacity .2s; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; background: var(--bg); border-radius: 18px 18px 0 0; transform: translateY(100%); transition: transform .25s ease;
  display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; }
.sheet.full { height: 96vh; max-height: 96vh; }
.sheet-wrap.open .sheet { transform: none; } .sheet-wrap.open .sheet-bg { opacity: 1; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 0 16px; } .sheet-head h2 { margin: 0; }
.sheet-body { overflow-y: auto; padding: 8px 16px calc(24px + env(safe-area-inset-bottom)); }
.sticky-actions { position: sticky; bottom: -24px; background: var(--bg); padding: 10px 0; }

.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; transition: .25s; background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; z-index: 100; max-width: calc(100vw - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* charts */
.chart { width: 100%; height: auto; display: block; }
.chart .band { fill: var(--band); } .chart .grid { stroke: var(--line); stroke-width: 1; } .chart .grid.v { stroke-dasharray: 2 4; }
.chart .axis { fill: var(--muted); font-size: 11px; } .chart .line { fill: none; stroke: var(--chart-line); stroke-width: 2.4; stroke-linejoin: round; }
.chart .thin { fill: none; stroke: var(--chart-line); stroke-width: 1.2; opacity: .3; }
.chart .baseline { stroke: var(--muted); stroke-dasharray: 5 4; } .chart .peak { fill: var(--bad); } .chart .label { fill: var(--text); font-size: 12px; font-weight: 700; }
.chart .empty { fill: var(--muted); font-size: 14px; }
.chart .pin { cursor: pointer; } .chart .pin line { stroke: var(--warn); stroke-width: 1.5; stroke-dasharray: 3 3; } .chart .pin circle { fill: var(--surface); stroke: var(--warn); }
.chart .pin text { font-size: 10px; } .chart .pin.exercise line, .chart .pin.exercise circle { stroke: var(--good); } .chart .pin.med line, .chart .pin.med circle { stroke: var(--low); }
.spark { flex: none; } .spark path { fill: none; stroke: var(--brand); stroke-width: 2; }
.rangebar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; margin: 10px 0 6px; background: var(--surface2); }
.rangebar .below { background: var(--low); } .rangebar .in { background: var(--good); } .rangebar .above { background: var(--warn); }
.stats4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; margin-top: 6px; }
.stats4 b { display: block; font-size: 1.2rem; } .stats4 small { font-size: .75rem; }
.hbars { display: flex; flex-direction: column; gap: 8px; } .hbar { display: grid; grid-template-columns: 7.5em 1fr auto; align-items: center; gap: 8px; font-size: .9rem; }
.hbar .hl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .hv { min-width: 4.5em; text-align: right; }
.track { height: 10px; background: var(--surface2); border-radius: 5px; overflow: hidden; display: block; } .fill { display: block; height: 100%; background: var(--brand); border-radius: 5px; }
.fill.good { background: var(--good); } .fill.warn { background: var(--warn); } .fill.bad { background: var(--bad); }

/* today */
.daynav { display: flex; align-items: center; justify-content: space-between; } .daynav h1 { margin: 0; }
.quick { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 10px 0; }
.qa { display: flex; flex-direction: column; align-items: center; gap: 2px; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 8px 2px; font-size: .78rem; cursor: pointer; min-height: 72px; }
.qa span { font-size: 1.4rem; } .qa small { font-size: .68rem; }
.timeline { display: flex; flex-direction: column; gap: 6px; }
.titem, .meal-card, .list-item, .meal-mini { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; text-decoration: none; color: inherit; }
.titem b, .meal-card b, .list-item b, .meal-mini b { display: block; overflow: hidden; text-overflow: ellipsis; } .titem small, .meal-card small, .list-item small, .meal-mini small { display: block; }
.ttime { font-size: .8rem; color: var(--muted); width: 4.6em; flex: none; }
.ticon { font-size: 1.4rem; width: 40px; text-align: center; flex: none; } .ticon.big { font-size: 2rem; width: 64px; }
.thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 8px; flex: none; background: var(--surface2); } .thumb.big { width: 64px; height: 64px; }
.grade { width: 34px; height: 34px; border-radius: 10px; display: inline-grid; place-items: center; font-weight: 800; flex: none; color: #fff; }
.gA { background: var(--good); } .gB { background: #7ab648; } .gC { background: var(--warn); } .gD { background: var(--bad); } .gx { background: var(--surface2); color: var(--muted); }
.chev { color: var(--muted); font-size: 1.3rem; }
.habits { display: flex; flex-direction: column; gap: 10px; } .habit { display: grid; grid-template-columns: 1fr 30% 5.5em; gap: 8px; align-items: center; font-size: .9rem; } .habit small { text-align: right; }
.score { background: var(--brand); color: var(--brand-ink); border-radius: 999px; padding: 2px 10px; font-size: .9rem; margin-left: 6px; }

/* lists */
.list { display: flex; flex-direction: column; gap: 6px; } .card.list { padding: 8px; } .card .list-item { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; } .card .list-item:last-child { border-bottom: 0; }
.list-item.on { border-color: var(--brand); }
.rank { width: 1.8em; text-align: center; font-weight: 700; color: var(--muted); }
.pill { border-radius: 999px; padding: 4px 10px; font-weight: 700; font-size: .85rem; white-space: nowrap; background: var(--surface2); }
.pill.good { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); } .pill.warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.pill.bad { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); } .pill.muted { color: var(--muted); }
.dayhead { margin: 1rem 0 .4rem; color: var(--muted); font-size: .9rem; }
.meal-list { display: flex; flex-direction: column; gap: 8px; }
.kinds { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.kind { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; font-size: .78rem; cursor: pointer; min-height: 76px; }
.kind span { font-size: 1.6rem; }
.photo-btn { margin-bottom: 10px; }
.photos { display: flex; gap: 8px; overflow-x: auto; } .photos img { height: 120px; border-radius: 12px; object-fit: cover; } .photos.big img { height: 220px; max-width: 100%; }

/* meal form */
.food-search { display: flex; gap: 8px; } .food-search input { flex: 1; }
.item { border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; margin-top: 8px; background: var(--surface); }
.item-top { display: flex; align-items: center; } .item-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.item-row select { width: auto; } .item .carbs { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; } .item .carbs input { width: 70px; }
.totals { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .88rem; margin-top: 8px; color: var(--muted); } .totals b { color: var(--text); }

/* meal detail */
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.metric { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; } .metric b { font-size: 1.25rem; } .metric small { font-size: .72rem; }
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; } .tbl th, .tbl td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; } .tbl th { color: var(--muted); font-weight: 600; }
.tbl.small { font-size: .8rem; }
.card { overflow-x: auto; }
.patterns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; } .pattern { margin: 0; }
.vs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; text-align: center; } .vs > div { background: var(--surface2); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; } .vs b { font-size: 1.3rem; }
.profile-card { display: flex; align-items: center; gap: 12px; } .profile-card small { display: block; }
.lab { flex-wrap: wrap; }

/* welcome */
.welcome { text-align: center; padding: 30px 6px; display: flex; flex-direction: column; gap: 14px; max-width: 460px; margin: 0 auto; }
.logo-big { font-size: 3.2rem; } .lead { font-size: 1.1rem; } .ticks { text-align: left; margin: 0 auto; padding-left: 1.2em; }

.report h1 { font-size: 1.3rem; }
@media print { .topbar, .tabbar, .fab, .noprint { display: none !important; } body { padding: 0; background: #fff; color: #000; } .card { box-shadow: none; } }

@media (max-width: 420px) {
  .metrics { grid-template-columns: repeat(2, 1fr); } .patterns { grid-template-columns: 1fr; } .stats4 b { font-size: 1.05rem; }
  .quick { gap: 5px; } .qa { font-size: .7rem; } .hbar { grid-template-columns: 6em 1fr auto; } .kinds { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 900px) { main { max-width: 860px; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
