:root {
  --bg: #161617;
  --bg2: #1f1f21;
  --bg3: #2a2a2d;
  --text: #fbfbff;
  --muted: #9a9aa0;
  --accent: #f21800;
  --accent-soft: rgba(242, 24, 0, .16);
  --rest: #2e9e5b;
  --radius: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button {
  font: inherit; color: inherit; background: none; border: 0; cursor: pointer;
}

/* ── layout ─────────────────────────────── */
#layout { display: flex; height: 100dvh; }
#sidebar {
  width: 340px; min-width: 340px; height: 100%;
  background: var(--bg2); border-right: 1px solid #000;
  display: flex; flex-direction: column;
}
#sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid #000;
}
.logo { font-weight: 800; letter-spacing: .5px; font-size: 18px; }
.logo span { color: var(--accent); }
#burger { display: none; font-size: 20px; padding: 4px 8px; }
#menu-open {
  display: none; position: fixed; z-index: 30;
  top: calc(10px + env(safe-area-inset-top)); left: 12px;
  background: var(--bg2); border: 1px solid #000; border-radius: 10px;
  font-size: 20px; padding: 8px 12px;
}
#nav { overflow-y: auto; padding: 10px 10px 40px; flex: 1; }

/* ── табы курсов ────────────────────────── */
#course-tabs {
  padding: 12px 10px 4px; display: flex; flex-direction: column; gap: 6px;
  border-bottom: 1px solid #000;
}
.course-tab {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-radius: 12px;
  color: var(--muted); font-size: 14px; font-weight: 600;
  border: 1px solid transparent; text-align: left;
}
.course-tab:hover { background: var(--bg3); }
.course-tab.active {
  background: var(--accent-soft); color: var(--text);
  border-color: rgba(242, 24, 0, .4);
}
.course-tab .ct-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.course-tab .ct-prog {
  font-size: 12px; font-variant-numeric: tabular-nums;
  background: var(--bg3); border-radius: 999px; padding: 3px 9px; flex: none;
}
.course-tab.active .ct-prog { background: rgba(242, 24, 0, .25); color: var(--text); }
#main { flex: 1; overflow-y: auto; }
#welcome { max-width: 620px; margin: 15vh auto; padding: 0 24px; text-align: center; color: var(--muted); }
#welcome h1 { color: var(--text); margin-bottom: 12px; font-size: 26px; }
.loading { color: var(--muted); padding: 20px; text-align: center; }

