/* Gallery Modal Enhancements */

/* Smooth modal transitions */
#imageModal {
    transition: opacity 300ms ease-in-out;
}

#imageModal.opacity-0 {
    pointer-events: none;
}

#imageModal.opacity-100 {
    pointer-events: auto;
}

/* Media loading state */
#modalImage,
#modalVideo,
#modalAudioContainer {
    transition: opacity 300ms ease-in-out;
}

/* Button hover effects - enhanced for touch devices */
#imageModal button {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Prevent text selection on buttons */
#imageModal button * {
    user-select: none;
    -webkit-user-select: none;
}

/* Disabled button state */
#imageModal button:disabled {
    pointer-events: none;
    transition: opacity 200ms ease-in-out;
}

/* Focus visible for accessibility */
#imageModal button:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
}

/* Image container optimization */
#modalImage {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* Smooth backdrop */
#imageModal::before {
    content: '';
    position: absolute;
    inset: 0;
    background: inherit;
    z-index: -1;
}

/* Mobile-specific optimizations */
@media (max-width: 640px) {
    /* Ensure buttons are easily tappable on mobile */
    #imageModal button {
        min-width: 44px;
        min-height: 44px;
    }
    /* Adjust image size for mobile */
    #modalImage {
        max-height: calc(100vh - 180px) !important;
        max-height: calc(100dvh - 180px) !important;
    }
    /* Optimize touch targets */
    #prevImage,
    #nextImage {
        opacity: 0.8;
    }
    #prevImage:active,
    #nextImage:active {
        opacity: 1;
    }
}

/* Tablet optimizations */
@media (min-width: 641px) and (max-width: 1024px) {
    #modalImage {
        max-height: calc(100vh - 200px) !important;
    }
}

/* Desktop optimizations */
@media (min-width: 1025px) {
    #modalImage {
        max-height: calc(100vh - 220px) !important;
    }
    /* Show navigation buttons on hover for desktop */
    #prevImage,
    #nextImage {
        transition: all 300ms ease-in-out;
    }
}

/* Landscape mobile optimization */
@media (max-width: 896px) and (orientation: landscape) {
    #modalImage {
        max-height: calc(100vh - 140px) !important;
        max-height: calc(100dvh - 140px) !important;
    }
    /* Reduce padding in landscape */
    #imageModal>div>div:first-child {
        padding: 0.5rem !important;
    }
    #imageModal>div>div:last-child {
        padding: 0.75rem !important;
    }
}

/* High DPI screens */
@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
    #modalImage {
        image-rendering: auto;
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    #imageModal,
    #imageModal *,
    #modalImage {
        transition: none !important;
        animation: none !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    #imageModal {
        background-color: rgba(0, 0, 0, 0.95);
    }
}

/* Loading state for images */
#modalImage[src=""],
#modalImage:not([src]) {
    opacity: 0;
}

/* Notification styles for share functionality */
.gallery-notification {
    animation: slideInUp 300ms ease-out, slideOutDown 300ms ease-in 2700ms;
}

@keyframes slideInUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideOutDown {
    from {
        transform: translateY(0);
        opacity: 1;
    }
    to {
        transform: translateY(100%);
        opacity: 0;
    }
}

/* Prevent body scroll when modal is open */
body[data-modal-open="true"] {
    overflow: hidden !important;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
    #modalImage,
    #modalVideo {
        max-height: calc(100vh - 200px) !important;
    }
    @media (max-width: 640px) {
        #modalImage,
        #modalVideo {
            max-height: calc(100vh - 180px) !important;
        }
    }
}

/* Video Player Styles */
#modalVideo {
    background-color: #000;
}

#modalVideo::-webkit-media-controls-panel {
    background-color: rgba(0, 0, 0, 0.8);
}

/* Custom Audio Player Styles */
#modalAudio {
    display: none;
}

#audioProgressContainer {
    cursor: pointer;
}

#audioProgress {
    will-change: width;
}

#audioProgressHandle {
    will-change: left;
    cursor: grab;
}

#audioProgressHandle:active {
    cursor: grabbing;
}

#audioPlayBtn {
    position: relative;
    overflow: hidden;
}

#audioPlayBtn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(30, 42, 74, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.3s, height 0.3s;
}

#audioPlayBtn:active::before {
    width: 100%;
    height: 100%;
}

#audioVolumeSlider {
    appearance: none;
    -webkit-appearance: none;
}

#audioVolumeSlider::-webkit-slider-thumb {
    appearance: none;
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #F4E4A6;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    transition: all 0.2s;
}

#audioVolumeSlider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 10px rgba(244, 228, 166, 0.3);
}

#audioVolumeSlider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #F4E4A6;
    border: none;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    transition: all 0.2s;
}

#audioVolumeSlider::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 10px rgba(244, 228, 166, 0.3);
}

#audioRepeatBtn.active {
    background: rgba(244, 228, 166, 0.3);
    box-shadow: inset 0 0 8px rgba(244, 228, 166, 0.4);
}

#audioRepeatBtn.active i {
    color: #F4E4A6;
}

/* Audio Container Animation */
#modalAudioContainer {
    animation: fadeInScale 400ms ease-out;
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Video and Audio responsive sizing */
@media (max-width: 640px) {
    #modalVideo,
    #modalImage {
        max-height: calc(100vh - 180px) !important;
        max-height: calc(100dvh - 180px) !important;
    }
    #modalAudioContainer {
        padding: 0 1rem;
    }
    #modalAudio {
        height: 48px;
    }
}

@media (min-width: 641px) and (max-width: 1024px) {
    #modalVideo,
    #modalImage {
        max-height: calc(100vh - 200px) !important;
    }
}

@media (min-width: 1025px) {
    #modalVideo,
    #modalImage {
        max-height: calc(100vh - 220px) !important;
    }
}

/* Landscape mobile optimization for video */
@media (max-width: 896px) and (orientation: landscape) {
    #modalVideo,
    #modalImage {
        max-height: calc(100vh - 140px) !important;
        max-height: calc(100dvh - 140px) !important;
    }
}

/* Audio Player Responsive Sizing */
@media (max-width: 480px) {
    #modalAudioContainer {
        max-width: 100%;
    }
    
    #audioPlayBtn {
        width: 56px;
        height: 56px;
    }
    
    #audioPlayIcon {
        font-size: 18px;
    }
}

@media (max-width: 640px) {
    #audioProgressContainer {
        height: 8px !important;
    }
    
    #audioProgressHandle {
        width: 16px !important;
        height: 16px !important;
    }
}

@media (min-width: 641px) and (max-width: 1024px) {
    #audioProgressContainer {
        height: 10px !important;
    }
    
    #audioProgressHandle {
        width: 20px !important;
        height: 20px !important;
    }
}

@media (min-width: 1025px) {
    #audioProgressContainer {
        height: 12px !important;
    }
    
    #audioProgressHandle {
        width: 24px !important;
        height: 24px !important;
    }
}
