/* ---------- tokens ---------- */
:root {
  --bg: #12151b;
  --bg-elev: #1a1f27;
  --bg-elev-2: #222833;
  --line: #2c3340;
  --line-soft: #232a35;
  --text: #e8ecf2;
  --text-dim: #98a2b3;
  --text-faint: #6b7684;
  --accent: #4c8dff;
  --ok: #34d399;
  --warn: #fbbf24;
  --skip: #f472b6;
  --danger: #f87171;
  --radius: 14px;
  --radius-sm: 9px;
  --bar-h: 96px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior-y: none;
}
body { min-height: 100dvh; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: var(--accent); }

/* Author rules below set `display`, which would otherwise beat the UA's
   [hidden] rule and leave the modal permanently on screen. */
[hidden] { display: none !important; }

/* Inline icons carry only a viewBox, so give them a text-sized default box.
   The rules further down (.btn svg, .empty svg, …) refine it per context. */
svg:not([width]) { width: 1.15em; height: 1.15em; vertical-align: -0.15em; }

/* ---------- layout ---------- */
.app { display: flex; flex-direction: column; min-height: 100dvh; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(var(--safe-t) + 10px) 12px 10px;
  background: rgba(18, 21, 27, .9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar h1 {
  font-size: 17px; font-weight: 650; margin: 0; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar .sub { display: block; font-size: 12px; font-weight: 400; color: var(--text-dim); }

.savepill {
  flex: 0 0 auto;
  padding: 3px 9px; border-radius: 999px;
  background: var(--bg-elev-2); border: 1px solid var(--line-soft);
  font-size: 11.5px; font-weight: 600; color: var(--text-dim);
  white-space: nowrap;
}
.savepill.saved { color: var(--ok); border-color: #24493c; }
.savepill.queued { color: var(--warn); border-color: #4a3c1c; }
.savepill.error { color: var(--danger); border-color: #4d2a2d; }

.iconbtn {
  width: 38px; height: 38px; flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 10px; background: var(--bg-elev); color: var(--text-dim);
  border: 1px solid var(--line-soft);
}
.iconbtn:active { background: var(--bg-elev-2); }
.iconbtn svg { width: 19px; height: 19px; }

.content { flex: 1; padding: 14px 12px; }
.content.has-bar { padding-bottom: calc(var(--bar-h) + var(--safe-b) + 28px); }

/* ---------- generic bits ---------- */
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 8px; }
.spacer { flex: 1; }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 13px; }
.tiny { font-size: 11.5px; }
.center { text-align: center; }
.mono { font-variant-numeric: tabular-nums; }
.wrap-any { word-break: break-word; }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 14px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 44px; padding: 0 16px;
  border-radius: 11px; font-weight: 600; font-size: 15px;
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--line);
  text-decoration: none;
}
.btn:active { transform: scale(.985); }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.ok { background: var(--ok); color: #06281c; border-color: transparent; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text-dim); }
.btn.danger { background: transparent; border-color: #4a2b2b; color: var(--danger); }
.btn.block { width: 100%; }
.btn.lg { min-height: 52px; font-size: 16px; }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn svg { width: 18px; height: 18px; flex: 0 0 auto; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 9px; border-radius: 999px;
  background: var(--bg-elev-2); border: 1px solid var(--line-soft);
  font-size: 12px; color: var(--text-dim);
}
.chip.tap:active { background: var(--line); }
.chip svg { width: 13px; height: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 12.5px; color: var(--text-dim); font-weight: 550; }
.input, textarea.input {
  width: 100%; min-height: 44px; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
.input:focus { outline: none; border-color: var(--accent); }
textarea.input { min-height: 70px; resize: vertical; }

.notice {
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px;
  background: #2a2318; border: 1px solid #4a3c1c; color: #f6dfa8;
}
.notice.bad { background: #2b1a1c; border-color: #4d2a2d; color: #f7c4c4; }
.notice.info { background: #17222e; border-color: #2b3d52; color: #bcd7f2; }

.empty { padding: 44px 20px; text-align: center; color: var(--text-dim); }
.empty h2 { color: var(--text); font-size: 17px; margin: 0 0 6px; }
.empty > svg { width: 40px; height: 40px; color: var(--text-faint); }
.empty p { max-width: 34em; margin-inline: auto; }

.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--line); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- workout list ---------- */
.wlist { display: grid; gap: 10px; }
.wcard {
  display: flex; align-items: center; gap: 12px; text-align: left;
  width: 100%; padding: 15px 14px;
  background: var(--bg-elev); border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}
.wcard:active { background: var(--bg-elev-2); }
.wcard .name { display: block; font-weight: 620; font-size: 16px; }
.wcard .meta { display: block; font-size: 12.5px; color: var(--text-dim); margin-top: 3px; }
.wcard .go { color: var(--text-faint); flex: 0 0 auto; }

/* ---------- exercise card ---------- */
.ex {
  background: var(--bg-elev);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
  scroll-margin: 40vh 0;
  transition: border-color .18s, box-shadow .18s, opacity .18s;
}
.ex + .ex { margin-top: 10px; }
.ex.current {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 10px 34px -16px var(--accent);
}
.ex.done { opacity: .62; }
.ex.done .idx { background: var(--ok); color: #06281c; border-color: transparent; }
.ex.skipped { opacity: .55; }
.ex.skipped .idx { background: var(--skip); color: #3d0b26; border-color: transparent; }
.ex.done .ex-title, .ex.skipped .ex-title {
  text-decoration: line-through; text-decoration-color: var(--text-faint);
}

.ex-head { display: flex; gap: 11px; align-items: flex-start; padding: 13px 13px 0; }
.ex-head .idx {
  flex: 0 0 auto; width: 26px; height: 26px; border-radius: 8px;
  display: grid; place-items: center; font-size: 12.5px; font-weight: 700;
  background: var(--bg-elev-2); border: 1px solid var(--line); color: var(--text-dim);
}
.ex-head .hgrow { flex: 1; min-width: 0; }
.ex-title { font-weight: 620; font-size: 15.5px; line-height: 1.3; }
.ex-sub { font-size: 12.5px; color: var(--text-dim); margin-top: 3px; }
.ex-body { padding: 11px 13px 13px; display: flex; flex-direction: column; gap: 11px; }

.media-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.media-strip::-webkit-scrollbar { display: none; }
.thumb {
  /* ~2cm square on a phone, where 1cm is roughly 62 CSS px */
  position: relative; flex: 0 0 auto;
  width: 120px; height: 120px; border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
  border: 1px solid var(--line-soft); overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .fallback {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--text-faint); font-size: 11px; gap: 4px;
}
.thumb .fallback svg { width: 20px; height: 20px; }
.thumb .play { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.28); }
.thumb .play svg { width: 26px; height: 26px; filter: drop-shadow(0 1px 3px rgba(0,0,0,.7)); }
.thumb .tag {
  position: absolute; top: 4px; left: 4px; max-width: calc(100% - 8px);
  background: rgba(0,0,0,.7); border-radius: 5px; padding: 1px 5px;
  font-size: 10px; font-weight: 650; color: #fff;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.targets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.target {
  position: relative;
  background: var(--bg); border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm); padding: 7px 9px;
}
.target.edited { border-color: var(--accent); }
.target.edited label { color: var(--accent); }
.target-all {
  position: absolute; right: 5px; bottom: 5px; z-index: 1;
  padding: 2px 7px; border-radius: 6px;
  background: var(--bg-elev-2); border: 1px solid var(--line);
  font-size: 10.5px; font-weight: 700; letter-spacing: .02em;
  color: var(--text-faint); line-height: 1.5;
}
.target-all:active { background: var(--line); }
.target-all.armed { background: var(--warn); color: #3a2a05; border-color: transparent; }
.target label {
  display: block; font-size: 10.5px; letter-spacing: .05em; text-transform: uppercase;
  color: var(--text-faint); font-weight: 650;
}
.target input {
  width: 100%; background: none; border: 0; padding: 2px 0 0;
  font-size: 19px; font-weight: 650; font-variant-numeric: tabular-nums;
}
.target input:focus { outline: none; }
.target .val { font-size: 19px; font-weight: 650; font-variant-numeric: tabular-nums; padding-top: 2px; }

.hint { font-size: 11.5px; color: var(--text-faint); }
.note-line { font-size: 13px; color: var(--text-dim); display: flex; gap: 7px; align-items: flex-start; }
.note-line svg { width: 14px; height: 14px; flex: 0 0 auto; margin-top: 2.5px; color: var(--warn); }

.ex-actions { display: flex; gap: 8px; }
.ex-actions .btn { flex: 1; min-height: 40px; font-size: 14px; padding: 0 10px; }

/* ---------- bottom bar ---------- */
.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 10px 12px calc(10px + var(--safe-b));
  background: rgba(18, 21, 27, .94);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 9px;
}
.bar-row { display: flex; gap: 8px; align-items: stretch; }
.bar-row .btn { flex: 1; }
.bar-row .btn.narrow { flex: 0 0 auto; }
.bar-now { font-size: 12.5px; color: var(--text-dim); display: flex; gap: 6px; align-items: baseline; min-width: 0; }
.bar-now b {
  color: var(--text); font-weight: 620; font-size: 13.5px; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* rest timer */
.rest { display: flex; align-items: center; gap: 12px; }
.rest-dial { position: relative; width: 54px; height: 54px; flex: 0 0 auto; }
.rest-dial svg { transform: rotate(-90deg); display: block; }
.rest-dial .t {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.rest-info { flex: 1; min-width: 0; }
.rest-info .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ok); font-weight: 700; }
.rest-info .nxt { font-size: 13px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rest-adj { display: flex; gap: 6px; flex: 0 0 auto; }
.rest-adj button {
  min-height: 36px; padding: 0 10px; border-radius: 9px;
  background: var(--bg-elev-2); border: 1px solid var(--line);
  font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums;
}

/* ---------- progress ---------- */
.progress { height: 3px; background: var(--line-soft); border-radius: 2px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--ok); transition: width .3s; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--bar-h) + var(--safe-b) + 24px);
  transform: translateX(-50%);
  z-index: 60; width: max-content; max-width: min(92vw, 460px);
  padding: 11px 15px; border-radius: 11px;
  background: #2a313d; border: 1px solid var(--line);
  box-shadow: 0 12px 32px -10px #000; font-size: 13.5px;
  animation: rise .2s ease-out;
}
.toast.bad { background: #3a2224; border-color: #5a3033; }
.toast.good { background: #1e3a30; border-color: #2f5c4b; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(6,8,12,.72); backdrop-filter: blur(3px);
  animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 560px; max-height: 88dvh; overflow-y: auto;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding: 16px 15px calc(16px + var(--safe-b));
  animation: slideup .22s cubic-bezier(.2,.8,.2,1);
}
@keyframes slideup { from { transform: translateY(16px); } }
.sheet h2 { margin: 0 0 4px; font-size: 17px; }
.sheet .sheet-sub { color: var(--text-dim); font-size: 13px; margin-bottom: 14px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 16px; }
.sheet-actions .btn { flex: 1; }
.grabber { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: -6px auto 12px; }

.modal.lightbox { align-items: center; background: rgba(0,0,0,.93); }
.lightbox-inner { width: 100%; max-width: 900px; padding: 12px; }
.lightbox-inner img, .lightbox-inner video, .lightbox-inner iframe {
  max-width: 100%; max-height: 74dvh; object-fit: contain; display: block;
  margin-inline: auto;
  border-radius: 12px; background: #000; border: 0;
}
/* width:auto keeps a small embedded image at its natural size rather than
   stretching it across the screen; big images still scale down to fit. */
.lightbox-inner img, .lightbox-inner video { width: auto; }
.lightbox-inner iframe { width: 100%; aspect-ratio: 16/9; }
.lightbox-cap { color: var(--text-dim); font-size: 13px; text-align: center; margin-top: 10px; }
.lightbox-cap a { display: inline-block; margin-top: 4px; }

/* ---------- option rows (alternatives) ---------- */
.opt {
  display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
  padding: 11px; border-radius: 11px;
  background: var(--bg); border: 1px solid var(--line-soft);
}
.opt:active { background: var(--bg-elev-2); }
.opt .thumb { width: 54px; height: 44px; }
.opt .n { flex: 1; min-width: 0; }
.opt .n b { display: block; font-weight: 600; font-size: 14px; }
.opt > svg { width: 18px; height: 18px; flex: 0 0 auto; color: var(--text-faint); }
.opt .n span { font-size: 12px; color: var(--text-dim); }

/* ---------- diff list (finish sheet) ---------- */
.diff { display: flex; flex-direction: column; gap: 7px; max-height: 38dvh; overflow-y: auto; }
.diff-row {
  display: flex; gap: 10px; align-items: center; font-size: 13px;
  background: var(--bg); border: 1px solid var(--line-soft); border-radius: 9px; padding: 8px 10px;
}
.diff-row .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.diff-row .v { font-variant-numeric: tabular-nums; color: var(--text-dim); font-size: 12.5px; flex: 0 0 auto; }
.diff-row .v b { color: var(--ok); font-weight: 620; }
.diff-row .v s { color: var(--text-faint); }

/* ---------- setup / settings ---------- */
.steps { counter-reset: s; display: flex; flex-direction: column; gap: 13px; }
.step { position: relative; padding-left: 32px; font-size: 13.5px; color: var(--text-dim); }
.step::before {
  counter-increment: s; content: counter(s);
  position: absolute; left: 0; top: 0;
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; font-size: 11.5px; font-weight: 700;
  background: var(--bg-elev-2); border: 1px solid var(--line); color: var(--text);
}
.step b { color: var(--text); font-weight: 600; }
.step-aside {
  display: block; margin-top: 7px; padding-left: 9px;
  border-left: 2px solid var(--line);
  font-size: 12px; color: var(--text-faint);
}
code {
  background: var(--bg); border: 1px solid var(--line); border-radius: 5px;
  padding: 1px 5px; font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
}
.section-title {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-faint); font-weight: 700; margin: 20px 0 8px;
}
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line-soft); font-size: 14px; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--text-dim); flex: 0 0 auto; }
.kv .v { text-align: right; min-width: 0; word-break: break-all; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line-soft); }
.switch:last-child { border-bottom: 0; }
.switch .lbl { font-size: 14px; }
.switch .lbl small { display: block; color: var(--text-faint); font-size: 12px; }
.switch input {
  width: 46px; height: 28px; appearance: none; -webkit-appearance: none; border-radius: 999px;
  background: var(--line); position: relative; transition: background .18s; flex: 0 0 auto; margin: 0;
}
.switch input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: #fff; transition: transform .18s;
}
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }
.switch input:disabled { opacity: .4; }

.tabspec { font-size: 12px; color: var(--text-dim); }
.tabspec h4 { margin: 13px 0 5px; font-size: 13px; color: var(--text); }
.tabspec .cols { display: flex; flex-wrap: wrap; gap: 4px; }
.tabspec .cols span {
  background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 2px 6px;
  font-family: ui-monospace, Menlo, monospace; font-size: 11px;
}
.tabspec .cols span.opt-col { color: var(--text-faint); border-style: dashed; }
