/**
 * Gallery Page 2026-2027 UX/UI Enhancements
 * Adds modern features like cursor-following shine, tap ripples,
 * filmstrip navigation, auto-hide UI, ambient lighting,
 * and @starting-style animations.
 */

/* ============================================================
   1. Gallery Cards
   ============================================================ */

/* Cursor-following shine effect */
.gallery-card {
    position: relative;
    /* Use starting-style for smooth entrance on load */
    transition: box-shadow 0.5s cubic-bezier(0.22, 1, 0.36, 1),
                border-color 0.4s ease,
                opacity 0.6s ease;
    
    /* Optimize paint performance */
    contain: layout style;
}

@supports (color: oklch(0 0 0)) {
    .gallery-card {
        border: 1px solid oklch(100% 0 0 / 0.08);
    }
}

/* Base shine layer */
.gallery-card::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(
        800px circle at var(--mouse-x, 50%) var(--mouse-y, 50%),
        rgba(255, 255, 255, 0.06),
        transparent 40%
    );
    z-index: 3;
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
    mix-blend-mode: overlay;
}

.gallery-card:hover::after {
    opacity: 1;
}

/* Mobile tap ripple */
.gallery-card-ripple {
    position: absolute;
    border-radius: 50%;
    transform: scale(0);
    animation: ripplePulse 0.6s linear;
    background-color: rgba(255, 255, 255, 0.3);
    z-index: 4;
    pointer-events: none;
    width: 100px;
    height: 100px;
    margin-top: -50px;
    margin-left: -50px;
}

@keyframes ripplePulse {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* Modern text balancing */
.gallery-card-title {
    text-wrap: balance;
}

/* ============================================================
   2. Masonry Photo Items
   ============================================================ */

.photo-masonry-item {
    /* Virtualize off-screen items for performance */
    content-visibility: auto;
    contain-intrinsic-size: auto 300px;
    will-change: transform;
    transition: box-shadow 0.4s ease;
}

.photo-masonry-item:hover {
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6), 0 0 15px rgba(220, 38, 38, 0.3);
    z-index: 2;
}

@supports selector(@starting-style) {
    .photo-masonry-item {
        transition: opacity 0.6s ease,
                    filter 0.6s ease,
                    box-shadow 0.4s ease;
        will-change: transform;
    }

    /* Starting style for smooth reveal as user scrolls */
    @starting-style {
        .photo-masonry-item {
            opacity: 0;
            transform: translateY(20px) scale(0.95);
            filter: blur(4px);
        }
    }
}

/* ============================================================
   3. Lightbox Filmstrip Navigation
   ============================================================ */

.gallery-lightbox__filmstrip {
    position: absolute;
    bottom: 80px; /* Above the bottom bar */
    left: 0;
    width: 100%;
    z-index: 9;
    padding: 10px 0;
    transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1),
                opacity 0.4s ease;
    /* Fade edges */
    -webkit-mask-image: linear-gradient(to right, transparent, black 10%, black 90%, transparent);
    mask-image: linear-gradient(to right, transparent, black 10%, black 90%, transparent);
}

.gallery-lightbox__filmstrip-track {
    display: flex;
    gap: 8px;
    padding: 0 50vw; /* Allow scrolling past edges */
    overflow-x: auto;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
    scroll-behavior: smooth;
    scroll-snap-type: x mandatory;
    overscroll-behavior-x: contain;
}

.gallery-lightbox__filmstrip-track::-webkit-scrollbar {
    display: none;
}

.gallery-lightbox__filmstrip-thumb {
    flex: 0 0 auto;
    width: 56px;
    height: 56px;
    border-radius: 8px;
    border: 2px solid transparent;
    padding: 0;
    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
    overflow: hidden;
    transition: all 0.2s ease;
    scroll-snap-align: center;
    opacity: 0.6;
}

.gallery-lightbox__filmstrip-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
}

.gallery-lightbox__filmstrip-thumb:hover {
    opacity: 0.9;
    transform: translateY(-2px);
}

