:root {
  --bg: #0f1720;
  --surface: #16212e;
  --surface-2: #1e2c3c;
  --line: #2a3a4d;
  --text: #e8eef5;
  --muted: #93a4b8;
  --accent: #22d3ee;
  --accent-2: #3b82f6;
  --good: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 16px;
  --pad: 16px;
  --maxw: 640px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

#app {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: calc(var(--pad) + env(safe-area-inset-top)) var(--pad) 96px;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 8px; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
p { margin: 0 0 12px; color: var(--muted); }
small { color: var(--muted); }

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.brand img { width: 44px; height: 44px; border-radius: 12px; }
.brand .sub { color: var(--muted); font-size: .85rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
  margin-bottom: 14px;
}
.card.tight { padding: 12px 14px; }

.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.mt { margin-top: 12px; }
.center { text-align: center; }

label { display: block; font-size: .9rem; margin: 12px 0 6px; color: var(--text); }
input, select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  appearance: none;
  border: 1px solid transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06131c;
  font-weight: 700;
  font-size: 1rem;
  padding: 14px 18px;
  border-radius: 14px;
  width: 100%;
  cursor: pointer;
  font-family: inherit;
}
.btn:active { transform: translateY(1px); }
.btn.secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--line);
  font-weight: 600;
}
.btn.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.btn.small { width: auto; padding: 8px 14px; font-size: .9rem; border-radius: 10px; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 12px; font-size: .8rem; color: var(--muted);
}