/* ── nav tree ───────────────────────────── */
.course-name {
  font-size: 12px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--muted); padding: 16px 12px 8px;
}
summary.course-name {
  cursor: pointer; list-style: none;
  display: flex; align-items: center; gap: 8px;
  border-radius: 10px; font-weight: 700;
}
summary.course-name::-webkit-details-marker { display: none; }
summary.course-name::before {
  content: "▸"; color: var(--accent); font-size: 10px; transition: transform .15s;
}
.course[open] > summary.course-name::before { transform: rotate(90deg); }
summary.course-name:hover { background: var(--bg3); }
.nav-section > summary {
  cursor: pointer; list-style: none;
  padding: 10px 12px; border-radius: 10px;
  font-weight: 600; font-size: 14px;
  display: flex; align-items: center; gap: 8px;
}
.nav-section > summary::-webkit-details-marker { display: none; }
.nav-section > summary::before {
  content: "▸"; color: var(--accent); transition: transform .15s;
}
.nav-section[open] > summary::before { transform: rotate(90deg); }
.nav-section > summary:hover { background: var(--bg3); }
.nav-section .sec-name { flex: 1; min-width: 0; }
.nav-section .sec-prog {
  margin-left: auto; font-size: 12px; color: var(--muted);
  font-variant-numeric: tabular-nums;
  background: var(--bg3); border-radius: 999px; padding: 2px 9px; flex: none;
}
.nav-section .sec-prog.all { background: var(--rest); color: #fff; }
.nav-section summary.sec-done { color: var(--rest); }

/* кнопка скачивания дня */
.dl-day {
  flex: none; font-size: 13px; color: var(--muted);
  padding: 3px 8px; border-radius: 8px; margin-left: 6px;
  min-width: 34px; text-align: center;
}
.dl-day:hover { background: var(--bg3); color: var(--text); }
.dl-day.dling { color: var(--accent); font-variant-numeric: tabular-nums; font-size: 11px; }
.dl-day.saved { color: var(--rest); }
.nav-lesson {
  display: flex; align-items: center; gap: 8px; width: 100%;
  text-align: left; padding: 8px 12px 8px 30px;
  color: var(--muted); font-size: 14px; border-radius: 10px;
}
.nav-lesson:hover { background: var(--bg3); color: var(--text); }
.nav-lesson.active { background: var(--accent-soft); color: var(--text); }
.nav-lesson .check {
  width: 16px; flex: none; font-size: 13px; color: var(--rest);
  opacity: 0; transition: opacity .15s;
}
.nav-lesson.done .check { opacity: 1; }
.nav-lesson.done { color: var(--rest); }
.nav-lesson .nl-title { flex: 1; min-width: 0; }

/* ── lesson view ────────────────────────── */
.lesson { max-width: 860px; margin: 0 auto; padding: 28px 24px 80px; }
.lesson-crumb { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.lesson h1 { font-size: 26px; margin-bottom: 14px; }
.lesson-meta { display: flex; gap: 14px; align-items: center; margin-bottom: 20px; flex-wrap: wrap; }
.badge {
  background: var(--bg3); border-radius: 999px; padding: 5px 12px;
  font-size: 13px; color: var(--muted);
}
#start-workout {
  background: var(--accent); color: #fff; font-weight: 700;
  padding: 12px 26px; border-radius: 999px; font-size: 16px;
  box-shadow: 0 6px 24px rgba(242, 24, 0, .35);
  transition: transform .1s;
}
#start-workout:hover { transform: scale(1.03); }
.lesson video, .lesson img {
  width: 100%; border-radius: var(--radius); background: #000; margin: 10px 0;
}
.lesson .md { line-height: 1.65; color: #d9d9de; margin: 14px 0; }
.lesson .md h1, .lesson .md h2, .lesson .md h3 { color: var(--text); margin: 22px 0 8px; }
.lesson .md h1 { font-size: 22px; } .lesson .md h2 { font-size: 19px; } .lesson .md h3 { font-size: 16px; }
.lesson .md p { margin: 8px 0; }
.lesson .md ul, .lesson .md ol { margin: 8px 0 8px 22px; }
.lesson .md hr { border: 0; border-top: 1px solid #333; margin: 20px 0; }
.lesson .md a { color: var(--accent); }
.lesson .md strong { color: var(--text); }

/* exercise cards */
.ex-card {
  display: flex; gap: 14px; align-items: center;
  background: var(--bg2); border-radius: var(--radius);
  padding: 12px; margin: 10px 0;
}
.ex-card video { width: 128px; height: 72px; object-fit: cover; border-radius: 8px; margin: 0; flex: none; }
.ex-thumb { position: relative; flex: none; cursor: pointer; }
.ex-thumb .ex-play {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 22px; text-shadow: 0 1px 8px #000;
  background: rgba(0,0,0,.25); border-radius: 8px;
}
.ex-thumb:hover .ex-play { background: rgba(0,0,0,.45); }
.ex-card .ex-info { flex: 1; min-width: 0; }
.ex-card .ex-title { font-weight: 600; font-size: 15px; }
.ex-card .ex-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.ex-card .ex-timer {
  font-variant-numeric: tabular-nums; font-weight: 700;
  color: var(--accent); font-size: 18px; flex: none;
}
.ex-card.rest .ex-timer { color: var(--rest); }

/* ── workout mode ───────────────────────── */
#workout {
  position: fixed; inset: 0; z-index: 50;
  background: #000; display: flex; flex-direction: column;
}
#workout.hidden { display: none; }
#wo-top {
  display: flex; align-items: center; gap: 14px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
#wo-exit { font-size: 20px; color: var(--muted); padding: 6px 10px; }
#wo-sound, #wo-expand { font-size: 18px; color: var(--muted); padding: 6px 8px; }
#wo-progress { flex: 1; height: 4px; background: #333; border-radius: 2px; overflow: hidden; }
#wo-progress-fill { height: 100%; background: var(--accent); width: 0; transition: width .3s; }
#wo-counter { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
#wo-stage { position: relative; flex: 1; overflow: hidden; }
#wo-video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; background: #000;
}
#wo-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
  padding: 30px 20px calc(30px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent 45%, rgba(0,0,0,.82));
  text-align: center;
  pointer-events: none; /* тапы по видео проходят к #wo-video */
}
#wo-overlay > * { pointer-events: auto; }
#wo-label {
  font-size: 12px; letter-spacing: 2px; color: var(--accent); font-weight: 700;
  text-transform: uppercase; margin-bottom: 6px;
}
#workout.rest-mode #wo-label { color: var(--rest); }
#wo-title { font-size: clamp(22px, 4vw, 34px); margin-bottom: 8px; text-shadow: 0 2px 12px #000; }
#wo-timer {
  font-size: clamp(64px, 14vw, 120px); font-weight: 800; line-height: 1;
  font-variant-numeric: tabular-nums; text-shadow: 0 2px 16px #000;
}
#workout.rest-mode #wo-timer { color: var(--rest); }
#wo-next { color: #cfcfd6; margin-top: 10px; font-size: 15px; text-shadow: 0 1px 8px #000; }
#wo-controls {
  display: flex; justify-content: center; gap: 26px;
  padding: 14px 16px calc(18px + env(safe-area-inset-bottom));
  background: #000;
}
#wo-controls button {
  width: 62px; height: 62px; border-radius: 50%;
  background: var(--bg3); font-size: 24px;
}
#wo-controls #wo-pause { background: var(--accent); width: 74px; height: 74px; margin-top: -6px; }
#wo-manual {
  margin: 14px 0 4px;
  background: var(--accent); padding: 14px 40px; border-radius: 999px;
  font-size: 18px; font-weight: 700; box-shadow: 0 6px 24px rgba(242,24,0,.4);
}
#wo-manual.hidden { display: none; }
#get-ready {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; background: rgba(0,0,0,.9); z-index: 5;
}
#get-ready .count { font-size: 110px; font-weight: 800; }
#get-ready .what { color: var(--muted); font-size: 18px; margin-top: 8px; }

