:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --ink: #1f2420;
  --muted: #6b716b;
  --line: #e6e1d8;
  --accent: #2f8a57;
  --accent-ink: #ffffff;
  --accent-soft: #e3f1e8;
  --over: #d2553f;
  --over-soft: #fbe6e1;
  --water: #3a86c8;
  --water-soft: #e2eef8;
  --p: #c77d2b;
  --c: #3a86c8;
  --f: #9a5bb5;
  --shadow: 0 1px 2px rgba(31, 36, 32, 0.06), 0 2px 10px rgba(31, 36, 32, 0.05);
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151714;
    --card: #20231f;
    --ink: #eef0ec;
    --muted: #a0a69f;
    --line: #333731;
    --accent: #5cc58a;
    --accent-ink: #0d1a12;
    --accent-soft: #1f3528;
    --over: #f07d67;
    --over-soft: #3d2420;
    --water: #6aaeea;
    --water-soft: #1d2c3a;
    --p: #e0a05a;
    --c: #6aaeea;
    --f: #c18ad8;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 96px; }
label { display: block; font-weight: 600; margin: 14px 0 6px; font-size: 15px; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
h3 { font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.num { font-variant-numeric: tabular-nums; }

#app { max-width: 560px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 96px); }
.boot { display: grid; place-items: center; min-height: 70dvh; }
.spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 20px; border-radius: 14px;
  background: var(--accent); color: var(--accent-ink); font-weight: 650;
}
.btn.block { width: 100%; }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.plain { background: transparent; color: var(--accent); }
.btn.danger { background: var(--over-soft); color: var(--over); }
.btn:disabled { opacity: 0.5; }
.btn:active, .tap:active { transform: scale(0.98); }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; color: var(--ink); }
.icon-btn svg, .btn svg { width: 22px; height: 22px; }

/* sign in */
.gate { min-height: 80dvh; display: grid; place-content: center; text-align: center; gap: 16px; padding: 24px 8px; }
.logo { width: 84px; height: 84px; margin: 0 auto 4px; }
.gbtn { background: var(--card); color: var(--ink); border: 1.5px solid var(--line); }
.gbtn img { width: 22px; height: 22px; }
.lang-switch { display: inline-flex; gap: 6px; margin: 0 auto; }
.lang-switch button { padding: 6px 14px; border-radius: 999px; border: 1.5px solid var(--line); font-size: 15px; }
.lang-switch button.on { border-color: var(--accent); color: var(--accent); font-weight: 650; }

/* top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.daybar { display: flex; align-items: center; gap: 4px; }
.daybar .label { min-width: 150px; text-align: center; font-weight: 650; font-size: 18px; }
.sync { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.sync.offline .dot { background: var(--muted); }
.sync.error .dot { background: var(--over); }
.sync.syncing .dot { background: var(--water); }

/* ring */
.summary { display: flex; align-items: center; gap: 16px; }
.ring-wrap { position: relative; flex: none; }
.ring-wrap .center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-wrap .big { font-size: 32px; font-weight: 750; line-height: 1; }
.ring-bg { fill: none; stroke: var(--accent-soft); stroke-width: 14; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 14; stroke-linecap: round; transition: stroke-dashoffset 0.4s; }
.ring.over .ring-fg { stroke: var(--over); }
.ring.over .ring-bg { stroke: var(--over-soft); }
.over-text { color: var(--over); }
.stats { flex: 1; display: grid; gap: 10px; }
.stat b { display: block; font-size: 19px; }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.macro .bar-bg { height: 7px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: 4px; }
.macro .bar-fg { height: 100%; border-radius: 4px; }
.macro .k { font-size: 13px; color: var(--muted); }
.macro .v { font-size: 14px; font-weight: 600; }

/* meals */
.meal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.meal-head .kc { color: var(--muted); font-size: 15px; }
.add-btn { width: 40px; height: 40px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 26px; line-height: 1; display: grid; place-items: center; flex: none; }
.items { margin-top: 8px; }
.item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 10px 0; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item .n { font-weight: 550; overflow: hidden; text-overflow: ellipsis; }
.item .s { font-size: 14px; color: var(--muted); }
.item .k { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tag { font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); vertical-align: 2px; margin-left: 4px; }
.empty { color: var(--muted); font-size: 15px; padding: 6px 0 2px; }

/* water */
.glasses { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.glass { width: 34px; height: 42px; border-radius: 6px 6px 10px 10px; border: 2px solid var(--water); position: relative; overflow: hidden; }
.glass.full { background: var(--water); }
.glass.next { border-style: dashed; opacity: 0.7; }
.glass.next::after { content: "+"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--water); font-weight: 700; }

