/* ==========================================================================
   Floating Video Player — triBBBal
   z-index: 9000 (above mini-player at 8500, below modals at 99999)
   ========================================================================== */

/* ---------- Custom Properties ---------- */
.floating-video {
  --fv-bg: var(--ml-color-bg-darker);
  --fv-text: var(--ml-color-text-emphasis);
  --fv-accent: var(--ml-color-accent);
  --fv-overlay: var(--ml-color-overlay);
  --fv-control-hover: var(--ml-color-control-hover-strong);
  --fv-radius: var(--ml-radius-md);
  --fv-transition: var(--ml-transition-default);
  --fv-width: var(--ml-floating-width);
  --fv-height: var(--ml-floating-height);
}

/* ---------- Keyframes ---------- */
@keyframes fvSlideUp {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ---------- Box-sizing Reset ---------- */
.floating-video,
.floating-video *,
.floating-video *::before,
.floating-video *::after {
  box-sizing: border-box;
}

/* ---------- Container ---------- */
.floating-video {
  position: fixed;
  z-index: var(--ml-z-floating);
  right: var(--ml-edge-margin);
  bottom: var(--ml-edge-margin);
  width: min(var(--fv-width), calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  background: var(--fv-bg);
  box-shadow: var(--ml-shadow-lg);
  font-family: inherit;
  overflow: hidden;
  border-radius: var(--fv-radius);
}

/* --- State: visible --- */
.floating-video.is-visible {
  display: block;
  animation: fvSlideUp var(--fv-transition) forwards;
}

/* --- State: dragging --- */
.floating-video.is-dragging {
  transition: none;
  will-change: transform;
}

/* --- State: snapping --- */
.floating-video.is-snapping {
  transition: transform 0.3s cubic-bezier(0.2, 0, 0, 1);
}

/* ---------- Desktop (>= 768px) ---------- */
@media (min-width: 768px) {
  .floating-video {
    height: auto;
    min-width: 260px;
  }

  /* Shift up when mini-player is active */
  .body-has-mini-player .floating-video {
    bottom: calc(var(--ml-edge-margin) + 88px);
  }
}

/* ---------- Mobile (< 768px) ---------- */
@media (max-width: 767px) {
  .floating-video {
    width: min(260px, calc(100vw - 24px));
    right: 12px;
    left: auto;
    bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  }

  /* Body padding to prevent content overlap */
  .body-has-floating-video {
    padding-bottom: 0;
  }

  .floating-video-info {
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }
}

/* ---------- Drag Handle ---------- */
.floating-video-drag-handle {
  position: relative;
  z-index: 3;
  width: 88px;
  height: 20px;
  margin: 6px auto -2px;
  cursor: grab;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.floating-video-drag-handle::before {
  content: '';
  width: 42px;
  height: 4px;
  background: rgba(255, 255, 255, 0.32);
  border-radius: 999px;
}

.is-dragging .floating-video-drag-handle {
  cursor: grabbing;
}

/* ---------- Video Content ---------- */
.floating-video-content {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: var(--fv-radius) var(--fv-radius) 0 0;
}

.floating-video-content video,
.floating-video-content iframe,
.floating-video-content > .video-js,
.floating-video-content > .artplayer-app,
.floating-video-content > .plyr,
.floating-video-content > .post-youtube,
.floating-video-content > .tp-inline-card {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* Video inside .tp-inline-card should fill the card, not the floating container */
.floating-video-content > .tp-inline-card video {
  position: relative;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.floating-video-content video {
  object-fit: contain;
}

/* Hide inline player controls when inside floating container */
.floating-video-content > .tp-inline-card {
  aspect-ratio: unset;
  border-radius: 0;
}
.floating-video-content > .tp-inline-card .tp-controls,
.floating-video-content > .tp-inline-card .tp-seek-footer,
.floating-video-content > .tp-inline-card .tp-inline-play-btn,
.floating-video-content > .tp-inline-card .tp-inline-duration,
.floating-video-content > .tp-inline-card .tp-settings-panel {
  display: none;
}

/* Placeholder that holds space while video is in floating mode */
.tp-float-placeholder {
  background: #111;
  border-radius: 0;
  position: relative;
}

.floating-video-content .video-js {
  position: absolute !important;
  top: 0;
  left: 0;
  width: 100% !important;
  height: 100% !important;
}

@media (max-width: 767px) {
  .floating-video-content {
    border-radius: var(--fv-radius) var(--fv-radius) 0 0;
  }
}

/* ---------- Controls Overlay ---------- */
.floating-video-controls {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--fv-overlay);
  opacity: 0;
  transition: opacity 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  pointer-events: none;
}

/* Show on hover/focus — use parent so controls overlay doesn't break the hover chain */
.floating-video:hover .floating-video-controls,
.floating-video:focus-within .floating-video-controls {
  opacity: 1;
  pointer-events: auto;
}

/* Show on tap (mobile — JS toggles .is-tapped) */
.floating-video-controls.is-tapped {
  opacity: 1;
  pointer-events: auto;
}

/* ---------- Control Buttons ---------- */
.floating-video-controls button {
  background: rgba(0, 0, 0, 0.6);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s ease;
}

.floating-video-controls button:hover {
  background: var(--fv-control-hover);
}

/* Play button — slightly larger */
.floating-video-play-btn {
  width: 48px;
  height: 48px;
  font-size: 20px;
}

/* PiP button — hidden unless JS confirms support */
.floating-video-pip {
  display: none;
}

.pip-supported .floating-video-pip {
  display: flex;
}

/* Go-to-source button — hidden by default, shown by JS when there's a source */
.floating-video-goto-source {
  display: none;
}

/* ---------- Info Bar ---------- */
.floating-video-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 10px;
  background: var(--fv-bg);
  min-height: 48px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  padding-right: 12px;
}

.floating-video-meta {
  display: flex;
  flex: 1;
  min-width: 0;
  flex-direction: column;
}

.floating-video-title {
  font-size: 12px;
  color: var(--fv-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.floating-video-source {
  color: var(--ml-color-text-secondary);
  font-size: 11px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.floating-video-info-close {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 5;
  width: 24px;
  height: 24px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(10, 10, 14, 0.88);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  touch-action: manipulation;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.18), 0 8px 20px rgba(0, 0, 0, 0.38);
}

.floating-video-info-close:hover,
.floating-video-info-close:focus-visible {
  background: rgba(18, 18, 24, 0.96);
  outline: none;
}

.floating-video-info-close i {
  font-size: 11px;
  line-height: 1;
}

.floating-video.is-dragging .floating-video-info {
  cursor: grabbing;
}

@media (max-width: 767px) {
  .floating-video-title {
    font-size: 13px;
  }
}

/* ---------- Social Meta Slots ---------- */
.floating-video-social-meta {
  display: flex;
  gap: 8px;
  padding: 0 12px 8px;
}

.floating-video-social-meta > * {
  min-height: 0;
}

@media (min-width: 768px) {
  .floating-video-social-meta {
    border-radius: 0 0 var(--fv-radius) var(--fv-radius);
  }
}

/* Poster avatar in floating video */
.floating-video-poster-link {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  margin-right: 6px;
  border-radius: 50%;
  overflow: hidden;
  display: block;
  line-height: 0;
}

.floating-video-poster-avatar {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 100%;
  min-height: 100%;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid var(--fv-accent, #e94560);
}

.floating-video-resize-handle {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
  opacity: 0.7;
  touch-action: none;
}

.floating-video-resize-handle::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: linear-gradient(135deg, transparent 0 40%, rgba(255, 255, 255, 0.45) 40% 52%, transparent 52% 64%, rgba(255, 255, 255, 0.45) 64% 76%, transparent 76% 100%);
}

.floating-video.is-resizing {
  transition: none;
}

.floating-video.is-resizing .floating-video-resize-handle,
.floating-video.is-dragging .floating-video-resize-handle {
  opacity: 1;
}