/* done screen */
#wo-done {
  position: absolute; inset: 0; z-index: 6;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: #000; text-align: center; padding: 20px;
}
#wo-done .big { font-size: 64px; margin-bottom: 10px; }
#wo-done h2 { font-size: 28px; margin-bottom: 8px; }
#wo-done p { color: var(--muted); margin-bottom: 26px; }
#wo-done button { background: var(--accent); padding: 13px 34px; border-radius: 999px; font-weight: 700; }
#wo-done .wo-stats {
  width: 100%; max-width: 340px; max-height: 38vh; overflow-y: auto;
  margin: 0 0 26px;
}
#wo-done .wo-stat {
  display: flex; justify-content: space-between; gap: 14px;
  padding: 7px 2px; font-size: 14px; color: var(--muted);
  border-bottom: 1px solid #222;
}
#wo-done .wo-stat b { color: var(--text); font-variant-numeric: tabular-nums; flex: none; }

/* ── полноэкранный просмотрщик ──────────── */
#viewer {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0,0,0,.97);
  display: flex; flex-direction: column;
}
#viewer.hidden { display: none; }
#viewer-head {
  display: flex; align-items: center; gap: 14px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
}
#viewer-title {
  flex: 1; min-width: 0; font-weight: 700; font-size: 16px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#viewer-close { font-size: 22px; color: var(--muted); padding: 6px 10px; }
#viewer-video {
  flex: 1; width: 100%; min-height: 0;
  object-fit: contain; background: #000;
}
#viewer-variants {
  display: flex; justify-content: center; gap: 10px;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
}
#viewer-variants.hidden { display: none; }
#viewer-variants button {
  padding: 9px 22px; border-radius: 999px;
  background: var(--bg3); color: var(--muted); font-weight: 600;
}
#viewer-variants button.active { background: var(--accent); color: #fff; }

/* ── PIN-экран ──────────────────────────── */
#pin-gate {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
#pin-gate .pin-box {
  display: flex; flex-direction: column; gap: 14px; align-items: center;
  width: min(320px, 86vw);
}
#pin-gate .logo { font-size: 22px; margin-bottom: 8px; }
#pin-gate input {
  width: 100%; padding: 14px 16px; font-size: 20px; text-align: center;
  background: var(--bg2); color: var(--text);
  border: 1px solid #000; border-radius: 12px; outline: none;
  letter-spacing: 4px;
}
#pin-gate input:focus { border-color: var(--accent); }
#pin-gate button {
  width: 100%; padding: 13px; border-radius: 12px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 16px;
}
#pin-gate .pin-err { color: var(--accent); font-size: 14px; }
#pin-gate .pin-err.hidden { display: none; }

/* ── офлайн-индикатор + баннер установки ── */
#sidebar-head::after {
  content: "офлайн"; display: none;
  font-size: 11px; color: #f2a900; border: 1px solid #f2a900;
  padding: 2px 8px; border-radius: 999px;
}
body.offline #sidebar-head::after { display: block; }
#install-banner {
  position: fixed; z-index: 40; /* ниже #workout (50) и #viewer (70) — не перекрывает их */
  left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 10px;
  background: var(--bg2); border: 1px solid #000; border-radius: 14px;
  padding: 12px 14px; font-size: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
#install-banner span { flex: 1; }
#install-banner button { color: var(--muted); font-size: 16px; padding: 4px 8px; }

/* ── mobile ─────────────────────────────── */
@media (max-width: 800px) {
  #sidebar {
    position: fixed; z-index: 40; height: 100dvh;
    transform: translateX(-100%); transition: transform .2s;
    width: min(86vw, 340px); min-width: 0;
  }
  #sidebar.open { transform: none; box-shadow: 0 0 60px #000; }
  #burger { display: block; }
  #menu-open { display: block; }
  #main { width: 100%; }
  .lesson { padding: 20px 16px 60px; }
}
