/* Mobile-first, dark by default, light via prefers-color-scheme. */
:root {
  --bg: #111418;
  --surface: #1b2027;
  --surface-2: #252c35;
  --line: #333c47;
  --text: #eef1f4;
  --muted: #9aa5b1;
  --accent: #3fb6ff;
  --accent-ink: #04121c;
  --good: #3ccf8e;
  --good-ink: #03140c;
  --warn: #f2b33d;
  --danger: #ff6b6b;
  --chart-line: #3fb6ff;
  --chart-grid: #2c343e;
  --radius: 14px;
  --tap: 48px;
  --nav-h: 58px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #eceff3;
    --line: #d5dbe2;
    --text: #12161b;
    --muted: #5b6672;
    --accent: #0a6fc2;
    --accent-ink: #ffffff;
    --good: #138a55;
    --good-ink: #ffffff;
    --warn: #9a6400;
    --danger: #c62828;
    --chart-line: #0a6fc2;
    --chart-grid: #e1e6ec;
    color-scheme: light;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  padding: calc(var(--sat) + 8px) calc(var(--sar) + 12px) calc(var(--sab) + var(--nav-h) + 16px) calc(var(--sal) + 12px);
}

body.modal-open { overflow: hidden; }

main { max-width: 560px; margin: 0 auto; }

