/* ============================================================
   FORMA — light, modern, product-grade SaaS
   Plus Jakarta Sans · Spline Sans Mono · coral flare accent
   Mobile-first: tuned to iPhone 13 Pro Max (430pt), desktop rail ≥920px
   ============================================================ */

:root {
  --bg:        #F7F7F5;
  --card:      #FFFFFF;
  --card-soft: #FBFBFA;
  --line:      #EBEBE8;
  --line-strong:#E0E0DC;
  --ink:       #16181D;
  --ink-dim:   #676D79;
  --ink-faint: #9CA1AB;
  --accent:    #F4501E;
  --accent-hot:#FF6B3D;
  --accent-tint:#FEEDE6;
  --accent-deep:#D93E10;
  --win:       #12B76A;
  --win-tint:  #E7F8F0;
  --win-deep:  #0E9355;
  --amber:     #F59E0B;
  --amber-tint:#FEF3E2;
  --sky:       #2E90FA;
  --danger:    #F04438;
  --danger-tint:#FEEDEC;
  --ring-track:#EFEFEC;
  --grad-flare: linear-gradient(135deg, #FF7A45 0%, #F4501E 60%, #E8420F 100%);
  --font-ui:   'Plus Jakarta Sans', -apple-system, 'SF Pro Text', sans-serif;
  --font-mono: 'Spline Sans Mono', ui-monospace, 'SF Mono', monospace;
  --nav-h: 72px;
  --shadow-card: 0 1px 2px rgba(22, 24, 29, .04), 0 4px 16px rgba(22, 24, 29, .05);
  --shadow-pop:  0 2px 6px rgba(22, 24, 29, .06), 0 12px 32px rgba(22, 24, 29, .12);
  --shadow-accent: 0 4px 14px rgba(244, 80, 30, .32);
  --ease-spring: cubic-bezier(.34, 1.45, .44, 1);
  --ease-out: cubic-bezier(.22, .9, .3, 1);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
body {
  background: var(--bg); color: var(--ink);
  font-family: var(--font-ui); line-height: 1.45;
  overscroll-behavior-y: none; -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button { font-family: inherit; color: inherit; background: none; border: none; cursor: pointer; font-size: inherit; }
input, select, textarea { font-family: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
::selection { background: rgba(244, 80, 30, .18); }

/* Subtle top wash so it isn't flat-boring */
body::before {
  content: ''; position: fixed; inset: 0 0 auto 0; height: 340px; pointer-events: none; z-index: 0;
  background:
    radial-gradient(60% 90% at 88% -20%, rgba(244, 80, 30, .07), transparent 70%),
    radial-gradient(50% 80% at 6% -14%, rgba(46, 144, 250, .05), transparent 70%);
}

#app {
  position: relative; z-index: 2; max-width: 500px; margin: 0 auto;
  padding: var(--safe-t) 20px calc(var(--nav-h) + var(--safe-b) + 24px);
}

/* ── Topbar ── */
#topbar { display: flex; align-items: center; justify-content: flex-end; padding: 12px 0 0; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 40px; height: 40px; border-radius: 12px; box-shadow: var(--shadow-card); }
.brand-name { font-weight: 800; font-size: 1.22rem; letter-spacing: -.03em; }
.brand-sub { font-size: .66rem; font-weight: 600; color: var(--ink-faint); letter-spacing: .02em; margin-top: -2px; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.chip-sync {
  font-family: var(--font-mono); font-size: .6rem; letter-spacing: .04em;
  color: var(--ink-faint); padding: 6px 11px; background: var(--card); border: 1px solid var(--line); border-radius: 99px;
  box-shadow: var(--shadow-card); transition: color .3s;
}
.chip-sync.on { color: var(--win-deep); }
.chip-sync.pending { color: var(--amber); }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 13px; color: var(--ink-dim);
  box-shadow: var(--shadow-card);
  transition: transform .2s var(--ease-spring);
}
.icon-btn:active { transform: scale(.9); }
.icon-btn svg { width: 18px; height: 18px; }

/* ── Reveal choreography ── */
.tab-section { display: none; }
.tab-section.active { display: block; }
.tab-section.active > * { animation: rise .45s var(--ease-out) both; }
.tab-section.active > *:nth-child(1) { animation-delay: .02s; }
.tab-section.active > *:nth-child(2) { animation-delay: .06s; }
.tab-section.active > *:nth-child(3) { animation-delay: .10s; }
.tab-section.active > *:nth-child(4) { animation-delay: .14s; }
.tab-section.active > *:nth-child(5) { animation-delay: .18s; }
.tab-section.active > *:nth-child(6) { animation-delay: .22s; }
.tab-section.active > *:nth-child(7) { animation-delay: .26s; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.section-label {
  font-size: .72rem; font-weight: 700; letter-spacing: .01em;
  color: var(--ink-faint); margin: 24px 4px 10px; text-transform: none;
  display: flex; align-items: center; gap: 8px;
}

/* ── Cards ── */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 18px;
  position: relative; box-shadow: var(--shadow-card);
}
.card + .card { margin-top: 12px; }
.card-tappable { transition: transform .18s var(--ease-spring), box-shadow .2s; }
.card-tappable:active { transform: scale(.977); }

/* ── Hero ── */
.hero { padding: 12px 4px 4px; }
.hero-date { font-size: .74rem; font-weight: 700; color: var(--accent); letter-spacing: .01em; }
.hero-title { font-size: 1.6rem; font-weight: 800; letter-spacing: -.035em; line-height: 1.14; margin-top: 4px; }
.hero-title em { font-style: normal; color: var(--ink-faint); font-weight: 700; }

/* ── Daily win ring ── */
.win-card { display: flex; gap: 20px; align-items: center; }
.ring-wrap { position: relative; width: 128px; height: 128px; flex-shrink: 0; }
.ring-wrap svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { stroke: var(--ring-track); }
.ring-fill { stroke: url(#heatGrad); stroke-linecap: round; transition: stroke-dashoffset 1s var(--ease-out); }
.ring-fill.won { stroke: var(--win); filter: drop-shadow(0 0 6px rgba(18, 183, 106, .35)); }
.ring-center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.ring-kcal { font-size: 1.5rem; font-weight: 800; letter-spacing: -.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.ring-kcal-sub { font-size: .62rem; font-weight: 600; color: var(--ink-faint); margin-top: 3px; }
.win-meta { flex: 1; min-width: 0; }
.macro-line { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.macro-line .label { font-size: .7rem; font-weight: 700; color: var(--ink-dim); }
.macro-line .val { font-family: var(--font-mono); font-size: .72rem; color: var(--ink-faint); }
.macro-line .val b { color: var(--ink); font-weight: 600; }
.bar { height: 6px; border-radius: 3px; background: var(--ring-track); overflow: hidden; margin-bottom: 11px; }
.bar > i { display: block; height: 100%; border-radius: 3px; background: var(--grad-flare); transition: width .9s var(--ease-out); }
.bar.ok > i { background: var(--win); }
.won-banner {
  margin-top: 2px; display: inline-flex; align-items: center; gap: 6px;
  font-size: .68rem; font-weight: 800; color: var(--win-deep);
  background: var(--win-tint); border-radius: 99px; padding: 5px 12px;
}

/* ── Streaks ── */
.streak-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.streak-cell {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 14px 8px 12px; text-align: center; box-shadow: var(--shadow-card);
}
.streak-num { font-size: 1.55rem; font-weight: 800; letter-spacing: -.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.streak-num.lit { color: var(--accent); }
.streak-lbl { font-size: .62rem; font-weight: 700; color: var(--ink-faint); margin-top: 4px; }

/* ── Quick actions ── */
.quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quick {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 14px; text-align: left; box-shadow: var(--shadow-card);
  display: flex; flex-direction: column; gap: 3px; min-height: 76px;
  transition: transform .18s var(--ease-spring);
}
.quick:active { transform: scale(.955); }
.quick.done { border-color: transparent; background: var(--win-tint); }
.quick-title { font-size: .86rem; font-weight: 700; letter-spacing: -.01em; display: flex; align-items: center; gap: 7px; }
.quick-title svg { width: 16px; height: 16px; color: var(--accent); }
.quick.done .quick-title svg { color: var(--win-deep); }
.quick-sub { font-size: .66rem; font-weight: 500; color: var(--ink-faint); }
.quick-check { margin-left: auto; width: 17px; height: 17px; color: var(--win-deep); }

/* ── Next workout ── */
.next-card { background: linear-gradient(135deg, #1A1C22 0%, #24262e 100%); border: none; color: #fff; }
.next-card .next-kicker { font-size: .64rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--accent-hot); }
.next-name { font-size: 1.5rem; font-weight: 800; letter-spacing: -.03em; margin: 4px 0 2px; }
.next-meta { font-size: .7rem; font-weight: 500; color: rgba(255, 255, 255, .55); }
.next-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 14px; padding: 13px 20px; font-weight: 750; font-size: .88rem; letter-spacing: -.01em;
  transition: transform .18s var(--ease-spring), box-shadow .25s;
}
.btn:active { transform: scale(.95); }
.btn-ember { background: var(--grad-flare); color: #fff; box-shadow: var(--shadow-accent); }
.btn-ghost { background: var(--card); border: 1px solid var(--line-strong); color: var(--ink-dim); }
.next-card .btn-ghost { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.16); color: rgba(255,255,255,.85); }
.btn-danger { background: var(--danger-tint); color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { padding: 9px 14px; font-size: .76rem; border-radius: 11px; }

/* ── Train: live session ── */
.session-strip {
  position: sticky; top: 0; z-index: 30; margin: 0 -20px 14px; padding: calc(var(--safe-t) + 10px) 20px 12px;
  background: rgba(247, 247, 245, .86); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.strip-time { font-family: var(--font-mono); font-size: 1rem; font-weight: 500; color: var(--accent); font-variant-numeric: tabular-nums; }
.strip-meta { font-size: .64rem; font-weight: 600; color: var(--ink-faint); }

.ex-card { margin-top: 12px; }
.ex-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; text-align: left; }
.ex-name { font-weight: 750; font-size: .95rem; letter-spacing: -.01em; }
.ex-tags { font-size: .64rem; font-weight: 500; color: var(--ink-faint); margin-top: 2px; }
.ex-target { font-family: var(--font-mono); font-size: .66rem; color: var(--accent); white-space: nowrap; }
.ex-progress { font-family: var(--font-mono); font-size: .62rem; color: var(--ink-faint); }
.ex-body { margin-top: 12px; display: none; }
.ex-card.open .ex-body { display: block; animation: rise .3s var(--ease-out); }

.set-row { display: grid; grid-template-columns: 26px 1fr 1fr 92px 46px; gap: 8px; align-items: center; padding: 6px 0; }
.set-row.head { font-size: .58rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-faint); padding-bottom: 2px; }
.set-idx { font-family: var(--font-mono); font-size: .72rem; color: var(--ink-faint); }
.set-input {
  background: var(--card-soft); border: 1.5px solid var(--line); border-radius: 12px;
  padding: 11px 8px; font-family: var(--font-mono); font-size: .92rem; text-align: center; width: 100%;
  transition: border-color .2s; font-variant-numeric: tabular-nums;
}
.set-input:focus { outline: none; border-color: var(--accent); background: #fff; }
.rir-pips { display: flex; gap: 5px; justify-content: center; }
.rir-pip { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--line-strong); transition: all .15s var(--ease-spring); padding: 0; }
.rir-pip.on { background: var(--accent); border-color: var(--accent); transform: scale(1.2); }
.set-done-btn {
  width: 42px; height: 42px; border-radius: 13px; border: 1.5px solid var(--line-strong);
  display: grid; place-items: center; color: var(--ink-faint);
  transition: all .2s var(--ease-spring);
}
.set-done-btn.done { background: var(--grad-flare); border-color: transparent; color: #fff; transform: scale(1.05); box-shadow: var(--shadow-accent); }
.set-done-btn svg { width: 16px; height: 16px; }
.set-row.flash { animation: setFlash .6s var(--ease-out); }
@keyframes setFlash { 0% { background: var(--accent-tint); border-radius: 12px; } 100% { background: transparent; } }

/* ── Rest bar ── */
.rest-bar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-b) + 12px); z-index: 40;
  width: min(92vw, 470px);
  background: #1A1C22; color: #fff;
  border-radius: 18px; padding: 13px 16px;
  display: flex; align-items: center; gap: 14px;
  animation: restIn .4s var(--ease-spring);
  box-shadow: var(--shadow-pop);
}
@keyframes restIn { from { transform: translateX(-50%) translateY(24px); opacity: 0; } }
.rest-count { font-family: var(--font-mono); font-size: 1.3rem; color: var(--accent-hot); min-width: 64px; font-variant-numeric: tabular-nums; }
.rest-label { font-size: .58rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: rgba(255,255,255,.45); }
.rest-track { flex: 1; height: 5px; border-radius: 3px; background: rgba(255,255,255,.14); overflow: hidden; }
.rest-track > i { display: block; height: 100%; background: var(--grad-flare); transition: width .25s linear; }
.rest-skip { font-size: .7rem; font-weight: 700; color: rgba(255,255,255,.6); padding: 8px; }

/* ── Plan / meso ── */
.meso-band { display: flex; gap: 5px; margin-top: 12px; }
.meso-week { flex: 1; height: 8px; border-radius: 4px; background: var(--ring-track); }
.meso-week.past { background: #FFC9B3; }
.meso-week.now { background: var(--grad-flare); box-shadow: 0 1px 6px rgba(244, 80, 30, .4); }
.meso-week.deload { background: repeating-linear-gradient(45deg, var(--ring-track), var(--ring-track) 4px, #E4E4E0 4px, #E4E4E0 8px); }
.plan-day { width: 100%; text-align: left; }
.plan-exercises { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; display: none; }
.plan-day.open .plan-exercises { display: block; animation: rise .3s var(--ease-out); }
.plan-ex-row { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.plan-ex-row:last-child { border-bottom: none; }
.plan-ex-name { font-size: .82rem; font-weight: 600; }
.plan-ex-rx { font-family: var(--font-mono); font-size: .64rem; color: var(--ink-faint); white-space: nowrap; }
.plan-ex-next { font-family: var(--font-mono); font-size: .6rem; color: var(--accent); }
.tag-next { color: var(--accent); font-size: .6rem; font-weight: 800; letter-spacing: .05em; }

/* ── Fuel ── */
.fuel-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }
.fuel-action {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px 6px 12px; display: flex; flex-direction: column; align-items: center; gap: 7px;
  box-shadow: var(--shadow-card);
  transition: transform .18s var(--ease-spring);
}
.fuel-action:active { transform: scale(.93); }
.fuel-action svg { width: 20px; height: 20px; color: var(--accent); }
.fuel-action span { font-size: .6rem; font-weight: 700; color: var(--ink-dim); }
.fuel-action.ai { background: linear-gradient(135deg, #FFF3ED, #FFE8DE); border-color: #FFD8C6; }

.meal-scroll { display: flex; gap: 9px; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.meal-scroll::-webkit-scrollbar { display: none; }
.meal-chip {
  flex: 0 0 auto; background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 12px 14px; text-align: left; min-width: 150px; box-shadow: var(--shadow-card);
  transition: transform .18s var(--ease-spring), border-color .2s;
}
.meal-chip:active { transform: scale(.94); border-color: var(--accent); }
.meal-chip .m-name { font-size: .8rem; font-weight: 700; letter-spacing: -.01em; }
.meal-chip .m-hint { font-size: .6rem; font-weight: 500; color: var(--ink-faint); margin-top: 2px; }
.meal-chip .m-macro { font-family: var(--font-mono); font-size: .62rem; color: var(--accent); margin-top: 6px; }

.log-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.log-row:last-child { border-bottom: none; }
.log-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.log-name { font-size: .84rem; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-macro { font-family: var(--font-mono); font-size: .64rem; color: var(--ink-faint); white-space: nowrap; }
.log-del { color: var(--ink-faint); padding: 6px; }
.log-del svg { width: 15px; height: 15px; }
.log-del.confirm { color: var(--danger); font-size: .6rem; font-weight: 800; }

/* ── Body ── */
.body-hero { display: flex; align-items: baseline; gap: 14px; }
.body-weight { font-size: 3rem; font-weight: 800; letter-spacing: -.045em; line-height: 1; font-variant-numeric: tabular-nums; }
.body-weight small { font-size: 1.1rem; color: var(--ink-faint); font-weight: 700; }
.body-delta { font-family: var(--font-mono); font-size: .7rem; font-weight: 500; }
.body-delta.up { color: var(--amber); } .body-delta.down { color: var(--win-deep); } .body-delta.flat { color: var(--ink-faint); }
.trend-note { font-size: .72rem; font-weight: 500; color: var(--ink-dim); margin-top: 10px; line-height: 1.55; }
.trend-note b { color: var(--accent); font-weight: 750; }
.spark { width: 100%; height: 72px; margin-top: 12px; }
.weigh-form { display: flex; gap: 10px; margin-top: 12px; }
.weigh-input {
  flex: 1; background: var(--card-soft); border: 1.5px solid var(--line); border-radius: 14px;
  padding: 13px; font-family: var(--font-mono); font-size: 1.05rem; text-align: center; font-variant-numeric: tabular-nums;
}
.weigh-input:focus { outline: none; border-color: var(--accent); background: #fff; }

/* ── Health ── */
.supp-row { display: flex; align-items: center; gap: 13px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.supp-row:last-child { border-bottom: none; }
.supp-info { flex: 1; }
.supp-title { font-size: .86rem; font-weight: 750; letter-spacing: -.01em; }
.supp-items { font-size: .64rem; font-weight: 500; color: var(--ink-faint); margin-top: 2px; }
.supp-check {
  width: 48px; height: 48px; border-radius: 15px; border: 1.5px solid var(--line-strong);
  display: grid; place-items: center; color: var(--ink-faint);
  transition: all .22s var(--ease-spring);
}
.supp-check.done { background: var(--win); border-color: transparent; color: #fff; transform: scale(1.04); box-shadow: 0 4px 12px rgba(18, 183, 106, .3); }
.supp-check svg { width: 19px; height: 19px; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-cell { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; box-shadow: var(--shadow-card); }
.stat-val { font-size: 1.35rem; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.stat-lbl { font-size: .62rem; font-weight: 700; color: var(--ink-faint); margin-top: 3px; }

.grocery-stop { padding: 10px 0; border-bottom: 1px solid var(--line); }
.grocery-stop:last-child { border-bottom: none; }
.grocery-head { display: flex; justify-content: space-between; font-size: .84rem; font-weight: 750; }
.grocery-head .zl { font-family: var(--font-mono); color: var(--accent); font-weight: 500; font-size: .72rem; }
.grocery-items { font-size: .66rem; font-weight: 500; color: var(--ink-dim); margin-top: 5px; line-height: 1.75; }

/* ── Charts ── */
.chart-bars { display: flex; align-items: flex-end; gap: 6px; height: 110px; margin-top: 12px; }
.chart-bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.chart-bar > i { display: block; width: 100%; border-radius: 7px 7px 4px 4px; background: var(--grad-flare); min-height: 4px; transition: height .8s var(--ease-out); }
.chart-bar.mute > i { background: var(--ring-track); }
.chart-bar span { font-family: var(--font-mono); font-size: .54rem; color: var(--ink-faint); }
.pr-row { display: flex; justify-content: space-between; align-items: baseline; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.pr-row:last-child { border-bottom: none; }
.pr-name { font-size: .8rem; font-weight: 600; }
.pr-val { font-family: var(--font-mono); font-size: .7rem; color: var(--accent); }

/* ── Bottom nav ── */
#bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; justify-content: space-around; align-items: stretch;
  padding: 8px 8px calc(var(--safe-b) + 6px);
  background: rgba(255, 255, 255, .94); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--line);
}
.nav-btn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 0 2px; flex: 1; color: var(--ink-faint);
  transition: color .25s, transform .2s var(--ease-spring);
}
.nav-btn:active { transform: scale(.92); }
.nav-btn svg { width: 23px; height: 23px; }
.nav-btn span { font-size: .58rem; font-weight: 700; letter-spacing: .01em; }
.nav-btn.active { color: var(--accent); }

/* ── Sheets ── */
.sheet-veil {
  position: fixed; inset: 0; z-index: 90; background: rgba(22, 24, 29, .4);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  animation: veilIn .25s ease both;
}
@keyframes veilIn { from { opacity: 0; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 91;
  max-width: 500px; margin: 0 auto;
  background: var(--card); border-radius: 26px 26px 0 0;
  padding: 14px 20px calc(var(--safe-b) + 26px);
  animation: sheetUp .38s var(--ease-spring) both;
  max-height: 88dvh; overflow-y: auto;
  box-shadow: var(--shadow-pop);
}
@keyframes sheetUp { from { transform: translateY(55%); opacity: .5; } }
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: 0 auto 16px; }
.sheet-title { font-size: 1.22rem; font-weight: 800; letter-spacing: -.03em; margin-bottom: 3px; }
.sheet-sub { font-size: .72rem; font-weight: 500; color: var(--ink-faint); margin-bottom: 14px; }

/* ── Scan overlay ── */
.scan-overlay { position: fixed; inset: 0; z-index: 100; background: #000; display: flex; flex-direction: column; }
.scan-video-wrap { position: relative; flex: 1; overflow: hidden; }
.scan-video-wrap video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-frame { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.scan-box { position: relative; width: 74%; aspect-ratio: 1; max-width: 340px; }
.scan-c { position: absolute; width: 34px; height: 34px; border: 3px solid #fff; opacity: .95; }
.scan-c.tl { top: 0; left: 0; border-right: none; border-bottom: none; border-radius: 12px 0 0 0; animation: cornerPulse 2.2s ease-in-out infinite; }
.scan-c.tr { top: 0; right: 0; border-left: none; border-bottom: none; border-radius: 0 12px 0 0; animation: cornerPulse 2.2s .15s ease-in-out infinite; }
.scan-c.bl { bottom: 0; left: 0; border-right: none; border-top: none; border-radius: 0 0 0 12px; animation: cornerPulse 2.2s .3s ease-in-out infinite; }
.scan-c.br { bottom: 0; right: 0; border-left: none; border-top: none; border-radius: 0 0 12px 0; animation: cornerPulse 2.2s .45s ease-in-out infinite; }
@keyframes cornerPulse { 50% { transform: scale(1.06); opacity: .7; } }
.scan-status {
  position: absolute; bottom: 16%; left: 0; right: 0; text-align: center;
  font-size: .72rem; font-weight: 700; letter-spacing: .04em; color: #fff;
  text-shadow: 0 1px 8px rgba(0,0,0,.5);
}
.scan-controls { display: flex; align-items: center; justify-content: space-around; padding: 22px 30px calc(var(--safe-b) + 26px); background: #000; }
.shutter { width: 74px; height: 74px; border-radius: 50%; border: 4px solid #fff; display: grid; place-items: center; transition: transform .15s var(--ease-spring); }
.shutter:active { transform: scale(.88); }
.shutter i { width: 56px; height: 56px; border-radius: 50%; background: var(--grad-flare); display: block; }
.scan-cancel { color: rgba(255,255,255,.75); font-size: .74rem; font-weight: 700; }

/* Scan results */
.result-conf { font-size: .62rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-faint); }
.result-name { font-size: 1.35rem; font-weight: 800; letter-spacing: -.03em; margin: 4px 0 10px; }
.macro-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.macro-cell { background: var(--card-soft); border: 1px solid var(--line); border-radius: 14px; padding: 12px 6px; text-align: center; }
.macro-cell b { font-size: .95rem; display: block; font-weight: 800; font-variant-numeric: tabular-nums; }
.macro-cell span { font-size: .56rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-faint); }
.ing-pill {
  display: inline-block; font-size: .64rem; font-weight: 600; color: var(--ink-dim);
  background: var(--card-soft); border: 1px solid var(--line); border-radius: 99px; padding: 5px 11px; margin: 0 5px 6px 0;
}

/* Quantity stepper */
.qty-row { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 16px 0; }
.qty-btn {
  width: 54px; height: 54px; border-radius: 17px; border: 1.5px solid var(--line-strong);
  font-size: 1.4rem; color: var(--ink-dim); display: grid; place-items: center;
  transition: transform .15s var(--ease-spring);
}
.qty-btn:active { transform: scale(.88); border-color: var(--accent); color: var(--accent); }
.qty-val { font-size: 2rem; font-weight: 800; letter-spacing: -.03em; min-width: 116px; text-align: center; font-variant-numeric: tabular-nums; }
.qty-val small { font-size: .85rem; color: var(--ink-faint); font-weight: 700; }

/* Search + inputs */
.search-input {
  width: 100%; background: var(--card-soft); border: 1.5px solid var(--line); border-radius: 15px;
  padding: 14px; font-size: .95rem; font-weight: 600;
}
.search-input:focus { outline: none; border-color: var(--accent); background: #fff; }
.search-input::placeholder { color: var(--ink-faint); font-weight: 500; }
.search-hit { display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 12px 2px; border-bottom: 1px solid var(--line); }
.search-hit-name { font-size: .84rem; font-weight: 650; }
.search-hit-brand { font-size: .62rem; font-weight: 500; color: var(--ink-faint); }
.search-hit-kcal { font-family: var(--font-mono); font-size: .66rem; color: var(--accent); white-space: nowrap; }

/* ── PIN ── */
#pin-screen {
  position: fixed; inset: 0; z-index: 200; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
}
#pin-screen img { width: 76px; height: 76px; border-radius: 20px; margin-bottom: 8px; box-shadow: var(--shadow-pop); animation: logoBreath 3.5s ease-in-out infinite; }
@keyframes logoBreath { 50% { transform: scale(1.04); } }
.pin-word { font-size: 1.4rem; font-weight: 800; letter-spacing: -.03em; }
.pin-sub { font-size: .68rem; font-weight: 600; color: var(--ink-faint); margin-bottom: 22px; }
.pin-dots { display: flex; gap: 14px; margin-bottom: 26px; }
.pin-dot { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--line-strong); transition: all .2s var(--ease-spring); }
.pin-dot.fill { background: var(--accent); border-color: var(--accent); transform: scale(1.18); }
.pin-dots.err { animation: shake .4s ease; }
@keyframes shake { 25% { transform: translateX(-8px); } 50% { transform: translateX(7px); } 75% { transform: translateX(-4px); } }
.pin-pad { display: grid; grid-template-columns: repeat(3, 78px); gap: 13px; }
.pin-key {
  height: 78px; border-radius: 50%; background: var(--card); border: 1px solid var(--line);
  font-size: 1.4rem; font-weight: 700; box-shadow: var(--shadow-card);
  transition: all .15s var(--ease-spring);
}
.pin-key:active { transform: scale(.9); border-color: var(--accent); }

/* ── Celebration ── */
#celebrate {
  position: fixed; inset: 0; z-index: 300; display: none;
  align-items: center; justify-content: center; flex-direction: column; gap: 6px;
  background: rgba(255, 255, 255, .88); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
#celebrate.show { display: flex; }
.cel-kicker { font-size: .7rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; color: var(--accent); animation: rise .5s var(--ease-out) both; }
.cel-title { font-size: 2.5rem; font-weight: 800; letter-spacing: -.04em; text-align: center; line-height: 1.08; animation: celPop .6s var(--ease-spring) both .1s; }
.cel-sub { font-family: var(--font-mono); font-size: .74rem; color: var(--ink-dim); animation: rise .5s var(--ease-out) both .25s; }
@keyframes celPop { from { transform: scale(.6); opacity: 0; } }
.cel-spark { position: absolute; width: 8px; height: 8px; border-radius: 2px; background: var(--accent); animation: sparkFly 1.1s var(--ease-out) both; }
@keyframes sparkFly { from { transform: translate(0, 0) scale(1) rotate(0); opacity: 1; } to { transform: translate(var(--dx), var(--dy)) scale(.2) rotate(140deg); opacity: 0; } }

/* ── Toast ── */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px); z-index: 80;
  background: #1A1C22; color: #fff; border-radius: 14px;
  padding: 12px 18px; font-size: .8rem; font-weight: 650; opacity: 0; pointer-events: none;
  transition: all .35s var(--ease-spring); max-width: 88vw; text-align: center;
  box-shadow: var(--shadow-pop);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.empty { text-align: center; padding: 26px 14px; color: var(--ink-faint); font-size: .74rem; font-weight: 500; line-height: 1.8; }

.coach-note {
  background: var(--accent-tint); border-radius: 16px; padding: 13px 15px; margin-top: 12px;
  font-size: .84rem; font-weight: 550; color: #7C2D12; line-height: 1.55;
}

/* ── iPhone 13 Pro Max sweet spot (428–430pt) ── */
@media (min-width: 415px) and (max-width: 500px) {
  #app { max-width: 100%; padding-left: 22px; padding-right: 22px; }
  .hero-title { font-size: 1.85rem; }
}
@media (max-width: 389px) {
  .hero-title { font-size: 1.5rem; }
  .ring-wrap { width: 106px; height: 106px; }
  .pin-pad { grid-template-columns: repeat(3, 66px); }
  .pin-key { height: 66px; }
  .set-row { grid-template-columns: 24px 1fr 1fr 78px 42px; gap: 6px; }
}

/* ── Desktop: left rail + wide column ── */
@media (min-width: 920px) {
  #app { max-width: 640px; padding-left: 0; padding-right: 0; padding-bottom: 40px; }
  #bottom-nav {
    left: calc(50% - 320px - 96px); right: auto; top: 50%; bottom: auto;
    translate: 0 -50%; width: 84px;
    flex-direction: column; border: 1px solid var(--line); border-radius: 26px; padding: 10px 8px;
    box-shadow: var(--shadow-pop);
  }
  .nav-btn { padding: 13px 16px; }
  .rest-bar { bottom: 24px; }
  #toast { bottom: 24px; }
  .sheet { max-width: 560px; border-radius: 26px; bottom: 5vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; transition-duration: .001s !important; }
}

/* ── Scan/analysis motion kit ─────────────────────────── */
.fx-in { opacity: 0; animation: fxRise .5s var(--ease-out) forwards; }
@keyframes fxRise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.fx-pop { opacity: 0; animation: fxPop .5s var(--ease-spring) forwards; }
@keyframes fxPop { from { opacity: 0; transform: scale(.7); } to { opacity: 1; transform: scale(1); } }
.fx-pill { opacity: 0; animation: fxPill .4s var(--ease-spring) forwards; }
@keyframes fxPill { from { opacity: 0; transform: translateY(8px) scale(.85); } to { opacity: 1; transform: none; } }

.scan-loading { text-align: center; padding: 26px 0 18px; }
.scan-orb {
  width: 74px; height: 74px; margin: 0 auto 18px; border-radius: 50%;
  background: var(--grad-flare); position: relative;
  animation: orbPulse 1.6s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(244, 80, 30, .25);
}
.scan-orb::after {
  content: ''; position: absolute; inset: 6px; border-radius: 50%;
  background: var(--card); 
}
.scan-orb::before {
  content: ''; position: absolute; inset: -10px; border-radius: 50%;
  border: 2px solid rgba(244, 80, 30, .25); border-top-color: var(--accent);
  animation: orbSpin 1.1s linear infinite;
}
@keyframes orbPulse { 50% { box-shadow: 0 0 0 16px rgba(244, 80, 30, 0); } }
@keyframes orbSpin { to { transform: rotate(360deg); } }
.scan-phase { font-size: .8rem; font-weight: 700; color: var(--ink-dim); min-height: 1.4em; transition: opacity .25s; }
.scan-phase.swap { opacity: 0; }
.shimmer-bar { height: 5px; border-radius: 3px; margin: 14px 24px 0; background: var(--ring-track); overflow: hidden; position: relative; }
.shimmer-bar::after {
  content: ''; position: absolute; inset: 0; width: 40%;
  background: var(--grad-flare); border-radius: 3px;
  animation: shimmerSweep 1.2s var(--ease-out) infinite;
}
@keyframes shimmerSweep { from { transform: translateX(-110%); } to { transform: translateX(280%); } }

.impact-line { display: flex; align-items: center; gap: 10px; margin: 4px 0 12px; }
.impact-line .lbl { font-size: .66rem; font-weight: 700; color: var(--ink-faint); white-space: nowrap; }
.impact-bar { flex: 1; height: 7px; border-radius: 4px; background: var(--ring-track); overflow: hidden; position: relative; }
.impact-bar .base { position: absolute; inset: 0 auto 0 0; background: #D8D8D3; border-radius: 4px; }
.impact-bar .add { position: absolute; inset: 0 auto 0 0; background: var(--grad-flare); border-radius: 4px; width: 0; transition: left .1s, width 1s var(--ease-out) .35s; }
.impact-line .num { font-family: var(--font-mono); font-size: .68rem; color: var(--accent); font-weight: 600; white-space: nowrap; }

.logged-morph {
  position: absolute; inset: 0; background: var(--card); border-radius: inherit;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  animation: veilIn .2s ease both; z-index: 5;
}
.logged-morph svg { width: 72px; height: 72px; }
.logged-morph circle { fill: var(--win-tint); }
.logged-morph path {
  stroke: var(--win-deep); stroke-width: 2.6; fill: none; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 30; stroke-dashoffset: 30; animation: checkDraw .45s var(--ease-out) .15s forwards;
}
@keyframes checkDraw { to { stroke-dashoffset: 0; } }
.logged-morph .txt { font-weight: 800; font-size: 1.05rem; letter-spacing: -.02em; animation: fxPop .5s var(--ease-spring) both .3s; }
.logged-morph .sub { font-size: .7rem; color: var(--ink-faint); font-weight: 600; animation: fxRise .5s var(--ease-out) both .4s; }

.bc-found {
  position: absolute; left: 0; right: 0; bottom: 26%; display: grid; place-items: center; pointer-events: none;
}
.bc-found span {
  background: rgba(18, 183, 106, .92); color: #fff; font-weight: 800; font-size: .8rem;
  border-radius: 99px; padding: 10px 18px; animation: fxPop .4s var(--ease-spring) both;
}
