/* =========================================================================
   Stop-motion студия — дизайн-система
   Токены → база → топ-бар/шаги → загрузка → воркспейс → кадры → галерея → оверлей
   Цель: спокойный тёмный UI уровня Linear/Figma, удобный в т.ч. на 14" MacBook
   (компактная вертикаль, двухпанельный воркспейс, липкие зоны с лимитом высоты).
   ========================================================================= */

:root {
  /* Поверхности и текст */
  --bg: #0c0e13;
  --surface-1: #14171d;
  --surface-2: #1b1f27;
  --surface-3: #232a33;
  --border: #272e39;
  --border-strong: #38404e;
  --text: #eceef2;
  --text-muted: #aab2c0; /* контраст к фону ≥ AA для основного вторичного текста */
  --text-subtle: #7e8796;

  /* Акценты */
  --brand: #5b8cff;
  --brand-hover: #6f9bff;
  --brand-weak: rgba(91, 140, 255, 0.14);
  --success: #34d39a;
  --success-ink: #052b1d;
  --danger: #ff6b6b;
  --warning: #f5b14c;

  /* Радиусы */
  --r-sm: 7px;
  --r: 10px;
  --r-lg: 14px;
  --r-xl: 18px;
  --r-full: 999px;

  /* Тени и фокус */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.5);
  --ring: 0 0 0 3px rgba(91, 140, 255, 0.45);

  /* Движение */
  --dur-1: 120ms;
  --dur-2: 200ms;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  /* Метрики раскладки */
  --topbar-h: 52px;
  --rail-w: clamp(300px, 30vw, 400px);

  /* фоны липких панелей (полупрозрачные) — отдельные токены ради светлой темы */
  --topbar-bg: rgba(12, 14, 19, 0.82);
  --bar-bg: rgba(14, 16, 21, 0.86);
  --viewer-bg: rgba(8, 10, 14, 0.94); /* фон полноэкранной галереи/модалок */
  --scrim: rgba(8, 10, 14, 0.78);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    "Apple Color Emoji", sans-serif;

  color-scheme: dark;
}

/* ===== Светлая тема ===== */
[data-theme='light'] {
  color-scheme: light;

  --bg: #f5f7fa;
  --surface-1: #ffffff;
  --surface-2: #f1f3f7;
  --surface-3: #e7ebf1;
  --border: #e2e6ed;
  --border-strong: #cbd2dd;
  --text: #181b21;
  --text-muted: #515a68;
  --text-subtle: #79828f;

  --brand: #3f7ae8;
  --brand-hover: #356ad2;
  --brand-weak: rgba(63, 122, 232, 0.12);
  --success: #15a877;
  --success-ink: #ffffff;
  --danger: #e5484d;

  --ring: 0 0 0 3px rgba(63, 122, 232, 0.35);
  --shadow-sm: 0 1px 2px rgba(20, 30, 50, 0.08);
  --shadow: 0 8px 24px rgba(20, 30, 50, 0.12);
  --shadow-lg: 0 18px 50px rgba(20, 30, 50, 0.18);

  --topbar-bg: rgba(255, 255, 255, 0.82);
  --bar-bg: rgba(255, 255, 255, 0.9);
  --viewer-bg: rgba(244, 246, 249, 0.97);
  --scrim: rgba(30, 38, 52, 0.45);
}

* {
  box-sizing: border-box;
}

/* hidden должен побеждать любые display-правила */
[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

html {
  scrollbar-color: var(--border-strong) transparent;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3 {
  margin: 0;
}

/* Единый видимый фокус */
:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: var(--r-sm);
}

/* =========================================================================
   Топ-бар + индикатор шагов
   ========================================================================= */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 clamp(16px, 3vw, 28px);
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}
.brand-mark {
  display: inline-flex;
  filter: drop-shadow(0 2px 7px rgba(91, 140, 255, 0.35));
}
.brand-name {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.015em;
}
.brand-sub {
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0;
}

.steps {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.step {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border-radius: var(--r-full);
  color: var(--text-subtle);
  font-size: 13px;
  font-weight: 500;
  transition: color var(--dur-2) var(--ease), background var(--dur-2) var(--ease);
}

.step-dot {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: var(--r-full);
  border: 1px solid var(--border-strong);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-subtle);
  transition: inherit;
}

