:root {
  --bg: #0d0f12;
  --card: #171a20;
  --card2: #1f232b;
  --line: #2a2f39;
  --text: #f2f4f7;
  --muted: #8b93a1;
  --accent: #c8f53c;
  --accent-ink: #11140a;
  --protein: #4fd1c5;
  --carbs: #f6ad55;
  --fat: #f687b3;
  --danger: #ff6b6b;
  --ok: #68d391;
  --radius: 18px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { font-size: 16px; }
[hidden] { display: none !important; }

/* Layout */
#top {
  position: sticky; top: 0; z-index: 5;
  padding: calc(var(--safe-t) + 10px) 18px 10px;
  background: linear-gradient(var(--bg) 75%, transparent);
  display: flex; align-items: center; justify-content: space-between;
}
#top h1 { margin: 0; font-size: 28px; letter-spacing: -0.02em; }
#view { padding: 4px 16px calc(var(--safe-b) + 110px); max-width: 640px; margin: 0 auto; }
#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(18, 20, 25, .94); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(var(--safe-b) + 6px);
}
#nav button { background: none; border: 0; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; padding: 6px 0; }
#nav svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#nav button.active { color: var(--accent); }

/* Cards & typography */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.card h2, .sec-title { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.sec-title { margin: 22px 4px 10px; }
.big { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }
.center { text-align: center; }
.mt { margin-top: 12px; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hint { background: rgba(200,245,60,.08); border: 1px solid rgba(200,245,60,.25); color: #e6f9b0; border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.warn { background: rgba(246,173,85,.1); border: 1px solid rgba(246,173,85,.3); color: #fbd38d; border-radius: 12px; padding: 10px 12px; font-size: 14px; }

/* Buttons */
.btn { border: 0; border-radius: 14px; padding: 14px 18px; font-weight: 600; background: var(--card2); color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: rgba(255,107,107,.15); color: var(--danger); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.block { width: 100%; }
.btn.sm { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn:active { transform: scale(.98); opacity: .9; }
.btn[disabled] { opacity: .4; }
.icon-btn { background: var(--card2); border: 0; border-radius: 12px; width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; font-size: 18px; flex: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile { background: var(--card2); border: 0; border-radius: 14px; padding: 14px 8px; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; }
.tile .emo { font-size: 24px; }

/* Forms */
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.inp { width: 100%; background: var(--card2); border: 1px solid transparent; border-radius: 12px; padding: 12px 14px; outline: none; }
.inp:focus { border-color: var(--accent); }
.inp.num { text-align: center; }
.seg { display: flex; background: var(--card2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 9px 4px; color: var(--muted); font-weight: 600; font-size: 14px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

/* Progress bars */
.bar { height: 8px; background: var(--card2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width .4s; }
.macro { margin-top: 10px; }
.macro .row { font-size: 14px; margin-bottom: 4px; }

/* Ring */
.ring-wrap { position: relative; width: 132px; height: 132px; flex: none; }
.ring-wrap svg { transform: rotate(-90deg); }
.ring-wrap .lbl { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-wrap .lbl b { font-size: 26px; }

/* Lists */
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.li { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--line); background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left; }
.li:last-child { border-bottom: 0; }
.li .sub { font-size: 13px; color: var(--muted); }
.thumb { width: 46px; height: 46px; border-radius: 12px; object-fit: cover; background: var(--card2); flex: none; display: flex; align-items: center; justify-content: center; font-size: 20px; }
.chip { display: inline-block; font-size: 12px; padding: 3px 9px; border-radius: 99px; background: var(--card2); color: var(--muted); }
.chip.acc { background: rgba(200,245,60,.15); color: var(--accent); }
.kcal { font-weight: 700; white-space: nowrap; }

/* Week dots */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; text-align: center; font-size: 12px; }
.week .d { background: var(--card2); border-radius: 12px; padding: 8px 0; color: var(--muted); }
.week .d.today { outline: 2px solid var(--accent); color: var(--text); }
.week .d.done { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.week .d small { display: block; font-size: 10px; opacity: .8; }

/* Workout */
.ex-card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.ex-head { display: flex; gap: 12px; align-items: center; }
.ex-head .thumb { width: 54px; height: 54px; }
.ex-name { font-weight: 700; font-size: 17px; }
.sets { margin-top: 12px; }
.set { display: grid; grid-template-columns: 30px 1fr 1fr 44px; gap: 8px; align-items: center; margin-bottom: 8px; }
.set .no { color: var(--muted); font-weight: 700; text-align: center; }
.set .inp { padding: 10px 6px; text-align: center; }
.set .chk { width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--card2); font-size: 20px; color: var(--muted); }
.set.done .chk { background: var(--accent); color: var(--accent-ink); }
.set.done .inp { background: rgba(200,245,60,.08); }
.set-head { display: grid; grid-template-columns: 30px 1fr 1fr 44px; gap: 8px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; text-align: center; margin-top: 10px; }
.last { font-size: 13px; color: var(--muted); margin-top: 6px; }
.prog { font-size: 13px; color: var(--accent); margin-top: 4px; }
.cue { font-size: 13px; color: var(--muted); margin-top: 8px; background: var(--card2); border-radius: 10px; padding: 8px 10px; }

/* Timer */
#timer {
  position: fixed; left: 12px; right: 12px; z-index: 11;
  bottom: calc(var(--safe-b) + 74px);
  background: var(--accent); color: var(--accent-ink); border-radius: 16px; padding: 10px 12px;
  display: flex; align-items: center; gap: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.5); max-width: 616px; margin: 0 auto;
}
#timer b { font-size: 24px; font-variant-numeric: tabular-nums; flex: 1; }
#timer button { border: 0; background: rgba(0,0,0,.12); color: var(--accent-ink); border-radius: 10px; padding: 8px 10px; font-weight: 700; }
#timer.over { background: var(--danger); color: #fff; }
#timer.over button { color: #fff; }

/* Sheet */
#sheet-wrap { position: fixed; inset: 0; z-index: 50; }
#sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); animation: fade .2s; }
#sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: #14171c; border-radius: 24px 24px 0 0; padding: 10px 18px calc(var(--safe-b) + 24px);
  animation: up .25s ease-out; max-width: 640px; margin: 0 auto;
}
#sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 14px; }
#sheet h3 { margin: 0 0 14px; font-size: 21px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* Toast */
#toast { position: fixed; left: 50%; transform: translateX(-50%); top: calc(var(--safe-t) + 14px); z-index: 80; background: #fff; color: #111; padding: 10px 16px; border-radius: 99px; font-weight: 600; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.4); max-width: 90vw; text-align: center; }

/* Loader */
.spin { width: 38px; height: 38px; border: 4px solid var(--card2); border-top-color: var(--accent); border-radius: 50%; animation: rot .8s linear infinite; margin: 20px auto; }
@keyframes rot { to { transform: rotate(360deg); } }

/* Onboarding */
#onboarding { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; flex-direction: column; padding: calc(var(--safe-t) + 16px) 20px calc(var(--safe-b) + 20px); overflow-y: auto; }
.ob-top { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.ob-bar { flex: 1; height: 6px; border-radius: 9px; background: var(--card2); overflow: hidden; }
.ob-bar i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.ob-body { flex: 1; max-width: 520px; width: 100%; margin: 0 auto; }
.ob-body h2 { font-size: 30px; line-height: 1.15; margin: 0 0 8px; letter-spacing: -0.02em; }
.ob-body p.lead { color: var(--muted); margin: 0 0 24px; }
.ob-foot { max-width: 520px; width: 100%; margin: 20px auto 0; }
.opt { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; background: var(--card); border: 2px solid transparent; border-radius: 16px; padding: 16px; margin-bottom: 10px; }
.opt .emo { font-size: 26px; }
.opt b { display: block; }
.opt small { color: var(--muted); }
.opt.on { border-color: var(--accent); background: rgba(200,245,60,.06); }
.stepper { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 30px 0; }
.stepper input { width: 150px; font-size: 44px; font-weight: 700; text-align: center; background: none; border: 0; border-bottom: 2px solid var(--line); outline: none; padding: 4px; }
.stepper input:focus { border-color: var(--accent); }
.stepper .unit { font-size: 20px; color: var(--muted); }
.stepper .icon-btn { width: 52px; height: 52px; font-size: 26px; }

/* Charts */
.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 10px; }

/* Food item editor */
.fi { background: var(--card2); border-radius: 14px; padding: 12px; margin-bottom: 10px; }
.fi .grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.fi .grid4 label { font-size: 11px; color: var(--muted); text-align: center; }
.fi .grid4 .inp { padding: 8px 4px; text-align: center; margin-top: 3px; background: var(--card); }
.photo-prev { width: 100%; max-height: 220px; object-fit: cover; border-radius: 16px; margin-bottom: 12px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.scan-frame { position: absolute; left: 4%; right: 4%; top: 50%; height: 34%; transform: translateY(-50%); border: 3px solid var(--accent); border-radius: 14px; box-shadow: 0 0 0 999px rgba(0,0,0,.35); pointer-events: none; }
.scan-frame::after { content: ''; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: #ff5a5a; animation: scanline 1.6s ease-in-out infinite; }
@keyframes scanline { 0%, 100% { transform: translateY(-30px); } 50% { transform: translateY(30px); } }
