/**
 * @file
 * Styles for FFmpeg Media Streaming Player.
 *
 * Uses ffmpeg_media design tokens for theme-neutral styling.
 */

/* Player container */
.ffmpeg-streaming-player {
  position: relative;
  width: 100%;
  background: var(--ffmpeg-bg, #000);
  border-radius: var(--ffmpeg-radius-m, 8px);
  overflow: hidden;
}

/* Aspect ratio reservation to prevent CLS */
.ffmpeg-streaming-player[style*="aspect-ratio"] {
  display: block;
}

/* Poster image placeholder — overlays Vidstack player until playback starts */
.ffmpeg-streaming-player__poster {
  position: absolute;
  top: 0;
  inset-inline-start: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 10;
  pointer-events: none;
}

/* Lazy load state - show placeholder */
.ffmpeg-streaming-player--lazy:not(.ffmpeg-streaming-player--initialized) {
  background: linear-gradient(135deg, var(--ffmpeg-player-lazy-start, #1a1a2e) 0%, var(--ffmpeg-player-lazy-end, #16213e) 100%);
}

.ffmpeg-streaming-player--lazy:not(.ffmpeg-streaming-player--initialized)::before {
  content: "";
  position: absolute;
  top: 50%;
  inset-inline-start: 50%;
  transform: translate(-50%, -50%);
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--ffmpeg-player-tint-hover, rgba(255, 255, 255, 0.1));
  animation: ffmpeg-player-pulse 2s ease-in-out infinite;
}

@keyframes ffmpeg-player-pulse {
  0%, 100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.5;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.1);
    opacity: 0.8;
  }
}

/* Initialized state */
.ffmpeg-streaming-player--initialized::before {
  display: none;
}

/* Vidstack player styling */
.ffmpeg-vidstack-player {
  --media-font-family: system-ui, sans-serif;

  width: 100%;
  height: 100%;
}

/* Theme: Minimal */
.ffmpeg-streaming-player--minimal .ffmpeg-vidstack-player,
.ffmpeg-player-layout--minimal {
  --media-controls-opacity: 0;
}

.ffmpeg-streaming-player--minimal:hover .ffmpeg-vidstack-player,
.ffmpeg-streaming-player--minimal:focus-within .ffmpeg-vidstack-player {
  --media-controls-opacity: 1;
}

/* Touch devices: always show controls for minimal theme */
@media (pointer: coarse) {
  .ffmpeg-streaming-player--minimal .ffmpeg-vidstack-player,
  .ffmpeg-player-layout--minimal {
    --media-controls-opacity: 1;
  }
}