.step.is-active {
  color: var(--text);
  background: var(--brand-weak);
}
.step.is-active .step-dot {
  border-color: transparent;
  background: var(--brand);
  color: #fff;
}

.step.is-done {
  color: var(--text-muted);
}
.step.is-done .step-dot {
  border-color: transparent;
  background: rgba(52, 211, 154, 0.18);
  color: var(--success);
}
.step.is-done .step-dot::after {
  content: "✓";
}
.step.is-done .step-dot {
  font-size: 0;
}
.step.is-done .step-dot::after {
  font-size: 11px;
}

/* На узких экранах прячем подписи шагов, оставляем кружки */
@media (max-width: 640px) {
  .step-label {
    display: none;
  }
  .step {
    padding: 5px;
  }
}

/* =========================================================================
   Баннеры
   ========================================================================= */
.banners {
  position: sticky;
  top: var(--topbar-h);
  z-index: 30;
}
.banner {
  max-width: 1320px;
  margin: 12px auto 0;
  padding: 11px 16px;
  border-radius: var(--r);
  font-size: 13.5px;
}
.banner-notice {
  background: var(--brand-weak);
  border: 1px solid var(--brand);
  color: var(--brand);
}
.banner-error {
  background: rgba(229, 72, 77, 0.12);
  border: 1px solid var(--danger);
  color: var(--danger);
}

/* =========================================================================
   Каркас приложения
   ========================================================================= */
.app {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px clamp(16px, 3vw, 28px) 72px;
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

.section-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.section-head h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}
.section-head .btn {
  margin-left: auto;
}

/* =========================================================================
   Шаг 1 — загрузка
   ========================================================================= */
.setup {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
  margin-bottom: 20px;
  display: grid;
  gap: 14px;
}

/* Свёрнутый вид: после нарезки панель ужимается в компактную плашку */
.setup-summary {
  display: none;
  align-items: center;
  gap: 10px;
}
.setup-summary .ico {
  color: var(--success);
  flex: none;
}
.setup-summary-text {
  font-size: 13.5px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.setup-summary .btn {
  margin-left: auto;
  flex: none;
}
.setup.is-collapsed {
  padding: 10px 14px;
  margin-bottom: 16px;
}
.setup.is-collapsed .setup-summary {
  display: flex;
}
.setup.is-collapsed .dropzone,
.setup.is-collapsed .setup-controls,
.setup.is-collapsed #videoMeta {
  display: none;
}

.dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-direction: column;
  text-align: center;
  padding: 30px 20px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color var(--dur-2) var(--ease), background var(--dur-2) var(--ease);
}
.dropzone:hover {
  border-color: var(--brand);
  background: var(--brand-weak);
}
.dropzone:focus-within {
  box-shadow: var(--ring);
  border-color: var(--brand);
}
.dropzone.is-dragover {
  border-color: var(--brand);
  background: var(--brand-weak);
}
.dropzone-icon {
  width: 34px;
  height: 34px;
  color: var(--brand);
  flex: none;
}
.dropzone-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.dropzone-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}
.dropzone-sub {
  font-size: 12.5px;
  color: var(--text-subtle);
}

/* Компактная зона после выбора файла */
.setup.has-file .dropzone {
  flex-direction: row;
  justify-content: flex-start;
  text-align: left;
  padding: 12px 16px;
}
.setup.has-file .dropzone-icon {
  width: 22px;
  height: 22px;
  color: var(--success);
}
.setup.has-file .dropzone-title {
  font-size: 14px;
}

.setup-controls {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}
.setup-controls .field-inline {
  margin: 0;
}
.setup-controls .btn {
  margin-left: auto;
}

.file-meta {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* =========================================================================
   Поля ввода
   ========================================================================= */
.field {
  margin-bottom: 14px;
}
.field:last-child {
  margin-bottom: 0;
}
.field label {
  display: block;
  font-size: 12.5px;
  margin-bottom: 6px;
  color: var(--text-muted);
}
.field-inline label {
  margin-bottom: 5px;
}
.field-inline input {
  width: 150px;
}

.hint {
  display: block;
  margin-top: 6px;
  color: var(--text-subtle);
  font-size: 12px;
}

input[type="file"],
input[type="number"],
select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--r-sm);
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}
input[type="number"]:hover,
select:hover {
  border-color: var(--border-strong);
}
input[type="number"]:focus-visible,
select:focus-visible {
  border-color: var(--brand);
  box-shadow: var(--ring);
}