h1 { font-size: 1.6rem; margin: 0.3em 0 0.4em; }
h2 { font-size: 1.1rem; margin: 0.2em 0 0.5em; }
h3 { font-size: 1rem; margin: 1em 0 0.4em; }
p { margin: 0.5em 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.grow { flex: 1 1 auto; min-width: 0; }
.loading { text-align: center; color: var(--muted); margin-top: 30vh; }

.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin: 12px 0;
  color: inherit;
  text-decoration: none;
}
.card.warn { border-color: var(--warn); color: var(--warn); font-weight: 600; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.btn:active { filter: brightness(1.2); transform: scale(0.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.small { min-height: 40px; padding: 0 12px; font-size: 0.9rem; }
.btn.big { width: 100%; min-height: 60px; font-size: 1.15rem; margin: 10px 0; }
.btn.log { min-height: 68px; font-size: 1.25rem; }
.file-btn { margin-top: 10px; width: 100%; }
.link-btn { background: none; border: 0; color: var(--accent); font: inherit; padding: 10px 0; min-height: 40px; cursor: pointer; }
.icon-btn {
  width: var(--tap); height: var(--tap); flex: 0 0 var(--tap);
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: 0; color: var(--muted); padding: 10px; cursor: pointer; font: inherit;
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:disabled { opacity: 0.3; }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row > .btn { flex: 1 1 0; }
.row.tight { gap: 0; flex-wrap: nowrap; }
.small-row { margin-top: 6px; }
.small-row > .btn { flex: 1 1 auto; }

.badge {
  display: inline-block; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 2px 6px; border-radius: 6px; background: var(--good); color: var(--good-ink); vertical-align: middle;
}
.chip { background: var(--accent); color: var(--accent-ink); font-weight: 800; border-radius: 8px; padding: 4px 8px; font-size: 0.9rem; flex: 0 0 auto; }

/* ---------- segmented ---------- */
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; margin: 6px 0; }
.seg button {
  flex: 1 1 0; min-width: 0; min-height: 44px; border: 0; border-radius: 9px; background: transparent; color: var(--text);
  font: inherit; font-weight: 600; font-size: 0.95rem; padding: 0 4px; cursor: pointer; touch-action: manipulation;
}
.seg button.on { background: var(--accent); color: var(--accent-ink); }

/* ---------- home ---------- */
.session-list { display: grid; gap: 8px; }
.session {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  width: 100%; min-height: 72px; padding: 12px 14px; border-radius: var(--radius);
  border: 2px solid var(--line); background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
}
.session.on { border-color: var(--accent); }
.session-name { font-weight: 700; font-size: 1.1rem; }
.resume { display: flex; align-items: center; gap: 12px; border-color: var(--accent); }
.links { text-align: center; }

/* ---------- workout ---------- */
.wk-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-top: 4px; }
.progress { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin: 8px 0 4px; }
.progress > div { height: 100%; background: var(--good); transition: width 0.3s; }

.rest { border-color: var(--accent); text-align: center; }
.rest.done { border-color: var(--good); background: color-mix(in srgb, var(--good) 18%, var(--surface)); animation: pulse 1s ease-in-out 3; }
.rest-top { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; flex-wrap: wrap; }
.rest.done .rest-top span:first-child { color: var(--good); font-size: 1.3rem; }
@keyframes pulse { 50% { transform: scale(1.02); } }

.clock { font-size: 3.4rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; line-height: 1.1; margin: 6px 0; text-align: center; }
.clock.running { color: var(--accent); }
.clock.reached { color: var(--good); }

.current { border-color: var(--accent); }
.cur-head { display: flex; align-items: center; gap: 10px; }
.cur-head h2 { margin: 0; font-size: 1.25rem; overflow-wrap: anywhere; }
.meta { font-weight: 600; margin: 6px 0 2px; }

.sugg { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 8px 0; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); font-weight: 600; font-size: 0.95rem; }
.sugg.add, .sugg.next { border-left: 4px solid var(--good); }
.sugg.easier { border-left: 4px solid var(--warn); }
.sugg.repeat, .sugg.harder { border-left: 4px solid var(--line); font-weight: 500; }

.inputs { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 10px 0 4px; }
.stepper-wrap { min-width: 0; }
.stepper-label { font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.stepper-unit { display: none; }
.stepper { display: flex; align-items: stretch; background: var(--surface-2); border-radius: 12px; overflow: hidden; }
.step {
  flex: 0 0 52px; min-height: 56px; border: 0; background: transparent; color: var(--text);
  font-size: 1.6rem; font-weight: 600; cursor: pointer; touch-action: manipulation;
}
.step:active { background: var(--line); }
.step-val {
  flex: 1 1 auto; min-width: 0; width: 100%; text-align: center; border: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums;
}
.step-val:focus { outline: 2px solid var(--accent); outline-offset: -2px; }

.toggle-row { margin-top: 8px; }
.rir { margin-top: 8px; }
.hold { text-align: center; }
.hold .row > .btn { flex: 1 1 0; }

.sets { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; }
.setrow {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: var(--tap);
  padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: transparent; color: var(--text);
  font: inherit; text-align: left; cursor: pointer;
}
.setrow .n { font-weight: 800; width: 1.4em; color: var(--muted); }
.setrow.done { background: color-mix(in srgb, var(--good) 14%, transparent); border-color: transparent; }
.setrow.done span:last-child { color: var(--good); font-weight: 800; }
.setrow.skipped { opacity: 0.55; }
.setrow.cur { border-color: var(--accent); border-width: 2px; }

.overview summary { cursor: pointer; font-weight: 700; min-height: 32px; list-style-position: inside; }
.ov-block { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 8px; }
.ov-head { display: flex; align-items: center; justify-content: space-between; }
.ov-item { display: flex; align-items: center; gap: 8px; }
.ov-item.skipped .ov-name { text-decoration: line-through; opacity: 0.6; }
.ov-item.cur .ov-name { color: var(--accent); font-weight: 700; }
.ov-name { background: none; border: 0; color: var(--text); font: inherit; text-align: left; min-height: var(--tap); padding: 4px 0; cursor: pointer; overflow-wrap: anywhere; }
.overview .btn.danger { margin-top: 12px; width: 100%; }

.notes span { display: block; font-weight: 700; margin-bottom: 6px; }
textarea, input, select { font: inherit; color: var(--text); }
textarea {
  width: 100%; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); padding: 10px; resize: vertical;
  font-size: 16px; /* >=16px stops iOS zooming on focus */
}

.warmup .checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { display: flex; align-items: center; }
.check {
  display: flex; align-items: center; gap: 10px; flex: 1 1 auto; min-width: 0; min-height: var(--tap);
  background: none; border: 0; color: var(--text); font: inherit; text-align: left; padding: 4px 0; cursor: pointer;
}
.check .box {
  flex: 0 0 26px; height: 26px; border-radius: 7px; border: 2px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 800; color: var(--good-ink);
}
.check.on .box { background: var(--good); border-color: var(--good); }
.check.on .grow { color: var(--muted); }

.update-banner {
  display: block; width: 100%; min-height: var(--tap); margin: 4px 0 8px; border: 0; border-radius: 12px;
  background: var(--good); color: var(--good-ink); font: inherit; font-weight: 700; cursor: pointer;
}

/* ---------- lists / history ---------- */
.list { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 8px; }
.list-item {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; min-height: 60px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); text-decoration: none;
  overflow-wrap: anywhere;
}
.chev { color: var(--muted); font-size: 1.5rem; }
.sum-row { padding: 8px 0; border-bottom: 1px solid var(--line); }
.sum-row:last-child { border-bottom: 0; }

