/**
 * LaShh YouTube Cover Block - Frontend Styles
 *
 * Styles for YouTube video backgrounds in Cover blocks.
 * JavaScript handles the exact sizing for object-fit: cover behavior.
 *
 * @package LaShh
 */

/* ==========================================================================
   YouTube Cover Wrapper
   ========================================================================== */

.wp-block-cover.has-youtube-background {
    position: relative;
    overflow: hidden;
}

.lashh-youtube-cover-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

/* ==========================================================================
   YouTube Container
   ========================================================================== */

.lashh-youtube-cover-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
}

/**
 * Iframe positioning - JavaScript calculates exact width/height
 * CSS handles centering via transform
 */
.lashh-youtube-iframe {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    border: none;
    /* Minimum size as fallback before JS runs */
    min-width: 100%;
    min-height: 100%;
}

/* ==========================================================================
   Cover Block Content - Ensure content is above video
   ========================================================================== */

.wp-block-cover.has-youtube-background > .wp-block-cover__inner-container {
    position: relative;
    z-index: 2;
}

/* Ensure any overlay stays above video but below content */
.wp-block-cover.has-youtube-background > .wp-block-cover__background,
.wp-block-cover.has-youtube-background > span[aria-hidden="true"] {
    z-index: 1;
}

/* Hide default video when YouTube is active */
.wp-block-cover.has-youtube-background > video {
    opacity: 0 !important;
    visibility: hidden;
}

/* Keep the background image as fallback until YouTube loads */
.wp-block-cover.has-youtube-background:not(.youtube-loaded) > img.wp-block-cover__image-background {
    opacity: 1;
    z-index: 0;
}

.wp-block-cover.has-youtube-background.youtube-loaded > img.wp-block-cover__image-background {
    opacity: 0;
    transition: opacity 0.5s ease;
}

/* ==========================================================================
   Mobile Video Handling
   ========================================================================== */

/* Desktop video - visible on larger screens */
.lashh-youtube-desktop {
    display: block;
}

/* Mobile video - hidden by default, JS handles switching */
.lashh-youtube-mobile {
    display: none;
}

/* CSS fallback for mobile breakpoint */
@media (max-width: 767px) {
    .wp-block-cover.has-youtube-mobile .lashh-youtube-desktop {
        display: none;
    }

    .wp-block-cover.has-youtube-mobile .lashh-youtube-mobile {
        display: block;
    }
}

/* ==========================================================================
   Loading State
   ========================================================================== */

.wp-block-cover.has-youtube-background .lashh-youtube-cover-wrapper {
    background-color: transparent;
}

/* Loading spinner */
.wp-block-cover.has-youtube-background:not(.youtube-loaded) .lashh-youtube-cover-wrapper::after {
    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: lashh-yt-spinner 0.8s linear infinite;
    z-index: 1;
}

@keyframes lashh-yt-spinner {
    to {
        transform: rotate(360deg);
    }
}

/* Remove spinner once loaded */
.wp-block-cover.has-youtube-background.youtube-loaded .lashh-youtube-cover-wrapper::after {
    display: none;
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .wp-block-cover.has-youtube-background .lashh-youtube-cover-wrapper {
        display: none;
    }

    .wp-block-cover.has-youtube-background > img.wp-block-cover__image-background {
        opacity: 1 !important;
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .lashh-youtube-cover-wrapper {
        display: none;
    }

    .wp-block-cover.has-youtube-background > img.wp-block-cover__image-background {
        opacity: 1 !important;
    }
}