.gallery-lightbox__filmstrip-thumb.is-active {
    opacity: 1;
    border-color: var(--accent-red, #dc2626);
    box-shadow: 0 0 12px rgba(220, 38, 38, 0.5);
    transform: scale(1.1);
}

@media (max-width: 768px) {
    .gallery-lightbox__filmstrip {
        bottom: 70px;
    }
    .gallery-lightbox__filmstrip-thumb {
        width: 44px;
        height: 44px;
    }
}

/* ============================================================
   4. Auto-Hide UI
   ============================================================ */

.gallery-lightbox--ui-hidden {
    cursor: none;
}

.gallery-lightbox--ui-hidden .gallery-lightbox__bar {
    transform: translateY(100%);
    opacity: 0;
}

.gallery-lightbox--ui-hidden .gallery-lightbox__filmstrip {
    transform: translateY(40px);
    opacity: 0;
}

.gallery-lightbox--ui-hidden .gallery-lightbox__close,
.gallery-lightbox--ui-hidden .gallery-lightbox__nav,
.gallery-lightbox--ui-hidden .gallery-lightbox__counter {
    opacity: 0;
    pointer-events: none;
}

/* Ensure transitions are smooth */
.gallery-lightbox__bar,
.gallery-lightbox__close,
.gallery-lightbox__nav,
.gallery-lightbox__counter {
    transition: all 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ============================================================
   5. Ambient Background Color
   ============================================================ */

.gallery-lightbox__ambient {
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    transition: background 0.8s ease;
    /* Soft blur on top of the backdrop blur */
    filter: blur(60px);
    opacity: 0.8;
}

/* ============================================================
   6. Image Loading Shimmer
   ============================================================ */

.gallery-lightbox__shimmer {
    position: absolute;
    inset: 0;
    z-index: 1;
    background: linear-gradient(90deg, 
        transparent 0%, 
        rgba(255, 255, 255, 0.05) 50%, 
        transparent 100%
    );
    background-size: 200% 100%;
    animation: shimmerSlide 1.5s infinite linear;
    border-radius: 6px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.gallery-lightbox__shimmer.is-active {
    opacity: 1;
}

@keyframes shimmerSlide {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ============================================================
   7. Pull-To-Dismiss (Mobile)
   ============================================================ */

.gallery-lightbox--pulling {
    transition: none !important;
}

.gallery-lightbox--pulling .gallery-lightbox__image {
    transform: translateY(var(--pull-translate, 0)) scale(var(--pull-scale, 1)) !important;
    transition: none !important;
}

.gallery-lightbox--pulling::backdrop {
    background: rgba(0, 0, 0, calc(0.96 * var(--pull-opacity, 1))) !important;
    backdrop-filter: blur(calc(24px * var(--pull-opacity, 1))) !important;
    -webkit-backdrop-filter: blur(calc(24px * var(--pull-opacity, 1))) !important;
}

.gallery-lightbox--pulling .gallery-lightbox__ambient {
    opacity: var(--pull-opacity, 1) !important;
}

.gallery-lightbox--dismissing .gallery-lightbox__image {
    transform: translateY(100vh) scale(0.8) !important;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.5, 0, 0, 1) !important;
}

/* ============================================================
   8. Search/Filter Bar
   ============================================================ */

.gallery-search-bar {
    max-width: 600px;
    margin: 0 auto 3rem;
}

.gallery-search-bar__inner {
    position: relative;
    display: flex;
    align-items: center;
}

.gallery-search-bar__icon {
    position: absolute;
    left: 1.25rem;
    color: rgba(255, 255, 255, 0.5);
    pointer-events: none;
}

.gallery-search-bar__input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 100px;
    padding: 0.85rem 3rem;
    color: #fff;
    font-size: 1rem;
    font-family: inherit;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: all 0.3s ease;
}

.gallery-search-bar__input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.gallery-search-bar__input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(220, 38, 38, 0.5);
    box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.15);
}

.gallery-search-bar__clear {
    position: absolute;
    right: 0.75rem;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    cursor: pointer;
    transition: background 0.2s ease;
}

.gallery-search-bar__clear:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ============================================================
   9. Floating Action Button (Mobile)
   ============================================================ */

.gallery-fab {
    position: fixed;
    bottom: max(2rem, env(safe-area-inset-bottom, 2rem));
    right: max(1.5rem, env(safe-area-inset-right, 1.5rem));
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent-red, #dc2626);
    color: #fff;
    border: none;
    box-shadow: 0 4px 20px rgba(220, 38, 38, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 90;
    opacity: 0;
    transform: translateY(20px) scale(0.9);
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.gallery-fab--visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.gallery-fab:hover,
.gallery-fab:focus-visible {
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 8px 24px rgba(220, 38, 38, 0.5);
    background: #ef4444; /* Lighter red */
}

/* Hide FAB on desktop */
@media (min-width: 1024px) {
    .gallery-fab {
        display: none !important;
    }
}

/* ============================================================
   10. Animated Stats
   ============================================================ */

.stat-value--animated {
    animation: statValuePulse 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes statValuePulse {
    0% { transform: scale(1); color: var(--accent-red, #dc2626); }
    50% { transform: scale(1.1); color: #fff; text-shadow: 0 0 10px rgba(220,38,38,0.8); }
    100% { transform: scale(1); color: var(--accent-red, #dc2626); }
}

/* ============================================================
   11. Accessibility & Reduced Motion
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
    .gallery-card,
    .gallery-card::after,
    .gallery-lightbox__filmstrip,
    .gallery-lightbox__filmstrip-thumb,
    .gallery-lightbox__bar,
    .gallery-lightbox__close,
    .gallery-lightbox__nav,
    .gallery-lightbox__counter,
    .gallery-search-bar__input,
    .gallery-fab,
    .stat-value--animated {
        transition: none !important;
        animation: none !important;
        transform: none !important;
    }
    
    .gallery-lightbox__shimmer {
        display: none !important;
    }
}

/* ============================================================
   12. View Transitions API
   ============================================================ */

/* Enable cross-document view transitions */
@view-transition {
    navigation: auto;
}

/* Custom morphing transition for gallery cards */
::view-transition-group(*) {
    animation-duration: 0.6s;
    animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}

::view-transition-old(root) {
    animation: 90ms cubic-bezier(0.4, 0, 1, 1) both fade-out;
}

::view-transition-new(root) {
    animation: 210ms cubic-bezier(0, 0, 0.2, 1) 90ms both fade-in;
}

/* ============================================================
   13. Scroll-Driven Parallax
   ============================================================ */

@supports (animation-timeline: view()) {
    .gallery-card-bg {
        /* Scale up slightly to prevent edges showing during parallax */
        transform: scale(1.15);
        animation: cardParallax linear;
        animation-timeline: view();
        animation-range: cover 0% cover 100%;
        transform-origin: center;
    }

    @keyframes cardParallax {
        0% { transform: scale(1.15) translateY(-10%); }
        100% { transform: scale(1.15) translateY(10%); }
    }
}


/* ============================================================
   15. Magnetic Buttons
   ============================================================ */

#back-btn, 
.gallery-slideshow-btn,
.gallery-filter-btn {
    transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1), background-color 0.2s ease;
}
