/* YouTube Video Background Block Styles */
.youtube-video-background {
    position: relative;
    overflow: hidden;
    width: 100%;
    height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Simplified iOS performance optimizations */
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    will-change: transform;
}

/* Embedded Video Styles */
.youtube-video-embed {
    position: relative;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    /* Simplified iOS performance optimizations */
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    will-change: transform;
}

.youtube-embed-container {
    position: relative;
    width: 100%;
    height: 0;
    overflow: hidden;
}

.youtube-embed-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
    /* Simplified iOS performance optimizations */
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    will-change: transform;
}

.youtube-video-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    /* Simplified iOS performance optimizations */
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    will-change: transform;
}

/* Thumbnail placeholder styles - Enhanced for mobile background */
.youtube-thumbnail-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease;
    /* Ensure thumbnail covers full background */
    z-index: 1;
}

.youtube-thumbnail-placeholder.loading {
    opacity: 0.7;
}

.youtube-thumbnail-placeholder.loaded {
    opacity: 0;
    pointer-events: none;
    z-index: 0;
}

/* YouTube play button styles */
.youtube-play-button {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    cursor: pointer;
    transition: transform 0.2s ease;
    z-index: 2;
}

.youtube-play-button:hover {
    transform: translate(-50%, -50%) scale(1.1);
}

.youtube-play-button-bg {
    fill: rgba(0, 0, 0, 0.8);
    transition: fill 0.2s ease;
}

.youtube-play-button:hover .youtube-play-button-bg {
    fill: rgba(255, 0, 0, 0.8);
}

.youtube-play-button-icon {
    fill: white;
}

/* Mobile play overlay styles - Enhanced for better UX */
.mobile-play-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    cursor: pointer;
    transition: background-color 0.2s ease;
    /* Ensure overlay is always on top */
    pointer-events: auto;
}

.mobile-play-overlay:hover {
    background: rgba(0, 0, 0, 0.4);
}

.mobile-play-overlay:active {
    background: rgba(0, 0, 0, 0.5);
}