/* Progress ring */
.ring-wrap { display: flex; align-items: center; gap: 18px; }
.ring { --p: 0; width: 108px; height: 108px; flex: none; position: relative; }
.ring svg { transform: rotate(-90deg); width: 100%; height: 100%; }
.ring .track { stroke: var(--surface-2); }
.ring .bar { stroke: url(#ringGrad); stroke-linecap: round; transition: stroke-dashoffset .5s ease; }
.ring .label {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-weight: 800; font-size: 1.35rem;
}

/* Water */
.cups { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.cup {
  width: 34px; height: 42px; border-radius: 6px 6px 10px 10px;
  border: 2px solid var(--line); background: transparent; cursor: pointer;
  display: grid; place-items: end center; overflow: hidden; position: relative;
  padding: 0;
}
.cup.filled { border-color: var(--accent); background: linear-gradient(180deg, transparent, rgba(34,211,238,.35)); }
.cup:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Exercise items */
.ex { border-top: 1px solid var(--line); padding: 14px 0; }
.ex:first-child { border-top: 0; }
.ex-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.ex-name { font-weight: 700; font-size: 1.05rem; }
.ex-group { font-size: .78rem; color: var(--muted); }
.ex-cue { font-size: .85rem; color: var(--muted); margin: 4px 0 10px; }
.sets { display: flex; gap: 8px; flex-wrap: wrap; }
.setbtn {
  min-width: 46px; padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font-weight: 700; cursor: pointer; font-family: inherit;
}
.setbtn.done { background: rgba(52,211,153,.18); border-color: var(--good); color: var(--good); }
.setbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.banner {
  background: rgba(251,191,36,.12); border: 1px solid var(--warn);
  color: var(--warn); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; font-size: .9rem;
}
.banner.good { background: rgba(52,211,153,.12); border-color: var(--good); color: var(--good); }

/* History bars */
.hist { display: flex; align-items: flex-end; gap: 6px; height: 120px; margin-top: 8px; }
.hbar { flex: 1; background: var(--surface-2); border-radius: 6px 6px 3px 3px; position: relative; min-height: 4px; }
.hbar > span { position: absolute; inset: auto 0 0 0; background: linear-gradient(180deg, var(--accent), var(--accent-2)); border-radius: 6px 6px 3px 3px; }
.hlabels { display: flex; gap: 6px; margin-top: 6px; }
.hlabels > div { flex: 1; text-align: center; font-size: .68rem; color: var(--muted); }

.streak { font-size: 2.4rem; font-weight: 800; }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}
.tabbar[hidden] { display: none; }
.tab {
  flex: 1; background: none; border: 0; color: var(--muted);
  padding: 10px 6px; font-size: .72rem; font-family: inherit; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tab .tab-ico { font-size: 1.25rem; }
.tab[aria-current="true"] { color: var(--accent); }

.field-row { display: flex; gap: 10px; }
.field-row > div { flex: 1; }
.choices { display: flex; gap: 8px; }
.choice {
  flex: 1; text-align: center; padding: 12px 8px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  cursor: pointer; font-family: inherit; font-size: .9rem;
}
.choice[aria-pressed="true"] { border-color: var(--accent); background: rgba(34,211,238,.14); color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  padding: 10px 16px; border-radius: 999px; font-size: .9rem; z-index: 40;
  opacity: 0; transition: opacity .25s ease, transform .25s ease; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }

/* Weight line chart */
.linechart { width: 100%; height: auto; display: block; }
.linechart .line { fill: none; stroke: url(#wgrad); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.linechart .dot { fill: var(--accent); }
.linechart .txt { fill: var(--muted); font-size: 10px; }
.linechart .grid { stroke: var(--line); stroke-width: 1; opacity: .5; }

/* Calorie dots under history */
.caldots { display: flex; gap: 6px; margin-top: 8px; }
.caldots > div { flex: 1; display: flex; justify-content: center; }
.caldot { width: 11px; height: 11px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); }
.caldot.light { background: var(--good); border-color: var(--good); }
.caldot.normal { background: var(--warn); border-color: var(--warn); }
.caldot.heavy { background: var(--danger); border-color: var(--danger); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: .78rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* Actual sets/reps inputs beside dose pill */
.exdose { flex-wrap: wrap; gap: 8px; }
.actual { display: inline-flex; align-items: center; gap: 6px; }
.actual .mul { color: var(--muted); }
.actual small { color: var(--muted); font-size: .72rem; white-space: nowrap; }
.act-in { width: 48px; text-align: center; padding: 6px 4px; font-size: .92rem; border-radius: 8px; }
.pill.prev { color: var(--text); border-color: var(--accent); }
.beat { color: var(--good); font-size: .78rem; font-weight: 700; }
.beat:not(:empty) { margin-top: 6px; }

/* Onboarding intro */
.intro { text-align: center; }
.intro-emoji { font-size: 3rem; line-height: 1; margin: 6px 0 10px; }
.intro h2 { font-size: 1.25rem; }
.intro p { color: var(--muted); max-width: 34ch; margin: 6px auto 14px; }
.dots { display: flex; justify-content: center; gap: 8px; margin: 6px 0 4px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); }
.dot.on { background: var(--accent); border-color: var(--accent); }
.intro .row { justify-content: center; }

/* Install / download button + modal */
.install-btn {
  flex: none; background: var(--surface-2); color: var(--accent);
  border: 1px solid var(--accent); border-radius: 999px;
  padding: 8px 14px; font-size: .82rem; font-weight: 700; cursor: pointer;
  font-family: inherit; white-space: nowrap;
}
.install-btn:active { transform: translateY(1px); }
.install-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.modal-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(4, 10, 16, .72);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0; animation: fade .2s ease;
}
.modal {
  width: 100%; max-width: var(--maxw);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px 20px 0 0; padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto; animation: slideup .25s ease;
}
.modal h2 { font-size: 1.15rem; }
.modal-close {
  flex: none; background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text); width: 34px; height: 34px; border-radius: 50%;
  cursor: pointer; font-size: 1rem; font-family: inherit;
}
.modal-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.steps { margin: 4px 0 0; padding-left: 20px; }
.steps li { margin: 8px 0; color: var(--text); font-size: .95rem; }
.steps b { color: var(--accent); }
.install-note { font-size: .82rem; color: var(--muted); margin-top: 10px; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideup { from { transform: translateY(24px); } to { transform: translateY(0); } }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .btn:active { transform: none; }
}
