/* «Турник» — сдержанный зальный интерфейс: тёмная тема по умолчанию, цвета из
   Telegram (--tg-theme-*) с фолбэками, один акцентный цвет, системный шрифт,
   крупные цифры таймеров, кнопки действий не ниже 56px. Mobile-first (375px),
   на десктопе колонка до 480px по центру. */

:root {
  color-scheme: dark;
  --bg: var(--tg-theme-bg-color, #0f1114);
  --surface: var(--tg-theme-secondary-bg-color, #181b20);
  --text: var(--tg-theme-text-color, #eceef1);
  --hint: var(--tg-theme-hint-color, #8b929d);
  --accent: var(--tg-theme-button-color, #ff8a3d);
  --on-accent: var(--tg-theme-button-text-color, #1b1005);
  --danger: var(--tg-theme-destructive-text-color, #ff6b6b);
  --line: rgba(128, 128, 128, 0.28);
  --radius: 14px;
  --gap: 12px;
  --pad: 16px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
h1 { margin: 0; font-size: 24px; line-height: 1.2; }
h2 { margin: 0 0 8px; font-size: 17px; line-height: 1.25; }
p { margin: 0; }
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.hint { color: var(--hint); }
.small { font-size: 13px; }
.center { text-align: center; }
.icon { display: inline-flex; }

/* ---------- каркас ---------- */
.shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: var(--tg-viewport-stable-height, 100dvh);
  display: flex;
  flex-direction: column;
}
@media (min-width: 520px) {
  .shell { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
.topbar {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 56px;
  padding: max(6px, env(safe-area-inset-top)) 8px 6px var(--pad);
}
.topbar-title {
  flex: 1;
  min-width: 0;
  font-size: 20px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  flex: none;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
}
.icon-btn:first-child { margin-left: -8px; }
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 4px var(--pad) 24px;
}
.stack { display: grid; gap: var(--gap); align-content: start; }
.footer-bar {
  position: sticky;
  bottom: 0;
  padding: 12px var(--pad) calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.tabbar {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
  padding: 6px 4px;
  border: 0;
  background: transparent;
  color: var(--hint);
  font-size: 12px;
  font-weight: 600;
}
.tab.is-active { color: var(--accent); }

/* ---------- служебные экраны ---------- */
.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.gate {
  max-width: 480px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
}
.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 8px;
  margin-bottom: var(--gap);
  padding: 8px 8px 8px 12px;
  background: var(--surface);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
}
.banner-text { flex: 1 1 200px; font-size: 15px; }
.banner-actions { display: flex; gap: 4px; }
.sync-note { color: var(--danger); font-size: 14px; }

/* ---------- кнопки ---------- */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 56px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 17px;
  font-weight: 600;
  text-align: center;
}
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-secondary { background: transparent; border-color: var(--line); }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-danger { background: transparent; border-color: var(--line); color: var(--danger); }
.btn-sm { width: auto; min-height: 44px; padding: 0 14px; font-size: 15px; }
.btn-xl { min-height: 72px; font-size: 22px; }
.btn-stack { flex-direction: column; gap: 2px; min-height: 64px; }
.btn-title { font-size: 18px; }
.btn-sub { font-size: 13px; font-weight: 500; opacity: 0.8; }
.btn:active:not(:disabled) { opacity: 0.8; }
.btn:disabled { opacity: 0.4; }
.btn-col { display: grid; gap: 8px; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ---------- карточки и списки ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.card > * + * { margin-top: 8px; }
.card-button { display: block; width: 100%; text-align: left; color: inherit; }
.card-kicker { font-size: 13px; color: var(--hint); }
.card-title { font-size: 18px; font-weight: 600; }
.row-card { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 8px 8px 16px; }
.row-card > * + * { margin-top: 0; }
.row-card-text { flex: 1; min-width: 0; }
.hint-card { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-color: var(--accent); padding: 8px 8px 8px 16px; }
.hint-card > * + * { margin-top: 0; }

.badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--hint);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  vertical-align: middle;
}
.badge-accent { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.ready-card .badge, .step-body .badge, .ready-row .badge { margin-left: 0; justify-self: start; }
.ready-text { margin: 6px 0 12px; font-size: 17px; font-weight: 600; }
.ready-row { display: grid; gap: 4px; padding-top: 8px; }
.ready-row .ready-text { margin: 2px 0 4px; }

.list {
  display: grid;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.row-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  padding: 12px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: inherit;
  text-align: left;
}
.row-btn:last-child { border-bottom: 0; }
.row-btn:active { background: rgba(128, 128, 128, 0.12); }
.row-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.row-title { font-size: 17px; font-weight: 600; }
.row-side { display: flex; align-items: center; gap: 8px; color: var(--hint); }
.row-count { font-variant-numeric: tabular-nums; }
.row-btn.is-selected { box-shadow: inset 3px 0 0 var(--accent); }
.row-btn.is-selected .row-side { color: var(--accent); }
.group-title { margin: 8px 4px; color: var(--hint); font-size: 14px; font-weight: 600; }
.list-foot { display: grid; gap: 8px; }
.empty { display: grid; gap: 6px; padding: 40px 16px; text-align: center; }
.empty-title { font-size: 20px; font-weight: 700; }

.meter { height: 4px; margin-top: 6px; overflow: hidden; border-radius: 2px; background: var(--line); }
.meter i { display: block; height: 100%; background: var(--accent); }
.meter-lg { width: 100%; height: 8px; border-radius: 4px; }

/* ---------- сегодня ---------- */
.week-head { display: flex; align-items: baseline; flex-wrap: wrap; }
.big-num { font-size: 48px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.week-text { color: var(--hint); }
.week-seg { display: flex; gap: 6px; margin-top: 12px; }
.week-seg i { flex: 1; height: 8px; border-radius: 4px; background: var(--line); }
.week-seg i.on { background: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: transparent;
  font-size: 15px;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.chips-big .chip { min-height: 56px; padding: 0 22px; font-size: 17px; }
.card .chips { margin-top: 12px; }

/* ---------- лестница ---------- */
.steps { display: grid; gap: 8px; }
.step {
  display: flex;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.step-num {
  flex: none;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 50%;
  color: var(--hint);
  font-weight: 700;
}
.step.is-done .step-num { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.step.is-current { border-color: var(--accent); }
.step.is-current .step-num { border-color: var(--accent); color: var(--accent); }
.step-body { flex: 1; min-width: 0; display: grid; gap: 6px; }
.step-name { font-weight: 600; }
.step-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.step-actions:empty { display: none; }
.cue { font-size: 15px; opacity: 0.9; }

/* ---------- план ---------- */
.progress-line { display: grid; gap: 2px; font-weight: 600; }
.slots { display: grid; gap: 8px; }
.slot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  text-align: left;
}
.slot.is-next { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.slot.is-done .slot-name { color: var(--hint); }
.slot-main { min-width: 0; }
.slot-name { font-size: 17px; font-weight: 600; }
.slot-side { display: grid; gap: 4px; justify-items: end; flex: none; }
.slot-target { font-weight: 600; font-variant-numeric: tabular-nums; }
.slot-target.is-result { color: var(--accent); font-size: 20px; }
.slot-target.muted { color: var(--hint); font-weight: 400; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 10px; height: 10px; border: 2px solid var(--line); border-radius: 50%; }
.dots i.on { background: var(--accent); border-color: var(--accent); }
.pair {
  display: grid;
  gap: 8px;
  padding: 10px 10px 10px 12px;
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: rgba(128, 128, 128, 0.08);
}
.pair-label { color: var(--hint); font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }

/* ---------- экран подхода (линейный поток) ---------- */
.set-screen { flex: 1; display: flex; flex-direction: column; gap: 12px; }
.set-progress .meter { margin-top: 0; }
.set-top { display: grid; gap: 4px; }
.set-title { font-size: 30px; line-height: 1.15; }
.set-sub { color: var(--accent); font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.cue-line {
  margin-top: 4px;
  color: var(--hint);
  font-size: 15px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  cursor: pointer;
}
.cue-line.is-open { -webkit-line-clamp: unset; display: block; }
.set-center { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 160px; }
.set-center .stepper { width: 100%; }
.timer-box { display: grid; justify-items: center; gap: 12px; text-align: center; }
.timer-digits.is-idle { color: var(--hint); }

.stepper { display: grid; grid-template-columns: 64px 1fr 64px; align-items: center; gap: 8px; }
.step-btn {
  height: 64px;
  min-height: 56px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-size: 32px;
  font-weight: 500;
  line-height: 1;
}
.step-btn:disabled { opacity: 0.35; }
.step-btn:active:not(:disabled) { background: rgba(128, 128, 128, 0.15); }
.stepper-big { grid-template-columns: 80px 1fr 80px; }
.stepper-big .step-btn { height: 96px; font-size: 40px; }
.step-center { display: grid; justify-items: center; min-width: 0; }
.step-input {
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 72px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  text-align: center;
  appearance: textfield;
  -moz-appearance: textfield;
}
.step-input::-webkit-inner-spin-button, .step-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.step-input:focus-visible { outline-offset: 4px; border-radius: 8px; }
.step-unit { color: var(--hint); font-size: 13px; }
.step-value { min-width: 64px; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: center; }

/* ---------- таймеры ---------- */
.timer-screen {
  flex: 1;
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
}
.timer-digits {
  font-size: clamp(64px, 24vw, 96px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.timer-digits.is-over { color: var(--accent); }
.timer-label { font-size: 18px; font-weight: 600; }
.timer-next { display: grid; gap: 2px; margin-top: 8px; }
.timer-next-name { font-size: 20px; font-weight: 600; }

/* ---------- итог, история ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
.stat { padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); text-align: center; }
.stat-num { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.place-row { padding: 6px 0; }
.level-card { text-align: center; }
.level-name { font-size: 36px; font-weight: 700; line-height: 1.2; }
.hlist { padding: 0; }
.hlist > * + * { margin-top: 0; }
.hrow { display: grid; gap: 6px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.hrow:last-child { border-bottom: 0; }
.hrow-name { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.hrow-name .badge { margin-left: 0; }
.vals { display: flex; flex-wrap: wrap; gap: 6px; }
.val {
  min-width: 44px;
  padding: 4px 10px;
  border-radius: 10px;
  background: rgba(128, 128, 128, 0.16);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.val.empty { color: var(--hint); }

/* ---------- настройки ---------- */
.settings-list { padding: 0; }
.settings-list > * + * { margin-top: 0; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.setting-text { min-width: 0; }
.setting-title { font-weight: 600; }
.setting .stepper { grid-template-columns: 48px auto 48px; flex: none; }
.setting .step-btn { height: 48px; min-height: 48px; font-size: 24px; }
.switch {
  position: relative;
  flex: none;
  width: 56px;
  height: 32px;
  border: 0;
  border-radius: 16px;
  background: var(--line);
  transition: background 0.15s;
}
.switch::after { content: ""; position: absolute; inset: -8px; }
.switch i {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"] i { transform: translateX(24px); }
.radio-list { display: grid; margin-top: 4px; }
.radio {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px 4px;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  color: inherit;
  text-align: left;
}
.radio-dot { flex: none; width: 22px; height: 22px; border: 2px solid var(--line); border-radius: 50%; }
.radio[aria-checked="true"] .radio-dot { border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 4px var(--surface); }
.radio-main { display: grid; }

/* ---------- свободная тренировка ---------- */
.pick-group { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.pick-group summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 0 16px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}
.pick-group summary::-webkit-details-marker { display: none; }
.pick-group summary > span:first-child { flex: 1; }
.pick-group summary .badge { margin-left: 0; }
.pick-group summary::after {
  content: "";
  width: 8px;
  height: 8px;
  margin-left: 4px;
  border-right: 2px solid var(--hint);
  border-bottom: 2px solid var(--hint);
  transform: rotate(45deg);
}
.pick-group[open] summary::after { transform: rotate(225deg); }
.subhead { padding: 10px 16px 4px; border-top: 1px solid var(--line); color: var(--hint); font-size: 13px; font-weight: 600; }
.pick-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 8px 16px;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  color: inherit;
  text-align: left;
}
.pick-sub > .subhead + .pick-row { border-top: 0; }
.pick-main { flex: 1; min-width: 0; display: grid; }
.pick-name { font-weight: 600; }
.pick-num {
  flex: none;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 50%;
  font-size: 14px;
  font-weight: 700;
}
.pick-row.is-on .pick-num { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.pick-row .icon { visibility: hidden; color: var(--accent); }
.pick-row.is-on .icon { visibility: visible; }
.pick-row:disabled { opacity: 0.4; }
.footer-inner { display: grid; gap: 10px; }
.footer-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sets-pick { display: flex; align-items: center; gap: 8px; flex: none; }
.sets-pick .stepper { grid-template-columns: 44px 32px 44px; }
.sets-pick .step-btn { height: 44px; min-height: 44px; font-size: 22px; }

/* ---------- онбординг ---------- */
.onboarding h1 { font-size: 28px; }
.steps-dots { display: flex; gap: 6px; }
.steps-dots i { width: 24px; height: 4px; border-radius: 2px; background: var(--line); }
.steps-dots i.on { background: var(--accent); }
.welcome-list { display: grid; gap: 16px; margin: 0; padding: 0; list-style: none; font-size: 17px; }
.welcome-list strong { display: block; font-size: 18px; }
.welcome-list span { color: var(--hint); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- место тренировки, превью плана, инвентарь по местам ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
}
.seg-btn {
  min-height: 56px;
  border: 0;
  border-radius: calc(var(--radius) - 4px);
  background: transparent;
  color: var(--hint);
  font-size: 17px;
  font-weight: 600;
}
.seg-btn.is-active { background: var(--accent); color: var(--on-accent); }
.card .preview { margin-top: 12px; }
.preview { display: grid; gap: 4px; min-height: 8px; }
.preview-names { font-size: 15px; line-height: 1.45; }
.skeleton { display: grid; gap: 8px; }
.skeleton i {
  display: block;
  height: 14px;
  border-radius: 7px;
  background: var(--line);
  animation: skeleton-pulse 1.2s ease-in-out infinite;
}
.skeleton i.short { width: 55%; }
@keyframes skeleton-pulse { 50% { opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) { .skeleton i { animation: none; } }
.places-editor { display: grid; gap: 16px; }
.place-block { display: grid; gap: 8px; }
.place-block > .chips { margin-top: 0; }
.place-title { margin: 0; color: var(--hint); font-size: 14px; font-weight: 600; }
.card .place-block .chips { margin-top: 0; }
.pick-row.is-unavailable .pick-name { color: var(--hint); }
.skipped-list { display: grid; gap: 4px; margin-top: 12px; }
.saving { display: grid; justify-items: center; align-content: center; gap: 12px; min-height: 50vh; text-align: center; }
.saving-text { font-size: 20px; font-weight: 600; }
