:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-elev: #1c232d;
  --border: #2a2f3a;
  --text: #e6edf3;
  --muted: #8a93a6;
  --primary: #4f8cff;
  --primary-d: #3b6fd4;
  --ok: #34c759;
  --partial: #ffb020;
  --miss: #ff453a;
  --radius: 14px;
  --tabbar-h: 60px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

#app { max-width: 560px; margin: 0 auto; min-height: 100vh; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 17px; }
.profile-btn {
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 14px; font-size: 14px; font-weight: 600; cursor: pointer;
  max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* main view */
#view { padding: 14px 14px calc(var(--tabbar-h) + 24px); }
/* when the rest timer is floating, reserve space so the Finish button clears it */
body.timer-active #view { padding-bottom: calc(var(--tabbar-h) + 100px); }

/* cards */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
}
.card.center { text-align: center; }
.card h2, .card h3 { margin: 0 0 10px; }
h2 { font-size: 20px; } h3 { font-size: 16px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { margin-left: auto; }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; }
.row.between { justify-content: space-between; }
.hr { height: 1px; background: var(--border); margin: 16px 0; }

.pill {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 999px; padding: 2px 10px; font-size: 12px; color: var(--muted);
}
.badge {
  display: inline-block; background: var(--primary); color: #fff;
  border-radius: 6px; padding: 1px 8px; font-weight: 700; font-size: 13px;
}

/* buttons */
.btn {
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 16px; font-size: 15px; font-weight: 600; cursor: pointer;
  transition: filter .12s ease;
}
.btn:active { filter: brightness(1.25); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.ghost { background: transparent; }
.btn.block { display: block; width: 100%; margin-top: 10px; }
.btn.big { padding: 15px; font-size: 17px; }
.btn.small { padding: 7px 12px; font-size: 13px; }

/* inputs */
.input {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 12px; font-size: 15px; margin: 6px 0;
}
.input:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
select.input { appearance: none; }
.field { display: block; margin: 8px 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 2px; }
.field.row { display: flex; align-items: center; gap: 10px; }
.field.row > span { margin: 0; }
.field.row input[type=checkbox] { width: 20px; height: 20px; }

/* preview list */
.preview { list-style: none; padding: 0; margin: 10px 0; }
.preview li { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--border); }
.preview li:last-child { border-bottom: none; }

/* exercise card */
.exercise h3 { margin-bottom: 4px; }
.weight-edit { display: flex; align-items: center; gap: 8px; }
.weight-edit .weight { font-weight: 700; min-width: 78px; text-align: center; font-variant-numeric: tabular-nums; }
.stepper {
  width: 38px; height: 38px; border-radius: 10px; font-size: 20px; line-height: 1;
  background: var(--bg-elev); border: 1px solid var(--border); color: var(--text); cursor: pointer;
}
.plates { margin: 6px 0; font-variant-numeric: tabular-nums; }
.warmups { margin: 8px 0; }
.warmups summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.warmups ul { margin: 6px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; }

/* set circles */
.sets { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0 6px; }
.set {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--bg-elev); border: 2px solid var(--border); color: var(--muted);
  font-size: 19px; font-weight: 700; cursor: pointer; font-variant-numeric: tabular-nums;
  transition: transform .08s ease;
}
.set:active { transform: scale(0.92); }
.set.ok { background: var(--ok); border-color: var(--ok); color: #06210f; }
.set.partial { background: var(--partial); border-color: var(--partial); color: #2b1d00; }
.set.miss { background: var(--miss); border-color: var(--miss); color: #2b0000; }

/* sticky header in active workout */
.sticky-h { margin-bottom: 6px; }

/* timer bar */
.timer-bar {
  position: fixed; left: 0; right: 0; bottom: var(--tabbar-h);
  background: var(--bg-elev); border-top: 1px solid var(--border);
  padding: 10px 14px; z-index: 15; max-width: 560px; margin: 0 auto;
}
.timer-bar.hidden { display: none; }
.timer-row { display: flex; align-items: center; justify-content: center; gap: 14px; }
.timer-clock { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 84px; text-align: center; }
.timer-done { text-align: center; font-weight: 700; color: var(--ok); }

/* summary changes */
.change { padding: 6px 0; font-weight: 600; }
.change.up { color: var(--ok); }
.change.down { color: var(--miss); }
.change.flat { color: var(--muted); }

/* history */
.hist summary { cursor: pointer; display: flex; align-items: center; gap: 8px; }
.hist summary::-webkit-details-marker { display: none; }

/* charts */
.chart { width: 100%; height: 190px; display: block; margin: 8px 0; }

/* tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; max-width: 560px; margin: 0 auto;
  background: var(--bg); border-top: 1px solid var(--border);
  height: var(--tabbar-h); padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; background: none; border: none; color: var(--muted);
  font-size: 11px; cursor: pointer; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px; padding: 8px 0;
}
.tab .ti { font-size: 20px; }
.tab.active { color: var(--primary); }

/* run tab */
.progressbar { height: 8px; background: var(--bg-elev); border-radius: 999px; overflow: hidden; margin: 8px 0; }
.progressbar-fill { height: 100%; background: var(--ok); border-radius: 999px; transition: width .3s ease; }
.run-summary { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }
.field.grow { flex: 1; }
.badge.run { background: #ff9f0a; color: #2b1d00; }

/* guided run player */
.run-stage {
  border-radius: var(--radius); padding: 32px 16px; margin: 12px 0; text-align: center;
  background: var(--bg-elev); border: 1px solid var(--border); transition: background .3s ease;
}
.run-stage.phase-run { background: linear-gradient(160deg, #1c5e35, #114023); border-color: #2e8b50; }
.run-stage.phase-walk,
.run-stage.phase-warmup,
.run-stage.phase-cooldown { background: linear-gradient(160deg, #1b3a5e, #112a40); border-color: #2e5e8b; }
.run-stage.paused { filter: grayscale(.5) brightness(.8); }
.run-phase { font-size: 22px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.run-clock { font-size: clamp(64px, 22vw, 96px); font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; margin: 6px 0; }
.run-next { font-size: 15px; min-height: 20px; }
.run-prog { margin-top: 6px; }
.run-controls { display: flex; gap: 10px; }
.run-controls .btn { flex: 1; }

/* plates panel */
.plate-list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.plate-row { display: flex; align-items: center; gap: 10px; }
.plate-wwrap { display: flex; align-items: center; gap: 6px; flex: 1; }
.plate-wwrap .plate-w { width: 100%; margin: 0; }
.plate-count { display: flex; align-items: center; gap: 8px; }
.plate-count .pcount { min-width: 28px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

/* profiles sheet */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 18px 18px 0 0; width: 100%; max-width: 560px;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 80vh; overflow-y: auto;
}
.plist { display: flex; flex-direction: column; gap: 8px; }
.prow { display: flex; align-items: center; gap: 8px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px; padding: 4px 8px; }
.prow.active { border-color: var(--primary); }
.prow-main { flex: 1; text-align: left; background: none; border: none; color: var(--text); padding: 10px 6px; cursor: pointer; }
