/**
 * YouTube Embed Styles
 * 
 * Responsive styling for YouTube embedded videos with proper aspect ratios
 * and integration with existing prose styling.
 */

/* YouTube Embed Container */
.youtube-embed-container {
    margin: 1.5rem 0;
    width: 100%;
    max-width: 100%;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    background: #f8fafc;
    position: relative;
}

/* Responsive 16:9 Aspect Ratio Wrapper */
.youtube-embed-wrapper {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 56.25%; /* 16:9 aspect ratio (9/16 = 0.5625) */
    background: #000;
    border-radius: 8px;
    overflow: hidden;
}

/* YouTube Embed Iframe */
.youtube-embed-iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 8px;
    background: #000;
}

/* Loading State */
.youtube-embed-container::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 48px;
    height: 48px;
    border: 3px solid #e5e7eb;
    border-top: 3px solid #3b82f6;
    border-radius: 50%;
    animation: youtube-embed-spin 1s linear infinite;
    z-index: 1;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.youtube-embed-container.loading::before {
    opacity: 1;
}

@keyframes youtube-embed-spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Error State */
.youtube-embed-container.error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    padding: 1rem;
    text-align: center;
    color: #991b1b;
    font-size: 14px;
}

.youtube-embed-container.error::before {
    content: '⚠️ Video unavailable';
    font-size: 16px;
}

/* Integration with Prose Styling */
.prose .youtube-embed-container {
    margin: 1.75rem 0;
}

.prose-lg .youtube-embed-container {
    margin: 2rem 0;
}

/* Hover Effects */
.youtube-embed-container:hover {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    transform: translateY(-1px);
    transition: all 0.3s ease;
}

/* Focus Styles for Accessibility */
.youtube-embed-iframe:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* Play Button Overlay (Optional Enhancement) */
.youtube-embed-wrapper::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 68px;
    height: 48px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 2;
}

.youtube-embed-wrapper:hover::after {
    opacity: 0.8;
}

/* Mobile Responsiveness */
@media (max-width: 640px) {
    .youtube-embed-container {
        margin: 1rem 0;
        border-radius: 6px;
    }
    
    .youtube-embed-wrapper {
        border-radius: 6px;
    }
    
    .youtube-embed-iframe {
        border-radius: 6px;
    }
    
    /* Slightly taller on mobile for better viewing */
    .youtube-embed-wrapper {
        padding-bottom: 58%; /* Slightly taller aspect ratio on mobile */
    }
}

@media (max-width: 480px) {
    .youtube-embed-container {
        margin: 0.75rem 0;
        border-radius: 4px;
    }
    
    .youtube-embed-wrapper,
    .youtube-embed-iframe {
        border-radius: 4px;
    }
}

/* Tablet Responsiveness */
@media (min-width: 641px) and (max-width: 1024px) {
    .youtube-embed-container {
        margin: 1.25rem 0;
    }
}

/* Large Screen Enhancements */
@media (min-width: 1024px) {
    .youtube-embed-container {
        margin: 2rem 0;
        border-radius: 10px;
    }
    
    .youtube-embed-wrapper,
    .youtube-embed-iframe {
        border-radius: 10px;
    }
    
    .youtube-embed-container:hover {
        transform: translateY(-2px);
        box-shadow: 0 12px 35px rgba(0, 0, 0, 0.2);
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .youtube-embed-container {
        background: #1f2937;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }
    
    .youtube-embed-container.error {
        background: #7f1d1d;
        border-color: #dc2626;
        color: #fecaca;
    }
    
    .youtube-embed-container::before {
        border-color: #4b5563;
        border-top-color: #60a5fa;
    }
}

/* Print Styles */
@media print {
    .youtube-embed-container {
        border: 1px solid #ccc;
        background: #f9f9f9;
        box-shadow: none;
        page-break-inside: avoid;
    }
    
    .youtube-embed-wrapper {
        padding-bottom: 40%;
        background: #f0f0f0;
    }
    
    .youtube-embed-iframe {
        display: none;
    }
    
    /* Show original URL in print */
    .youtube-embed-container::after {
        content: "Video: " attr(data-original-url);
        display: block;
        padding: 1rem;
        font-size: 12px;
        color: #666;
        text-align: center;
        background: #fff;
        border-top: 1px solid #ddd;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    .youtube-embed-container {
        transition: none;
        transform: none;
    }
    
    .youtube-embed-container:hover {
        transform: none;
    }
    
    .youtube-embed-container::before {
        animation: none;
    }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .youtube-embed-container {
        border: 2px solid currentColor;
        box-shadow: none;
    }
    
    .youtube-embed-iframe:focus {
        outline: 3px solid currentColor;
        outline-offset: 3px;
    }
}