:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --card: #ffffff;
  --ink: #141413;
  --ink-2: #57564f;
  --ink-3: #8a897f;
  --line: #e4e3dc;
  --chip: #ecebe5;
  --header: #0d6b50;
  --header-ink: #ffffff;
  --accent: #0e8a66;
  --accent-ink: #ffffff;
  --accent-soft: #e0f2ea;
  --good: #157a3c;
  --warn: #a35f00;
  --danger: #c4372f;
  --series-1: #2a78d6;
  --surface-1: #ffffff;
  --grid: #e9e8e2;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 1px 1px rgba(0, 0, 0, .03);
  --tabs-h: 58px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --card: #1c1c1a;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --ink-3: #8e8d84;
    --line: #2e2e2b;
    --chip: #2a2a27;
    --header: #0b3d2f;
    --header-ink: #f0efec;
    --accent: #2bb88c;
    --accent-ink: #052019;
    --accent-soft: #13332a;
    --good: #4cc27a;
    --warn: #e6a640;
    --danger: #ef6b62;
    --series-1: #3987e5;
    --surface-1: #1c1c1a;
    --grid: #2b2b28;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --card: #1c1c1a; --ink: #f0efec; --ink-2: #c3c2b7; --ink-3: #8e8d84; --line: #2e2e2b; --chip: #2a2a27;
  --header: #0b3d2f; --header-ink: #f0efec; --accent: #2bb88c; --accent-ink: #052019; --accent-soft: #13332a;
  --good: #4cc27a; --warn: #e6a640; --danger: #ef6b62; --series-1: #3987e5; --surface-1: #1c1c1a; --grid: #2b2b28; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
