/* ========================================
   Плавающий видео-плеер (Floating Player)
   VK Video / Twitch style

   Единственный iframe: при уходе из зоны видимости
   его обёртка .video-modal-wrapper получает класс
   .fp-is-floating и сама становится мини-окном.
   Видео не перезагружается и играет непрерывно.
   ======================================== */

/* ---- Шапка мини-окна (вставляется в обёртку) ---- */
.float-player-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  user-select: none;
  cursor: grab;
  z-index: 10;
  /* на тачскринах перетаскивание за шапку не должно скроллить страницу */
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.float-player-header:active {
  cursor: grabbing;
}

.float-player-title {
  font-size: 12px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.float-player-close {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.float-player-close:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.float-player-close {
  touch-action: manipulation;
}

/* ---- Центральная кнопка Плей/Пауза ---- */
.fp-play-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease,
    visibility 0.2s;
  z-index: 5;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.fp-play-overlay svg {
  position: absolute;
  width: 28px;
  height: 28px;
  fill: #fff;
  transition: opacity 0.15s ease;
}

/* по умолчанию показываем «плей», во время воспроизведения — «паузу» */
.fp-play-overlay .fp-icon-pause {
  opacity: 0;
}

.fp-play-overlay.is-playing .fp-icon-play {
  opacity: 0;
}

.fp-play-overlay.is-playing .fp-icon-pause {
  opacity: 1;
}

/* Десктоп: кнопка появляется при наведении на мини-окно */
@media (hover: hover) and (pointer: fine) {
  .video-modal-wrapper.fp-is-floating:hover .fp-play-overlay {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* Тач-устройства: наведения нет — кнопка всегда видна */
@media (hover: none), (pointer: coarse) {
  .fp-play-overlay {
    opacity: 0.85;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* ---- Состояние мини-окна ---- */
.video-modal-wrapper.fp-is-floating {
  position: fixed;
  bottom: 20px;
  left: 20px;
  top: auto;
  right: auto;
  z-index: 999999;
  width: 380px;
  max-width: calc(100vw - 40px);
  /* убираем мобильные отрицательные отступы из style.css */
  margin: 0 !important;
  /* ВАЖНО: базовая высота задана через padding-bottom:56.25%,
     но у position:fixed процент считается от ШИРИНЫ ВЬЮПОРТА,
     из-за чего окно вытягивается по вертикали.
     Поэтому здесь высоту задаём явно через aspect-ratio. */
  height: auto;
  padding-bottom: 0;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  box-shadow:
    0 8px 40px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.08);

  /* Плавное появление/исчезновение (как у VK Video):
     стартуем скрытым и сдвинутым вниз, класс fp-shown
     переводит в видимое состояние через transition */
  opacity: 0;
  transform: translateY(32px) scale(0.94);
  transition:
    opacity var(--fp-anim-duration, 280ms) var(--fp-anim-easing, cubic-bezier(0.4, 0, 0.2, 1)),
    transform var(--fp-anim-duration, 280ms) var(--fp-anim-easing, cubic-bezier(0.4, 0, 0.2, 1));
  will-change: opacity, transform;
}

.video-modal-wrapper.fp-is-floating.fp-shown {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* ---- Плейсхолдер на месте «большого» окна ---- */
.video-float-placeholder {
  position: relative;
  width: 100%;
  height: 0;
  padding-bottom: 56.25%;
  background-color: #000;
  background-size: cover;
  background-position: center;
}

.video-float-placeholder::after {
  content: '\25B6\00A0 Видео закреплено внизу экрана';
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
  color: rgba(255, 255, 255, 0.85);
  font-size: 11px;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
}

/* ---- Адаптивность мини-окна ---- */

/* Планшеты и телефоны (≤900px):
   внизу экрана в этом диапазоне появляется липкая панель покупки
   (.iptv-sticky-buybar, ~64px + safe-area), поэтому мини-окно
   поднимаем НАД ней, чтобы оно не перекрывало кнопку «Купить» */
@media (max-width: 900px) {
  .video-modal-wrapper.fp-is-floating {
    width: min(400px, calc(100vw - 20px));
    left: 10px;
    bottom: calc(84px + env(safe-area-inset-bottom));
    border-radius: 12px;
  }

  .float-player-header {
    min-height: 36px;
    padding: 6px 8px 6px 12px;
  }

  .float-player-title {
    font-size: 12px;
  }
}

/* Телефоны — окно почти во всю ширину экрана, как мини-плеер VK */
@media (max-width: 480px) {
  .video-modal-wrapper.fp-is-floating {
    width: calc(100vw - 16px);
    left: 8px;
    aspect-ratio: 16 / 9;
    border-radius: 12px;
    box-shadow:
      0 6px 24px rgba(0, 0, 0, 0.45),
      0 0 0 1px rgba(255, 255, 255, 0.06);
  }

  /* шапка с удобной высотой под палец */
  .float-player-header {
    min-height: 40px;
    padding: 6px 6px 6px 12px;
    gap: 8px;
  }

  .float-player-title {
    font-size: 12px;
  }

  /* увеличенная зона нажатия для кнопки закрытия */
  .float-player-close {
    width: 32px;
    height: 32px;
    margin: -2px -2px;
    font-size: 15px;
  }

  .video-float-placeholder::after {
    font-size: 10px;
    bottom: 8px;
  }
}

/* Маленькие телефоны (SE, старые Android) */
@media (max-width: 360px) {
  .video-modal-wrapper.fp-is-floating {
    width: calc(100vw - 12px);
    left: 6px;
  }

  .float-player-close {
    width: 30px;
    height: 30px;
    font-size: 14px;
  }
}

/* Телефон в горизонтальной ориентации:
   окно уводим вправо и делаем компактнее по высоте */
@media (max-width: 1024px) and (max-height: 500px) {
  .video-modal-wrapper.fp-is-floating {
    width: min(46vw, 340px);
    left: auto;
    right: 10px;
    aspect-ratio: 16 / 9;
  }

  .float-player-header {
    min-height: 32px;
    padding: 5px 8px;
  }

  .float-player-close {
    width: 26px;
    height: 26px;
    font-size: 13px;
  }
}

/* ---- Скрытие шапки при печати ---- */
@media print {
  .float-player-header,
  .video-float-placeholder::after {
    display: none !important;
  }
}

/* ---- Prefers reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  .video-modal-wrapper.fp-is-floating {
    transition-duration: 0.01ms !important;
  }
}
