/**
 * V2 Video Block Styles
 * Optimized and responsive video player
 */

:root {
  --v2-video-transition: all 0.3s ease;
}

/* Container */
.v2-video {
  --v2-video-max-width: 100%;
  width: 100%;
  max-width: var(--v2-video-max-width);
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 2rem;
}

/* Alignment */
.v2-video--align-left {
  margin-left: 0;
  margin-right: auto;
}

.v2-video--align-right {
  margin-left: auto;
  margin-right: 0;
}

.v2-video--align-center {
  margin-left: auto;
  margin-right: auto;
}

/* Full and wide alignment overrides */
.v2-video.alignwide,
.v2-video.alignfull {
  max-width: 100%;
}

/* Video wrapper - maintains aspect ratio */
.v2-video__wrapper {
  position: relative;
  width: 100%;
  background-color: #000;
  overflow: hidden;}

/* Aspect ratios using modern approach */
.v2-video--ratio-16-9 .v2-video__wrapper {
  aspect-ratio: 16 / 9;
}

.v2-video--ratio-4-3 .v2-video__wrapper {
  aspect-ratio: 4 / 3;
}

.v2-video--ratio-1-1 .v2-video__wrapper {
  aspect-ratio: 1 / 1;
}

.v2-video--ratio-21-9 .v2-video__wrapper {
  aspect-ratio: 21 / 9;
}

.v2-video--ratio-9-16 .v2-video__wrapper {
  aspect-ratio: 9 / 16;
}

/* Fallback for browsers without aspect-ratio support */
@supports not (aspect-ratio: 16 / 9) {
  .v2-video--ratio-16-9 .v2-video__wrapper {
    padding-bottom: 56.25%; /* 9/16 = 0.5625 */
  }

  .v2-video--ratio-4-3 .v2-video__wrapper {
    padding-bottom: 75%; /* 3/4 = 0.75 */
  }

  .v2-video--ratio-1-1 .v2-video__wrapper {
    padding-bottom: 100%;
  }

  .v2-video--ratio-21-9 .v2-video__wrapper {
    padding-bottom: 42.857%; /* 9/21 */
  }

  .v2-video--ratio-9-16 .v2-video__wrapper {
    padding-bottom: 177.778%; /* 16/9 */
  }

  .v2-video__wrapper {
    position: relative;
    height: 0;
  }

  .v2-video__player,
  .v2-video__embed,
  .v2-video__embed iframe {
    position: absolute;
    top: 0;
    left: 0;
  }
}

/* Video player */
.v2-video__player {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background-color: #000;
}

/* Embed container for iframe videos */
.v2-video__embed {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* Modern browsers with aspect-ratio support */
@supports (aspect-ratio: 16 / 9) {
  .v2-video__embed {
    position: relative;
    height: 100%;
  }
}

.v2-video__embed iframe,
.v2-video__embed video,
.v2-video__embed object,
.v2-video__embed embed {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

/* Loading state */
.v2-video__wrapper::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  animation: v2-video-spin 0.8s linear infinite;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.v2-video__wrapper.is-loading::before {
  opacity: 1;
}

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

/* Focus states for accessibility */
.v2-video__player:focus {
  outline: 2px solid #4a90e2;
  outline-offset: 2px;
}

.v2-video__player:focus:not(:focus-visible) {
  outline: none;
}

/* Responsive adjustments */
@media (max-width: 1024px) {
  .v2-video {
    margin-bottom: 1.5rem;
  }

  .v2-video__wrapper {
    border-radius: 6px;
  }
}

@media (max-width: 768px) {
  .v2-video {
    margin-bottom: 1rem;
  }

  .v2-video__wrapper {
    border-radius: 4px;
  }

  /* Reset alignment on mobile for better UX */
  .v2-video--align-left,
  .v2-video--align-right {
    margin-left: auto;
    margin-right: auto;
  }
}

/* Print styles */
@media print {
  .v2-video__player,
  .v2-video__embed {
    display: none;
  }

  .v2-video::after {
    content: 'Video content available in digital version';
    display: block;
    padding: 2rem;
    text-align: center;
    background-color: #f0f0f0;
    border: 1px solid #ddd;
  }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  .v2-video__wrapper::before {
    animation: none;
  }

  .v2-video,
  .v2-video__player {
    transition: none;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .v2-video__wrapper {
    border: 2px solid currentColor;
  }
}

/* Dark mode optimization (if theme supports it) */
@media (prefers-color-scheme: dark) {
  .v2-video__wrapper {
    background-color: #1a1a1a;
  }
}

/* Performance optimizations */
.v2-video__player,
.v2-video__embed iframe {
  will-change: transform;
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* Editor styles */
.block-editor-block-list__block .v2-video {
  margin-bottom: 1rem;
}
