/**
 * Hover Video Preview Styles
 * YouTube-like video preview styling
 * 
 * @version 1.0.0
 * @author MioHentai Theme
 */

/* Main hover video container - Fill thumbnail container */
.hover-video-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3;
    border-radius: 8px;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    background: #000;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    /* Remove aspect-ratio constraint to respect existing container */
}

.hover-video-container.visible {
    opacity: 1 !important;
    visibility: visible !important;
}

/* Video player element - Smart aspect ratio handling */
.hover-video-player {
    width: 100%;
    height: 100%;
    border-radius: 8px;
    background: #000;
    position: absolute;
    top: 0;
    left: 0;
    transition: all 0.3s ease;
}

/* Smart video fitting for tall thumbnail containers */
.hover-video-player.fit-cover {
    object-fit: cover;
    width: 100%;
    height: 100%;
    /* Will crop video to fill the tall container, showing center portion */
}

/* For very portrait videos - fit with letterboxing */
.hover-video-player.fit-contain {
    object-fit: contain;
    width: 100%;
    height: 100%;
    background: #000; /* Black letterboxing for unused space */
}

/* For perfect matches - direct fill */
.hover-video-player.fit-perfect {
    object-fit: fill;
    width: 100%;
    height: 100%;
}

/* Loading indicator */
.hover-video-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.hover-video-loader.visible {
    opacity: 1;
    visibility: visible;
}

.hover-video-loader.error {
    color: #ff6b6b;
}

/* Spinner animation */
.loader-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid #ffffff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error message */
.error-message {
    color: #ff6b6b;
    font-size: 12px;
    text-align: center;
    padding: 8px;
    background: rgba(0, 0, 0, 0.8);
    border-radius: 4px;
    white-space: nowrap;
}

/* Video controls overlay */
.hover-video-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    padding: 20px 12px 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 1002;
}

.hover-video-container:hover .hover-video-controls {
    opacity: 1;
    visibility: visible;
}

/* Mute button */
.hover-video-mute {
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
    flex-shrink: 0;
}

.hover-video-mute:hover {
    background: #ffffff;
    transform: scale(1.1);
}

.hover-video-mute svg {
    width: 14px;
    height: 14px;
    color: #333;
    display: block;
}

/* Progress bar container */
.hover-video-progress {
    flex: 1;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.hover-video-progress:hover {
    height: 6px;
    margin: -1px 0;
}

/* Progress bar fill */
.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--hover-video-progress-color, #ff6b6b);
    border-radius: 2px;
    transition: width 0.1s ease;
    position: relative;
}

.progress-bar::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 0;
    width: 12px;
    height: 12px;
    background: var(--hover-video-progress-color, #ff6b6b);
    border-radius: 50%;
    transform: translate(50%, -50%);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.hover-video-progress:hover .progress-bar::after {
    opacity: 1;
}

/* Ensure parent containers have relative positioning */
.entry-thumbnail,
.post-thumbnail {
    position: relative !important;
}

.entry-thumbnail a,
.post-thumbnail a {
    display: block;
    position: relative;
}

.entry-thumbnail img,
.post-thumbnail img {
    transition: none; /* Disabled to prevent thumbnail scaling during video hover */
}

/* Disabled: Thumbnail zoom effect conflicts with video overlay */
.entry-thumbnail:hover img,
.post-thumbnail:hover img {
    transform: none; /* Disabled: video overlay handles hover effects now */
}

/* Prevent hover effects on mobile devices */
@media (hover: none) and (pointer: coarse) {
    .hover-video-container {
        display: none !important;
    }
    
    .entry-thumbnail:hover img,
    .post-thumbnail:hover img {
        transform: none;
    }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .hover-video-controls {
        padding: 15px 8px 6px;
        gap: 6px;
    }
    
    .hover-video-mute {
        width: 28px;
        height: 28px;
    }
    
    .hover-video-mute svg {
        width: 12px;
        height: 12px;
    }
    
    .hover-video-progress {
        height: 3px;
    }
    
    .hover-video-progress:hover {
        height: 4px;
        margin: -0.5px 0;
    }
    
    .progress-bar::after {
        width: 10px;
        height: 10px;
    }
}

@media (max-width: 480px) {
    .hover-video-container {
        border-radius: 4px;
    }
    
    .hover-video-player {
        border-radius: 4px;
    }
    
    .hover-video-controls {
        padding: 10px 6px 4px;
        gap: 4px;
    }
    
    .hover-video-mute {
        width: 24px;
        height: 24px;
    }
    
    .hover-video-mute svg {
        width: 10px;
        height: 10px;
    }
    
    .loader-spinner {
        width: 24px;
        height: 24px;
        border-width: 2px;
    }
    
    .error-message {
        font-size: 11px;
        padding: 6px;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .hover-video-container {
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    }
}

/* Focus states for accessibility */
.hover-video-mute:focus {
    outline: 2px solid #ff6b6b;
    outline-offset: 2px;
}

.hover-video-progress:focus {
    outline: 2px solid #ff6b6b;
    outline-offset: 2px;
}

/* Animation for smooth appearance */
@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.hover-video-container.visible {
    animation: fadeInScale 0.3s ease-out;
}

/* Ensure video doesn't interfere with clicking */
.hover-video-container.visible ~ * {
    pointer-events: none;
}

/* Special handling for carousel items */
.carousel-item .hover-video-container {
    border-radius: 8px;
}

.carousel-item .hover-video-player {
    border-radius: 8px;
}

/* Integration with existing theme styles */
.blog-view .hover-video-container,
.single-view .hover-video-container {
    border-radius: inherit;
}

/* Dark mode support (if theme supports it) */
@media (prefers-color-scheme: dark) {
    .hover-video-loader {
        color: #ffffff;
    }
    
    .error-message {
        background: rgba(0, 0, 0, 0.9);
        color: #ff8a8a;
    }
}

/* Performance optimization: GPU acceleration */
.hover-video-container,
.hover-video-player,
.hover-video-controls {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Ensure proper layering */
.hover-video-container {
    isolation: isolate;
}

/* Loading state improvements */
.hover-video-loader.visible + .hover-video-player {
    opacity: 0.5;
}

.hover-video-loader:not(.visible) + .hover-video-player {
    opacity: 1;
    transition: opacity 0.3s ease;
}