/* broadcast-player.css — shared Netflix-style live broadcast player
 *
 * Sizing strategy (YouTube theater-mode approach):
 *   - Width: 100% of parent
 *   - Height: derived from width (56.25vw = 16:9) so aspect ratio is always perfect
 *   - max-height: clamped so it doesn't consume the viewport on wide/short screens
 *   - On ultrawide: player shrinks height, width auto-adjusts via max-width = height * 16/9
 *   - This avoids object-fit:cover cropping the broadcast frame
 *
 * Layout: --bp-header-h controls header offset (default 0px)
 */

:root {
  --bp-header-h: 64px;             /* desktop header height */
  --bp-max-h: calc(100vh - var(--bp-header-h));
  --bp-ratio: 16 / 9;
}

.bp-container {
  position: relative;
  width: 100%;

  /* Height = 56.25% of viewport width (= 16:9 ratio) */
  height: 56.25vw;

  /* Clamp: never shorter than 220px, never taller than available viewport minus header,
     and hard-cap at 810px so 4K monitors don't make a comically tall player */
  max-height: clamp(220px, var(--bp-max-h, 80vh), 810px);

  /* When max-height kicks in, constrain width to maintain 16:9 (no cropping) */
  max-width: calc(clamp(220px, var(--bp-max-h, 80vh), 810px) * 16 / 9);
  margin-inline: auto; /* center when width-constrained */

  background: #000;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* Mobile: smaller header */
@media (max-width: 767px) {
  :root { --bp-header-h: 56px; }
  .bp-container {
    max-height: clamp(220px, calc(100dvh - 56px), 810px);
    max-width: calc(clamp(220px, calc(100dvh - 56px), 810px) * 16 / 9);
  }
}

/* dvh fallback for mobile Safari (URL bar awareness) */
@supports (max-height: 1dvh) {
  .bp-container {
    max-height: clamp(220px, calc(100dvh - var(--bp-header-h)), 810px);
    max-width: calc(clamp(220px, calc(100dvh - var(--bp-header-h)), 810px) * 16 / 9);
  }
}

/* Fallback for browsers without clamp() (pre-2020) */
@supports not (max-height: clamp(1px, 1vh, 2px)) {
  .bp-container {
    max-height: 80vh;
    max-width: calc(80vh * 16 / 9);
  }
}

.bp-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;       /* cover is fine now — container IS 16:9, no cropping */
  display: block;
}

/* Mute indicator — top-left circle */
.bp-mute-indicator {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4;
  transition: opacity .3s ease;
  pointer-events: none;
}

.bp-mute-indicator svg {
  width: 20px;
  height: 20px;
  fill: #fff;
}

.bp-mute-indicator.bp-hidden {
  opacity: 0;
}

/* Live badge — top-right, red pulse */
.bp-live-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 4px;
  background: rgba(230, 57, 70, .9);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #fff;
  letter-spacing: .04em;
  z-index: 4;
  pointer-events: none;
}

.bp-live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
  animation: bp-pulse 1.5s ease-in-out infinite;
}

@keyframes bp-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .3; }
}

/* Quality badge — top-right, left of live badge */
.bp-quality-badge {
  position: absolute;
  top: 12px;
  right: 72px;
  padding: 4px 8px;
  border-radius: 4px;
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-size: .6rem;
  font-weight: 600;
  color: #fff;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s ease;
}

.bp-container.bp-controls-visible .bp-quality-badge {
  opacity: 1;
}

/* Bottom gradient — ONLY with controls */
.bp-gradient {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 80px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .6));
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s ease;
}

.bp-container.bp-controls-visible .bp-gradient {
  opacity: 1;
}

/* Controls bar */
.bp-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  background: rgba(0, 0, 0, .4);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 3;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .3s ease, transform .3s ease;
}

.bp-container.bp-controls-visible .bp-controls {
  opacity: 1;
  transform: translateY(0);
}

.bp-controls-left,
.bp-controls-right {
  display: flex;
  align-items: center;
  gap: 2px;
}

/* Buttons */
.bp-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background .15s ease;
}

.bp-btn:hover {
  background: rgba(255, 255, 255, .12);
}

.bp-btn svg {
  width: 20px;
  height: 20px;
  fill: #fff;
}

/* Volume wrapper — expandable */
.bp-volume-wrap {
  display: flex;
  align-items: center;
  width: 36px;
  overflow: hidden;
  transition: width .25s ease;
}

.bp-volume-wrap:hover {
  width: 110px;
}

.bp-volume-range {
  width: 70px;
  height: 3px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, .3);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  margin-left: 2px;
  opacity: 0;
  transition: opacity .2s ease;
}

.bp-volume-wrap:hover .bp-volume-range {
  opacity: 1;
}

.bp-volume-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
}

.bp-volume-range::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fff;
  border: none;
  cursor: pointer;
}

.bp-volume-range::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
}

.bp-volume-range::-moz-range-track {
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, .3);
}

/* Loading spinner */
.bp-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s ease;
}

.bp-loading.bp-active {
  opacity: 1;
}

.bp-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid transparent;
  border-top-color: #fff;
  border-radius: 50%;
  animation: bp-spin .8s linear infinite;
}

@keyframes bp-spin {
  to { transform: rotate(360deg); }
}

/* Fullscreen: remove all constraints */
.bp-container:fullscreen,
.bp-container:-webkit-full-screen {
  max-height: none;
  max-width: none;
  height: 100%;
  width: 100%;
}

/* Mobile: use dvh (dynamic viewport height) to account for browser chrome */
@media (max-width: 600px) {
  .bp-container {
    height: 56.25vw;        /* still 16:9 from width */
    max-height: 50dvh;      /* leave room for controls/info below */
    max-width: calc(50dvh * 16 / 9);
  }

  /* Landscape mobile: fill available height */
  @media (orientation: landscape) {
    .bp-container {
      max-height: 100dvh;
      max-width: calc(100dvh * 16 / 9);
    }
  }
}

@media (max-width: 600px) {
  .bp-mute-indicator {
    width: 32px;
    height: 32px;
    top: 8px;
    left: 8px;
  }

  .bp-mute-indicator svg {
    width: 16px;
    height: 16px;
  }

  .bp-live-badge {
    top: 8px;
    right: 8px;
    font-size: .58rem;
    padding: 3px 6px;
  }

  .bp-quality-badge {
    top: 8px;
    right: 60px;
    font-size: .55rem;
  }

  .bp-btn {
    width: 32px;
    height: 32px;
  }

  .bp-btn svg {
    width: 18px;
    height: 18px;
  }

  /* Hide volume slider on mobile — tap mute button to toggle */
  .bp-volume-wrap {
    width: 32px;
  }

  .bp-volume-wrap:hover {
    width: 32px;
  }

  .bp-volume-range {
    display: none;
  }

  .bp-spinner {
    width: 32px;
    height: 32px;
  }
}
