:root {
  color-scheme: dark;
  --bg: #0e1014;
  --surface: #171a21;
  --surface-2: #20242d;
  --line: #2b303b;
  --text: #eef0f4;
  --muted: #98a0b0;
  --accent: #ff8a3d;
  --accent-ink: #1d0e02;
  --ok: #34d399;
  --ok-ink: #02150e;
  --ok-soft: rgba(52, 211, 153, 0.12);
  --danger: #f87171;
  --fig-body: #e3e7ee;
  --fig-eq: #5a6274;
  --radius: 16px;
  --tabs-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f3f4f6;
    --surface: #ffffff;
    --surface-2: #eef0f3;
    --line: #dde1e7;
    --text: #15171c;
    --muted: #5d6474;
    --accent: #e8680f;
    --accent-ink: #ffffff;
    --ok: #0f9f6e;
    --ok-ink: #ffffff;
    --ok-soft: rgba(15, 159, 110, 0.1);
    --danger: #d63b3b;
    --fig-body: #1e2229;
    --fig-eq: #a4abb8;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding: calc(var(--safe-t) + 8px) 0 calc(var(--tabs-h) + var(--safe-b) + 16px);
  overscroll-behavior-y: none;
}
body.has-timer { padding-bottom: calc(var(--tabs-h) + var(--safe-b) + 96px); }
body.sheet-open { overflow: hidden; }

#view { max-width: 640px; margin: 0 auto; padding: 0 16px; }

h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 28px; letter-spacing: -0.02em; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
p { margin: 0; }
.muted { color: var(--muted); }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 20px 4px 8px; }

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; }

.top { padding: 12px 4px 16px; }
.sub { color: var(--muted); margin-top: 4px; font-size: 15px; }

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

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px;
  background: var(--surface-2); color: var(--text); font-weight: 600;
  border: 1px solid var(--line);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.big { width: 100%; min-height: 52px; font-size: 17px; margin-top: 10px; }
