:root {
  color-scheme: light;
  --bg: #e8edef;
  --surface: #ffffff;
  --surface-2: #f2f5f6;
  --rule: #dce3e6;
  --ink: #0f1f29;
  --ink-2: #44545e;
  --muted: #74838b;
  --hero: #0f1f29;
  --hero-ink: #f2f6f7;
  --hero-muted: #9db0b9;
  --hero-track: #233743;
  --lime: #c6f432;
  --sky: #8ecbff;
  --trend: #4d7c0f;
  --dot: #a8b5bb;
  --bad: #d33f36;
  --good: #2e7d32;
  --btn: #0f1f29;
  --btn-ink: #ffffff;
  --focus: #4d7c0f;
  --toast-action: #c6f432;
  --display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --body: "Barlow", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0b151b; --surface: #13212a; --surface-2: #192b36; --rule: #233845;
    --ink: #e9f0f2; --ink-2: #b2c1c8; --muted: #7d919a;
    --hero: #1a2f3b; --hero-track: #2a4352;
    --trend: #c6f432; --dot: #4c606c; --bad: #ff7b6e; --good: #8fd694;
    --btn: #c6f432; --btn-ink: #0f1f29; --focus: #c6f432; --toast-action: #3f6b00;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--body);
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h2 { font: 600 18px/1.2 var(--body); margin: 0 0 14px; }
.num { font-family: var(--display); font-weight: 600; letter-spacing: 0.005em; }

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 10px; border: 0;
  background: var(--surface-2); color: var(--ink); font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--btn); color: var(--btn-ink); }
.btn.quiet { background: transparent; color: var(--ink-2); padding: 0 10px; }
.btn:disabled { opacity: 0.35; cursor: default; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 13px; color: var(--ink-2); }
.field input {
  width: 100%; min-height: 46px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--rule); background: var(--surface-2); font-size: 17px;
}
.field input:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 1px var(--focus); }
.field input::placeholder { color: var(--muted); }

/* ---------- sign-in ---------- */
.gate {
  min-height: 100vh; min-height: 100dvh; background: var(--hero); color: var(--hero-ink);
  display: flex; align-items: center; justify-content: center; padding: 32px 24px;
}
.gate-inner { width: 100%; max-width: 400px; }
.gate-art { display: block; width: 100%; height: auto; margin-bottom: 28px; }
.wordmark {
  font: 700 clamp(64px, 20vw, 96px)/0.86 var(--display); text-transform: uppercase;
  letter-spacing: -0.01em; margin: 0 0 20px;
}
.wordmark span { color: var(--lime); }
.gate p { color: var(--hero-muted); font-size: 17px; margin: 0 0 28px; max-width: 34ch; }
.google {
  width: 100%; min-height: 54px; border-radius: 12px; border: 0; cursor: pointer;
  background: #ffffff; color: #1f1f1f; font-weight: 600; font-size: 17px;
  display: flex; align-items: center; justify-content: center; gap: 12px;
}
.google:focus-visible { outline-color: var(--lime); }
.gate .note { color: #ffb4ab; font-size: 14px; min-height: 1.4em; margin: 14px 0 0; }

/* ---------- app shell ---------- */
.app { max-width: 1080px; margin: 0 auto; padding: 0 16px 56px; padding-bottom: calc(56px + env(safe-area-inset-bottom)); }
.top {
  display: flex; align-items: center; gap: 12px; padding: 14px 0 6px;
  padding-top: max(14px, env(safe-area-inset-top));
}
.brand { font: 700 24px/1 var(--display); text-transform: uppercase; letter-spacing: 0.01em; margin-right: auto; }
.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.sync i { width: 7px; height: 7px; border-radius: 50%; background: var(--good); }
.sync.busy i { background: var(--dot); }
.sync.warn { color: var(--bad); }
.sync.warn i { background: var(--bad); }
.avatar-btn { width: 36px; height: 36px; border-radius: 50%; border: 0; padding: 0; overflow: hidden; background: var(--surface-2); cursor: pointer; }
.avatar-btn img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-btn::after { content: attr(data-initial); font: 700 17px/36px var(--display); color: var(--ink-2); }

.daynav { display: flex; align-items: center; gap: 4px; margin: 6px 0 14px; }
.daynav .arrow { width: 44px; height: 44px; border-radius: 10px; border: 0; background: transparent; font-size: 24px; color: var(--ink-2); cursor: pointer; }
.daynav .arrow:disabled { opacity: 0.25; cursor: default; }
.daypick { position: relative; flex: 1; text-align: center; }
.daypick button { border: 0; background: transparent; cursor: pointer; padding: 4px 12px; }
.daypick .d1 { display: block; font: 700 28px/1 var(--display); text-transform: uppercase; }
.daypick .d2 { display: block; font-size: 14px; color: var(--muted); margin-top: 2px; }
.daypick input { position: absolute; inset: 0; opacity: 0; pointer-events: none; }
.back-today { font-size: 14px; font-weight: 600; color: var(--trend); background: none; border: 0; padding: 0 8px; min-height: 44px; cursor: pointer; }

.layout { display: grid; gap: 14px; grid-template-columns: 1fr; }
.col { display: grid; gap: 14px; align-content: start; min-width: 0; }
/* On phones the two desktop columns melt into one list, ordered by how often each part is used (--order on each section). */
@media (max-width: 899px) {
  .col { display: contents; }
  .layout > .col > * { order: var(--order); }
}
@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
  .col { gap: 18px; }
}
.card { background: var(--surface); border-radius: 16px; padding: 18px; min-width: 0; }