/* Unavailable state */
.ffmpeg-streaming-player__unavailable {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-height: 200px;
  color: var(--ffmpeg-text-muted, #94a3b8);
  font-size: 0.875rem;
  text-align: center;
  padding: 2rem;
}

/* Converting/Pending state */
.ffmpeg-streaming-player__converting,
.ffmpeg-streaming-player__pending {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-height: 200px;
  padding: 2rem;
  color: var(--ffmpeg-text, #e2e8f0);
  text-align: center;
}

.ffmpeg-streaming-player__pending-icon {
  display: inline-block;
  width: 48px;
  height: 48px;
  margin-bottom: 1rem;
  border: 3px solid var(--ffmpeg-text-muted, #64748b);
  border-top-color: var(--ffmpeg-accent, #2563eb);
  border-radius: 50%;
  animation: ffmpeg-player-spin 1s linear infinite;
}

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

/* Error state */
.ffmpeg-streaming-player__error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  width: 100%;
  height: 100%;
  min-height: 200px;
  padding: 2rem;
  color: var(--ffmpeg-text, #e2e8f0);
  text-align: center;
  background: linear-gradient(135deg, var(--ffmpeg-player-error-start, #1a1a2e) 0%, var(--ffmpeg-player-error-end, #2d1b2e) 100%);
}

/* Respect native hidden attribute. */
.ffmpeg-streaming-player__error[hidden] {
  display: none !important;
}

.ffmpeg-streaming-player__error-icon {
  display: inline-block;
  width: 48px;
  height: 48px;
  border: 3px solid var(--ffmpeg-player-error-accent, #dc2626);
  border-radius: 50%;
  position: relative;
}

.ffmpeg-streaming-player__error-icon::after {
  content: "!";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.5rem;
  font-weight: bold;
  color: var(--ffmpeg-player-error-accent, #dc2626);
}

.ffmpeg-streaming-player__error-message {
  font-size: 0.875rem;
  color: var(--ffmpeg-text-muted, #94a3b8);
}

.ffmpeg-streaming-player__retry-button {
  padding: 0.5rem 1.5rem;
  border: 1px solid var(--ffmpeg-accent, #2563eb);
  border-radius: var(--ffmpeg-radius-s, 8px);
  background: transparent;
  color: var(--ffmpeg-accent, #2563eb);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.ffmpeg-streaming-player__retry-button:hover {
  background: var(--ffmpeg-accent, #2563eb);
  color: var(--ffmpeg-player-text, #ffffff);
}

.ffmpeg-streaming-player__retry-button:focus-visible {
  outline: 2px solid var(--ffmpeg-accent, #2563eb);
  outline-offset: 2px;
}

.ffmpeg-streaming-player--error .ffmpeg-vidstack-player {
  display: none;
}

/* Hide playback speed menu */
.ffmpeg-streaming-player--speed-hidden media-menu[data-media-menu] media-menu-item[data-media-speed-menu-item],
.ffmpeg-streaming-player--speed-hidden [data-media-menu] [data-media-speed-up-button],
.ffmpeg-streaming-player--speed-hidden media-speed-slider,
.ffmpeg-streaming-player--speed-hidden [part~="speed"] {
  display: none !important;
}

/* Hide PiP button */
.ffmpeg-streaming-player--pip-hidden media-pip-button,
.ffmpeg-streaming-player--pip-hidden [part~="pip"] {
  display: none !important;
}

/* Local runtime deliberately disables Google Cast to avoid external requests. */
.ffmpeg-streaming-player--local-runtime .vds-google-cast,
.ffmpeg-streaming-player--local-runtime media-google-cast-button,
.ffmpeg-streaming-player--local-runtime [part~="google-cast"] {
  display: none !important;
}

/* Noscript fallback video */
.ffmpeg-streaming-player noscript video {
  width: 100%;
  height: auto;
}

/* Accessibility: Focus styles */
.ffmpeg-streaming-player:focus-within {
  outline: none;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .ffmpeg-streaming-player {
    border-radius: 0;
  }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .ffmpeg-streaming-player--lazy:not(.ffmpeg-streaming-player--initialized)::before {
    animation: none;
  }

  .ffmpeg-streaming-player__pending-icon {
    animation: none;
  }

  .ffmpeg-streaming-player__retry-button {
    transition: none;
  }

  .ffmpeg-streaming-player__help-button {
    transition: none;
  }
}

/* Keyboard shortcut help button */
.ffmpeg-streaming-player__help-button {
  position: absolute;
  top: 0.5rem;
  inset-inline-end: 0.5rem;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--ffmpeg-player-overlay, rgba(0, 0, 0, 0.6));
  color: var(--ffmpeg-player-text, #ffffff);
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, background 0.2s;
}

.ffmpeg-streaming-player:hover .ffmpeg-streaming-player__help-button,
.ffmpeg-streaming-player:focus-within .ffmpeg-streaming-player__help-button,
.ffmpeg-streaming-player__help-button:focus-visible {
  opacity: 1;
}

.ffmpeg-streaming-player__help-button:hover {
  background: var(--ffmpeg-player-overlay-hover, rgba(0, 0, 0, 0.85));
}

.ffmpeg-streaming-player__help-button:focus-visible {
  outline: none;
  box-shadow: var(--ffmpeg-focus-ring, 0 0 0 3px rgba(38, 132, 255, 0.5));
}

/* Help dialog overlay */
.ffmpeg-streaming-player-help {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ffmpeg-streaming-player-help--hidden,
.ffmpeg-streaming-player-help[hidden] {
  display: none !important;
}

.ffmpeg-streaming-player-help__backdrop {
  position: absolute;
  inset: 0;
  background: var(--ffmpeg-player-backdrop, rgba(0, 0, 0, 0.8));
}

.ffmpeg-streaming-player-help__content {
  position: relative;
  width: 90%;
  max-width: 320px;
  background: var(--ffmpeg-player-surface, #1f2937);
  border-radius: var(--ffmpeg-radius-m, 8px);
  box-shadow: var(--ffmpeg-player-shadow, 0 8px 32px rgba(0, 0, 0, 0.5));
  overflow: hidden;
}

.ffmpeg-streaming-player-help__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--ffmpeg-player-border, rgba(255, 255, 255, 0.1));
}

.ffmpeg-streaming-player-help__title {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ffmpeg-player-text, #ffffff);
}

.ffmpeg-streaming-player-help__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--ffmpeg-player-text-softer, rgba(255, 255, 255, 0.6));
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.ffmpeg-streaming-player-help__close:hover {
  color: var(--ffmpeg-player-text, #ffffff);
  background: var(--ffmpeg-player-tint-hover, rgba(255, 255, 255, 0.1));
}

.ffmpeg-streaming-player-help__close:focus-visible {
  outline: none;
  box-shadow: var(--ffmpeg-focus-ring, 0 0 0 3px rgba(38, 132, 255, 0.5));
}

.ffmpeg-streaming-player-help__body {
  margin: 0;
  padding: 0.5rem 1rem 0.75rem;
}

.ffmpeg-streaming-player-help__item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.375rem 0;
}

.ffmpeg-streaming-player-help__key {
  flex: 0 0 auto;
}

.ffmpeg-streaming-player-help__key kbd {
  display: inline-block;
  min-width: 1.75rem;
  padding: 0.125rem 0.375rem;
  border: 1px solid var(--ffmpeg-player-border-strong, rgba(255, 255, 255, 0.2));
  border-radius: 4px;
  background: var(--ffmpeg-player-tint, rgba(255, 255, 255, 0.08));
  color: var(--ffmpeg-player-text, #ffffff);
  font-family: system-ui, sans-serif;
  font-size: 0.75rem;
  text-align: center;
}

.ffmpeg-streaming-player-help__desc {
  margin: 0;
  color: var(--ffmpeg-player-text-soft, rgba(255, 255, 255, 0.7));
  font-size: 0.8125rem;
}

/* High contrast mode */
@media (prefers-contrast: high) {
  .ffmpeg-streaming-player {
    border: 2px solid currentColor;
  }
}
