:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface2: #222631;
  --line: #2c313d;
  --text: #eef1f5;
  --muted: #98a1b1;
  --accent: #c6f432;
  --accent-ink: #11140a;
  --ok: #3ddc97;
  --warn: #ffb547;
  --danger: #ff6464;
  --radius: 14px;
  --tap: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f4f7; --surface: #ffffff; --surface2: #eceef3; --line: #dde0e7;
    --text: #151821; --muted: #5d6573; --accent: #4f7d00; --accent-ink: #ffffff;
    --ok: #0f9d63; --warn: #b36b00; --danger: #d33a3a;
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 15px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- layout */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-t)) 8px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar .title { flex: 1; min-width: 0; font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }
.iconbtn {
  min-width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent;
  display: inline-flex; align-items: center; justify-content: center; font-size: 22px; padding: 0 8px;
}
.iconbtn:active { background: var(--surface2); }
.sync { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); margin: 0 10px; flex: none; }
.sync.pending { background: var(--warn); }
.sync.offline { background: var(--danger); }

.page { max-width: 600px; margin: 0 auto; padding: 16px 16px calc(96px + var(--safe-b)); }
.page.has-sessnav { padding-bottom: calc(170px + var(--safe-b)); }
.stack > * + * { margin-top: 12px; }
.section { margin-top: 24px; }
.section > h3 { margin-bottom: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 6px calc(6px + var(--safe-b));
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; font-size: 11px; color: var(--muted); border-radius: 10px; }
.tabbar a span { display: block; width: 24px; height: 24px; }
.tabbar svg { width: 24px; height: 24px; display: block; }
.tabbar a.on { color: var(--accent); }

/* ---------- cards & lists */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card.hero { background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 18%, var(--surface)) 0%, var(--surface) 70%); }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 60px; border-top: 1px solid var(--line); width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; }
.item:first-child { border-top: 0; }
.item:active { background: var(--surface2); }
.item .t { font-weight: 600; }
.item .s { font-size: 13px; color: var(--muted); }
.item .chev { color: var(--muted); font-size: 20px; }
.thumb { width: 46px; height: 46px; border-radius: 10px; object-fit: cover; background: var(--surface2); flex: none; }
.thumb.empty { display: grid; place-items: center; color: var(--muted); font-size: 18px; }
.label {
  display: inline-grid; place-items: center; min-width: 34px; height: 26px; padding: 0 6px;
  border-radius: 8px; background: var(--surface2); font-weight: 700; font-size: 13px; flex: none;
}
.label.done { background: color-mix(in srgb, var(--ok) 25%, var(--surface2)); color: var(--ok); }
.ss-group { border-left: 3px solid var(--accent); }
.ss-tag { font-size: 11px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .05em; padding: 8px 14px 0; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--surface2); }
.badge.ok { background: color-mix(in srgb, var(--ok) 22%, transparent); color: var(--ok); }
.badge.pr { background: color-mix(in srgb, var(--warn) 25%, transparent); color: var(--warn); }
.progress { height: 6px; border-radius: 3px; background: var(--surface2); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-height: 96px; display: flex; flex-direction: column; justify-content: space-between; text-align: left; }
.tile:active { background: var(--surface2); }
.tile .big { font-size: 34px; font-weight: 800; line-height: 1; }
.tile.next { border-color: var(--accent); }