.mobile-play-button {
    text-align: center;
    color: white;
    transition: transform 0.2s ease;
    /* Enhanced styling for better visibility */
    padding: 20px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.mobile-play-overlay:hover .mobile-play-button {
    transform: scale(1.05);
    background: rgba(0, 0, 0, 0.7);
}

.mobile-play-overlay:active .mobile-play-button {
    transform: scale(0.95);
    background: rgba(0, 0, 0, 0.8);
}

.mobile-play-text {
    margin-top: 10px;
    font-size: 14px;
    font-weight: bold;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
    color: white;
    /* Enhanced text styling */
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* Iframe container styles - OPTION 1: Smart Aspect Ratio */
.youtube-iframe-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.youtube-iframe-container iframe {
    position: absolute;
    top: 50%;
    left: 50%;
    /* Smart sizing that maintains aspect ratio while covering full background */
    width: 100%;
    height: 100%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    /* Use object-fit-like behavior with CSS */
    object-fit: cover;
    /* Simplified iOS performance optimizations */
    -webkit-transform: translate(-50%, -50%) translate3d(0, 0, 0);
    transform: translate(-50%, -50%) translate3d(0, 0, 0);
    will-change: transform;
    /* Prevent iOS Safari from refreshing on video loop */
    -webkit-overflow-scrolling: touch;
}

/* OPTION 2: CSS-only aspect ratio with better coverage */
.youtube-iframe-container.enhanced-coverage iframe {
    /* Calculate size to ensure full coverage */
    width: calc(100% + 20%);
    height: calc(100% + 20%);
    min-width: 120%;
    min-height: 120%;
}

/* OPTION 3: Responsive aspect ratio based on container */
.youtube-iframe-container.responsive iframe {
    width: 100vw;
    height: 56.25vw; /* 16:9 aspect ratio */
    min-height: 100%;
    min-width: 177.77vh; /* 16:9 aspect ratio */
}

.youtube-video-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1;
}

.youtube-video-content {
    position: relative;
    z-index: 2;
    color: white;
    padding: 2rem;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Apply container alignment */
.youtube-content-align-center .youtube-video-content {
    text-align: center;
}

.youtube-content-align-left .youtube-video-content {
    text-align: left;
}

.youtube-content-align-right .youtube-video-content {
    text-align: right;
}

/* Override alignment for specific blocks that should stay left-aligned */
.youtube-video-content .wp-block-list {
    text-align: left !important;
}

.youtube-video-content .wp-block-list li {
    text-align: left !important;
}

.youtube-video-content .wp-block-table {
    text-align: left !important;
}

.youtube-video-content .wp-block-code {
    text-align: left !important;
}

/* Allow WordPress alignment classes to override */
.youtube-video-content .has-text-align-left {
    text-align: left !important;
}

.youtube-video-content .has-text-align-center {
    text-align: center !important;
}

.youtube-video-content .has-text-align-right {
    text-align: right !important;
}

/* Ensure all text is white */
.youtube-video-content * {
    color: white !important;
}

.youtube-video-content h1,
.youtube-video-content h2,
.youtube-video-content h3,
.youtube-video-content h4,
.youtube-video-content h5,
.youtube-video-content h6 {
    color: white !important;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7);
    margin-bottom: 1rem;
}

.youtube-video-content p {
    color: white !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
    margin-bottom: 1rem;
}

.youtube-video-content .wp-block-button .wp-block-button__link {
    text-shadow: none;
}

/* Handle buttons alignment */
.youtube-content-align-center .youtube-video-content .wp-block-buttons {
    justify-content: center;
}

.youtube-content-align-right .youtube-video-content .wp-block-buttons {
    justify-content: flex-end;
}

.youtube-content-align-left .youtube-video-content .wp-block-buttons {
    justify-content: flex-start;
}

/* Error and placeholder styles */
.youtube-bg-placeholder,
.youtube-bg-error {
    padding: 2rem;
    text-align: center;
    background-color: #f8f9fa;
    border: 2px dashed #dee2e6;
    color: #6c757d;
    font-style: italic;
}

.youtube-bg-error {
    background-color: #f8d7da;
    border-color: #f5c6cb;
    color: #721c24;
}

.youtube-bg-iframe {
    clip-path: inset(0px 0px 0px 0px);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .youtube-video-content {
        padding: 1rem;
    }
    
    /* Simplified mobile sizing */
    .youtube-iframe-container iframe {
        width: 100%;
        height: 100%;
    }
    
    /* Enhanced coverage on mobile */
    .youtube-iframe-container.enhanced-coverage iframe {
        width: calc(100% + 10%);
        height: calc(100% + 10%);
        min-width: 110%;
        min-height: 110%;
    }
    
    /* Enhanced mobile play button */
    .mobile-play-button {
        padding: 15px;
        border-radius: 6px;
    }
    
    .mobile-play-text {
        font-size: 12px;
        margin-top: 8px;
    }
    
    /* Ensure thumbnail is always visible on mobile */
    .youtube-thumbnail-placeholder {
        opacity: 1 !important;
        z-index: 1;
    }
    
    /* Hide iframe on mobile until user chooses to play */
    .youtube-iframe-container {
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    
    .youtube-iframe-container.video-active {
        opacity: 1;
    }
}

/* iOS-specific optimizations */
@supports (-webkit-touch-callout: none) {
    .youtube-video-background,
    .youtube-video-embed,
    .youtube-video-container,
    .youtube-embed-container,
    .youtube-iframe-container {
        /* Reduce transform complexity for iOS */
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
    
    .youtube-iframe-container iframe {
        /* Simplified transform for iOS */
        -webkit-transform: translate(-50%, -50%) translateZ(0);
        transform: translate(-50%, -50%) translateZ(0);
        /* Reduce memory usage */
        -webkit-filter: none;
        filter: none;
    }
    
    /* Use enhanced coverage on iOS for better visual effect */
    .youtube-iframe-container iframe {
        width: calc(100% + 15%);
        height: calc(100% + 15%);
        min-width: 115%;
        min-height: 115%;
    }
    
    /* Enhanced mobile play button for iOS */
    .mobile-play-button {
        background: rgba(0, 0, 0, 0.7);
        border: 2px solid rgba(255, 255, 255, 0.3);
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    .youtube-video-container iframe {
        background: linear-gradient(45deg, #667eea 0%, #764ba2 100%);
    }
    
    .youtube-play-button,
    .mobile-play-button {
        transition: none;
    }
}