/* Современные ползунки: заливка слева до бегунка (--fill ставит JS) */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 22px;
  background: transparent;
  cursor: pointer;
  --fill: 0%;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: var(--r-full);
  background: linear-gradient(to right, var(--brand) var(--fill), var(--surface-3) var(--fill));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -5px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--brand);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}
input[type="range"]:hover::-webkit-slider-thumb {
  transform: scale(1.14);
}
input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.14);
  box-shadow: 0 0 0 6px var(--brand-weak);
}
input[type="range"]:focus-visible::-webkit-slider-thumb {
  box-shadow: var(--ring);
}
input[type="range"]:disabled {
  opacity: 0.5;
}
/* Firefox */
input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: var(--r-full);
  background: var(--surface-3);
}
input[type="range"]::-moz-range-progress {
  height: 6px;
  border-radius: var(--r-full);
  background: var(--brand);
}
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 2px solid var(--brand);
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
}

/* Числовое поле со степпером: [−] [ N ] [+] */
.stepper {
  display: flex;
  align-items: stretch;
  height: 38px;
}
.stepper input[type="number"] {
  width: 100%;
  min-width: 0;
  border-radius: 0;
  border-left: none;
  border-right: none;
  text-align: center;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.stepper input[type="number"]::-webkit-outer-spin-button,
.stepper input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.stepper-btn {
  flex: none;
  width: 36px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.stepper-btn:first-child {
  border-radius: var(--r-sm) 0 0 var(--r-sm);
}
.stepper-btn:last-child {
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
}
.stepper-btn:hover {
  background: var(--surface-3);
  color: var(--brand);
}
.stepper-btn:active {
  background: var(--brand);
  color: #fff;
}

.field-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
}
.field-row label {
  margin: 0;
}
.field-value {
  font-size: 12.5px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.slider {
  width: 100%;
  margin: 2px 0;
}

/* =========================================================================
   Кнопки
   ========================================================================= */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  padding: 9px 15px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  font-weight: 550;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: transform var(--dur-1) var(--ease), background var(--dur-1) var(--ease),
    border-color var(--dur-1) var(--ease), opacity var(--dur-1) var(--ease);
}
.btn:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: var(--border-strong);
}
.btn:active:not(:disabled) {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--brand);
  border-color: transparent;
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) {
  background: var(--brand-hover);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.btn-small {
  padding: 6px 11px;
  font-size: 12.5px;
}

/* Inline-иконки фиксированного размера — кнопки не «скачут» */
.ico {
  width: 16px;
  height: 16px;
  flex: none;
  display: inline-block;
  vertical-align: middle;
}
/* кнопка-тогл предпросмотра держит ширину при смене подписи */
#previewBtn {
  min-width: 154px;
  justify-content: center;
}

.btn-cta {
  width: 100%;
  padding: 11px 16px;
  font-size: 14px;
}

/* =========================================================================
   Воркспейс: слева предпросмотр+сборка, справа кадры
   ========================================================================= */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, var(--rail-w)) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.rail {
  position: sticky;
  top: calc(var(--topbar-h) + 16px);
}

.work-main {
  display: grid;
  gap: 20px;
  min-width: 0;
}

/* Узкий экран — стек, предпросмотр липнет сверху */
@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .rail {
    position: sticky;
    top: var(--topbar-h);
    z-index: 20;
    margin: 0 calc(-1 * clamp(16px, 3vw, 28px));
    padding: 12px clamp(16px, 3vw, 28px) 0;
    background: linear-gradient(var(--bg) 78%, transparent);
  }
}

/* =========================================================================
   Предпросмотр + панель сборки (левая колонка)
   ========================================================================= */
.preview-section {
  padding: 14px;
}

.play-dot {
  width: 9px;
  height: 9px;
  border-radius: var(--r-full);
  background: var(--success);
  box-shadow: 0 0 0 0 rgba(52, 211, 154, 0.5);
  animation: pulse 1.4s var(--ease) infinite;
}
@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(52, 211, 154, 0.5);
  }
  70% {
    box-shadow: 0 0 0 7px rgba(52, 211, 154, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(52, 211, 154, 0);
  }
}

