:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #15171c;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #f97316;
  --accent-2: #fb923c;
  --accent-soft: #fff1e6;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 4px 16px rgb(0 0 0 / 0.04);
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --card: #181b21;
    --text: #eceef2;
    --muted: #9aa3b2;
    --line: #2a2f38;
    --accent-soft: #3a2414;
    --ok-soft: #12321f;
    --warn: #fbbf24;
    --warn-soft: #3a2e10;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    calc(96px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

h2 { font-size: 1.25rem; margin: 0 0 8px; }
h3 { font-size: 1.05rem; margin: 0 0 6px; }
p { margin: 0 0 10px; }
a { color: var(--accent); }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  padding: 16px;
  margin-bottom: 12px;
  display: block;
  color: inherit;
  text-decoration: none;
}

.card.warn { background: var(--warn-soft); border-color: transparent; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.tiny { font-size: 0.72rem; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.eyebrow { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 4px; }
.tag { display: inline-block; font-size: 0.72rem; background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: 99px; vertical-align: middle; }
.note { background: var(--accent-soft); border-radius: 10px; padding: 8px 12px; margin: 8px 0; font-size: 0.9rem; }
.back { display: inline-block; margin-bottom: 10px; text-decoration: none; }
.group { margin: 20px 4px 10px; }

/* кнопки */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  min-height: 44px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); background: transparent; border-color: var(--danger); }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: 0.9rem; }
.btn.block { display: block; width: 100%; margin-top: 10px; }
.btn:active { transform: scale(0.98); }

/* герой: уровень и серии */
.hero-row { display: flex; gap: 14px; align-items: center; }
.lvl-badge {
  width: 56px; height: 56px; flex: none;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), #ef4444);
  color: #fff; font-size: 1.6rem; font-weight: 800;
  display: grid; place-items: center;
}
.hero-title { font-weight: 700; font-size: 1.1rem; }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 6px 0 4px; }
.bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); border-radius: 99px; transition: width 0.4s; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.stat { display: flex; gap: 8px; align-items: center; }
.stat .big { font-size: 1.15rem; font-weight: 700; }
.stat:not(:first-child) { flex-direction: column; align-items: flex-start; gap: 0; }
.ring { width: 38px; height: 38px; transform: rotate(-90deg); flex: none; }
.ring circle { fill: none; stroke-width: 4; }
.ring-bg { stroke: var(--line); }
.ring-fg { stroke: var(--ok); stroke-linecap: round; transition: stroke-dasharray 0.4s; }

/* план тренировки */
.plan { list-style: none; padding: 0; margin: 8px 0 0; }
.plan li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.slot {
  flex: none; min-width: 32px; height: 32px; padding: 0 6px;
  border-radius: 10px; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 700; font-size: 0.85rem;
}