/* ---------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface2); font-weight: 650; font-size: 16px; text-align: center;
}
.btn:active { filter: brightness(1.15); transform: scale(.99); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.block { display: flex; width: 100%; }
.btn.xl { min-height: 64px; font-size: 18px; }
.btn.sm { min-height: 40px; padding: 0 12px; font-size: 14px; border-radius: 11px; }
.btn[disabled] { opacity: .45; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 14px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* ---------- video */
.video-wrap { margin: -16px -16px 0; background: #000; position: relative; }
.video-wrap video { display: block; width: 100%; max-height: 46vh; object-fit: contain; background: #000; }
.video-wrap .novideo { height: 120px; display: grid; place-items: center; color: #8a8f99; font-size: 14px; }
.vtabs { display: flex; gap: 6px; position: absolute; top: 8px; left: 8px; }
.vtabs button { border: 0; border-radius: 8px; padding: 4px 10px; background: rgba(0,0,0,.55); color: #fff; font-size: 13px; font-weight: 700; }
.vtabs button.on { background: var(--accent); color: var(--accent-ink); }
.vcontrols { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; padding: 6px 8px 8px; background: #000; }
.vcontrols button { height: 44px; border: 0; border-radius: 10px; background: #1b1d22; color: #fff; font-size: 15px; font-weight: 650; }
.vcontrols button:active { background: #2c2f36; }
.vcontrols button.on { color: var(--accent); }
.vseek { width: 100%; display: block; margin: 0; padding: 0 8px; background: #000; accent-color: var(--accent); height: 28px; }

/* ---------- exercise page */
.ex-head { margin-top: 16px; }
.ex-head h1 { font-size: 23px; }
.target { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.target .badge { font-size: 13px; padding: 5px 10px; }
.last { font-size: 14px; color: var(--muted); }
.last b { color: var(--text); font-weight: 600; }
.hint { font-size: 14px; padding: 10px 12px; border-radius: 12px; background: var(--surface2); }

.sets { margin-top: 16px; }
.setline {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 12px 14px; min-height: 56px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface); text-align: left; margin-top: 8px;
}
.setline .n { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 800; background: var(--surface2); flex: none; }
.setline.logged .n { background: var(--ok); color: #06140d; }
.setline.optional { border-style: dashed; }
.setline .v { flex: 1; font-weight: 650; font-variant-numeric: tabular-nums; }
.setline .e { font-size: 12px; color: var(--muted); }

.editor { margin-top: 8px; padding: 14px; border-radius: 16px; background: var(--surface); border: 2px solid var(--accent); }
.editor .lbl { font-size: 13px; color: var(--muted); font-weight: 600; margin: 10px 0 6px; display: flex; justify-content: space-between; }
.editor .lbl:first-child { margin-top: 0; }
.stepper { display: grid; grid-template-columns: 64px 1fr 64px; gap: 8px; }
.stepper button { height: 58px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface2); font-size: 28px; font-weight: 600; }
.stepper button:active { background: var(--line); }
.stepper input {
  height: 58px; width: 100%; border-radius: 14px; border: 1px solid var(--line); background: var(--bg);
  text-align: center; font-size: 26px; font-weight: 750; font-variant-numeric: tabular-nums;
}
.stepper input:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.rir { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.rir button { height: 50px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface2); font-size: 18px; font-weight: 750; }
.rir button.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.rir button.tgt { box-shadow: inset 0 -3px 0 color-mix(in srgb, var(--accent) 55%, transparent); }
.editor .actions { display: flex; gap: 8px; margin-top: 14px; }
.editor .actions .btn.primary { flex: 1; }

textarea, .input {
  width: 100%; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  padding: 12px; font-size: 16px;
}
textarea { min-height: 72px; resize: vertical; }
select.input { appearance: none; -webkit-appearance: none; }

/* ---------- session nav + timer */
.sessnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px;
  padding: 8px 10px calc(8px + var(--safe-b));
  background: color-mix(in srgb, var(--surface) 95%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.sessnav a, .sessnav button {
  min-height: 54px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface2);
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 4px 10px;
  font-weight: 700; font-size: 15px; overflow: hidden;
}
.sessnav small { display: block; font-size: 11px; font-weight: 500; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.sessnav .mid { font-size: 20px; padding: 0 14px; }
.sessnav .next.go { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.sessnav .next.go small { color: color-mix(in srgb, var(--accent-ink) 70%, transparent); }
.sessnav .off { opacity: .35; pointer-events: none; }

#timer {
  position: fixed; left: 10px; right: 10px; z-index: 40;
  bottom: calc(80px + var(--safe-b));
  max-width: 580px; margin: 0 auto;
  border-radius: 16px; background: var(--surface2); border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(0,0,0,.35); overflow: hidden;
}
body.no-sessnav #timer { bottom: calc(80px + var(--safe-b)); }
#timer .bar { height: 4px; background: var(--accent); transition: width .25s linear; }
#timer .in { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 14px; }
#timer .clock { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 84px; }
#timer .what { flex: 1; min-width: 0; font-size: 12px; color: var(--muted); line-height: 1.35; }
#timer .what > div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#timer .what b { color: var(--text); }
#timer button { height: 44px; min-width: 50px; border-radius: 11px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; }
#timer.done { background: var(--accent); color: var(--accent-ink); animation: pulse 1s ease-in-out 3; }
#timer.done .what { color: inherit; }
@keyframes pulse { 50% { transform: scale(1.03); } }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
  top: calc(64px + var(--safe-t)); max-width: calc(100% - 32px);
  padding: 10px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-weight: 600; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
}

/* ---------- misc */
.login { max-width: 360px; margin: 18vh auto 0; padding: 0 16px; }
.login h1 { font-size: 32px; margin-bottom: 6px; }
.login .input { margin: 18px 0 12px; height: 56px; font-size: 18px; }
.err { color: var(--danger); font-size: 14px; min-height: 20px; }
.chart { width: 100%; height: auto; display: block; }
.chart .ln { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.chart .dot { fill: var(--accent); }
.chart .ax { fill: var(--muted); font-size: 10px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
table.log { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.log td, table.log th { padding: 7px 4px; border-top: 1px solid var(--line); text-align: left; vertical-align: top; }
table.log th { color: var(--muted); font-weight: 600; font-size: 12px; }
.check { width: 30px; height: 30px; border-radius: 9px; border: 2px solid var(--line); display: grid; place-items: center; flex: none; font-weight: 900; }
.check.on { background: var(--ok); border-color: var(--ok); color: #06140d; }
.notes li { margin: 4px 0; }
.notes { padding-left: 20px; margin: 8px 0 0; color: var(--muted); font-size: 14px; }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv > :nth-child(odd) { color: var(--muted); }
.stat { text-align: center; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.check { background: transparent; color: transparent; padding: 0; }
.check.on { color: #06140d; }
.video-wrap.inline { margin: 0; border-radius: 0; }
.ss-group { border-top: 1px solid var(--line); }
.list > .ss-group:first-child { border-top: 0; }
.ss-group + .item { border-top: 1px solid var(--line); }
.ss-tag + .item { border-top: 0; }
body.timer-on .page { padding-bottom: calc(180px + var(--safe-b)); }
body.timer-on .page.has-sessnav { padding-bottom: calc(250px + var(--safe-b)); }

.iconbtn svg { width: 24px; height: 24px; display: block; }
.timerrow { display: flex; gap: 8px; margin-top: 10px; }
.timerrow .btn { flex: 1; }
#sheet { position: fixed; inset: 0; z-index: 60; }
#sheet .sheet-bg { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); }
#sheet .sheet-card {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 600px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px 20px 0 0;
  padding: 14px 16px calc(20px + var(--safe-b));
}
#sheet h3 { margin: 18px 0 10px; }
.presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.presets .btn { padding: 0; }
