:root {
  --radius: 14px;
  --gap: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
[data-theme="dark"] {
  --bg: #0e1520; --surface: #16202e; --surface-2: #1e2b3d; --line: #2a3a50;
  --text: #e7edf5; --muted: #8b9bb0; --accent: #2fd3a5; --accent-ink: #062a20; --accent-soft: rgba(47, 211, 165, .14);
  --blue: #6e9bff; --ok: #2fd3a5; --fail: #ff6b78; --fail-soft: rgba(255, 107, 120, .14); --warn: #f5b74e;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset;
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f3f6fa; --surface: #ffffff; --surface-2: #eef2f7; --line: #dbe2eb;
  --text: #142033; --muted: #5e6d82; --accent: #0b9c79; --accent-ink: #ffffff; --accent-soft: rgba(11, 156, 121, .1);
  --blue: #2f5fd0; --ok: #0b9c79; --fail: #d93848; --fail-soft: rgba(217, 56, 72, .09); --warn: #b7791f;
  --shadow: 0 1px 2px rgba(20, 32, 51, .06);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 var(--font); }
body { min-height: 100vh; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 18px; margin: 20px 0 10px; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: var(--gap); }
.center { text-align: center; }
[hidden] { display: none !important; }

/* шапка и вкладки */
#top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 6px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px; background: var(--bg); border-bottom: 1px solid var(--line);
}
#title { font-size: 19px; font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#net { font-size: 12px; color: var(--warn); }
main { max-width: 640px; margin: 0 auto; padding: 14px; }
#tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
#tabs a {
  flex: 1; max-width: 160px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px 9px; color: var(--muted); font-size: 11px; font-weight: 500;
}
#tabs a svg { width: 24px; height: 24px; }
#tabs a.active { color: var(--accent); }

/* карточки */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card + .card { margin-top: 10px; }
a.card { display: block; color: inherit; }
a.card:active, button.card:active { transform: scale(.99); }
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; color: inherit; }
.list-item .chev { color: var(--muted); }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--accent-soft); color: var(--accent); font-weight: 700; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

/* кнопки и поля */
button { font: inherit; cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font-weight: 600; font-size: 15px; white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--fail); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 10px; background: transparent; color: var(--text); flex: none; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn.sm { width: 30px; height: 30px; color: var(--muted); }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; width: 100%; min-height: 44px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
label.field { display: block; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: 20px; height: 20px; min-height: 0; }

/* бейджи */
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--accent-soft); color: var(--ok); }
.badge.fail { background: var(--fail-soft); color: var(--fail); }
.badge.today { background: rgba(110, 155, 255, .15); color: var(--blue); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--blue); display: inline-block; }

/* прогресс */
.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .2s; }

/* неделя */
.weeknav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.weeknav b { font-size: 15px; }
.day { margin-top: 14px; }
.day-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; font-size: 14px; color: var(--muted); font-weight: 600; }
.day-head > span:first-child::first-letter { text-transform: uppercase; }
.day-head.is-today { color: var(--blue); }
.wcard { display: flex; align-items: center; gap: 10px; }
.card .t { font-weight: 600; }
.day-empty { font-size: 14px; color: var(--muted); padding: 2px 0 4px; }

/* выполнение тренировки */
.note { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: 14px; white-space: pre-wrap; }
.note.trainer { border-left: 3px solid var(--accent); }
.note.client { border-left: 3px solid var(--blue); }
.ex-card h3 { display: flex; align-items: center; gap: 8px; }
.ex-num { width: 24px; height: 24px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: 13px; color: var(--muted); flex: none; }
.set-row { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.set-row:first-of-type { border-top: 0; }
.set-n { color: var(--muted); font-size: 13px; text-align: center; }
.set-inputs { display: flex; gap: 6px; align-items: center; min-width: 0; }
.set-inputs input { min-height: 40px; padding: 6px 8px; text-align: center; width: 64px; }
.set-inputs input.wide { width: 84px; }
.set-inputs .x { color: var(--muted); font-size: 13px; }
.set-plan { font-size: 12px; color: var(--muted); }
.mark { display: flex; gap: 6px; }
.mark button { width: 42px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); display: grid; place-items: center; }
.mark button.on.ok { background: var(--ok); border-color: var(--ok); color: var(--accent-ink); }
.mark button.on.fail { background: var(--fail); border-color: var(--fail); color: #fff; }
.set-row.ok .set-inputs input { border-color: color-mix(in srgb, var(--ok) 50%, var(--line)); }
.res { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; }
.res.ok { color: var(--ok); } .res.fail { color: var(--fail); } .res.none { color: var(--muted); }

/* редактор */
.ed-item { padding: 12px; }
.ed-item .set-row { grid-template-columns: 22px 1fr 30px; }
.ed-sets-head { display: grid; grid-template-columns: 22px 1fr 30px; gap: 8px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.picker { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column; }
.picker-head { padding: calc(10px + env(safe-area-inset-top)) 14px 10px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; }
.picker-body { flex: 1; overflow-y: auto; padding: 8px 14px 24px; max-width: 640px; width: 100%; margin: 0 auto; }
.group-title { font-size: 13px; color: var(--muted); font-weight: 600; margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .03em; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip { flex: none; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 14px; }
.chip.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* модалка */
.sheet-wrap { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 640px; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 85vh; overflow-y: auto; }
.sheet h3 { margin-bottom: 12px; }

/* статистика */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.tile b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.tile span { font-size: 12px; color: var(--muted); }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.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 .barm { fill: var(--accent); }
.chart .barm.dim { fill: color-mix(in srgb, var(--accent) 35%, var(--surface-2)); }
.chart .hit { fill: transparent; }
.chart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .lbl { fill: var(--text); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12px; padding: 5px 8px; border-radius: 8px; white-space: nowrap; transform: translate(-50%, -110%); font-variant-numeric: tabular-nums; }
.rec { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 15px; }
.rec:first-child { border-top: 0; }
.rec b { font-variant-numeric: tabular-nums; }

#toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0;
  transition: all .2s; pointer-events: none; z-index: 50; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.loading { text-align: center; color: var(--muted); padding: 40px 0; }
.err { color: var(--fail); text-align: center; padding: 30px 10px; }
.hero { text-align: center; padding: 40px 10px 20px; }
.hero .logo { width: 72px; height: 72px; margin: 0 auto 14px; }
.hero h1 { font-size: 28px; margin-bottom: 6px; }
a.card.wcard { display: flex; }
.cap::first-letter { text-transform: uppercase; }
.ex-names { font-size: 13px; color: var(--muted); margin-top: 6px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mark button:disabled { opacity: .55; cursor: default; }