.preview-canvas {
  display: block;
  width: 100%;
  background: #000;
  border-radius: var(--r);
  border: 1px solid var(--border);
  max-height: clamp(150px, 32vh, 340px);
  height: auto;
  object-fit: contain;
}

.preview-hint {
  margin: 8px 0 0;
}

/* Скраббер предпросмотра */
.scrub {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}
.scrub-range {
  flex: 1;
  accent-color: var(--brand);
  cursor: pointer;
}
.scrub-range:disabled {
  opacity: 0.5;
  cursor: default;
}
.scrub-pos {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 56px;
  text-align: right;
}

/* Дубль ползунка длительности под предпросмотром */
.preview-duration {
  margin-top: 12px;
  gap: 5px;
}
.preview-duration .ctl-label {
  font-size: 12.5px;
  color: var(--text-muted);
}

.build {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 12px;
}
.build-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* На узком экране панель сборки компактнее */
@media (max-width: 1080px) {
  .preview-canvas {
    max-height: 30vh;
  }
}

/* =========================================================================
   Пустое состояние
   ========================================================================= */
.empty-state {
  display: grid;
  place-items: center;
  gap: 8px;
  text-align: center;
  padding: 56px 24px;
  border: 1px dashed var(--border);
  border-radius: var(--r-lg);
  color: var(--text-subtle);
}
.empty-art {
  width: 56px;
  height: 56px;
  color: var(--border-strong);
}
.empty-title {
  margin: 6px 0 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
}
.empty-sub {
  margin: 0;
  font-size: 13px;
}

/* =========================================================================
   Шаг 3 — сетка кадров
   ========================================================================= */
.frames-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.frames-title {
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.frames-title h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}
.counter {
  color: var(--text-muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.frames-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Панель авто-подбора */
.auto-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 11px 13px;
  margin-bottom: 16px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r);
}
.auto-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 13.5px;
}
.auto-select {
  width: auto;
  padding: 7px 10px;
}
.auto-ctl {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 12.5px;
}
.auto-ctl input[type="range"] {
  width: 130px;
}
.auto-ctl input[type="number"] {
  width: 84px;
}
.auto-info {
  margin-left: auto;
  font-size: 12.5px;
  color: var(--text-subtle);
  font-variant-numeric: tabular-nums;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.frame {
  position: relative;
  border: 2px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
  cursor: pointer;
  background: #000;
  aspect-ratio: 16 / 9;
  transition: border-color var(--dur-1) var(--ease), transform var(--dur-1) var(--ease),
    box-shadow var(--dur-1) var(--ease);
}
.frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.frame img:not([src]) {
  visibility: hidden;
}
.frame:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
}
.frame:focus-visible {
  box-shadow: var(--ring);
  border-color: var(--brand);
}
.frame.selected {
  border-color: var(--success);
}

.frame .num {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: var(--r-sm);
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(2px);
}

.frame .check {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: var(--r-full);
  background: var(--success);
  color: var(--success-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  transform: scale(0.4);
  opacity: 0;
  transition: transform var(--dur-2) var(--ease), opacity var(--dur-1) var(--ease);
}
.frame.selected .check {
  transform: scale(1);
  opacity: 1;
}

/* =========================================================================
   Результат
   ========================================================================= */
.result-section {
  padding: 16px;
  animation: rise var(--dur-2) var(--ease);
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}
.result-video {
  display: block;
  max-width: 100%;
  max-height: 60vh; /* вертикальные ролики не растягиваются на всю высоту */
  width: auto;
  height: auto;
  margin: 0 auto;
  background: #000;
  border-radius: var(--r);
  border: 1px solid var(--border);
}

/* =========================================================================
   Нижний бар главных действий + окно готового ролика
   ========================================================================= */
.actionbar {
  display: none;
}
body.has-frames .actionbar {
  display: block;
}
.actionbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  gap: 8px;
}

/* Блоки панели — отдельные сегменты-карточки */
.ab-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
}
.ab-render {
  gap: 12px;
  margin-left: auto; /* блок сборки — к правому краю */
  background: var(--brand-weak); /* подсвечен — это цель */
  border-color: rgba(91, 140, 255, 0.32);
}

