/* Shared video player (templates/components/video_player.html + js/video_player.js).
   Loaded by base.html and embed.html. */

/* ── Video framing: the box follows the clip's real aspect ratio ─────────
   --media-ar (width / height) starts at the 16/9 guess that only holds space
   while the thumbnail loads; setMediaAspect() in js.html replaces it with the
   thumbnail's natural ratio as soon as the image reports its size. Without
   this a portrait clip was letterboxed inside a fixed 16/9 box and rendered
   as a narrow strip, then jumped to full size once the <video> — which has
   no fixed ratio — took over on play. max-width caps how tall a portrait
   clip may get without bringing the side gutters back. */
.video-frame {
  aspect-ratio: var(--media-ar, 16 / 9);
  width: 100%;
  max-width: calc(var(--media-max-h, 80vh) * (var(--media-ar, 16 / 9)));
  margin-left: auto;
  margin-right: auto;
  /* Isolate stacking so the play overlay paints above <video> on desktop
     (GPU-composited video layers often cover later siblings otherwise). */
  isolation: isolate;
  position: relative;
}

.video-frame > img,
.video-frame > video {
  width: 100%;
  height: 100%;
  max-height: none;
  object-fit: contain;
  position: relative;
  z-index: 0;
}

/* Feed videos — user-started playback only */
video.feed-video,
video.feed-autoplay-video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #000;
}
/* Instagram-style round speaker toggle, bottom-right of the video */
.video-mute-toggle {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 30px;
  height: 30px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: rgba(38, 38, 38, 0.72);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: transform 0.15s ease, background 0.15s ease;
}
/* Bigger hit area than the visible circle, for thumbs */
.video-mute-toggle::after {
  content: '';
  position: absolute;
  inset: -8px;
}
.video-mute-toggle:hover { background: rgba(38, 38, 38, 0.88); }
.video-mute-toggle:active { transform: scale(0.9); }
.video-mute-toggle .icon-unmuted { display: none; }
.video-mute-toggle:not(.is-muted) .icon-muted { display: none; }
.video-mute-toggle:not(.is-muted) .icon-unmuted { display: block; }
.video-play-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  touch-action: manipulation;
  background: transparent;
  -webkit-tap-highlight-color: transparent;
}
.video-mute-toggle {
  z-index: 6;
}
.video-play-overlay::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0.12) 0%, rgba(0,0,0,0.28) 100%);
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.video-play-overlay.is-hidden {
  display: none !important;
}
.video-play-badge {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 68px;
  height: 68px;
  border-radius: 999px;
  color: #fff;
  background: rgba(15, 23, 42, 0.55);
  border: 1.5px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}
.video-play-icon {
  display: block;
  margin-left: 3px; /* optical center for the triangle */
}
.video-play-overlay:hover .video-play-badge,
.video-play-overlay:focus-visible .video-play-badge {
  transform: scale(1.06);
  background: rgba(15, 23, 42, 0.72);
  border-color: rgba(255, 255, 255, 0.85);
}
.video-play-overlay:active .video-play-badge {
  transform: scale(0.96);
}
.video-type-chip {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #fff;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  padding: 4px 7px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  pointer-events: none;
}
@media (pointer: coarse) {
  .video-play-badge {
    width: 76px;
    height: 76px;
  }
  .video-play-icon {
    width: 32px;
    height: 32px;
  }
}

/* Thin tap/drag-to-seek bar along the bottom edge, shown once playback starts */
.video-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 14px;          /* hit area; the visible track is the ::before */
  z-index: 6;
  cursor: pointer;
  touch-action: none;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.video-progress.is-active {
  opacity: 1;
  pointer-events: auto;
}
.video-progress::before,
.video-progress-fill {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  transition: height 0.15s ease;
}
.video-progress::before {
  right: 0;
  background: rgba(255, 255, 255, 0.3);
}
.video-progress-fill {
  width: 0;
  background: #fff;
}
.video-progress:hover::before,
.video-progress:hover .video-progress-fill,
.video-progress.is-seeking::before,
.video-progress.is-seeking .video-progress-fill {
  height: 5px;
}
/* Keep the speaker button clear of the seek bar */
.video-frame .video-mute-toggle { bottom: 16px; }
