:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-2: #eef2ee;
  --text: #17201b;
  --muted: #56635b;
  --line: #d7ded8;
  --primary: #1f7a5c;
  --primary-ink: #ffffff;
  --primary-soft: #dff1e8;
  --accent-soft: #fff4d6;
  --warn-soft: #fdeceb;
  --warn-line: #e3a29c;
  --danger: #b3261e;
  --danger-ink: #ffffff;
  --good: #1b7a3f;
  --c-food: #3f9b52;
  --c-protein: #d0743c;
  --c-carb: #d9b44a;
  --c-move: #2f7fc1;
  --c-sleep: #6b5bc4;
  --c-mind: #b0558f;
  --c-life: #8a6d1f;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 10px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1512; --surface: #18201c; --surface-2: #212b26; --text: #e8eee9; --muted: #a4b2a9; --line: #33413a;
    --primary: #5cc79d; --primary-ink: #0b1a13; --primary-soft: #1d3a2e; --accent-soft: #3a3217; --warn-soft: #3b2020; --warn-line: #8a4a44;
    --danger: #ff8a80; --danger-ink: #2a0606; --good: #6fdc95; --c-food: #5cba6e; --c-protein: #e89060; --c-carb: #e6c766; --c-move: #6aa9e3; --c-sleep: #a294f0; --c-mind: #e08cc0; --c-life: #d1b25a;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Rubik, Assistant, Arial, sans-serif;
  font-size: 16px; line-height: 1.55;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
body.modal-open { overflow: hidden; }
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h2 { font-size: 1.12rem; }
h3 { font-size: 1rem; margin-top: 1rem; }
p { margin: 0 0 .6rem; }
.muted { color: var(--muted); }
.small, small { font-size: .85rem; }
.center { text-align: center; }
.lead { font-size: 1.08rem; }
.big { font-size: 1.35rem; font-weight: 700; margin: .2rem 0 .4rem; }
.good { color: var(--good); }
.ok { color: var(--good); font-weight: 600; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; top: -40px; right: 8px; background: var(--primary); color: var(--primary-ink); padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip:focus { top: 8px; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

main { max-width: 600px; margin: 0 auto; padding: 12px 16px 24px; outline: none; }

/* top & tab bars */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px; max-width: 600px; margin: 0 auto;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: var(--bg); }
.topbar:empty { display: none; }
.topbar h1 { flex: 1; font-size: 1.2rem; margin: 0; }
.logo { font-size: 1.4rem; width: 40px; text-align: center; }
.tabbar { position: fixed; bottom: 0; inset-inline: 0; z-index: 10; display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); }
.tabbar[hidden] { display: none; }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 10px; text-decoration: none; color: var(--muted); font-size: .78rem; min-height: 56px; }
.tab span { font-size: 1.25rem; line-height: 1.1; }
.tab.on { color: var(--primary); font-weight: 700; }
.tab.on span { transform: translateY(-1px); }