/* nav */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center; gap: 4px;
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px);
  background: var(--card); border-top: 1px solid var(--line);
}
.nav button { flex: 1; max-width: 160px; display: grid; justify-items: center; gap: 2px; padding: 6px 0; border-radius: 12px; color: var(--muted); font-size: 13px; font-weight: 600; }
.nav button svg { width: 24px; height: 24px; }
.nav button.on { color: var(--accent); background: var(--accent-soft); }

/* sheet */
.sheet { position: fixed; inset: 0; z-index: 10; background: var(--bg); overflow-y: auto; overscroll-behavior: contain; }
.sheet-in { max-width: 560px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 24px); }
.sheet-head { display: flex; align-items: center; gap: 6px; margin-bottom: 12px; position: sticky; top: 0; background: var(--bg); padding: 4px 0; z-index: 1; }
.sheet-head h2 { flex: 1; }
.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.quick button { background: var(--card); box-shadow: var(--shadow); border-radius: 16px; padding: 14px 6px; display: grid; justify-items: center; gap: 6px; font-weight: 600; font-size: 15px; }
.quick svg { width: 28px; height: 28px; color: var(--accent); }
.tabs { display: flex; gap: 6px; margin: 12px 0 6px; overflow-x: auto; }
.tabs button { padding: 8px 14px; border-radius: 999px; background: var(--card); border: 1.5px solid var(--line); font-size: 15px; font-weight: 600; white-space: nowrap; }
.tabs button.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.results .item { padding: 12px 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { padding: 10px 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); font-size: 15px; }
.chips button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button { width: 50px; height: 50px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); font-size: 26px; font-weight: 600; flex: none; }
.stepper input { text-align: center; font-size: 22px; font-weight: 650; }
.big-kcal { font-size: 36px; font-weight: 750; text-align: center; margin: 16px 0 4px; }
.mini-macros { display: flex; justify-content: center; gap: 16px; font-size: 14px; color: var(--muted); }
.mini-macros b { color: var(--ink); }
.star { font-size: 26px; color: var(--muted); }
.star.on { color: #e3a21a; }
.actions { display: flex; gap: 10px; margin-top: 18px; }
.actions .btn { flex: 1; }

.scan-video { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius); background: #000; display: block; }
.scan-frame { position: relative; }
.scan-frame::after { content: ""; position: absolute; left: 12%; right: 12%; top: 38%; bottom: 38%; border: 3px solid #fff; border-radius: 10px; opacity: 0.85; }
.photo-preview { width: 100%; max-height: 300px; object-fit: cover; border-radius: var(--radius); display: block; margin-bottom: 10px; }
.review-row { display: grid; grid-template-columns: 1fr 86px 70px 36px; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.review-row input { padding: 9px 10px; }
.review-row .k { text-align: right; font-weight: 600; font-size: 15px; }
.note { background: var(--accent-soft); color: var(--accent); border-radius: 12px; padding: 10px 12px; font-size: 14px; }

/* onboarding */
.steps { display: flex; gap: 6px; margin: 8px 0 18px; }
.steps i { flex: 1; height: 5px; border-radius: 3px; background: var(--line); }
.steps i.on { background: var(--accent); }
.choice { display: grid; gap: 10px; }
.choice button { text-align: left; padding: 14px 16px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--card); font-weight: 550; }
.choice button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.goal-big { font-size: 48px; font-weight: 800; color: var(--accent); text-align: center; }

/* reports */
.chart { width: 100%; height: auto; display: block; margin-top: 8px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 10px; }
.chart .bar { fill: var(--accent); }
.chart .bar.over { fill: var(--over); }
.chart .goal { stroke: var(--ink); stroke-width: 1.2; stroke-dasharray: 4 4; opacity: 0.55; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.chart .dot { fill: var(--card); stroke: var(--accent); stroke-width: 2; }
.chart.water .bar { fill: var(--water); }
.hbar { display: grid; grid-template-columns: 100px 1fr auto; gap: 10px; align-items: center; font-size: 15px; margin-top: 8px; }
.hbar .bg { height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; }
.hbar .fg { height: 100%; border-radius: 5px; }
.bmi-scale { position: relative; height: 12px; border-radius: 6px; margin: 18px 0 6px; background: linear-gradient(90deg, #7fb3e0 0 14%, #5cc58a 14% 41%, #e8c35a 41% 64%, #e89a5a 64% 82%, #d2553f 82%); }
.bmi-scale i { position: absolute; top: -6px; width: 4px; height: 24px; border-radius: 2px; background: var(--ink); transform: translateX(-2px); }

/* settings */
.list-btn { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 14px 2px; border-top: 1px solid var(--line); text-align: left; font-weight: 550; }
.list-btn:first-of-type { border-top: 0; }
.list-btn.danger { color: var(--over); }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 96px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 15px; font-weight: 600; z-index: 20;
  max-width: calc(100% - 32px); text-align: center;
}