/* Дропдаун «Выбор кадров» — все настройки отбора в одном поповере */
.popover-wrap {
  position: relative;
}
#autoToggle .ico-chev {
  opacity: 0.65;
  transition: transform var(--dur-1) var(--ease);
}
#autoToggle[aria-expanded='true'] .ico-chev {
  transform: rotate(180deg);
}
.popover {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  z-index: 50;
  width: 270px;
  max-width: 86vw;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
}
.popover .ctl-label {
  font-size: 12px;
  color: var(--text-muted);
}
.popover select,
.popover input[type='range'],
.popover input[type='number'] {
  width: 100%;
}
.popover-actions {
  display: flex;
  gap: 8px;
}
.popover-actions .btn {
  flex: 1;
}
.popover .auto-info {
  font-size: 12px;
  color: var(--text-subtle);
  min-height: 1em;
}
.actionbar .auto-bar {
  margin: 0; /* гасим прежний отступ авто-бара */
}

/* компактные контролы: микро-лейбл сверху, без инлайн-подписей */
.ab-cap {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  white-space: nowrap;
}
.ctl {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.ctl-label {
  font-size: 10.5px;
  line-height: 1.1;
  color: var(--text-subtle);
  white-space: nowrap;
}
.ctl > select,
.ctl > input {
  margin: 0;
}
.ctl select {
  padding: 6px 9px;
}
.ctl input[type='number'] {
  width: 78px;
  padding: 6px 9px;
}
.actionbar input[type='range'] {
  width: 132px;
}
.ab-render .btn-cta {
  width: auto;
}
/* фиксируем ширину значения, чтобы лейбл не «прыгал» при смене мс/fps */
#frameMsValue,
#frameMsValuePrev {
  display: inline-block;
  min-width: 104px;
  font-variant-numeric: tabular-nums;
}

/* Десктоп: прибиваем панель к нижнему краю (липкая плавающая карта-контейнер) */
@media (min-width: 1081px) {
  body.has-frames .actionbar {
    position: sticky;
    bottom: 16px;
    z-index: 30;
    margin-top: 24px;
  }
  .actionbar-inner {
    padding: 8px;
    background: var(--bar-bg);
    backdrop-filter: blur(14px);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-lg);
  }
}

/* Узкий экран: блоки в столбик на всю ширину */
@media (max-width: 1080px) {
  .actionbar-inner {
    margin-top: 16px;
  }
  .ab-group {
    width: 100%;
  }
  .ab-render {
    justify-content: flex-end;
  }
  .ab-render .btn-cta {
    flex: 1;
  }
}

/* Окно готового ролика */
.result-modal {
  position: fixed;
  inset: 0;
  z-index: 65;
  background: var(--scrim);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fade var(--dur-2) var(--ease);
}
.result-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  padding: 18px;
  width: min(720px, 96vw);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: rise var(--dur-2) var(--ease);
}
.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.result-head h2 {
  font-size: 16px;
}
.result-close {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
}
.result-close:hover {
  background: var(--surface-2);
}
.result-actions {
  display: flex;
  justify-content: center;
}
.result-actions .btn-cta {
  width: 100%;
  max-width: 320px;
}

/* =========================================================================
   Галерея: фильтр сверху, кадр в центре, лента миниатюр снизу
   ========================================================================= */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--viewer-bg);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  animation: fade var(--dur-2) var(--ease);
}
@keyframes fade {
  from {
    opacity: 0;
  }
}

.viewer-top {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}
.viewer-title {
  font-weight: 600;
  white-space: nowrap;
}
.viewer-filter {
  margin-inline: auto;
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
}
.vf-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 5px 13px;
  border-radius: var(--r-full);
  font-size: 12.5px;
  font-weight: 550;
  font-family: inherit;
  cursor: pointer;
  transition: color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.vf-btn:hover {
  color: var(--text);
}
.vf-btn.is-active {
  background: var(--brand);
  color: #fff;
}
.viewer-counter {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.viewer-close {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
}
.viewer-close:hover {
  background: var(--surface-2);
}

.viewer-main {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.viewer-stage {
  position: relative;
  display: flex;
  max-width: 92vw;
  max-height: 100%;
}
.viewer-img {
  max-width: 92vw;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: #000;
}
.viewer-empty {
  color: var(--text-subtle);
  font-size: 15px;
}
.viewer-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(0, 0, 0, 0.65);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: var(--r-sm);
  font-size: 13px;
}
.viewer-badge.on {
  background: var(--success);
  color: var(--success-ink);
  font-weight: 600;
}
.viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-full);
  width: 50px;
  height: 50px;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--dur-1) var(--ease);
  z-index: 2;
}
.viewer-nav:hover {
  background: var(--surface-3);
}
.viewer-prev {
  left: 24px;
}
.viewer-next {
  right: 24px;
}