/* cards */
.card { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); color: inherit; }
.card.accent { background: var(--primary-soft); border-color: transparent; }
.card.tip { background: var(--accent-soft); border-color: transparent; }
.card.warn { background: var(--warn-soft); border-color: var(--warn-line); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card-h h2 { margin: 0; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; background: var(--surface-2); font-weight: 700; font-size: .85rem; }
.pill.ok { background: var(--primary-soft); color: var(--good); }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; padding: 1px 8px; border-radius: 99px; background: color-mix(in srgb, var(--tc) 16%, transparent); color: var(--text); margin-inline-end: 6px; border: 1px solid color-mix(in srgb, var(--tc) 40%, transparent); }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { background: var(--danger); color: var(--danger-ink); border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn.sm { min-height: 36px; padding: 4px 12px; font-size: .9rem; }
.btn.xs { min-height: 32px; padding: 2px 8px; font-size: .8rem; }
.btn.block { display: flex; width: 100%; margin-top: 8px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; color: var(--text); font-size: 1.15rem; cursor: pointer; text-decoration: none; flex: none; }
.icon-btn:hover { background: var(--surface-2); }
.row { display: flex; align-items: center; gap: 8px; }
.row.gap { gap: 10px; margin-top: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

/* forms */
.field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 12px; border: 0; padding: 0; min-width: 0; }
.field > span, legend { font-weight: 600; font-size: .95rem; padding: 0; margin-bottom: 4px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%; }
textarea { resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--primary); flex: none; margin: 2px 0 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.seg span { display: inline-flex; align-items: center; min-height: 40px; padding: 6px 14px; border: 1px solid var(--line); border-radius: 99px; background: var(--surface); font-weight: 600; font-size: .92rem; }
.seg input:checked + span { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.seg input:checked + span::before { content: "✓ "; }
.seg input:focus-visible + span { outline: 3px solid var(--primary); outline-offset: 2px; }
.seg.sm span { min-height: 36px; padding: 4px 14px; }
.choices { display: grid; gap: 8px; }
.choices.two { grid-template-columns: 1fr 1fr; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; background: var(--surface); }
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.choice.neg:has(input:checked) { border-color: var(--warn-line); background: var(--warn-soft); }
.choice span { display: flex; flex-direction: column; }
.choice small { color: var(--muted); }
.yn { border: 0; padding: 8px 0; margin: 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.yn legend { font-weight: 500; float: right; width: 100%; margin-bottom: 6px; }

/* onboarding */
.onb .hero { text-align: center; padding: 24px 8px 12px; }
.onb .hero h1 { font-size: 2rem; }
.big-emoji { font-size: 3rem; line-height: 1; }
.big-emoji.sm { font-size: 1.8rem; }
.steps { display: flex; gap: 4px; list-style: none; padding: 0; margin: 4px 0 12px; font-size: .75rem; }
.steps li { flex: 1; text-align: center; padding-top: 6px; border-top: 4px solid var(--line); color: var(--muted); }
.steps li.done { border-color: var(--primary); }
.steps li.on { border-color: var(--primary); color: var(--text); font-weight: 700; }
.list { padding-inline-start: 20px; margin: 0 0 .6rem; }
.list li { margin-bottom: 6px; }
.pick-list { display: grid; gap: 8px; }
.pick { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.pick:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.pick span { display: flex; flex-direction: column; gap: 2px; align-items: flex-start; }
.pick small { color: var(--muted); }

/* today */
.hello { margin: 4px 2px 12px; }
.hello h2 { font-size: 1.4rem; margin: 0; }
.habit-list { display: grid; gap: 8px; }
.habit { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 12px; background: var(--surface-2); }
.habit .grow { display: flex; flex-direction: column; }
.habit.done b { text-decoration: line-through; text-decoration-color: var(--muted); }
.check { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--primary); background: var(--surface); color: var(--primary-ink); font-size: 1.3rem; font-weight: 800; cursor: pointer; }
.habit.done .check { background: var(--primary); }
.nudge { display: block; background: var(--accent-soft); border-radius: 8px; padding: 4px 8px; margin-top: 4px; font-size: .82rem; }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.q-item { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 10px; border-radius: 12px; background: var(--surface-2); }
.q-item input { min-height: 40px; padding: 6px 10px; }
.q-l { font-weight: 700; font-size: .9rem; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper .icon-btn { background: var(--surface); border: 1px solid var(--line); width: 36px; height: 36px; }
.mood { margin-top: 12px; }
.mood-row { display: flex; gap: 6px; margin-top: 4px; }
.mood-b { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0; padding: 6px 2px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); cursor: pointer; font: inherit; color: var(--text); }
.mood-b span { font-size: 1.5rem; }
.mood-b small { font-size: .72rem; }
.mood-b.on { border-color: var(--primary); background: var(--primary-soft); font-weight: 700; }
.actions4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.act { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 4px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); color: var(--text); text-decoration: none; font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; text-align: center; }
.act span { font-size: 1.6rem; }
.act.sos { background: var(--warn-soft); border-color: var(--warn-line); }
.rings { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.ring { position: relative; width: 100%; max-width: 120px; margin: 0 auto; aspect-ratio: 1; }
.ring svg { width: 100%; height: 100%; }
.ring-bg { fill: none; stroke: var(--surface-2); stroke-width: 8; }
.ring-fg { fill: none; stroke: var(--primary); stroke-width: 8; stroke-linecap: round; transition: stroke-dashoffset .6s; }
.ring-t { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.ring-t b { font-size: 1.05rem; }
.ring-t small { font-size: .68rem; color: var(--muted); max-width: 70%; line-height: 1.2; }

/* habits */
.hcard { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.cue { margin: 6px 0 2px; font-size: .92rem; }
.dots { display: grid; grid-template-columns: repeat(14, 1fr); gap: 3px; margin: 8px 0; direction: ltr; }
.dots .d { aspect-ratio: 1; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; font-size: .6rem; color: var(--primary-ink); }
.dots .d.on { background: var(--primary); border-color: var(--primary); }
.dots .d.na { opacity: .35; border-style: dashed; }
.hmeta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .82rem; color: var(--muted); }
.auto { margin-top: 8px; }
.auto-bar, .progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 6px 0; }
.auto-bar i, .progress i { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
details { margin-top: 8px; }
summary { cursor: pointer; font-weight: 600; padding: 8px 0; min-height: 40px; }
.lib { border-top: 1px solid var(--line); }
.lib-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.lib-item .grow { display: flex; flex-direction: column; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin-bottom: 10px; }
.stats > div { background: var(--surface-2); border-radius: 12px; padding: 8px 10px; display: flex; flex-direction: column; }
.stats b { font-size: 1.2rem; }
.stats small { color: var(--muted); font-size: .76rem; }

/* charts */
.chart { margin: 6px 0 8px; }
.chart svg { width: 100%; height: auto; display: block; }
.grid { stroke: var(--line); stroke-width: 1; }
.axis { fill: var(--muted); font-size: 10px; font-family: inherit; }
.line { fill: none; stroke-width: 2; }
.line.raw { stroke: var(--muted); stroke-width: 1.2; stroke-dasharray: 3 3; }
.line.avg { stroke: var(--primary); stroke-width: 3; }
.dot { fill: var(--muted); }
.goal { stroke: var(--c-protein); stroke-width: 1.5; stroke-dasharray: 6 4; }
.goal-t { fill: var(--c-protein); }
.bar { fill: color-mix(in srgb, var(--primary) 45%, var(--surface-2)); }
.bar.met { fill: var(--primary); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .78rem; color: var(--muted); align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.sw { display: inline-block; width: 14px; height: 4px; border-radius: 2px; }
.sw.raw { background: var(--muted); }
.sw.avg { background: var(--primary); height: 5px; }
.sw.goal { background: var(--c-protein); }
.sw.met { background: var(--primary); height: 10px; width: 10px; }
.legend-list { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .9rem; }
.legend-list .sw { width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; margin-inline-end: 4px; }
.heatmap { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; max-width: 260px; }
.hm { display: block; aspect-ratio: 1; border-radius: 4px; background: var(--surface-2); }
.hm-h { font-size: .72rem; color: var(--muted); text-align: center; }
.hm.l1 { background: color-mix(in srgb, var(--primary) 30%, var(--surface-2)); }
.hm.l2 { background: color-mix(in srgb, var(--primary) 55%, var(--surface-2)); }
.hm.l3 { background: color-mix(in srgb, var(--primary) 78%, var(--surface-2)); }
.hm.l4 { background: var(--primary); }
.hm.future { background: transparent; border: 1px dashed var(--line); }
.hm-legend { margin-top: 8px; }
.hm-legend .hm { width: 14px; height: 14px; }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.badge { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 10px 6px; border-radius: 12px; background: var(--surface-2); border: 1px dashed var(--line); }
.badge:not(.got) span:first-child { filter: grayscale(1); opacity: .6; }
.badge.got { background: var(--accent-soft); border: 1px solid transparent; }
.badge span:first-child { font-size: 1.6rem; }
.badge small { color: var(--muted); font-size: .72rem; }
.plain { list-style: none; padding: 0; margin: 0; }
.plain li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.plain li:last-child { border-bottom: 0; }

/* menu, tiles */
.menu { display: grid; }
.menu-item { display: flex; align-items: center; gap: 12px; padding: 12px 4px; color: var(--text); text-decoration: none; border: 0; border-bottom: 1px solid var(--line); background: none; font: inherit; text-align: start; width: 100%; cursor: pointer; }
.menu-item:last-child { border-bottom: 0; }
.menu-item > span:first-child { font-size: 1.4rem; }
.menu-item .grow { display: flex; flex-direction: column; }
a.card.menu-item { border: 1px solid var(--line); padding: 14px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.tile { display: flex; flex-direction: column; gap: 4px; padding: 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); border-top: 5px solid var(--tcol); color: var(--text); text-decoration: none; min-height: 120px; }
.tile small { color: var(--muted); }
.c-food { --tcol: var(--c-food); } .c-move { --tcol: var(--c-move); } .c-sleep { --tcol: var(--c-sleep); } .c-mind { --tcol: var(--c-mind); }
.sos-card { display: flex; align-items: center; gap: 12px; width: 100%; text-align: start; font: inherit; cursor: pointer; background: var(--warn-soft); border-color: var(--warn-line); }
.sos-card .grow { display: flex; flex-direction: column; }

/* food */
.plate { width: 180px; max-width: 60%; display: block; margin: 4px auto 10px; }
.plate-t { fill: #fff; font-size: 14px; font-weight: 700; font-family: inherit; paint-order: stroke; stroke: rgba(0,0,0,.35); stroke-width: 2px; }
.meal { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.meal .grow { display: flex; flex-direction: column; }
.meal-items { font-size: 1.2rem; letter-spacing: 2px; }
.score { min-width: 44px; height: 32px; border-radius: 99px; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: .9rem; }
.score.shi { background: var(--primary-soft); color: var(--good); }
.score.smid { background: var(--accent-soft); color: var(--text); }
.score.slo { background: var(--warn-soft); color: var(--text); }
.hunger { display: grid; grid-template-columns: repeat(10, 1fr); list-style: none; padding: 0; margin: 0 0 8px; gap: 2px; }
.hunger li { text-align: center; padding: 6px 0; font-weight: 700; color: #fff; font-size: .85rem; }
.hunger li:first-child { border-radius: 8px 0 0 8px; } .hunger li:last-child { border-radius: 0 8px 8px 0; }
.h1, .h2 { background: #a23b2c; } .h3, .h4 { background: #2f7d4a; } .h5 { background: #5c6e63; } .h6, .h7 { background: #2f6f9c; } .h8, .h9, .h10 { background: #8a4f2a; }
.swaps { list-style: none; padding: 0; margin: 0; }
.swaps li { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--line); }
.swaps s { color: var(--muted); }

/* move */
.tbl { width: 100%; border-collapse: collapse; font-size: .85rem; }
.tbl th, .tbl td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: start; vertical-align: top; }
.tbl tr.on { background: var(--primary-soft); font-weight: 700; }
.ex-list li { display: flex; flex-direction: column; }
.timer { font-size: 3.4rem; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; margin: 8px 0; }
.timer.sm { font-size: 2rem; color: var(--muted); }
.timeline li b { display: inline-block; min-width: 60px; font-variant-numeric: tabular-nums; }

/* breathing */
.breath-stage { text-align: center; padding: 24px 16px; }
.breath-circle { width: 200px; height: 200px; max-width: 70vw; max-height: 70vw; margin: 8px auto 16px; border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--primary) 40%, var(--surface)), var(--primary)); transform: scale(.55); opacity: .9; }
.breath-label { font-size: 1.4rem; font-weight: 700; min-height: 2rem; margin: 0; }
@media (prefers-reduced-motion: reduce) { .breath-circle { transition: none !important; } .ring-fg { transition: none; } }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal { position: relative; background: var(--surface); color: var(--text); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); outline: none; }
.modal h2 { padding-inline-end: 40px; }
.modal-x { position: absolute; top: 10px; left: 10px; }
@media (min-width: 640px) { .modal-back { align-items: center; } .modal { border-radius: 20px; } }
.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 12px; }
.modal .seg.wrap { margin-bottom: 12px; }

/* article */
.article p, .article li { font-size: 1.02rem; }
.sources { font-size: .82rem; color: var(--muted); padding-inline-start: 18px; }

.toast { position: fixed; bottom: calc(86px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 380px) {
  .grid3 { grid-template-columns: 1fr 1fr; }
  .choices.two { grid-template-columns: 1fr; }
  .actions4 { grid-template-columns: 1fr 1fr; }
}
