:root {
  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1f2630;
  --line: #2a323d;
  --text: #eef1f5;
  --text-2: #a9b3c1;
  --muted: #768194;
  --accent: #f5a524;
  --accent-ink: #1a1206;
  --accent-soft: rgba(245, 165, 36, .14);
  --good: #3fb97a;
  --good-soft: rgba(63, 185, 122, .15);
  --warn: #e5534b;
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f5f7; --surface: #ffffff; --surface-2: #eef0f3; --line: #dde1e7;
    --text: #12161c; --text-2: #465061; --muted: #6b7584;
    --accent: #c77700; --accent-ink: #ffffff; --accent-soft: rgba(199, 119, 0, .12);
    --good: #1f8a52; --good-soft: rgba(31, 138, 82, .12); --warn: #c62f27;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #eef0f3; --line: #dde1e7;
  --text: #12161c; --text-2: #465061; --muted: #6b7584;
  --accent: #c77700; --accent-ink: #ffffff; --accent-soft: rgba(199, 119, 0, .12);
  --good: #1f8a52; --good-soft: rgba(31, 138, 82, .12); --warn: #c62f27;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-padding-bottom: calc(var(--nav-h) + 90px); scroll-padding-top: 70px; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
h4 { margin: 16px 0 6px; font-size: 15px; }
p { margin: 8px 0; }
ul, ol { padding-left: 20px; margin: 8px 0; }
li { margin: 4px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.top-right { display: flex; align-items: center; gap: 8px; }
.icon-btn { background: none; border: 0; font-size: 20px; padding: 4px 6px; color: var(--text-2); }
.sync { font-size: 12px; color: var(--muted); }
.sync.ok { color: var(--good); }
.sync.err { color: var(--warn); }

main { max-width: 760px; margin: 0 auto; padding: 14px 16px; }

/* Bottom nav */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabs button {
  background: none; border: 0; color: var(--muted); font-size: 11px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
}
.tabs button span { font-size: 18px; line-height: 1; }
.tabs button.on { color: var(--accent); font-weight: 600; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin: 12px 0;
}
.card.accent { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.h-big { font-size: 24px; font-weight: 800; margin: 4px 0 2px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; font-weight: 600; color: var(--text);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.block { width: 100%; padding: 14px; font-size: 16px; }
.btn.ghost { background: none; }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.btn.danger { color: var(--warn); }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line);
}
.chip.acc { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.good { background: var(--good-soft); color: var(--good); border-color: transparent; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg button {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 4px;
  font-size: 13px; font-weight: 600; color: var(--text-2);
}
.seg button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.progress-bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress-bar > div { height: 100%; background: var(--accent); border-radius: 99px; }

/* Week strip */
.days { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.day {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 8px;
  text-align: left; min-height: 64px;
}
.day b { display: block; font-size: 16px; }
.day small { color: var(--muted); font-size: 11px; display: block; }
.day.done { background: var(--good-soft); border-color: transparent; }
.day.done b::after { content: " ✓"; color: var(--good); }
.day.next { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }

/* Exercise card in session */
.ex {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  margin: 10px 0; overflow: hidden;
}
.ex.grouped { border-left: 3px solid var(--accent); }
.ex.complete { opacity: .72; }
.ex-head { display: flex; gap: 12px; padding: 12px; align-items: center; background: none; border: 0; width: 100%; text-align: left; }
.thumb {
  width: 64px; height: 48px; flex: none; border-radius: 8px; object-fit: cover; background: var(--surface-2);
}
.ex-name { font-weight: 700; font-size: 15px; }
.ex-presc { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.ex-presc b { color: var(--accent); }
.tag { font-size: 11px; font-weight: 800; color: var(--accent-ink); background: var(--accent); border-radius: 6px; padding: 1px 5px; margin-right: 6px; }
.ex-note { font-size: 13px; color: var(--text-2); padding: 0 12px 8px; }
.ex-body { padding: 0 12px 12px; }
.sets { width: 100%; border-collapse: collapse; }
.sets th { font-size: 11px; font-weight: 600; color: var(--muted); text-align: center; padding: 4px 2px; }
.sets td { padding: 3px 2px; text-align: center; }
.sets td:first-child { color: var(--muted); font-size: 13px; width: 26px; }
.sets input {
  width: 100%; min-width: 0; text-align: center; padding: 9px 4px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; font-size: 16px;
}
.sets input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.check {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); font-size: 18px; color: var(--muted);
}
.check.on { background: var(--good); border-color: var(--good); color: #fff; }
.ex-actions { display: flex; gap: 8px; margin-top: 8px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

.group-label { font-size: 12px; color: var(--muted); margin: 16px 2px 0; font-weight: 600; }

/* Sheet */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow: auto;
  background: var(--bg); border-radius: 18px 18px 0 0; padding: 18px 16px calc(24px + env(safe-area-inset-bottom));
  max-width: 760px; margin: 0 auto;
}
.sheet-close {
  position: sticky; top: 0; float: right; z-index: 2;
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
}
.video { position: relative; aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; background: #000; margin: 12px 0; }
.video img { width: 100%; height: 100%; object-fit: cover; opacity: .85; }
.video iframe { width: 100%; height: 100%; border: 0; }
.video .play {
  position: absolute; inset: 0; margin: auto; width: 68px; height: 48px; border-radius: 14px; border: 0;
  background: #e5302a; color: #fff; font-size: 22px;
}
.photos { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.photos figure { margin: 0; }
.photos img { width: 100%; border-radius: 10px; display: block; }
.photos figcaption { font-size: 11px; color: var(--muted); text-align: center; margin-top: 3px; }
.cues li { margin: 6px 0; }

/* Timer */
.timer {
  position: fixed; left: 12px; right: 12px; z-index: 40;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 10px);
  max-width: 520px; margin: 0 auto;
  display: flex; align-items: center; gap: 8px;
  background: var(--accent); color: var(--accent-ink); border-radius: 14px; padding: 10px 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .35);
}
.timer-label { font-weight: 700; font-size: 13px; }
.timer-time { font-size: 24px; font-weight: 800; flex: 1; font-variant-numeric: tabular-nums; }
.timer button { background: rgba(0, 0, 0, .15); border: 0; border-radius: 9px; padding: 8px 10px; font-weight: 700; color: inherit; }
.timer.done { background: var(--good); color: #fff; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 60;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 70px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  max-width: 90vw;
}

/* Forms */
.field { display: block; margin: 10px 0; }
.field span { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
.field input, .field select {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); font-size: 16px;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px; }
.stat .v { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--muted); }
.delta { font-size: 12px; font-weight: 700; color: var(--good); }
.delta.neg { color: var(--warn); }

.chart { width: 100%; height: auto; display: block; margin-top: 8px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent-soft); }
.chart .pt { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .hit { fill: transparent; }
.chart-tip { font-size: 12px; color: var(--text-2); min-height: 18px; margin-top: 4px; }

.tbl { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 14px; }
.tbl td, .tbl th { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; }

details.acc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin: 10px 0; }
details.acc > summary { list-style: none; padding: 14px; font-weight: 700; display: flex; justify-content: space-between; cursor: pointer; }
details.acc > summary::-webkit-details-marker { display: none; }
details.acc > summary::after { content: "+"; color: var(--muted); font-weight: 400; }
details.acc[open] > summary::after { content: "−"; }
details.acc > .acc-body { padding: 0 14px 14px; }

.week-row { display: grid; grid-template-columns: 58px repeat(4, 1fr); gap: 6px; align-items: center; margin: 6px 0; }
.week-row .wk { font-size: 13px; font-weight: 700; }
.week-row .wk small { display: block; color: var(--muted); font-weight: 400; font-size: 11px; }
.pill {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 8px 0;
  font-size: 13px; font-weight: 700; text-align: center;
}
.pill.done { background: var(--good-soft); color: var(--good); border-color: transparent; }
.pill.cur { border-color: var(--accent); color: var(--accent); }
.pill.deload { border-style: dashed; }

.mini-ex { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left; }
.mini-ex:last-child { border-bottom: 0; }
.mini-ex .thumb { width: 52px; height: 40px; }

.macro { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.empty { text-align: center; color: var(--muted); padding: 20px 8px; font-size: 14px; }

@media (min-width: 640px) {
  .thumb { width: 84px; height: 60px; }
}
.macro .stat { padding: 10px 8px; }
.macro .stat .v { font-size: 17px; white-space: nowrap; }
