/* Движение · ИПИИР — тёмная тема, портрет, крупные цифры (читать с двух метров). */

:root {
  --bg: #0b0f14;
  --panel: #121923;
  --panel-2: #1a2330;
  --line: #24303f;
  --ink: #eef4fb;
  --ink-dim: #8ea0b6;
  --ink-faint: #5d6e84;
  --accent: #35d6a4;
  --accent-ink: #04231a;
  --active: #ffb020;
  --danger: #ff6b6b;
  --radius: 14px;
  --tap: 52px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Атрибут hidden должен побеждать всегда. Без этого правила любой display,
   заданный ниже по файлу (а у нас почти везде flex и grid), перебивает
   hidden из стилей браузера, и «скрытый» блок остаётся на экране. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  user-select: none;
}

/* ── Верхняя панель ─────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  flex: 0 0 auto;
}

.brand {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}
.brand b { font-size: 17px; letter-spacing: 0.2px; }
.brand span { font-size: 11px; color: var(--ink-faint); letter-spacing: 1.6px; text-transform: uppercase; }

.segmented {
  display: flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.segmented button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-dim);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 9px 18px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.segmented button.on { background: var(--accent); color: var(--accent-ink); }
.segmented.small button { font-size: 13px; padding: 8px 12px; }

/* ── Сцена с видео ──────────────────────────────────────────────── */

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0 12px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #05080c;
  border: 1px solid var(--line);
}

#view { display: block; width: 100%; height: 100%; }

/* ── HUD с показаниями ──────────────────────────────────────────── */

.hud {
  position: absolute;
  inset: 10px 10px auto 10px;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hud-main { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }

.stat {
  background: rgba(8, 12, 18, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 7px 13px 9px;
  min-width: 108px;
}
.stat-label {
  font-size: 11px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 1px;
}
.stat-value {
  font-size: clamp(42px, 13vw, 76px);
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: -2px;
}
.stat-value i { font-style: normal; font-size: 0.5em; font-weight: 600; color: var(--ink-dim); margin-left: 2px; }
/* Прочерк «нет данных»: в кегле 76px длинное тире выглядит как зелёная полоса,
   поэтому короткое тире и втрое мельче. */
.stat-value em { font-style: normal; font-size: 0.38em; letter-spacing: 0; opacity: 0.4; vertical-align: 0.3em; }
.stat-angle .stat-value { color: var(--accent); }
.stat-reps { text-align: right; }
.stat-reps .stat-value { color: var(--ink); }

.hud-sub { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: flex;
  align-items: baseline;
  gap: 6px;
  background: rgba(8, 12, 18, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 13px;
}
.chip span { color: var(--ink-faint); }
.chip b { font-weight: 700; font-size: 15px; }
.chip-phase.is-active { border-color: var(--active); }
.chip-phase.is-active b { color: var(--active); }

/* Вспышка при засчитанном повторе — видно краем глаза, не отвлекает. */
.rep-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 0 0 var(--accent);
  opacity: 0;
}
.rep-flash.go { animation: flash 0.42s ease-out; }
@keyframes flash {
  0% { opacity: 1; box-shadow: inset 0 0 0 6px var(--accent); }
  100% { opacity: 0; box-shadow: inset 0 0 0 28px transparent; }
}

/* ── Сообщения поверх кадра ─────────────────────────────────────── */

.notice {
  position: absolute;
  left: 12px; right: 12px; bottom: 12px;
  display: flex;
  justify-content: center;
  pointer-events: none;
}
.notice-box {
  pointer-events: auto;
  background: rgba(10, 15, 22, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 15px;
  max-width: 460px;
  text-align: center;
}
.notice-box p { margin: 0; font-size: 16px; line-height: 1.4; color: var(--ink); }
.notice-box.warn { border-color: var(--active); }
.notice-box.error { border-color: var(--danger); }
.notice-actions { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }
.notice-actions:empty { display: none; }
.notice-actions .btn { min-height: 42px; font-size: 14px; }

.boot {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: #05080c;
  padding: 24px;
  text-align: center;
}
.boot p { margin: 0; font-size: 16px; color: var(--ink); }
.boot .boot-sub { font-size: 13px; color: var(--ink-faint); max-width: 300px; line-height: 1.45; }
.boot-spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.boot.failed .boot-spinner { display: none; }
.boot.failed p { color: var(--danger); }

/* ── Нижние органы управления ───────────────────────────────────── */

.controls {
  flex: 0 0 auto;
  padding: 10px 12px 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.row { display: flex; gap: 8px; align-items: center; }
.row-ex { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.row-tools { justify-content: space-between; }
.row-source .btn { flex: 1 1 0; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  min-height: var(--tap);
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
}
.btn:active { background: var(--panel-2); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; }
.btn-reset { flex: 0 0 auto; }
.btn-file { flex: 1 1 0; }

.ex-btn { flex-direction: column; gap: 2px; line-height: 1.15; padding: 9px 6px; font-size: 14px; }
.ex-btn small { font-size: 11px; font-weight: 500; color: var(--ink-faint); letter-spacing: 0.6px; text-transform: uppercase; }
.ex-btn.on small { color: rgba(4, 35, 26, 0.65); }

/* ── Подвал ─────────────────────────────────────────────────────── */

.fineprint {
  flex: 0 0 auto;
  padding: 6px 14px calc(8px + env(safe-area-inset-bottom));
  font-size: 10.5px;
  line-height: 1.45;
  color: var(--ink-faint);
  text-align: center;
}
.fineprint a { color: var(--ink-dim); text-decoration: none; border-bottom: 1px solid var(--line); }

/* ── Подсказка про установку на домашний экран ──────────────────── */

/* Плашка живёт в обычном потоке, а не поверх экрана: иначе она накрывает
   кнопки выбора стороны и сброса, а это единственное, что нужно нажать
   быстро во время показа. */
.install {
  flex: 0 0 auto;
  margin: 2px 12px 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
}
.install-text { font-size: 14.5px; line-height: 1.45; }
.install-text b { color: var(--accent); }
.install-actions { display: flex; gap: 8px; }
.install-actions .btn { flex: 1 1 0; min-height: 44px; }

/* Скрытый источник кадров: видеоэлемент нужен, но показываем мы канвас. */
#src {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
  left: -10px; top: -10px;
}

/* Широкий экран (ноутбук, проектор на конгрессе) — держим портретную колонку. */
@media (min-width: 720px) {
  body { max-width: 560px; margin: 0 auto; }
}

@media (prefers-reduced-motion: reduce) {
  .rep-flash.go { animation: none; }
  .boot-spinner { animation-duration: 3s; }
}
