:root {
  --green: #3bb273;
  --green-dark: #2f6f4e;
  --orange: #ff8a3d;
  --bg: #f4f7f1;
  --card: #ffffff;
  --text: #1f2a1c;
  --muted: #6b7565;
  --line: #e3e8de;
  --carbs: #f5b83d;
  --fat: #4f8cff;
  --protein: #3bb273;
  --radius: 20px;
  --shadow: 0 6px 20px rgba(31, 42, 28, 0.07);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); }
h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.2; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 8px; line-height: 1.45; }
[hidden] { display: none !important; }

.app { max-width: 480px; margin: 0 auto; padding-bottom: 96px; }
.screen { padding: 12px 16px 24px; display: flex; flex-direction: column; gap: 14px; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px; background: rgba(244, 247, 241, 0.92); backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.1rem; color: var(--green-dark); }
.chips { display: flex; gap: 6px; }
.chip { background: var(--card); border-radius: 999px; padding: 5px 10px; font-weight: 700; font-size: 0.9rem; box-shadow: var(--shadow); white-space: nowrap; }
.chip.cloud { text-decoration: none; padding: 5px 8px; }
.chip.cloud.local { opacity: 0.6; }
.chip.cloud.signed-out, .chip.cloud.error { background: #fff4e0; }
@media (max-width: 430px) { .brand-name { display: none; } }
.heart { color: #c9d1c4; }
.heart.on { color: #ff5d73; }

/* bottom nav */
.bottomnav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}
.nav-item { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 0.72rem; color: var(--muted); text-decoration: none; }
.nav-item.active { color: var(--green-dark); font-weight: 700; }
.nav-icon { font-size: 1.25rem; }
.nav-add {
  justify-self: center; width: 56px; height: 56px; margin-top: -26px; border-radius: 50%;
  display: grid; place-items: center; background: var(--green); color: #fff;
  font-size: 2rem; text-decoration: none; box-shadow: 0 8px 18px rgba(59, 178, 115, 0.45);
}

/* cards */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.muted { color: var(--muted); }
.small-text { font-size: 0.85rem; }
.empty { text-align: center; color: var(--muted); padding: 18px; }
.disclaimer { font-size: 0.78rem; color: var(--muted); text-align: center; }

/* pet */
.pet-card { text-align: center; background: linear-gradient(180deg, #c9f1df 0%, #e9f8d9 72%, #d6f0c2 100%); }
.pet { display: grid; place-items: center; }
.pet svg { width: 100%; height: 100%; }
.pet-big { width: 190px; height: 190px; margin: 0 auto; }
.pet-medium { width: 140px; height: 140px; margin: 0 auto; }
.pet-small { width: 84px; height: 84px; }
.pet-big .pet-body, .pet-medium .pet-body { animation: bob 2.6s ease-in-out infinite; transform-origin: 100px 180px; }
.pet-eyes { animation: blink 5s infinite; transform-origin: 100px 110px; }
@keyframes bob { 0%, 100% { transform: translateY(0) scale(1, 1); } 50% { transform: translateY(-4px) scale(1.02, 0.98); } }
@keyframes blink { 0%, 95%, 100% { transform: scaleY(1); } 97% { transform: scaleY(0.1); } }
@media (prefers-reduced-motion: reduce) { .pet-body, .pet-eyes { animation: none !important; } }

/* today */
.today-grid { display: grid; grid-template-columns: 128px 1fr; gap: 14px; align-items: center; }
.ring { position: relative; width: 128px; height: 128px; }
.ring-svg, .ring-svg svg { width: 100%; height: 100%; }
.ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-label strong { font-size: 1.5rem; }
.ring-label span { font-size: 0.8rem; color: var(--muted); }
.remaining { font-weight: 700; }
.macro { margin-bottom: 8px; }
.macro-head { display: flex; justify-content: space-between; font-size: 0.82rem; margin-bottom: 4px; }
.bar { height: 8px; border-radius: 99px; background: #eef2ea; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 99px; }
.bar-fill.carbs { background: var(--carbs); }
.bar-fill.fat { background: var(--fat); }
.bar-fill.protein { background: var(--protein); }

/* meals */
.meals { display: flex; flex-direction: column; gap: 10px; }
.section-head { display: flex; align-items: center; justify-content: space-between; }
.meal { display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; align-items: start; padding: 12px; }
.thumb { width: 64px; height: 64px; border-radius: 14px; object-fit: cover; }
.thumb.placeholder { display: grid; place-items: center; background: #eef2ea; font-size: 1.6rem; }
.meal-head { display: flex; justify-content: space-between; gap: 8px; }
.meal-head .muted { white-space: nowrap; font-size: 0.85rem; }
.meal-kcal { font-size: 0.85rem; color: var(--muted); margin: 2px 0 6px; }
.tip { background: #f1f9ec; border-radius: 12px; padding: 8px 10px; font-size: 0.88rem; }

/* buttons & forms */
.btn {
  display: inline-flex; justify-content: center; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 14px; padding: 11px 16px; font: inherit; font-weight: 700; cursor: pointer;
}
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { color: #c62f3f; border-color: #f2c1c7; }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 12px; font-size: 0.88rem; border-radius: 12px; }
.btn.big { padding: 16px; font-size: 1.05rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; font-size: 1.05rem; cursor: pointer; padding: 4px; color: var(--muted); }
.form, .choose, .review { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.88rem; font-weight: 600; flex: 1; }
.field small { font-weight: 400; color: var(--muted); }
.row { display: flex; gap: 10px; }
input, select, textarea {
  font: inherit; font-weight: 400; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: #fbfcfa; color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }
.target-preview { background: #f1f9ec; border-radius: 12px; padding: 10px 12px; font-weight: 700; color: var(--green-dark); }
.actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

/* onboarding */
.onboarding .hero { text-align: center; padding-top: 12px; }
.onboarding h1 { font-size: 1.6rem; }

/* log flow */
.preview { width: 100%; max-height: 300px; object-fit: cover; border-radius: 16px; }
.preview.small { max-height: 180px; }
.analyzing { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 4px solid #dcebd5; border-top-color: var(--green); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error { display: flex; flex-direction: column; gap: 10px; }
.error-text { color: #a12b38; font-weight: 600; }
.item { border: 1px solid var(--line); border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.item-head { display: flex; gap: 6px; align-items: center; }
.item-portion { display: flex; gap: 6px; align-items: center; }
.item-portion input { flex: 1; min-width: 0; }
.item-portion .btn { white-space: nowrap; }
.item-nums { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.btn.ai { background: #eaf7ef; border-color: #bfe3cb; color: var(--green-dark); }
.described { font-style: italic; text-align: center; font-weight: 600; overflow-wrap: anywhere; }
.mini { display: flex; flex-direction: column; font-size: 0.72rem; color: var(--muted); gap: 2px; }
.mini input { padding: 8px 6px; }
.totals { font-weight: 800; }
.notice { background: #fff4e0; color: #8a5a00; border-radius: 12px; padding: 10px 12px; font-size: 0.88rem; font-weight: 600; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: #eef2ea; border-radius: 14px; padding: 4px; }
.tab { border: 0; background: transparent; border-radius: 10px; padding: 9px; font: inherit; font-weight: 700; color: var(--muted); cursor: pointer; }
.tab.active { background: var(--card); color: var(--green-dark); box-shadow: var(--shadow); }
.sync-line { font-weight: 700; }
.sync-line.synced { color: var(--green-dark); }
.sync-line.signed-out, .sync-line.error { color: #a12b38; }
.account-cta { display: flex; flex-direction: column; gap: 8px; text-align: center; }
.confidence { font-size: 0.85rem; font-weight: 700; }
.confidence.alta { color: var(--green-dark); }
.confidence.media { color: #9a6b00; }
.confidence.baja { color: #a12b38; }

/* stats */
.chart svg { width: 100%; height: auto; }
.legend { font-size: 0.8rem; }
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--card); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px; }
.stat strong { font-size: 1.4rem; color: var(--green-dark); }
.stat span { font-size: 0.8rem; color: var(--muted); }

/* shop */
.shop-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.shop-item { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.shop-item.equipped { outline: 2px solid var(--green); }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: 100px; transform: translate(-50%, 20px);
  background: #1f2a1c; color: #fff; padding: 10px 16px; border-radius: 14px; font-weight: 600;
  opacity: 0; transition: opacity 0.2s, transform 0.2s; pointer-events: none; z-index: 10; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