.btn.sm { min-height: 36px; padding: 0 14px; font-size: 15px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.danger { color: var(--danger); }
.btn.danger:not(.ghost) { background: var(--danger); color: #fff; border-color: transparent; }
.btn:active { transform: scale(0.98); }
.link { color: var(--accent); font-weight: 600; font-size: 15px; padding: 8px 0; min-height: 36px; }
.link.danger { color: var(--danger); }

.letter {
  width: 56px; height: 56px; border-radius: 14px; flex: none;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  font-size: 30px; font-weight: 800;
}
.letter.sm { width: 38px; height: 38px; border-radius: 10px; font-size: 20px; }

/* ---------- home ---------- */
.eyebrow { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 10px; }
.next-row { display: flex; gap: 14px; align-items: center; }
.next-row p { margin-top: 2px; font-size: 15px; }
.plan-list { list-style: none; margin: 16px 0 6px; padding: 0; counter-reset: n; }
.plan-list li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 8px 0; border-top: 1px solid var(--line); font-size: 15px;
  counter-increment: n;
}
.plan-list li span:first-child::before { content: counter(n) ". "; color: var(--muted); }
.plan-list li span:last-child { white-space: nowrap; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stats b { display: block; font-size: 17px; }
.stats span { font-size: 13px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; font-size: 14px;
}
.chip b {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); font-size: 13px;
}

/* ---------- workout ---------- */
.wk-head {
  position: sticky; top: 0; z-index: 5;
  margin: calc(-8px - var(--safe-t)) -16px 12px;
  padding: calc(var(--safe-t) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.wk-row { display: flex; align-items: center; gap: 12px; }
.wk-title { flex: 1; min-width: 0; }
.wk-title h2 { font-size: 18px; }
.wk-title .muted { font-size: 14px; font-variant-numeric: tabular-nums; }
.progress { height: 4px; background: var(--surface-2); border-radius: 4px; margin-top: 10px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--ok); transition: width 0.3s; }

.ex { padding: 14px; }
.ex-head { display: flex; gap: 12px; align-items: flex-start; position: relative; }
.fig {
  width: 104px; height: 78px; flex: none; border-radius: 12px;
  background: var(--surface-2); padding: 2px; overflow: hidden;
}
.fig > div { width: 100%; height: 100%; }
.ex-meta { flex: 1; min-width: 0; padding-top: 2px; }
.muscle { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.ex-meta h3 { margin: 2px 0 6px; font-size: 17px; }
.target { display: flex; flex-wrap: wrap; gap: 4px 6px; }
.target span {
  font-size: 13px; padding: 2px 8px; border-radius: 6px;
  background: var(--surface-2); color: var(--text); white-space: nowrap;
}
.target span:first-child { background: color-mix(in srgb, var(--accent) 18%, transparent); font-weight: 600; }
.done-mark {
  display: none; position: absolute; right: 0; top: 0;
  width: 26px; height: 26px; border-radius: 50%; background: var(--ok); place-items: center;
}
.done-mark svg { width: 16px; height: 16px; fill: none; stroke: var(--ok-ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.ex.done { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.ex.done .done-mark { display: grid; }
.ex.done .cues { display: none; }

.cues { margin: 12px 0 0; padding: 0 0 0 18px; font-size: 14px; color: var(--muted); }
.cues li { margin: 3px 0; }
.cues li::marker { color: var(--accent); }
.cues.big { font-size: 16px; color: var(--text); padding-left: 20px; margin-bottom: 4px; }

.last { margin-top: 10px; font-size: 14px; font-variant-numeric: tabular-nums; }
.last .lbl { color: var(--muted); margin-right: 4px; }
.hint { margin-top: 6px; font-size: 14px; padding: 8px 10px; border-radius: 10px; }
.hint.up { background: var(--ok-soft); color: var(--ok); font-weight: 600; }

.sets { margin-top: 12px; display: grid; gap: 8px; }
.set { display: grid; grid-template-columns: 26px 1fr 1fr 48px; gap: 8px; align-items: center; }
.set-n { text-align: center; color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; }
.fld {
  display: flex; align-items: baseline; gap: 4px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 0 10px; height: 48px; align-items: center;
}
.fld:focus-within { border-color: var(--accent); }
.fld input {
  width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text);
  font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; padding: 0;
}
.fld input::placeholder { color: var(--muted); opacity: 0.6; font-weight: 500; }
.fld span { font-size: 13px; color: var(--muted); }
.tick {
  width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center;
  border: 2px solid var(--line); background: transparent;
}
.tick svg { width: 24px; height: 24px; fill: none; stroke: var(--muted); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; opacity: 0.5; }
.set.done .tick { background: var(--ok); border-color: var(--ok); }
.set.done .tick svg { stroke: var(--ok-ink); opacity: 1; }
.set.done .fld { background: var(--ok-soft); border-color: transparent; }
.set.extra:not(.done) { opacity: 0.6; }

.ex-actions { display: flex; justify-content: space-between; margin-top: 6px; }

.collapsed { padding: 12px 14px; border-style: dashed; }
.opt-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.opt-row b { font-size: 15px; }
.opt-row .muted { font-size: 14px; }

.ss-group {
  border-left: 3px solid var(--accent);
  padding-left: 10px; margin: 0 0 12px -2px;
}
.ss-group.off { border-left-color: var(--line); }
.ss-group .ex { margin-bottom: 8px; }
.ss-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 0 8px; font-size: 14px; }
.ss-head .muted { flex: 1; }
.ss-badge {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  background: var(--accent); color: var(--accent-ink); padding: 3px 8px; border-radius: 6px;
}
.ss-group.off .ss-badge { background: var(--surface-2); color: var(--muted); }

.wk-foot { margin: 20px 0 8px; }

/* ---------- history ---------- */
.hist { padding: 0; }
.hist summary {
  list-style: none; display: flex; align-items: center; gap: 12px; padding: 14px; cursor: pointer;
}
.hist summary::-webkit-details-marker { display: none; }
.hist-meta { flex: 1; display: flex; flex-direction: column; }
.hist-meta .muted { font-size: 14px; }
.chev { width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform 0.2s; }
.hist[open] .chev { transform: rotate(90deg); }
.hist-items { list-style: none; margin: 0; padding: 0 14px; }
.hist > .hist-items { border-top: 1px solid var(--line); }
.hist-items li {
  display: flex; justify-content: space-between; gap: 12px; padding: 10px 0;
  border-bottom: 1px solid var(--line); font-size: 15px;
}
.hist-items li:last-child { border-bottom: 0; }
.hist-items .muted { text-align: right; font-variant-numeric: tabular-nums; }
.hist-actions { padding: 4px 14px 10px; }
.backup h3 { margin-bottom: 6px; }
.backup .row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.empty { text-align: center; padding: 28px 16px; }
.empty p + p { margin-top: 6px; }

/* ---------- program ---------- */
.prose h3 { margin: 18px 0 8px; }
.prose h3:first-child { margin-top: 0; }
.prose ul, .prose ol { margin: 0; padding-left: 20px; }
.prose li { margin: 4px 0; }
.prose p { margin: 6px 0; }
.rule { margin-top: 16px !important; padding: 12px; border-radius: 10px; background: var(--surface-2); font-weight: 600; }
.card > h3 .muted { font-weight: 400; font-size: 14px; margin-left: 4px; }
.ptable { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 14px; }
.ptable th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; padding: 6px 4px; }
.ptable td { padding: 8px 4px; border-top: 1px solid var(--line); vertical-align: top; }
.ptable td:first-child b { display: block; font-weight: 600; }
.ptable td:first-child .muted { font-size: 12px; }
.ptable td:nth-child(2), .ptable td:nth-child(3) { white-space: nowrap; }

/* ---------- timer ---------- */
#timer {
  position: fixed; z-index: 20; left: 8px; right: 8px;
  bottom: calc(var(--tabs-h) + var(--safe-b) + 8px);
  max-width: 624px; margin: 0 auto;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35); overflow: hidden;
}
#timer[hidden] { display: none; }
.t-row { display: flex; align-items: center; gap: 6px; padding: 10px 10px 10px 16px; }
.t-main { flex: 1; min-width: 0; }
.t-label { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-time { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
#timer button {
  min-width: 52px; height: 44px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line);
  font-weight: 700; font-variant-numeric: tabular-nums;
}
#timer .t-skip { color: var(--accent); }
.t-bar { height: 4px; background: var(--line); }
.t-bar i { display: block; height: 100%; background: var(--accent); transition: width 0.25s linear; }
#timer.over { background: var(--ok); border-color: var(--ok); animation: pulse 1s ease-in-out infinite alternate; }
#timer.over .t-label, #timer.over .t-time { color: var(--ok-ink); }
@keyframes pulse { from { opacity: 1; } to { opacity: 0.85; } }

/* ---------- tabs ---------- */
#tabs {
  position: fixed; z-index: 15; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center;
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
#tabs button {
  flex: 1; max-width: 200px; height: var(--tabs-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11px; font-weight: 600; position: relative;
}
#tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#tabs button.active { color: var(--accent); }
#tabs button.live::after {
  content: ""; position: absolute; top: 8px; left: calc(50% + 10px);
  width: 8px; height: 8px; border-radius: 50%; background: var(--ok);
}

