:root {
  --bg: #0a0b0d;
  --bg-soft: #111317;
  --card: #15181d;
  --card-2: #1b1f26;
  --line: #262b33;
  --txt: #f3f5f7;
  --txt-dim: #9aa3ad;
  --txt-faint: #5b636d;
  --accent: #22c55e;
  --accent-dim: #16351f;
  --red: #ef4444;
  --red-dim: #3a1518;
  --amber: #f59e0b;
  --blue: #3b82f6;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--txt);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select { font-family: inherit; }

/* layout */
#app { max-width: 520px; margin: 0 auto; min-height: 100%; padding-bottom: calc(78px + var(--safe-bot)); }
.view { display: none; padding: 0 16px; animation: fade .25s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.topbar {
  position: sticky; top: 0; z-index: 30;
  padding: calc(var(--safe-top) + 14px) 16px 12px;
  background: linear-gradient(180deg, var(--bg) 60%, rgba(10,11,13,0));
  display: flex; align-items: center; justify-content: space-between;
}
.topbar h1 { font-size: 22px; font-weight: 800; letter-spacing: -.4px; }
.topbar .date { font-size: 13px; color: var(--txt-dim); font-weight: 600; }

/* cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}
.card h2 { font-size: 15px; font-weight: 700; margin-bottom: 14px; letter-spacing: -.2px; }
.muted { color: var(--txt-dim); }
.faint { color: var(--txt-faint); }

/* rings */
.rings { display: flex; gap: 14px; align-items: center; }
.ring-wrap { position: relative; width: 132px; height: 132px; flex: 0 0 auto; }
.ring-wrap svg { transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--card-2); stroke-width: 12; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 12; stroke-linecap: round; transition: stroke-dashoffset .6s cubic-bezier(.4,0,.2,1), stroke .3s; }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-center .big { font-size: 28px; font-weight: 800; letter-spacing: -1px; line-height: 1; }
.ring-center .lbl { font-size: 11px; color: var(--txt-dim); margin-top: 3px; font-weight: 600; }

.stat-col { flex: 1; display: flex; flex-direction: column; gap: 12px; }
.stat { }
.stat .row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.stat .row .k { font-size: 13px; color: var(--txt-dim); font-weight: 600; }
.stat .row .v { font-size: 14px; font-weight: 700; }
.bar { height: 8px; background: var(--card-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; transition: width .6s cubic-bezier(.4,0,.2,1); }
.bar.protein > i { background: var(--blue); }
.bar.water > i { background: #38bdf8; }

/* water big */
.water-card { text-align: center; }
.water-glasses { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 4px 0 16px; }
.glass { width: 22px; height: 30px; border-radius: 4px 4px 7px 7px; border: 2px solid var(--line); background: var(--card-2); transition: .25s; }
.glass.full { background: #38bdf8; border-color: #38bdf8; box-shadow: 0 0 10px rgba(56,189,248,.4); }
.water-num { font-size: 30px; font-weight: 800; letter-spacing: -1px; }
.water-num small { font-size: 15px; color: var(--txt-dim); font-weight: 600; }
.water-btns { display: flex; gap: 10px; margin-top: 14px; }

/* buttons */
.btn {
  background: var(--accent); color: #04140a; font-weight: 800; font-size: 15px;
  padding: 14px 18px; border-radius: 14px; width: 100%; transition: .15s; letter-spacing: -.2px;
}
.btn:active { transform: scale(.97); }
.btn.ghost { background: var(--card-2); color: var(--txt); border: 1px solid var(--line); }
.btn.sm { width: auto; padding: 11px 16px; font-size: 14px; }
.btn.red { background: var(--red); color: #fff; }
.btn:disabled { opacity: .5; }

/* meal */
.seg { display: flex; gap: 8px; margin-bottom: 14px; }
.seg button { flex: 1; padding: 12px 6px; border-radius: 12px; background: var(--card-2); border: 1px solid var(--line); font-weight: 700; font-size: 14px; color: var(--txt-dim); transition: .15s; }
.seg button.on { background: var(--accent); color: #04140a; border-color: var(--accent); }
textarea, input[type=text], input[type=number] {
  width: 100%; background: var(--card-2); border: 1px solid var(--line); color: var(--txt);
  border-radius: 12px; padding: 13px 14px; font-size: 15px; resize: vertical;
}
textarea:focus, input:focus { outline: none; border-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin: 10px 0 0; }
.chip { background: var(--card-2); border: 1px solid var(--line); padding: 7px 12px; border-radius: 99px; font-size: 13px; font-weight: 600; color: var(--txt-dim); }
.chip:active { background: var(--accent-dim); }

.meal-result { margin-top: 14px; }
.meal-result .macros { display: flex; gap: 10px; margin: 12px 0; }
.macro-pill { flex: 1; background: var(--card-2); border-radius: 12px; padding: 12px; text-align: center; }
.macro-pill .n { font-size: 20px; font-weight: 800; letter-spacing: -.5px; }
.macro-pill .l { font-size: 11px; color: var(--txt-dim); font-weight: 600; margin-top: 2px; }
.recipe { white-space: pre-wrap; line-height: 1.55; font-size: 14px; color: var(--txt); }
.recipe h3 { font-size: 16px; margin: 4px 0 8px; }

.logged-list { margin-top: 6px; }
.logged-item { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.logged-item:last-child { border-bottom: none; }
.logged-item .name { font-weight: 600; font-size: 14px; }
.logged-item .meta { font-size: 12px; color: var(--txt-dim); margin-top: 2px; }
.logged-item .kcal { font-weight: 800; font-size: 15px; }
.del { color: var(--txt-faint); font-size: 13px; padding: 6px; }

/* challenge calendar */
.challenge-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.challenge-head .big { font-size: 34px; font-weight: 800; letter-spacing: -1.5px; }
.streak-row { display: flex; gap: 10px; margin: 14px 0 4px; }
.streak-box { flex: 1; background: var(--card-2); border-radius: 12px; padding: 12px; text-align: center; }
.streak-box .n { font-size: 22px; font-weight: 800; }
.streak-box .l { font-size: 11px; color: var(--txt-dim); font-weight: 600; margin-top: 3px; }
.cal-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; margin-top: 6px; }
.cal-cell {
  aspect-ratio: 1; border-radius: 8px; background: var(--card-2); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: var(--txt-faint);
  position: relative;
}
.cal-cell.green { background: var(--accent); color: #04140a; border-color: var(--accent); }
.cal-cell.red { background: var(--red-dim); color: #fca5a5; border-color: #5b2226; }
.cal-cell.today { border-color: var(--amber); border-width: 2px; color: var(--amber); box-shadow: 0 0 0 1px var(--amber); }
.legend { display: flex; gap: 16px; margin-top: 14px; font-size: 12px; color: var(--txt-dim); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 6px; vertical-align: -1px; }

/* progress */
.chart { width: 100%; height: 160px; }
.weight-now { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.weight-now .n { font-size: 40px; font-weight: 800; letter-spacing: -1.5px; }
.weight-now .u { font-size: 16px; color: var(--txt-dim); font-weight: 600; }
.weight-now .delta { font-size: 14px; font-weight: 700; margin-left: auto; }
.delta.down { color: var(--accent); }
.delta.up { color: var(--red); }

/* tabbar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  max-width: 520px; margin: 0 auto;
  background: rgba(17,19,23,.92); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  display: flex; padding: 8px 8px calc(8px + var(--safe-bot));
}
.tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; color: var(--txt-faint); font-size: 10px; font-weight: 700; }
.tabbar button.on { color: var(--accent); }
.tabbar svg { width: 24px; height: 24px; }

/* onboarding / modal */
.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(5,6,8,.72); backdrop-filter: blur(6px); display: flex; align-items: flex-end; }
.sheet { background: var(--bg-soft); border: 1px solid var(--line); border-radius: 22px 22px 0 0; width: 100%; max-width: 520px; margin: 0 auto; padding: 24px 20px calc(24px + var(--safe-bot)); max-height: 92vh; overflow-y: auto; animation: up .3s cubic-bezier(.2,.8,.2,1); }
@keyframes up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet h2 { font-size: 22px; font-weight: 800; letter-spacing: -.5px; margin-bottom: 6px; }
.sheet p.sub { color: var(--txt-dim); font-size: 14px; margin-bottom: 18px; line-height: 1.5; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--txt-dim); margin-bottom: 7px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.targets { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin: 4px 0 16px; }
.targets .t-row { display: flex; justify-content: space-between; padding: 7px 0; font-size: 14px; }
.targets .t-row b { font-weight: 800; }
.targets .t-row + .t-row { border-top: 1px solid var(--line); }

.hint { font-size: 12px; color: var(--txt-faint); margin-top: 8px; line-height: 1.5; }
.spinner { width: 22px; height: 22px; border: 3px solid rgba(255,255,255,.2); border-top-color: #04140a; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; vertical-align: -4px; }
@keyframes spin { to { transform: rotate(360deg); } }
.err { color: #fca5a5; font-size: 13px; margin-top: 10px; }

.toast { position: fixed; bottom: calc(94px + var(--safe-bot)); left: 50%; transform: translateX(-50%); background: var(--accent); color: #04140a; font-weight: 700; font-size: 14px; padding: 11px 18px; border-radius: 99px; z-index: 200; opacity: 0; transition: .25s; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }
.toast.bad { background: var(--red); color: #fff; }

.footer-note { text-align: center; font-size: 11px; color: var(--txt-faint); padding: 8px 0 16px; }
