:root {
  --bg: #0b1220;
  --bg2: #111827;
  --card: #151e2e;
  --card2: #1a2438;
  --border: rgba(148, 163, 184, 0.14);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #10b981;
  --accent2: #34d399;
  --accent-dim: rgba(16, 185, 129, 0.15);
  --warn: #f59e0b;
  --danger: #ef4444;
  --protein: #60a5fa;
  --carbs: #fbbf24;
  --fat: #f472b6;
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 64px;
  font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  min-height: 100%;
  overscroll-behavior: none;
}
body {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(16,185,129,0.12), transparent 60%),
    var(--bg);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
img { max-width: 100%; display: block; }

.app-shell { min-height: 100dvh; padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px); }
.screen { display: none; padding: 20px 18px 8px; animation: fade .25s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -0.02em; }
.brand img { width: 36px; height: 36px; border-radius: 10px; }
.pill {
  font-size: 12px; padding: 6px 10px; border-radius: 999px;
  background: var(--accent-dim); color: var(--accent2); font-weight: 600;
}
.pill.warn { background: rgba(245,158,11,.15); color: var(--warn); }
.pill.demo { background: rgba(96,165,250,.15); color: var(--protein); }

h1 { font-size: 1.55rem; margin: 0 0 6px; letter-spacing: -0.03em; }
h2 { font-size: 1.15rem; margin: 0 0 12px; letter-spacing: -0.02em; }
.sub { color: var(--muted); font-size: 0.92rem; line-height: 1.45; margin: 0 0 18px; }

.card {
  background: linear-gradient(180deg, var(--card), var(--card2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.card.tight { padding: 12px 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 14px 16px; border-radius: 14px;
  font-weight: 650; letter-spacing: -0.01em;
  transition: transform .12s ease, opacity .12s ease, background .12s;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: linear-gradient(135deg, #10b981, #059669); color: #042f1e; }
.btn.secondary { background: rgba(148,163,184,.12); color: var(--text); border: 1px solid var(--border); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { background: rgba(239,68,68,.15); color: #fecaca; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.row { width: auto; padding: 10px 14px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

.goal-grid { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 16px; }
.goal-opt {
  text-align: left; padding: 14px 16px; border-radius: 14px;
  border: 1px solid var(--border); background: rgba(255,255,255,.02);
}
.goal-opt.active { border-color: var(--accent); background: var(--accent-dim); }
.goal-opt strong { display: block; margin-bottom: 2px; }
.goal-opt span { color: var(--muted); font-size: .86rem; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  background: rgba(0,0,0,.35); border: 1px solid var(--border); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.ring-wrap {
  display: grid; grid-template-columns: 140px 1fr; gap: 16px; align-items: center;
}
.ring {
  width: 140px; height: 140px; position: relative;
}
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { fill: none; stroke: rgba(148,163,184,.15); stroke-width: 10; }
.ring .prog { fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round;
  transition: stroke-dashoffset .4s ease; }
.ring .center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
}
.ring .center .big { font-size: 1.55rem; font-weight: 750; letter-spacing: -0.03em; }
.ring .center .lbl { font-size: .72rem; color: var(--muted); }

.macros { display: grid; gap: 10px; }
.macro { display: grid; grid-template-columns: 56px 1fr auto; gap: 8px; align-items: center; font-size: .88rem; }
.macro .bar { height: 8px; background: rgba(148,163,184,.12); border-radius: 99px; overflow: hidden; }
.macro .bar > i { display: block; height: 100%; border-radius: 99px; }
.macro.protein .bar > i { background: var(--protein); }
.macro.carbs .bar > i { background: var(--carbs); }
.macro.fat .bar > i { background: var(--fat); }
.macro .val { color: var(--muted); font-variant-numeric: tabular-nums; }

.fab-wrap { margin: 8px 0 18px; }
.capture-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.capture-card {
  padding: 22px 14px; border-radius: 16px; text-align: center;
  border: 1px dashed rgba(16,185,129,.4); background: rgba(16,185,129,.06);
}
.capture-card .ico { font-size: 1.6rem; margin-bottom: 6px; }
.capture-card strong { display: block; margin-bottom: 2px; }
.capture-card span { color: var(--muted); font-size: .8rem; }

.meal-list { display: grid; gap: 10px; }
.meal-item {
  display: grid; grid-template-columns: 1fr auto; gap: 8px;
  padding: 12px; border-radius: 14px; background: rgba(0,0,0,.22); border: 1px solid var(--border);
}
.meal-item .title { font-weight: 650; }
.meal-item .meta { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.meal-item .kcal { font-weight: 700; color: var(--accent2); }

.preview {
  width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 16px;
  background: #000; margin-bottom: 12px;
}
.edit-item {
  border: 1px solid var(--border); border-radius: 14px; padding: 12px; margin-bottom: 10px;
  background: rgba(0,0,0,.2);
}
.edit-item .row { display: grid; grid-template-columns: 1fr 90px; gap: 8px; margin-bottom: 8px; }
.edit-item .macros-mini { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; font-size: .75rem; color: var(--muted); }
.edit-item .actions { display: flex; justify-content: flex-end; margin-top: 8px; }

.nav {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 0; width: min(480px, 100%);
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding: 8px 10px var(--safe-bottom);
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: rgba(11,18,32,.92); backdrop-filter: blur(14px);
  border-top: 1px solid var(--border); z-index: 40;
}
.nav button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); font-size: .7rem; font-weight: 600; padding: 6px;
}
.nav button.active { color: var(--accent2); }
.nav .ico { font-size: 1.2rem; }

.empty {
  text-align: center; padding: 28px 12px; color: var(--muted);
}
.spinner {
  width: 28px; height: 28px; border: 3px solid rgba(255,255,255,.15);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite; margin: 20px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  background: #0f172a; border: 1px solid var(--border); color: var(--text);
  padding: 12px 16px; border-radius: 12px; z-index: 60;
  box-shadow: 0 12px 40px rgba(0,0,0,.4); max-width: min(420px, 92vw);
  display: none;
}
.toast.show { display: block; animation: fade .2s ease; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.hr { height: 1px; background: var(--border); margin: 14px 0; border: 0; }

.history-day { margin-bottom: 16px; }
.history-day h3 { font-size: .9rem; color: var(--muted); margin: 0 0 8px; font-weight: 600; }

.onboarding-hero {
  text-align: center; padding: 28px 8px 10px;
}
.onboarding-hero img { width: 88px; height: 88px; margin: 0 auto 14px; border-radius: 22px; }
