:root {
  --bg: #070b14;
  --bg2: #0d1320;
  --card: #121a2b;
  --card2: #172033;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e8eef8;
  --muted: #8b97b0;
  --mint: #3dffc8;
  --mint-dim: rgba(61, 255, 200, 0.14);
  --coral: #ff6b3d;
  --gold: #f5c542;
  --blue: #6ea8ff;
  --danger: #ff5d73;
  --radius: 18px;
  --nav: 72px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
img { max-width: 100%; display: block; }

.app { height: 100%; display: flex; flex-direction: column; }
.view {
  display: none;
  flex: 1;
  overflow: auto;
  padding: calc(18px + var(--safe-t)) 18px calc(var(--nav) + var(--safe-b) + 18px);
  -webkit-overflow-scrolling: touch;
}
.view.active { display: block; animation: fade .28s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

h1 { font-size: 1.55rem; letter-spacing: -0.03em; font-weight: 750; }
h2 { font-size: 1.05rem; letter-spacing: -0.02em; font-weight: 700; }
.muted { color: var(--muted); }
.tiny { font-size: 0.75rem; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 18px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
}
.logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: #0a1220 center/cover no-repeat;
  box-shadow: 0 0 0 1px var(--line), 0 8px 24px rgba(61,255,200,.12);
}
.brand small { display: block; color: var(--muted); font-size: 0.72rem; margin-top: -2px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line);
  font-size: 0.78rem; color: var(--muted);
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: #556; }
.dot.on { background: var(--mint); box-shadow: 0 0 10px var(--mint); }
.dot.warn { background: var(--gold); }
.dot.off { background: var(--coral); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 16px; border-radius: 14px; font-weight: 650;
  transition: transform .12s ease, background .15s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--mint); color: #052018; }
.btn-coral { background: var(--coral); color: #1a0800; }
.btn-ghost { background: var(--card); border: 1px solid var(--line); color: var(--text); }
.btn-full { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 0.85rem; border-radius: 12px; }

.hero {
  position: relative; border-radius: 24px; overflow: hidden;
  background: #0a101c; margin-bottom: 16px; min-height: 168px;
  border: 1px solid var(--line);
}
.hero img { width: 100%; height: 180px; object-fit: cover; opacity: 0.85; }
.hero .overlay {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(7,11,20,.1), rgba(7,11,20,.92));
  display: flex; flex-direction: column; justify-content: flex-end; padding: 16px;
}
.hero h2 { font-size: 1.25rem; }
.kpi-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0 18px; }
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px;
}
.kpi b { display: block; font-size: 1.2rem; letter-spacing: -0.03em; }
.kpi span { font-size: 0.72rem; color: var(--muted); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 12px;
}
.card-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 8px; }

.plan-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.plan-day {
  text-align: center; padding: 8px 2px; border-radius: 12px;
  background: var(--bg2); border: 1px solid transparent; font-size: 0.7rem;
}
.plan-day b { display: block; font-size: 0.62rem; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.plan-day.active { border-color: var(--mint); background: var(--mint-dim); }
.plan-day.rest { color: var(--muted); }

.workout-list { display: flex; flex-direction: column; gap: 10px; }
.w-card {
  display: grid; grid-template-columns: 1fr auto; gap: 8px 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 14px; text-align: left; width: 100%;
}
.w-card:active { transform: scale(0.995); }
.w-card h3 { font-size: 1rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  font-size: 0.7rem; padding: 3px 8px; border-radius: 999px;
  background: rgba(255,255,255,.05); color: var(--muted);
}
.chip.fat { color: var(--coral); background: rgba(255,107,61,.12); }
.chip.muscle { color: var(--mint); background: var(--mint-dim); }
.chip.mix { color: var(--gold); background: rgba(245,197,66,.12); }
.w-meta { text-align: right; color: var(--muted); font-size: 0.78rem; }
.w-meta b { display: block; color: var(--text); font-size: 1.05rem; }

.filters { display: flex; gap: 8px; overflow: auto; padding-bottom: 12px; margin: -4px 0 8px; }
.filters .btn { flex: 0 0 auto; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--nav) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: rgba(10, 14, 24, 0.86);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(4, 1fr);
  z-index: 20;
}
.nav button {
  color: var(--muted); font-size: 0.68rem; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
}
.nav button svg { width: 22px; height: 22px; }
.nav button.active { color: var(--mint); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.field.span2 { grid-column: 1 / -1; }
.field label { font-size: 0.75rem; color: var(--muted); }
.field input, .field select {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 12px; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--mint); }