body.noscroll { overflow: hidden; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; background: none; border: 0; padding: 0; }
button:disabled { opacity: .35; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
ul, ol { margin: 0; padding: 0; list-style: none; }
small { font-size: 13px; }
.muted { color: var(--ink-2); }
.small { font-size: 14px; }

/* ---------- shell ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--header); color: var(--header-ink);
}
.top h1 { font-size: 22px; font-weight: 700; flex: 1; }
.sync { font-size: 13px; padding: 4px 10px; border-radius: 99px; background: rgba(255, 255, 255, .16); color: var(--header-ink); }
.sync.ok { display: none; }
.sync.err { background: rgba(255, 190, 120, .3); }
.icon-btn.hdr { color: var(--header-ink); }
main {
  max-width: 560px; margin: 0 auto;
  padding: 12px 16px calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px);
  display: flex; flex-direction: column; gap: 12px;
}
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-around;
  padding: 4px 4px calc(env(safe-area-inset-bottom) + 2px);
  background: var(--card); border-top: 1px solid var(--line);
}
.tab {
  flex: 1; height: var(--tabs-h); max-width: 110px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; font-weight: 600; color: var(--ink-3);
}
.tab.on { color: var(--accent); }

/* ---------- cards & basics ---------- */
.card { background: var(--card); border-radius: 16px; padding: 14px 16px; box-shadow: var(--shadow); border: 1px solid var(--line); display: block; width: 100%; text-align: left; }
.card h3 { font-size: 17px; margin-bottom: 8px; }
.card h4, .sheet h4 { font-size: 15px; margin: 14px 0 6px; }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 6px; }
.title { font-size: 18px; font-weight: 650; }
.row-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.chev { font-size: 26px; color: var(--ink-3); }
.pill { font-size: 13px; font-weight: 650; padding: 4px 10px; border-radius: 99px; background: var(--chip); }
.pill.good { color: var(--good); background: var(--accent-soft); }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: #f6e7c8; color: #7a4a00; vertical-align: 1px; }
.tag.soft { background: var(--chip); color: var(--ink-2); font-weight: 600; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tag:not(.soft) { background: #4a3714; color: #f4cf86; } }
:root[data-theme="dark"] .tag:not(.soft) { background: #4a3714; color: #f4cf86; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: 12px;
  background: var(--chip); font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.block { display: flex; width: 100%; }
.btn.big { min-height: 52px; font-size: 17px; }
.btn.small { min-height: 36px; padding: 6px 14px; font-size: 15px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btn-row .btn { flex: 1; }
.link { color: var(--accent); font-weight: 600; padding: 10px 0; }
.link.block { display: block; width: 100%; text-align: center; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; font-size: 24px; line-height: 1; color: var(--ink-2); flex: none; }
.icon-btn.small { width: 32px; height: 32px; font-size: 20px; color: var(--ink-3); }
.icon-btn.add { background: var(--accent-soft); color: var(--accent); width: 36px; height: 36px; font-size: 22px; }

input[type="text"], input[type="search"], input[type="date"], textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg); outline: none;
  -webkit-appearance: none; appearance: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-top: 10px; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { flex: 1; min-width: 0; }
.unit { color: var(--ink-2); font-weight: 600; }
.grid2, .grid4 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

/* ---------- today ---------- */
.hero-nums { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 10px; }
.big { font-size: 40px; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.05; }
.big small { font-size: 20px; font-weight: 650; }
.big.over { color: var(--danger); }
.lbl { color: var(--ink-2); font-size: 14px; font-weight: 600; }
.meter-row { margin: 8px 0; }
.meter { height: 8px; border-radius: 99px; background: var(--accent-soft); overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.meter.over span { background: var(--danger); }
.meter-lbl { font-size: 13px; color: var(--ink-2); margin-top: 3px; font-variant-numeric: tabular-nums; }
.hero .btn { margin-top: 12px; }
#wt { max-width: 120px; font-size: 20px; font-weight: 650; }
.card .inline-form + .muted { margin-top: 8px; }

.checks { margin-top: 8px; }
.checks li { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); }
.checks li:first-child { border-top: 0; }
.checks li > span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.checks li.done > span { color: var(--ink-3); text-decoration: line-through; }
.check { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--ink-3); flex: none; display: inline-flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 800; }
.check.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.checks.numbered { counter-reset: step; }
.checks.numbered li > span::before { counter-increment: step; content: counter(step) ". "; color: var(--ink-3); font-weight: 600; }
.checks + .inline-form { margin-top: 6px; }

/* ---------- food ---------- */
.datenav { display: flex; align-items: center; gap: 8px; }
.datenav-lbl { flex: 1; text-align: center; font-weight: 700; font-size: 17px; display: flex; flex-direction: column; }
.datenav-lbl small { font-weight: 500; color: var(--ink-2); }
.datenav .icon-btn { background: var(--card); border: 1px solid var(--line); }
.tot-main { font-size: 17px; font-variant-numeric: tabular-nums; }
.tot-main b { font-size: 26px; }
.tot-macros { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 4px; color: var(--ink-2); font-size: 14px; font-variant-numeric: tabular-nums; }
.tot-macros b { color: var(--ink); }
.meal-head { display: flex; align-items: center; gap: 8px; }
.meal-head h3 { margin: 0; flex: 1; }
.entries { margin-top: 8px; }
.entries li + li { border-top: 1px solid var(--line); }
.entry { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; text-align: left; }
.e-name, .r-name { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; font-weight: 550; }
.e-name small, .r-name small, .ing-name small { color: var(--ink-2); font-weight: 400; }
.tag { width: fit-content; }
.e-kcal { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; display: flex; flex-direction: column; flex: none; }
.e-kcal small { color: var(--ink-2); font-weight: 500; }
.lib li + li { border-top: 1px solid var(--line); }
.lib button { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; text-align: left; }
.lib + .eyebrow, .btn-row + .eyebrow { margin-top: 14px; }

/* ---------- gym ---------- */
.session-title { font-size: 24px; margin-bottom: 4px; }
.ex li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); }
.ex li:first-child { border-top: 0; }
.ex li b { font-variant-numeric: tabular-nums; white-space: nowrap; }
.ex .ex-group { font-size: 13px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .03em; padding-top: 14px; }
.empty { text-align: center; padding: 28px 16px; }
.empty h2 { margin-bottom: 6px; }
.done-banner { text-align: center; font-weight: 700; color: var(--good); background: var(--accent-soft); border-radius: 14px; padding: 10px; }

/* ---------- prep ---------- */
.seg { display: flex; background: var(--chip); border-radius: 12px; padding: 3px; gap: 2px; margin: 10px 0; }
.seg button { flex: 1; min-height: 36px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--ink-2); padding: 0 4px; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.seg.wide { margin: 0; }
.group { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); margin: 8px 2px -4px; }
.recipe-row { display: flex; align-items: center; gap: 10px; }
.recipe-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; text-align: left; }
.ings-view { margin-top: 10px; }
.ings-view li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 15px; }
.ings-view li > span:first-child { display: flex; flex-direction: column; }
.ings-view li > span:last-child { text-align: right; white-space: nowrap; }
.notes { white-space: pre-line; color: var(--ink-2); font-size: 15px; margin: 10px 0 0; }
.prep-head { display: flex; justify-content: space-between; align-items: flex-start; }
.b-portion { text-align: right; font-weight: 700; display: flex; flex-direction: column; flex: none; }
.b-portion small { font-weight: 500; color: var(--ink-2); }