.viewer-bottom {
  border-top: 1px solid var(--border);
  padding: 10px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.filmstrip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scroll-padding-inline: 48px;
  scrollbar-width: thin;
}
.film-thumb {
  position: relative;
  flex: 0 0 auto;
  width: 84px;
  height: 50px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: var(--r-sm);
  overflow: hidden;
  background: #000;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}
.film-thumb:hover {
  opacity: 0.9;
}
.film-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.film-thumb.selected {
  border-color: var(--success);
}
.film-thumb.is-current {
  opacity: 1;
  border-color: var(--brand);
  box-shadow: var(--ring);
}
.film-num {
  position: absolute;
  left: 3px;
  bottom: 2px;
  font-size: 9px;
  line-height: 1.4;
  padding: 0 4px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-variant-numeric: tabular-nums;
}
.viewer-hint {
  text-align: center;
  color: var(--text-subtle);
  font-size: 13px;
}

/* =========================================================================
   Оверлей прогресса
   ========================================================================= */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 70;
  animation: fade var(--dur-2) var(--ease);
}
.overlay-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 30px 36px;
  box-shadow: var(--shadow-lg);
  width: min(420px, 90vw);
  text-align: center;
}
.spinner {
  width: 42px;
  height: 42px;
  margin: 0 auto 16px;
  border: 3px solid var(--surface-3);
  border-top-color: var(--brand);
  border-radius: var(--r-full);
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.overlay-label {
  margin: 0 0 16px;
  font-size: 15px;
  font-weight: 550;
}
.progress-track {
  height: 8px;
  background: var(--surface-3);
  border-radius: var(--r-full);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--brand), var(--success));
  border-radius: var(--r-full);
  transition: width var(--dur-2) var(--ease);
}
.progress-pct {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* =========================================================================
   Топ-бар: ссылка «Как снимать?»
   ========================================================================= */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.theme-switch {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
}
.theme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 24px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-subtle);
  border-radius: var(--r-full);
  cursor: pointer;
  transition: color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.theme-btn:hover {
  color: var(--text);
}
.theme-btn.is-active {
  background: var(--brand);
  color: #fff;
}
.theme-btn svg {
  width: 15px;
  height: 15px;
}

.topbar-link {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--r-full);
  padding: 6px 13px;
  font-size: 13px;
  font-weight: 550;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}
.topbar-link:hover {
  color: var(--text);
  border-color: var(--border-strong);
}
@media (max-width: 560px) {
  .topbar-link {
    display: none;
  }
}

/* =========================================================================
   Герой (лендинг) — сворачивается, когда появляются кадры
   ========================================================================= */
.hero {
  margin-bottom: 24px;
}
.hero-marketing {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: clamp(24px, 4vw, 48px);
  align-items: center;
  margin-bottom: 20px;
}
.hero-eyebrow {
  display: inline-block;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--brand);
  background: var(--brand-weak);
  padding: 5px 11px;
  border-radius: var(--r-full);
  margin-bottom: 16px;
}
.hero-title {
  font-size: clamp(28px, 4.2vw, 44px);
  line-height: 1.08;
  letter-spacing: -0.025em;
  margin: 0 0 14px;
}
.hero-sub {
  font-size: clamp(15px, 1.5vw, 17px);
  color: var(--text-muted);
  max-width: 48ch;
  margin: 0 0 18px;
}
.hero-points {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 9px;
}
.hero-points li {
  position: relative;
  padding-left: 28px;
  color: var(--text-muted);
  font-size: 14px;
}
.hero-points li::before {
  content: "✓";
  position: absolute;
  left: 0;
  top: -1px;
  width: 19px;
  height: 19px;
  border-radius: var(--r-full);
  background: rgba(52, 211, 154, 0.16);
  color: var(--success);
  font-size: 11px;
  font-weight: 800;
  display: grid;
  place-items: center;
}