.chart-box { height: 180px; position: relative; }
.chart-box canvas { width: 100%; height: 100%; display: block; }
.heat-wrap { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.heat { aspect-ratio: 1; border-radius: 5px; background: rgba(255,255,255,.06); }
.heat-1 { background: rgba(61,255,200,.28); }
.heat-2 { background: rgba(61,255,200,.55); }
.heat-3 { background: var(--mint); }

.session-item {
  display: flex; justify-content: space-between; gap: 10px; padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.session-item:last-child { border-bottom: 0; }

/* Live */
#live {
  position: fixed; inset: 0; z-index: 40; background: var(--bg);
  display: none; flex-direction: column;
  padding: calc(12px + var(--safe-t)) 16px calc(16px + var(--safe-b));
}
#live.open { display: flex; }
.live-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.phase-bar { height: 6px; background: rgba(255,255,255,.08); border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.phase-bar > i { display: block; height: 100%; width: 0; background: var(--mint); border-radius: 99px; }
.phase-bar.work > i { background: var(--coral); }
.phase-bar.rest > i { background: var(--gold); }
.live-phase { display: flex; justify-content: space-between; font-size: 0.82rem; color: var(--muted); }
.live-clock {
  text-align: center; margin: 6px 0 4px;
}
.live-clock .big {
  font-variant-numeric: tabular-nums;
  font-size: clamp(2.6rem, 12vw, 4.2rem);
  font-weight: 780; letter-spacing: -0.05em; line-height: 1;
}
.spm-wrap { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; margin: 8px 0; }
.spm-num { text-align: center; }
.spm-num b { font-size: 2.4rem; letter-spacing: -0.04em; display: block; }
.target-ok { color: var(--mint); }
.target-hi { color: var(--coral); }
.target-lo { color: var(--gold); }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.metric {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px;
  text-align: center;
}
.metric b { display: block; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.metric span { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.stroke {
  height: 54px; margin: 10px 0; position: relative;
  background: var(--card); border-radius: 14px; overflow: hidden; border: 1px solid var(--line);
}
.stroke .water {
  position: absolute; inset: auto 0 0 0; height: 40%;
  background: linear-gradient(180deg, rgba(61,255,200,.18), rgba(61,255,200,.04));
}
.stroke .boat {
  position: absolute; top: 14px; width: 42px; height: 14px; border-radius: 8px 14px 14px 8px;
  background: var(--mint); left: 8%;
  box-shadow: 0 0 16px rgba(61,255,200,.4);
  transition: left .25s linear;
}

.live-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: auto; padding-top: 12px; }
.cue {
  min-height: 44px; text-align: center; color: var(--muted); font-size: 0.9rem; margin-top: 4px;
}

/* Onboarding */
#onboard {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: none; overflow: auto;
  padding: calc(24px + var(--safe-t)) 20px calc(24px + var(--safe-b));
}
#onboard.open { display: block; }
#onboard .art { border-radius: 24px; overflow: hidden; margin: 12px 0 18px; border: 1px solid var(--line); }
#onboard .art img { width: 100%; height: 200px; object-fit: cover; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav) + var(--safe-b) + 16px);
  transform: translateX(-50%) translateY(20px);
  background: #1b2438; border: 1px solid var(--line); color: var(--text);
  padding: 10px 14px; border-radius: 12px; font-size: 0.85rem;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 60; max-width: 90%;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.install-banner {
  display: none; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--mint-dim); border: 1px solid rgba(61,255,200,.25);
  border-radius: 16px; padding: 10px 12px; margin-bottom: 14px;
}
.install-banner.show { display: flex; }

.note { font-size: 0.85rem; color: var(--muted); }

.modal {
  position: fixed; inset: 0; z-index: 45; background: rgba(0,0,0,.55);
  display: none; align-items: flex-end; justify-content: center;
}
.modal.open { display: flex; }
.sheet {
  width: 100%; max-width: 560px; background: var(--card2);
  border-radius: 22px 22px 0 0; padding: 16px 16px calc(20px + var(--safe-b));
  border: 1px solid var(--line);
}

@media (min-width: 860px) {
  body { overflow: auto; }
  .app { max-width: 1100px; margin: 0 auto; flex-direction: row; height: 100vh; }
  .nav {
    position: sticky; top: 0; left: auto; width: 88px; height: 100vh;
    grid-template-columns: 1fr; padding: 18px 8px; border-top: 0;
    border-right: 1px solid var(--line); order: -1;
  }
  .view { padding: 28px 32px 32px; }
  #live, #onboard { max-width: 1100px; left: 50%; transform: translateX(-50%); width: 100%; }
}

.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; }
.bt-help { font-size: 0.8rem; color: var(--muted); margin-top: 8px; }
.goal-cards { display: grid; grid-template-columns: 1fr; gap: 8px; }
.goal-opt {
  text-align: left; padding: 12px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--bg2); width: 100%;
}
.goal-opt.sel { border-color: var(--mint); background: var(--mint-dim); }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.big-stat { font-size: 1.6rem; font-weight: 750; letter-spacing: -0.04em; }
.progress-thin { height: 8px; background: rgba(255,255,255,.08); border-radius: 99px; overflow: hidden; }
.progress-thin > i { display: block; height: 100%; background: var(--mint); width: 0; }