/* ---------- sheet ---------- */
#sheet-root:empty { display: none; }
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.5);
  opacity: 0; transition: opacity 0.2s;
}
.sheet {
  position: fixed; z-index: 41; left: 0; right: 0; bottom: 0;
  max-width: 640px; margin: 0 auto; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(16px + var(--safe-b));
  transform: translateY(100%); transition: transform 0.25s ease;
}
#sheet-root.open .sheet-backdrop { opacity: 1; }
#sheet-root.open .sheet { transform: none; }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.sheet h2 { margin: 4px 0 8px; }
.sheet > p { margin-bottom: 8px; }
.info-fig { height: 210px; background: var(--surface-2); border-radius: 14px; margin-bottom: 14px; padding: 6px; }
.swap-list { display: grid; gap: 8px; margin-top: 12px; }
.swap {
  display: flex; align-items: center; gap: 12px; text-align: left; padding: 8px;
  background: var(--surface-2); border: 2px solid transparent; border-radius: 12px;
}
.swap.current { border-color: var(--accent); }
.swap > span:last-child { display: flex; flex-direction: column; }
.swap .muted { font-size: 13px; }
.swap-fig { width: 80px; height: 60px; flex: none; }

/* ---------- toast ---------- */
#toast {
  position: fixed; z-index: 50; left: 50%; top: calc(var(--safe-t) + 12px);
  transform: translate(-50%, -150%); transition: transform 0.25s ease;
  background: var(--text); color: var(--bg); font-weight: 600; font-size: 15px;
  padding: 10px 16px; border-radius: 12px; max-width: calc(100vw - 32px); text-align: center;
  pointer-events: none;
}
#toast.show { transform: translate(-50%, 0); }

/* ---------- exercise figures ---------- */
.figsvg { width: 100%; height: 100%; display: block; overflow: visible; }
.figsvg line { stroke-linecap: round; }
.figsvg .bd { stroke: var(--fig-body); stroke-width: 4.4; }
.figsvg .far { stroke: var(--fig-body); stroke-opacity: 0.38; stroke-width: 4.4; }
.figsvg .head { fill: var(--fig-body); }
.figsvg .eq { stroke: var(--fig-eq); stroke-width: 2.2; fill: none; }
.figsvg .eqf, .figsvg .padf, .figsvg .barEnd { fill: var(--fig-eq); }
.figsvg .pad { stroke: var(--fig-eq); stroke-width: 5; }
.figsvg .padl { stroke: var(--fig-eq); stroke-width: 6; }
.figsvg .plat { stroke: var(--fig-eq); stroke-width: 3.5; }
.figsvg .gnd { stroke: var(--line); stroke-width: 1.5; }
.figsvg .cab { stroke: var(--fig-eq); stroke-width: 1; stroke-dasharray: 2 1.5; }
.figsvg .wt, .figsvg .dbbar { fill: var(--accent); }
.figsvg .hub { fill: var(--surface-2); }
.figsvg .bar { stroke: var(--accent); stroke-width: 2.8; fill: none; stroke-linejoin: round; }

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