/* ---------- week ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; box-shadow: var(--shadow); }
.tile-lbl { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.tile-val { font-size: 26px; font-weight: 750; font-variant-numeric: tabular-nums; margin: 2px 0; }
.tile-sub { font-size: 13px; color: var(--ink-2); }
.days li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.days li:first-child { border-top: 0; }
.days li.is-today .d-name b { color: var(--accent); }
.d-name { width: 48px; display: flex; flex-direction: column; flex: none; }
.d-name small { color: var(--ink-2); }
.d-main { flex: 1; min-width: 0; font-size: 15px; font-variant-numeric: tabular-nums; }
.d-sub { display: flex; gap: 10px; font-size: 13px; color: var(--ink-2); }
.status { font-size: 13px; font-weight: 700; text-align: right; flex: none; }
.good { color: var(--good); }
.warn { color: var(--warn); }
.status.muted { color: var(--ink-3); font-weight: 500; }

.chart { position: relative; margin-top: 8px; }
.chart svg { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .ax { fill: var(--ink-3); font-size: 11px; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.chart .lastlbl { fill: var(--ink); font-size: 12px; font-weight: 700; }
.chart .xh { stroke: var(--ink-3); stroke-width: 1; }
.chart .hit { fill: transparent; }
.tip { position: absolute; transform: translateX(-50%); background: var(--ink); color: var(--bg); font-size: 13px; font-weight: 600; padding: 4px 8px; border-radius: 8px; white-space: nowrap; pointer-events: none; }
.chart-empty { padding: 12px 0; }
.wtable { margin-top: 10px; font-size: 14px; }
.wtable summary { color: var(--accent); font-weight: 600; cursor: pointer; padding: 6px 0; }
.wtable table { width: 100%; border-collapse: collapse; }
.wtable td { padding: 5px 0; border-top: 1px solid var(--line); }
.wtable td:last-child { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- sheet ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; }
.backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .4); opacity: 0; transition: opacity .2s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 560px;
  max-height: calc(100% - env(safe-area-inset-top) - 24px); overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  background: var(--card); border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 20px);
  transform: translateY(100%); transition: transform .22s ease;
}
.sheet-wrap.open .backdrop { opacity: 1; }
.sheet-wrap.open .sheet { transform: none; }
.sheet-head { position: sticky; top: -8px; z-index: 2; display: flex; align-items: center; gap: 4px; padding: 8px 0; background: var(--card); }
.sheet-head h2 { flex: 1; font-size: 18px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-head .sp { width: 40px; flex: none; }
.sheet .eyebrow { margin-top: 12px; }
.search { margin-top: 4px; }
.results li + li { border-top: 1px solid var(--line); }
.result { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; text-align: left; }
#ingres .results { margin-top: 4px; }
.amount { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.amount input { font-size: 28px; font-weight: 700; text-align: center; max-width: 160px; min-height: 56px; }
.amount span { font-size: 18px; font-weight: 600; color: var(--ink-2); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 36px; padding: 6px 12px; border-radius: 99px; background: var(--chip); font-size: 14px; font-weight: 600; }
.live { margin: 14px 0; padding: 12px 14px; border-radius: 14px; background: var(--accent-soft); }
.live-kcal { font-size: 30px; font-weight: 750; font-variant-numeric: tabular-nums; }
.live-kcal small { font-size: 16px; font-weight: 600; }
.live-macros { font-weight: 600; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.sheet .btn.block { margin-top: 10px; }
.ings li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.ings li:first-child { border-top: 0; }
.ing-name { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 15px; overflow-wrap: anywhere; }
.ings input { width: 76px; min-height: 40px; padding: 6px 8px; text-align: right; }
.total { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: var(--accent-soft); font-size: 14px; display: flex; flex-direction: column; gap: 3px; font-variant-numeric: tabular-nums; }

/* ---------- toast & lock ---------- */
.toast {
  position: fixed; left: 16px; right: 16px; z-index: 60; margin: 0 auto; width: fit-content; max-width: 528px;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
  display: flex; align-items: center; gap: 14px;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 14px; font-weight: 600; font-size: 15px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.noscroll .toast { bottom: auto; top: calc(env(safe-area-inset-top) + 12px); }
.toast button { color: var(--accent); font-weight: 800; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .toast button { color: #0e8a66; } }
.lock { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; background: var(--bg); }
.lock-card { width: 100%; max-width: 360px; text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.lock-icon { border-radius: 18px; }
.lock-card h1 { font-size: 30px; }
.lock-card p { margin: 0; }
.lock-card input { text-align: center; font-size: 20px; letter-spacing: .06em; }
.err { color: var(--danger); min-height: 20px; font-size: 14px; }
[hidden] { display: none !important; }