/* упражнение */
.ex-head { display: flex; gap: 10px; align-items: flex-start; }
.target { font-weight: 600; margin: 8px 0; }
.cues { font-size: 0.92rem; }
.sets { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin: 10px 0; }
.set {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 0.78rem; color: var(--muted);
  border: 1px solid var(--line); border-radius: 12px; padding: 8px;
  transition: background 0.2s;
}
.set input {
  width: 100%; border: 0; background: transparent; color: var(--text);
  font-family: inherit; font-size: 1.5rem; font-weight: 700; line-height: 1.1; padding: 0; outline: none;
}
.set.ok { background: var(--accent-soft); border-color: transparent; }
.set.top { background: var(--ok-soft); border-color: transparent; }
.check { display: flex; gap: 8px; align-items: center; padding: 6px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.checks { margin: 8px 0 12px; }
.pain { font-size: 0.85rem; color: var(--muted); }
.sticky-actions {
  position: sticky; bottom: calc(76px + env(safe-area-inset-bottom));
  background: var(--bg); padding: 8px 0; margin: 0;
}

/* видео */
.video { display: flex; gap: 12px; margin: 10px 0; align-items: flex-start; }
.thumb { position: relative; flex: none; width: 140px; aspect-ratio: 16 / 9; border: 0; padding: 0; border-radius: 10px; overflow: hidden; cursor: pointer; background: #000; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.play { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 1.6rem; background: rgb(0 0 0 / 0.25); }
.video-meta { min-width: 0; }
.video-title { font-size: 0.88rem; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.links { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.link { font-size: 0.85rem; text-decoration: none; }
.frame { width: 100%; aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden; }
.frame iframe { width: 100%; height: 100%; border: 0; }
.video:has(.frame) { flex-direction: column; }

/* дерево */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.grid .card { margin: 0; }
.chain-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.nodes { display: flex; gap: 6px; margin: 10px 0 8px; flex-wrap: wrap; }
.node { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); }
.node.done { background: var(--ok); border-color: var(--ok); }
.node.current { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.node.noeq { border-style: dashed; }
.chain.is-locked { opacity: 0.6; }
.stage.done { opacity: 0.8; }
.stage.current { border-color: var(--accent); }
.history { padding-left: 18px; margin: 0; }
.history li { margin-bottom: 8px; }

/* тест */
.big-input {
  width: 120px; font-family: inherit; font-size: 1.5rem; font-weight: 700; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text);
}

/* достижения и замеры */
.achs { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.ach { text-align: center; padding: 10px 6px; border-radius: 12px; border: 1px solid var(--line); opacity: 0.55; }
.ach.earned { opacity: 1; background: var(--accent-soft); border-color: transparent; }
.ach-icon { font-size: 1.6rem; }
.ach-name { font-size: 0.8rem; font-weight: 600; margin: 2px 0; }
.measures { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; margin-bottom: 10px; }
.measure b { font-size: 1.2rem; }
.up { color: var(--ok); }
.down { color: var(--warn); }
.spark { width: 100%; height: 30px; display: block; margin-top: 4px; }
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.mform { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin: 10px 0; align-items: end; }
.mform label, .field { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.mform input, .field input {
  font: inherit; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text);
}
summary { cursor: pointer; color: var(--accent); font-weight: 600; }

/* документы */
.docs { list-style: none; padding: 0; margin: 0; }
.docs li a { display: block; padding: 12px 0; border-top: 1px solid var(--line); text-decoration: none; color: var(--text); text-transform: capitalize; }
.doc { overflow-wrap: anywhere; }
.doc table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 0.88rem; margin: 10px 0; }
.doc th, .doc td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; min-width: 8em; }
.doc td:first-child, .doc th:first-child { min-width: 4em; }
.doc pre { overflow-x: auto; background: var(--bg); padding: 10px; border-radius: 10px; font-size: 0.8rem; }
.doc blockquote { margin: 10px 0; padding: 8px 12px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 10px 10px 0; }
.doc h1 { font-size: 1.4rem; }

/* навигация */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 10px; font-size: 0.7rem; color: var(--muted); text-decoration: none;
}
.tabs a span { font-size: 1.25rem; filter: grayscale(1); opacity: 0.7; }
.tabs a.active { color: var(--accent); font-weight: 600; }
.tabs a.active span { filter: none; opacity: 1; }

.offline { background: var(--warn-soft); color: var(--warn); text-align: center; padding: 6px; font-size: 0.85rem; }

/* таймер, тосты, модалка */
.timer {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(148px + env(safe-area-inset-bottom)); z-index: 20;
  background: var(--text); color: var(--bg);
  border-radius: 99px; padding: 6px 8px 6px 18px;
  display: flex; gap: 8px; align-items: center; box-shadow: 0 8px 24px rgb(0 0 0 / 0.25);
  width: max-content; white-space: nowrap;
}
.timer b { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.timer .btn { color: var(--bg); border-color: transparent; }
.toast {
  position: fixed; top: calc(16px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 40;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  max-width: calc(100% - 32px); font-size: 0.9rem; animation: fade 3.5s forwards;
}
@keyframes fade { 0%, 85% { opacity: 1; } 100% { opacity: 0; } }
.overlay {
  position: fixed; inset: 0; z-index: 30; background: rgb(0 0 0 / 0.55);
  display: grid; place-items: center; padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom)); overflow: hidden;
}
.modal {
  background: var(--card); color: var(--text); border-radius: 20px; padding: 24px;
  width: 100%; max-width: 420px; text-align: center; animation: pop 0.35s ease-out;
  max-height: 90vh; overflow-y: auto;
}
.modal-emoji { font-size: 3.5rem; }
.events { text-align: left; padding: 0; list-style: none; margin: 12px 0; }
.events li { padding: 8px 0; border-top: 1px solid var(--line); }
@keyframes pop { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.confetti {
  position: absolute; top: -10px; width: 8px; height: 14px; border-radius: 2px;
  animation: fall 2.4s ease-in forwards; pointer-events: none;
}
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); opacity: 0.6; } }

@media (prefers-reduced-motion: reduce) {
  .confetti { display: none; }
  .modal, .toast { animation: none; }
}

/* отказ от ответственности */
.legal-foot { margin-top: 24px; padding: 12px 4px 0; font-size: 0.75rem; color: var(--muted); border-top: 1px solid var(--line); }
.legal-foot a, .legal-note a { color: inherit; }
.legal-note { font-size: 0.78rem; color: var(--muted); margin: 6px 0 4px; }
.pain-warn { display: none; background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 8px 12px; font-size: 0.88rem; margin: 4px 0 8px; }
.check.pain:has(input:checked) + .pain-warn, .pain-warn.on { display: block; }
.consent ul { padding-left: 20px; margin: 10px 0 14px; }
.consent li { margin-bottom: 8px; }
.consent .btn { width: 100%; margin-top: 12px; }
.consent .btn:disabled { opacity: 0.45; cursor: not-allowed; }
.selfcheck fieldset { border: 0; border-top: 1px solid var(--line); padding: 10px 0; margin: 0; }
.selfcheck legend { padding: 0; margin-bottom: 6px; font-size: 0.95rem; }
.selfcheck .row { margin-top: 0; gap: 16px; }

[hidden] { display: none !important; }