.edit-row { display: flex; align-items: flex-end; gap: 6px; margin: 6px 0; }
.edit-row .n { font-weight: 800; color: var(--muted); width: 1.2em; padding-bottom: 12px; }
.mini { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; }
.mini span { font-size: 0.75rem; color: var(--muted); }
.mini input {
  width: 100%; min-height: 44px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2);
  text-align: center; font-size: 16px; padding: 0 4px;
}

.chart { width: 100%; height: auto; display: block; margin-top: 6px; }
.chart-line { fill: none; stroke: var(--chart-line); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: var(--chart-line); stroke: var(--surface); stroke-width: 2; }
.chart-grid { stroke: var(--chart-grid); stroke-width: 1; }
.chart-axis { fill: var(--muted); font-size: 11px; }

.cues { padding-left: 1.2em; }
.prog { padding-left: 0; list-style: none; counter-reset: p; }
.prog li { display: flex; align-items: center; gap: 8px; min-height: 44px; border-bottom: 1px solid var(--line); counter-increment: p; }
.prog li::before { content: counter(p) "."; color: var(--muted); width: 1.5em; }
.prog li.cur { font-weight: 700; }

/* ---------- settings ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
.field > span { font-size: 0.9rem; color: var(--muted); }
.field input[type="number"], .field select {
  min-height: var(--tap); border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); padding: 0 12px; font-size: 16px; width: 100%;
}
.field.switch { flex-direction: row; align-items: center; justify-content: space-between; min-height: var(--tap); }
.field.switch input { width: 28px; height: 28px; accent-color: var(--accent); }

/* ---------- bottom sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 85vh; overflow-y: auto;
  background: var(--surface); border-radius: 18px 18px 0 0; border-top: 1px solid var(--line);
  padding: 14px calc(var(--sar) + 16px) calc(var(--sab) + 20px) calc(var(--sal) + 16px);
  max-width: 600px; margin: 0 auto; -webkit-overflow-scrolling: touch;
}
.sheet-head { display: flex; align-items: center; gap: 8px; position: sticky; top: -14px; background: var(--surface); padding: 4px 0; }

/* ---------- bottom nav ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 0 var(--sar) var(--sab) var(--sal);
}
.tabs a {
  flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--nav-h); color: var(--muted); text-decoration: none; font-size: 0.75rem; font-weight: 600; position: relative;
}
.tabs a svg { width: 24px; height: 24px; }
.tabs a.active { color: var(--accent); }
.tabs a.live::after { content: ""; position: absolute; top: 8px; right: calc(50% - 18px); width: 8px; height: 8px; border-radius: 50%; background: var(--good); }

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