:root {
  --bg: #101418;
  --surface: #182028;
  --surface-2: #212b35;
  --text: #e8edf2;
  --muted: #8b98a5;
  --border: #2a3540;
  --accent: #39d353;
  --accent-ink: #062b0e;
  --danger: #f85149;
  --protein: #58a6ff;
  --carbs: #e3b341;
  --fat: #db61a2;
  --track: #26313b;
  --hm-empty: #2a323b;
  --radius: 16px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-2: #eef1f4;
    --text: #15202b;
    --muted: #5d6b78;
    --border: #dde3e8;
    --accent: #1f9e3a;
    --accent-ink: #ffffff;
    --track: #e4e9ee;
    --hm-empty: #e1e5ea;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
}
h1, h2 { margin: 0; }
h2 { font-size: 1rem; margin-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.error { color: var(--danger); margin: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

.brand { font-size: 1.3rem; letter-spacing: .02em; }
.brand span { color: var(--accent); }
.title { font-size: 1.1rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--muted); }
input, textarea {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 12px; padding: 12px 16px; min-height: 46px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn:disabled { opacity: .45; cursor: default; }
.icon-btn {
  font-size: 1.2rem; width: 42px; height: 42px; border-radius: 12px; cursor: pointer;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
}
.link-btn { background: none; border: 0; color: var(--muted); text-decoration: underline; font: inherit; cursor: pointer; padding: 12px; }

/* ---------- login ---------- */
.login { min-height: 80vh; display: flex; flex-direction: column; justify-content: center; gap: 8px; }
.login .brand { font-size: 2rem; }
.login form { margin-top: 16px; }

/* ---------- topbar ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 8px; }
.topbar-actions { display: flex; gap: 8px; }

/* ---------- rings ---------- */
.rings { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.ring { position: relative; display: grid; place-items: center; }
.ring svg { transform: rotate(-90deg); display: block; }
.ring .track { stroke: var(--track); }
.ring .bar { transition: stroke-dashoffset .6s ease; stroke-linecap: round; }
.ring .over { stroke: var(--danger); stroke-linecap: round; }
.ring .label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-main .value { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.ring-main .unit { color: var(--muted); font-size: .9rem; }
.ring-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; }
.ring-small { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.ring-small .value { font-size: .85rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.ring-small .name { font-size: .8rem; color: var(--muted); }

/* ---------- meals ---------- */
.meals { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.meal { display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.meal img, .meal .ph { width: 48px; height: 48px; border-radius: 10px; object-fit: cover; background: var(--surface-2); display: grid; place-items: center; }
.meal .desc {
  font-weight: 600; overflow: hidden; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
}
.meal .meta { font-size: .8rem; color: var(--muted); }
.meal .kcal { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.meal .del { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: .8rem; padding: 4px 0 0; }
.empty { color: var(--muted); text-align: center; padding: 8px 0; }

/* ---------- heatmap ---------- */
.heatmap-wrap { overflow-x: auto; padding-bottom: 4px; direction: rtl; } /* starts scrolled at today */
.heatmap { direction: ltr; display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 13px); gap: 3px; width: max-content; }
.heatmap .d { width: 13px; height: 13px; border-radius: 3px; background: var(--hm-empty); border: 0; padding: 0; cursor: pointer; }
.heatmap .d.today { outline: 1.5px solid var(--text); outline-offset: 1px; }
.heatmap .d.future { visibility: hidden; }
.legend { display: flex; align-items: center; gap: 3px; font-size: .7rem; color: var(--muted); }
.legend i { width: 11px; height: 11px; border-radius: 2px; background: var(--c); display: inline-block; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom));
  font: inherit; font-weight: 700; font-size: 1.05rem;
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 999px;
  padding: 16px 28px; white-space: nowrap; box-shadow: 0 8px 24px rgba(0,0,0,.35); cursor: pointer;
}

/* ---------- add flow ---------- */
.photo-drop {
  border: 2px dashed var(--border); border-radius: var(--radius); min-height: 200px;
  display: grid; place-items: center; cursor: pointer; overflow: hidden; color: var(--text); font-size: 1.05rem;
}
.photo-drop img { width: 100%; max-height: 340px; object-fit: cover; display: block; }
.loading { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 32px 16px; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid var(--track); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.estimate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; margin-top: 10px; }
.estimate b { display: block; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.estimate span { font-size: .75rem; color: var(--muted); }

.q { padding: 14px 0; border-top: 1px solid var(--border); }
.q:first-of-type { border-top: 0; padding-top: 0; }
.q-text { font-weight: 600; margin-bottom: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit; font-weight: 600; cursor: pointer; min-height: 44px; padding: 8px 16px;
  border-radius: 12px; border: 1.5px solid var(--border); background: var(--surface-2); color: var(--text);
  text-transform: uppercase; font-size: .85rem; letter-spacing: .03em;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.grams { display: grid; grid-template-columns: 1fr 52px 52px auto; gap: 8px; align-items: center; }
.grams .gval { font-size: 1.15rem; font-weight: 700; text-align: center; background: var(--surface-2); border: 1.5px solid var(--border); border-radius: 12px; min-height: 44px; display: grid; place-items: center; font-variant-numeric: tabular-nums; }
.grams.touched .gval { border-color: var(--accent); }
.grams.unknown .gval { color: var(--muted); }
.grams .chip { padding: 8px 10px; text-transform: none; }
.round-info { font-size: .8rem; color: var(--muted); }
.skip { display: block; margin: 8px auto 0; }

.items { list-style: none; padding: 0; margin: 0; }
.items li { display: grid; grid-template-columns: minmax(0, 1fr) 84px 28px; overflow-wrap: anywhere; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--border); }
.items li:first-child { border-top: 0; }
.items .iname { font-weight: 600; }
.items .imacro { font-size: .75rem; color: var(--muted); }
.items input { width: 84px; padding: 8px; text-align: right; }
.items .rm { background: none; border: 0; color: var(--muted); font-size: 1.1rem; cursor: pointer; }

/* ---------- onboarding wizard ---------- */
.wiz-progress { flex: 1; height: 6px; background: var(--track); border-radius: 99px; overflow: hidden; margin: 0 6px; }
.wiz-progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }
.wiz { padding-top: 12px; }
.wiz-q { font-size: 1.5rem; font-weight: 700; margin: 8px 0 6px; }
.wiz-hint { color: var(--muted); margin: 0 0 22px; }
.choices { display: flex; flex-direction: column; gap: 10px; }
.choices .chip { text-transform: none; font-size: 1.05rem; min-height: 58px; text-align: left; padding: 12px 18px; }
.choices .chip small { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; margin-top: 2px; }
.choices .chip[aria-pressed="true"] small { color: inherit; opacity: .8; }
.stepper { display: grid; grid-template-columns: 64px 1fr 64px; gap: 10px; align-items: center; margin-bottom: 22px; }
.stepper .chip { font-size: 1.6rem; min-height: 64px; }
.stepper input { width: 100%; min-width: 0; font-size: 2rem; font-weight: 700; text-align: center; padding: 10px 4px; font-variant-numeric: tabular-nums; }
.wiz .btn { width: 100%; }
.breakdown { list-style: none; padding: 0; margin: 0 0 4px; }
.breakdown li { display: flex; justify-content: space-between; padding: 6px 0; border-top: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.breakdown li:first-child { border-top: 0; }
.breakdown li.total { font-weight: 700; }
.big-kcal { font-size: 3rem; font-weight: 800; text-align: center; color: var(--accent); font-variant-numeric: tabular-nums; line-height: 1.1; }
.goal-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.goal-grid input { width: 100%; min-width: 0; }

/* ---------- dialog ---------- */
dialog.sheet {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  width: min(420px, calc(100vw - 32px)); padding: 20px;
}
dialog.sheet::backdrop { background: rgba(0,0,0,.5); }
