:root {
  /* Light (default) */
  --bg: #f4f4f7;
  --surface: #ffffff;
  --surface-2: #f0f0f4;
  --text: #1d1d1f;
  --muted: #86868b;
  --faint: #a1a1a6;
  --separator: rgba(60, 60, 67, 0.10);
  --blue: #007aff;
  --green: #34c759;
  --red: #ff3b30;
  --amber: #ff9f0a;
  --ring-track: #e8e8ec;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 14px 30px -12px rgba(0, 0, 0, 0.12);

  --r-lg: 22px;
  --r-md: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --text: #f5f5f7;
    --muted: #98989f;
    --faint: #8e8e93;
    --separator: rgba(84, 84, 88, 0.55);
    --blue: #0a84ff;
    --green: #30d158;
    --red: #ff453a;
    --amber: #ffd60a;
    --ring-track: #2a2a2c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 16px 34px -14px rgba(0, 0, 0, 0.7);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(40px + var(--safe-bottom));
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.ic { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; display: block; }

main { padding: 0 20px; max-width: 480px; margin: 0 auto; }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 20px 12px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}
.brand { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.date-pill {
  appearance: none;
  background: var(--surface-2);
  color: var(--text);
  border: none;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 590;
  letter-spacing: -0.01em;
}
.date-pill:active { opacity: 0.6; }

/* Hero */
.hero { text-align: center; padding: 22px 0 26px; }
.ring-wrap { position: relative; width: 216px; height: 216px; margin: 0 auto; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
.ring-bg { fill: none; stroke: var(--ring-track); stroke-width: 13; }
.ring-fg {
  fill: none;
  stroke: url(#ringGood);
  stroke-width: 13;
  stroke-linecap: round;
  stroke-dasharray: 326.7;
  stroke-dashoffset: 326.7;
  transition: stroke-dashoffset 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}
.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.net-value {
  font-size: 54px;
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.net-label { font-size: 14px; color: var(--muted); margin-top: 7px; letter-spacing: -0.01em; }

.verdict { margin: 20px auto 0; font-size: 15px; color: var(--muted); font-weight: 500; letter-spacing: -0.01em; min-height: 19px; }

.pills {
  display: inline-flex;
  align-items: center;
  gap: 22px;
  margin-top: 20px;
  padding: 14px 22px;
  background: var(--surface);
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.pill { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.pill-label { font-size: 12px; color: var(--muted); letter-spacing: -0.01em; }
.pill-value { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.pill-sep { width: 1px; height: 30px; background: var(--separator); }

.move-goal {
  display: flex;
  align-items: center;
  gap: 12px;
  width: max-content;
  max-width: 320px;
  margin: 14px auto 0;
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 18px 8px 8px;
  box-shadow: var(--shadow);
}
.move-goal.hidden { display: none; }
.move-ring { width: 44px; height: 44px; flex-shrink: 0; }
.move-ring .gauge { width: 44px; height: 44px; transform: rotate(-90deg); }
.move-text { display: flex; flex-direction: column; text-align: left; }
.move-label { font-size: 12px; color: var(--muted); letter-spacing: -0.01em; }
.move-val { font-size: 13px; font-weight: 590; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.move-pct { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-left: 2px; }

/* Actions */
.actions { margin: 4px 0 30px; }
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: var(--r-md);
  padding: 15px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
}
.btn-primary .ic { width: 21px; height: 21px; stroke-width: 1.7; }
.btn-primary:active { opacity: 0.85; transform: scale(0.99); }
.btn-text {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--blue);
  font-size: 15px;
  font-weight: 500;
  padding: 14px;
  letter-spacing: -0.01em;
}
.btn-text:active { opacity: 0.5; }

/* Section groups */
.group { margin-bottom: 30px; }
.eyebrow {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: -0.01em;
  margin: 0 0 10px 4px;
}
.eyebrow-note { color: var(--faint); font-weight: 500; }

/* Nutrition grid */
.nutri-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.ncell {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 15px 6px 13px;
  box-shadow: var(--shadow);
  text-align: center;
}
.gauge-wrap { position: relative; width: 62px; height: 62px; margin: 0 auto 9px; }
.gauge { width: 62px; height: 62px; transform: rotate(-90deg); }
.g-bg { fill: none; stroke: var(--ring-track); stroke-width: 6; }
.g-fg { fill: none; stroke-width: 6; stroke-linecap: round; transition: stroke-dashoffset 0.6s cubic-bezier(0.22, 1, 0.36, 1); }
.gauge-pct {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 600; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.ncell-label { font-size: 13px; font-weight: 590; letter-spacing: -0.01em; }
.ncell-abs { font-size: 11px; color: var(--muted); margin-top: 2px; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }

/* Weekly balance chart */
.week-card {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 18px 16px 14px;
  box-shadow: var(--shadow);
  min-height: 150px;
}
.wc-svg { width: 100%; height: auto; display: block; overflow: visible; }
.wc-weekend { fill: var(--surface-2); }
.wc-baseline { stroke: var(--separator); stroke-width: 1; }
.wc-bar { transition: y 0.5s cubic-bezier(0.22, 1, 0.36, 1), height 0.5s cubic-bezier(0.22, 1, 0.36, 1); }
.wc-dot { fill: var(--faint); opacity: 0.5; }
.wc-labels { display: flex; margin-top: 8px; }
.wc-labels span {
  flex: 1;
  text-align: center;
  font-size: 10px;
  color: var(--faint);
  letter-spacing: -0.01em;
}
.wc-labels span.wknd { color: var(--muted); font-weight: 700; }
.wc-labels span.today { color: var(--text); font-weight: 700; }
.wc-empty { text-align: center; color: var(--muted); font-size: 14px; padding: 20px 8px; letter-spacing: -0.01em; }

/* Trends */
.trend-cards { display: flex; gap: 12px; }
.trend-card {
  flex: 1;
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 16px 16px 15px;
  box-shadow: var(--shadow);
}
.trend-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 8px; letter-spacing: -0.01em; }
.trend-value { display: block; font-size: 25px; font-weight: 600; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.trend-sub { font-size: 12px; color: var(--muted); letter-spacing: -0.01em; }
.trend-card.good .trend-value, .trend-card.good .trend-sub { color: var(--green); }
.trend-card.bad .trend-value, .trend-card.bad .trend-sub { color: var(--red); }

.weight-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 16px;
  margin-top: 12px;
  box-shadow: var(--shadow);
}
.weight-icon {
  width: 38px; height: 38px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
}
.weight-icon .ic { width: 20px; height: 20px; }
.weight-card.good .weight-icon { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); }
.weight-card.bad .weight-icon { background: color-mix(in srgb, var(--red) 16%, transparent); color: var(--red); }
.weight-text { display: flex; flex-direction: column; }
.weight-value { font-size: 17px; font-weight: 600; letter-spacing: -0.02em; }
.weight-card.good .weight-value { color: var(--green); }
.weight-card.bad .weight-value { color: var(--red); }
.weight-cap { font-size: 12px; color: var(--muted); margin-top: 2px; letter-spacing: -0.01em; }

.trend-note { font-size: 12px; color: var(--faint); margin: 12px 4px 0; letter-spacing: -0.01em; line-height: 1.4; }

/* Food log — iOS inset grouped list */
.food-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.food-list:empty { display: none; }
.food-item {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 12px 14px;
  position: relative;
}
.food-item + .food-item::before {
  content: "";
  position: absolute;
  top: 0; left: 61px; right: 0;
  height: 1px;
  background: var(--separator);
}
.food-thumb {
  width: 42px; height: 42px; border-radius: 11px; object-fit: cover;
  background: var(--surface-2); flex-shrink: 0;
}
.food-thumb.placeholder { display: flex; align-items: center; justify-content: center; color: var(--faint); }
.food-thumb.placeholder .ic { width: 20px; height: 20px; }
.food-info { flex: 1; min-width: 0; }
.food-name { font-size: 16px; font-weight: 500; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.food-meta { font-size: 13px; color: var(--muted); letter-spacing: -0.01em; margin-top: 1px; }
.food-cal { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.food-del { background: none; border: none; color: var(--faint); padding: 6px; display: flex; }
.food-del .ic { width: 19px; height: 19px; }
.food-del:active { opacity: 0.5; }
.empty { text-align: center; color: var(--muted); font-size: 15px; padding: 26px 20px; letter-spacing: -0.01em; }
.empty.hidden { display: none; }

/* Sheet */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  animation: fade 0.2s ease;
}
.sheet.hidden { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet-panel {
  background: var(--surface);
  width: 100%;
  max-width: 480px;
  border-radius: 26px 26px 0 0;
  padding: 8px 20px calc(22px + var(--safe-bottom));
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.34s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.grabber { width: 36px; height: 5px; border-radius: 999px; background: var(--separator); margin: 6px auto 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h3 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.02em; }
.icon-btn { background: var(--surface-2); border: none; color: var(--muted); width: 30px; height: 30px; border-radius: 999px; display: flex; align-items: center; justify-content: center; }
.icon-btn .ic { width: 17px; height: 17px; }
.icon-btn:active { opacity: 0.6; }
.preview { width: 100%; max-height: 200px; object-fit: cover; border-radius: var(--r-md); margin-bottom: 16px; }

.describe-area { margin-bottom: 16px; }
.describe-input {
  width: 100%;
  background: var(--surface-2);
  border: none;
  border-radius: var(--r-md);
  padding: 12px 13px;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  letter-spacing: -0.01em;
  line-height: 1.4;
  resize: none;
  margin-bottom: 10px;
}
.describe-input:focus { outline: 2px solid color-mix(in srgb, var(--blue) 55%, transparent); }

.analyzing { text-align: center; padding: 34px 0; color: var(--muted); font-size: 15px; letter-spacing: -0.01em; }
.analyzing.hidden { display: none; }
.spinner {
  width: 34px; height: 34px; margin: 0 auto 16px;
  border: 3px solid var(--surface-2);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.edit-area.hidden { display: none; }
.items-editor { display: flex; flex-direction: column; gap: 10px; }
.item-row { display: grid; grid-template-columns: 1fr 80px 28px; gap: 8px; align-items: center; }
.item-row input {
  background: var(--surface-2);
  border: none;
  border-radius: 11px;
  padding: 12px 13px;
  color: var(--text);
  font-size: 16px;
  letter-spacing: -0.01em;
  width: 100%;
  font-family: inherit;
}
.item-row input:focus { outline: 2px solid color-mix(in srgb, var(--blue) 55%, transparent); }
.item-row input.cal { text-align: right; font-variant-numeric: tabular-nums; }
.item-row .row-del { background: none; border: none; color: var(--faint); display: flex; justify-content: center; padding: 4px; }
.item-row .row-del .ic { width: 18px; height: 18px; }
.add-item {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  background: none; border: none; color: var(--blue);
  padding: 14px; width: 100%; font-size: 15px; font-weight: 500; letter-spacing: -0.01em; margin-top: 4px;
}
.add-item .ic { width: 18px; height: 18px; }
.add-item:active { opacity: 0.5; }

.total-row { display: flex; justify-content: space-between; align-items: baseline; margin: 14px 2px 4px; font-size: 15px; color: var(--muted); }
.total-row strong { font-size: 22px; color: var(--text); font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.analyze-macros { font-size: 12px; color: var(--muted); margin: 10px 2px 0; letter-spacing: -0.01em; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.analyze-macros span { white-space: nowrap; font-variant-numeric: tabular-nums; }
.analyze-note { font-size: 13px; color: var(--faint); margin: 8px 2px 0; letter-spacing: -0.01em; line-height: 1.45; }

.sheet-actions { margin-top: 18px; }
.btn-primary.wide { padding: 16px; }

.sheet-error {
  background: color-mix(in srgb, var(--red) 12%, transparent);
  color: var(--red);
  border-radius: var(--r-md);
  padding: 14px;
  font-size: 14px;
  letter-spacing: -0.01em;
  margin-top: 12px;
  white-space: pre-line;
  line-height: 1.4;
}
.sheet-error.hidden { display: none; }

/* Inline error banner */
.banner {
  max-width: 480px;
  margin: 4px auto 16px;
  background: color-mix(in srgb, var(--red) 10%, transparent);
  color: var(--red);
  border-radius: var(--r-md);
  padding: 12px 16px;
  font-size: 13px;
  letter-spacing: -0.01em;
  line-height: 1.4;
}
.banner.hidden { display: none; }
