/* ============================================
   Morpheus Custom Video Player — Styles
   Frosted-glass pill control bar, Apple aesthetic
   ============================================ */

/* --- Player Container --- */
.player-container {
  position: relative;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.player-container video {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius-lg);
}

/* Hide native controls when custom player is active */
.player-container video::-webkit-media-controls {
  display: none !important;
}

/* --- Frosted Glass Control Bar --- */
.mp-controls {
  position: absolute;
  bottom: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 980px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 10;
}

/* The player container is focusable so its keyboard shortcuts can be scoped to it (player.js
   handleKeyboard). Show a ring for keyboard focus only, not for the click that focuses it. */
.mp-focus-host:focus { outline: none; }
.mp-focus-host:focus-visible { outline: 2px solid #0a84ff; outline-offset: 2px; }

.player-container:hover .mp-controls,
.player-container.mp-controls-visible .mp-controls,
.player-container:focus-within .mp-controls {
  opacity: 1;
  pointer-events: auto;
}

/* Always show when paused */
.player-container.mp-paused .mp-controls {
  opacity: 1;
  pointer-events: auto;
}

/* --- Control Buttons --- */
.mp-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease;
  padding: 0;
}

.mp-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.mp-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

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

.mp-btn.active {
  color: #fff;
}

/* --- Time Display --- */
.mp-time {
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.7);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 36px;
  text-align: center;
}

.mp-time-current { text-align: right; }
.mp-time-duration { text-align: left; }

/* --- Live badge ---
   Shown instead of the time readout + scrubber on a live broadcast (the
   scrubber is the flex:1 element that normally pushes the right-hand buttons
   over, so this takes margin-right:auto to keep that layout). */
.mp-live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: auto;
  padding: 3px 9px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: #fff;
  background: rgba(255, 59, 48, 0.9);
  white-space: nowrap;
  flex-shrink: 0;
  cursor: default;
}

.mp-live-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
  animation: mp-live-pulse 2s ease-in-out infinite;
}

@keyframes mp-live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@media (prefers-reduced-motion: reduce) {
  .mp-live-badge::before { animation: none; }
}

/* --- Scrubber --- */
.mp-scrubber {
  flex: 1;
  position: relative;
  height: 32px;
  display: flex;
  align-items: center;
  cursor: pointer;
  min-width: 60px;
  /* Touch drags seek instead of scrolling the page (pointer events in player.js). */
  touch-action: none;
}
.mp-scrubber:focus { outline: none; }
.mp-scrubber:focus-visible { outline: 2px solid #0a84ff; outline-offset: 2px; border-radius: 4px; }

.mp-scrubber-track {
  position: relative;
  width: 100%;
  height: 3px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
  overflow: hidden;
  transition: height 0.15s ease;
}

.mp-scrubber:hover .mp-scrubber-track,
.mp-scrubber:focus-visible .mp-scrubber-track {
  height: 5px;
}

.mp-scrubber-buffer {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  pointer-events: none;
}

.mp-scrubber-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: #fff;
  border-radius: 2px;
  pointer-events: none;
}

/* Scrubber thumb */
.mp-scrubber-thumb {
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0);
  transition: transform 0.15s ease;
  pointer-events: none;
  z-index: 2;
}

.mp-scrubber:hover .mp-scrubber-thumb,
.mp-scrubber:focus-visible .mp-scrubber-thumb {
  transform: translate(-50%, -50%) scale(1);
}

/* Hover time tooltip */
.mp-scrubber-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  padding: 3px 8px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  font-size: 11px;
  font-weight: 500;
  border-radius: 4px;
  transform: translateX(-50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.mp-scrubber:hover .mp-scrubber-tooltip,
.mp-scrubber:focus-visible .mp-scrubber-tooltip {
  opacity: 1;
}

/* --- Volume --- */
.mp-volume {
  display: flex;
  align-items: center;
  position: relative;
}

.mp-volume-slider-wrap {
  width: 0;
  overflow: hidden;
  transition: width 0.2s ease;
  display: flex;
  align-items: center;
}

.mp-volume:hover .mp-volume-slider-wrap {
  width: 70px;
}

.mp-volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 60px;
  height: 3px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  margin: 0 6px;
}

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

/* --- Speed & Quality Flyout --- */
.mp-flyout-anchor {
  position: relative;
}

.mp-flyout {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  min-width: 80px;
  background: rgba(0, 0, 0, 0.8);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 4px;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 20;
}

.mp-flyout.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.mp-flyout-item {
  display: block;
  width: 100%;
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.1s ease, color 0.1s ease;
  white-space: nowrap;
}

.mp-flyout-item:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.mp-flyout-item.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