/* ---------- today panel ---------- */
.hero { background: var(--hero); color: var(--hero-ink); border-radius: 22px; padding: 22px 20px 20px; }
.hero-top { display: flex; align-items: baseline; gap: 10px; }
.hero-big { font: 700 clamp(72px, 22vw, 104px)/0.85 var(--display); letter-spacing: -0.02em; }
.hero-big.over { color: #ff8a7a; }
.hero-unit { font: 600 20px/1.1 var(--display); color: var(--hero-muted); text-transform: uppercase; }
.meter { height: 12px; border-radius: 6px; background: var(--hero-track); overflow: hidden; margin: 18px 0 8px; }
.meter > span { display: block; height: 100%; width: 0; background: var(--lime); border-radius: 6px; transition: width .35s ease; }
.meter.over > span { background: #ff8a7a; }
.meter.sm { height: 8px; margin: 8px 0 0; }
.meter.sm > span { background: var(--sky); }
.hero-row { display: flex; justify-content: space-between; font-size: 15px; color: var(--hero-muted); }
.hero-row b { color: var(--hero-ink); font-weight: 600; }
.hero-protein { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--hero-track); }
.hero-protein .hero-row { align-items: baseline; }
.hero-protein .p-val { font: 600 30px/1 var(--display); color: var(--hero-ink); }
.hero-protein .p-val small { font-size: 18px; color: var(--hero-muted); font-weight: 500; }
.hero-hint { font-size: 14px; color: var(--hero-muted); margin: 10px 0 0; }
.hero-hint button { color: var(--lime); background: none; border: 0; padding: 0; font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
@media (prefers-reduced-motion: reduce) { .meter > span { transition: none; } }

/* ---------- add food ---------- */
.presets { display: flex; gap: 8px; overflow-x: auto; margin: 0 -18px 16px; padding: 2px 18px 4px; scrollbar-width: none; }
.presets::-webkit-scrollbar { display: none; }
.chip {
  flex: none; text-align: left; border: 1px solid var(--rule); background: var(--surface-2);
  border-radius: 12px; padding: 8px 14px; cursor: pointer; min-height: 52px;
}
.chip b { display: block; font-weight: 600; font-size: 15px; }
.chip span { display: block; font-size: 13px; color: var(--muted); }
.chip:active { transform: scale(0.97); }
.presets-empty { font-size: 14px; color: var(--muted); margin: -4px 0 14px; }

.food-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.food-form .name { grid-column: 1 / -1; }
.form-foot { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; color: var(--ink-2); cursor: pointer; min-height: 44px; }
.check input { width: 20px; height: 20px; accent-color: var(--trend); margin: 0; }
.form-foot .btn { min-width: 120px; }
.form-error { grid-column: 1 / -1; color: var(--bad); font-size: 14px; margin: -2px 0 0; }

.entries { list-style: none; padding: 0; margin: 18px 0 0; }
.entries li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--rule); }
.entries .e-main { flex: 1; min-width: 0; }
.entries .e-name { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entries .e-meta { display: block; font-size: 13px; color: var(--muted); }
.entries .e-kcal { font: 600 22px/1 var(--display); }
.entries .e-kcal small { font-size: 14px; color: var(--muted); font-weight: 500; margin-left: 2px; }
.icon-btn { width: 40px; height: 40px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; flex: none; }
.icon-btn:hover { color: var(--bad); background: var(--surface-2); }
.empty { color: var(--muted); font-size: 15px; padding: 14px 0 2px; border-top: 1px solid var(--rule); }

/* ---------- weight ---------- */
.weight-form { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; }
.stat .label { font-size: 13px; color: var(--ink-2); }
.stat .value { font: 600 34px/1.05 var(--display); margin-top: 2px; }
.stat .value small { font-size: 17px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.stat .sub { font-size: 13px; color: var(--muted); }
.stat .value.down { color: var(--good); }
.stat .value.up { color: var(--bad); }
.link-btn { background: none; border: 0; padding: 0; color: var(--ink-2); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; margin-top: 4px; }

/* ---------- trend ---------- */
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.chart-head h2 { margin: 0; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; border-radius: 8px; padding: 6px 10px; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; min-height: 34px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(15, 31, 41, .12); }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--ink-2); margin: 4px 0 6px; }
.legend i { display: inline-block; vertical-align: middle; margin-right: 6px; }
.legend .l-line { width: 16px; height: 3px; border-radius: 2px; background: var(--trend); }
.legend .l-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dot); }
.chart-wrap { position: relative; touch-action: pan-y; }
.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-wrap text { fill: var(--muted); font: 12px var(--body); }
.tooltip {
  position: absolute; pointer-events: none; background: var(--ink); color: var(--surface);
  border-radius: 10px; padding: 8px 12px; font-size: 13px; white-space: nowrap;
  transform: translate(-50%, calc(-100% - 10px)); display: none;
}
.tooltip b { display: block; font-weight: 600; margin-bottom: 2px; }