/* CSS-демо stop-motion */
.hero-demo {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.demo-screen {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: radial-gradient(120% 80% at 50% 15%, #1e2632, #0d1117);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
}
.demo-rec {
  position: absolute;
  top: 10px;
  left: 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--danger);
}
.demo-ground {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 18%;
  height: 1px;
  background: var(--border-strong);
}
.demo-ball {
  position: absolute;
  left: 8%;
  bottom: 18%;
  width: 16%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #a9c6ff, var(--brand));
  box-shadow: 0 4px 14px rgba(91, 140, 255, 0.4);
  /* steps(1) даёт «телепорт» между позами — характерная рывками анимация stop-motion */
  animation: smHop 3s steps(1, end) infinite;
}
@keyframes smHop {
  0% { left: 8%; bottom: 18%; }
  14% { left: 20%; bottom: 44%; }
  28% { left: 32%; bottom: 18%; }
  42% { left: 44%; bottom: 44%; }
  56% { left: 56%; bottom: 18%; }
  70% { left: 68%; bottom: 44%; }
  84% { left: 80%; bottom: 18%; }
  100% { left: 80%; bottom: 18%; }
}
.demo-strip {
  display: flex;
  gap: 4px;
}
.demo-strip span {
  flex: 1;
  height: 22px;
  border-radius: 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  animation: stripGlow 3s steps(1, end) infinite;
}
.demo-strip span:nth-child(1) { animation-delay: 0s; }
.demo-strip span:nth-child(2) { animation-delay: 0.5s; }
.demo-strip span:nth-child(3) { animation-delay: 1s; }
.demo-strip span:nth-child(4) { animation-delay: 1.5s; }
.demo-strip span:nth-child(5) { animation-delay: 2s; }
.demo-strip span:nth-child(6) { animation-delay: 2.5s; }
@keyframes stripGlow {
  0%, 15% { background: var(--brand); border-color: transparent; }
  16%, 100% { background: var(--surface-2); border-color: var(--border); }
}
.demo-caption {
  text-align: center;
  font-size: 12px;
  color: var(--text-subtle);
}

/* Сворачивание героя, когда уже идёт работа над кадрами */
body.has-frames .hero-marketing {
  display: none;
}
body.has-frames .hero {
  margin-bottom: 16px;
}

@media (max-width: 860px) {
  .hero-marketing {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 560px) {
  .hero-demo {
    display: none;
  }
}

/* =========================================================================
   Гайд: как это работает + как снимать
   ========================================================================= */
.guide {
  margin-top: 44px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 40px;
  scroll-margin-top: calc(var(--topbar-h) + 16px);
}
.guide-title {
  font-size: clamp(20px, 2.4vw, 26px);
  letter-spacing: -0.015em;
  margin: 0 0 20px;
}
.guide-lead {
  color: var(--text-muted);
  max-width: 70ch;
  margin: -8px 0 22px;
  font-size: 15px;
}
.hiw {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.hiw-step {
  display: flex;
  gap: 14px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
}
.hiw-num {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: var(--r-full);
  background: var(--brand-weak);
  color: var(--brand);
  font-weight: 700;
  display: grid;
  place-items: center;
}
.hiw-step h3 {
  font-size: 15px;
  margin: 3px 0 6px;
}
.hiw-step p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13.5px;
}
.tips {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}
.tip {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
  transition: border-color var(--dur-1) var(--ease), transform var(--dur-1) var(--ease);
}
.tip:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
}
.tip-ico {
  display: inline-flex;
  color: var(--brand);
}
.tip-ico svg {
  width: 26px;
  height: 26px;
}
.tip h3 {
  font-size: 14.5px;
  margin: 9px 0 6px;
}
.tip p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13.5px;
}

/* =========================================================================
   Уважение к prefers-reduced-motion (спиннер-прогресс оставляем как обратную связь)
   ========================================================================= */
@media (prefers-reduced-motion: reduce) {
  *:not(.spinner) {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