/* Speed label */
.mp-speed-label {
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* --- Disabled state (non-HLS quality button) --- */
.mp-btn.mp-disabled {
  opacity: 0.3;
  cursor: default;
}

.mp-btn.mp-disabled:hover {
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
}

.mp-flyout-item.mp-flyout-disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

/* --- Big Center Play Button (shown when paused) --- */
.mp-big-play {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  width: 64px;
  height: 64px;
  background: rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 5;
}

.mp-big-play svg {
  width: 28px;
  height: 28px;
  fill: #fff;
  margin-left: 3px; /* optical center for play triangle */
}

.player-container.mp-paused .mp-big-play {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

/* Hide big play once video has started and is playing */
.player-container.mp-started:not(.mp-paused) .mp-big-play {
  opacity: 0;
  pointer-events: none;
}

/* --- Fullscreen --- */
.player-container:fullscreen,
.player-container:-webkit-full-screen {
  border-radius: 0;
  background: #000;
}

.player-container:fullscreen video,
.player-container:-webkit-full-screen video {
  border-radius: 0;
  height: 100vh;
  object-fit: contain;
}

.player-container:fullscreen .mp-controls,
.player-container:-webkit-full-screen .mp-controls {
  bottom: 24px;
  left: 24px;
  right: 24px;
}

/* --- Loading Spinner --- */
.mp-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: #fff;
  border-radius: 50%;
  animation: mp-spin 0.8s linear infinite;
  opacity: 0;
  pointer-events: none;
  z-index: 4;
}

.player-container.mp-buffering .mp-loading {
  opacity: 1;
}

@keyframes mp-spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* --- Caption styling (custom cues) --- */
.player-container video::cue {
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 1rem;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  line-height: 1.4;
  border-radius: 4px;
  padding: 2px 6px;
}

/* ============================================
   Light Mode — Player stays dark (standard)
   Only subtle border adjustment for embedding
   ============================================ */
.light-mode .player-container {
  box-shadow: 0 0 40px 8px color-mix(in srgb, var(--player-glow, #0071e3) 50%, transparent),
              0 0 80px 20px color-mix(in srgb, var(--player-glow, #0071e3) 25%, transparent),
              0 4px 20px rgba(0, 0, 0, 0.12);
  border: 1px solid rgba(0, 0, 0, 0.08);
}

/* ============================================
   "Dim the Lights" focus mode
   Hovering top-right toggle + full-page dark backdrop; the player is
   elevated above the backdrop so only it (and its accent glow) stays lit.
   ============================================ */

/* The toggle — frosted-glass circle, top-right, reveals with the controls. */
.mp-lights {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 11;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, color 0.2s ease, background 0.2s ease;
}
.mp-lights svg { width: 18px; height: 18px; }
.mp-lights:hover { color: #fff; background: rgba(0, 0, 0, 0.7); }

/* Reveal on hover / focus / paused — same triggers as .mp-controls. */
.player-container:hover .mp-lights,
.player-container.mp-controls-visible .mp-lights,
.player-container:focus-within .mp-lights,
.player-container.mp-paused .mp-lights {
  opacity: 1;
  pointer-events: auto;
}
/* While the lights are off, keep the toggle visible so it's always findable. */
html.lights-off .mp-lights {
  opacity: 1;
  pointer-events: auto;
  color: var(--player-glow, #0071e3);
}

/* The dark fill is a huge box-shadow emitted by the player itself, listed
   AFTER the accent-glow layers. Per the box-shadow spec the first-listed
   shadow paints on top, so the glow always blooms over the dark, and the
   video — which sits above the element's box-shadow entirely — is never
   dimmed. No separate backdrop element, so nothing can be trapped above the
   player by the page's stacking contexts. z-index lifts the player (and thus
   the reach of its shadow) over the rest of the page chrome. */
html.lights-off .player-container {
  position: relative;
  z-index: 950;
  box-shadow:
    0 0 60px 12px color-mix(in srgb, var(--player-glow, #0071e3) 60%, transparent),
    0 0 140px 40px color-mix(in srgb, var(--player-glow, #0071e3) 30%, transparent),
    0 0 0 100vmax rgba(0, 0, 0, 0.9);
}
/* Light-mode morpheus2 has a higher-specificity glow rule (the .light-mode
   selector), so the lights-off override must out-specify it to take hold. */
html[data-page-style="morpheus2"].light-mode.lights-off .player-container {
  box-shadow:
    0 0 32px 3px color-mix(in srgb, var(--player-glow, #0071e3) 70%, transparent),
    0 0 66px 16px color-mix(in srgb, var(--player-glow, #0071e3) 40%, transparent),
    0 0 130px 52px color-mix(in srgb, var(--player-glow, #0071e3) 22%, transparent),
    0 0 0 100vmax rgba(0, 0, 0, 0.9);
}

/* The floating page header is a separate position:fixed layer above the player,
   so the player's dim box-shadow can't reach it. Fade it down to roughly match
   the ~90%-dark page while the lights are off (and drop its pointer events so
   it's not interactable behind the focus mode). */
html.lights-off .nav-bar {
  opacity: 0.12;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

/* ── Specter 4.x wrapper ─────────────────────────────────────────────────────
   ac-video draws its OWN controls on the DRM path (see the comment block on
   init() in js/player.js), so its injected `.ac-video-player { cursor: none }` is
   now doing the job it was designed for: hiding the pointer while its control bar
   is auto-hidden, with its own `hide-cursor` logic restoring it. We previously
   overrode that with `cursor: inherit` because headless mode left nothing to
   restore it. That override is REMOVED — fighting the framework's cursor handling
   now would break behaviour it manages correctly.

   Morpheus's own affordances must not sit on top of that control bar. init() marks
   the container so mp-controls and the big-play button stay out of the way on this
   path. The standalone "dim the lights" button is the deliberate exception, since
   that effect is container-level rather than control-level. */
.player-container.mp-external-controls .mp-controls,
.player-container.mp-external-controls .mp-big-play,
.player-container.mp-external-controls .mp-loading {
  display: none !important;
}
/* The lights toggle stays, and must clear ac-video's control bar. */
.player-container.mp-external-controls .mp-lights {
  opacity: 1;
  pointer-events: auto;
  z-index: 30;
}