.grid4 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- history & settings ---------- */
details.card > summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; font-weight: 600; font-size: 18px; min-height: 28px; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: "+"; font: 500 26px/1 var(--display); color: var(--muted); }
details.card[open] > summary::after { content: "–"; }
details.card[open] > summary { margin-bottom: 12px; }
.table-scroll { overflow-x: auto; max-height: 440px; overflow-y: auto; margin: 0 -6px; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: right; padding: 9px 6px; border-top: 1px solid var(--rule); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-weight: 500; color: var(--muted); font-size: 13px; border-top: 0; position: sticky; top: 0; background: var(--surface); }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--surface-2); }

.settings-block + .settings-block { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--rule); }
.settings-block h3 { font-size: 15px; font-weight: 600; margin: 0 0 10px; }
.goal-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.preset-list { list-style: none; padding: 0; margin: 0; }
.preset-list li { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.preset-list .p-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preset-list .p-meta { color: var(--muted); font-size: 14px; }
.muted { color: var(--muted); font-size: 14px; margin: 0; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.account-row { display: flex; align-items: center; gap: 12px; }
.account-row img { width: 40px; height: 40px; border-radius: 50%; }
.account-row .who { flex: 1; min-width: 0; }
.account-row .who b { display: block; font-weight: 600; }
.account-row .who span { display: block; font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }

.banner { background: var(--surface); border-radius: 16px; padding: 14px 18px; margin-bottom: 14px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.banner p { margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--surface); border-radius: 12px; padding: 6px 6px 6px 16px;
  display: flex; align-items: center; gap: 12px; font-size: 15px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { background: transparent; border: 0; color: var(--toast-action); font-weight: 600; min-height: 40px; padding: 0 12px; cursor: pointer; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
.hint { margin-top: 8px; }

/* ---------- settings popup: a bottom sheet on phones, a centred panel on wider screens ---------- */
.sheet {
  border: 0; padding: 0 20px 24px; color: var(--ink); background: var(--surface);
  width: 100%; max-width: 100%; max-height: 88dvh; margin: auto 0 0; border-radius: 22px 22px 0 0;
  padding-bottom: calc(24px + env(safe-area-inset-bottom)); overflow-y: auto; overscroll-behavior: contain;
}
.sheet::backdrop { background: rgba(8, 16, 22, 0.55); }
.sheet[open] { animation: sheet-up .22s ease-out; }
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } }
@media (min-width: 640px) {
  .sheet { max-width: 480px; margin: auto; border-radius: 20px; }
}
@media (prefers-reduced-motion: reduce) { .sheet[open] { animation: none; } }
.sheet-head {
  position: sticky; top: 0; z-index: 1; background: var(--surface);
  display: flex; align-items: center; justify-content: space-between; padding: 18px 0 10px;
}
.sheet-head h2 { margin: 0; }
.sheet-head h2:focus { outline: none; }

/* ---------- progress ---------- */
.progress-top { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; }
.progress-big { font: 700 56px/0.95 var(--display); letter-spacing: -0.01em; }
.progress-big.down { color: var(--good); }
.progress-big.up { color: var(--bad); }
.progress-since { color: var(--ink-2); font-size: 15px; }
.goal-track { height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; margin: 16px 0 6px; }
.goal-track > span { display: block; height: 100%; width: 0; background: var(--trend); border-radius: 5px; transition: width .35s ease; }
.progress-row { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); }
.legend .l-dash { width: 16px; height: 0; border-top: 2px dashed var(--trend); }
.legend .l-bar { width: 8px; height: 12px; border-radius: 2px 2px 0 0; background: var(--trend); }
.legend .l-bar.over { background: var(--bad); }
.legend .l-dash.ink { border-top-color: var(--ink-2); }
td.down { color: var(--good); }
td.up { color: var(--bad); }
@media (prefers-reduced-motion: reduce) { .goal-track > span { transition: none; } }
.progress-big small { font-size: 24px; font-weight: 500; color: var(--muted); }
