/**
 * Liquid Flow Gallery – Frontend Styles
 *
 * Covers:
 *  - Layout & containment
 *  - CSS-tier wave animations (low-end fallback)
 *  - Reflection gradient (mobile fallback for WebGL reflection)
 *  - Rain-drop particle layer
 *  - Lightbox overlay
 *  - Accessibility (reduced-motion)
 */

/* ── Reset / containment ───────────────────────────────────────────────────── */
.lfg-liquid-scene,
.lfg-liquid-scene * {
    box-sizing: border-box;
}

.lfg-liquid-scene {
    position: relative;
    width: 100%;
    overflow: hidden;
    /* Ensure child canvases are contained */
    isolation: isolate;
}

.lfg-no-images {
    text-align: center;
    padding: 2rem;
    color: #888;
    font-style: italic;
}

/* ── Gallery grid ──────────────────────────────────────────────────────────── */
.lfg-gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    padding: 1rem;
}

@media (max-width: 600px) {
    .lfg-gallery-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
        padding: 0.5rem;
    }
}

/* ── Gallery item ──────────────────────────────────────────────────────────── */
.lfg-item {
    position: relative;
    overflow: visible; /* allow reflection to bleed below */
    border-radius: 6px;
    /* will-change hints help compositor promote layer early */
    will-change: transform;
    cursor: pointer;
    /* subtle box-shadow simulates depth in water */
    box-shadow: 0 4px 24px rgba(0, 60, 120, 0.18);
    transition: box-shadow 0.3s ease;
}

.lfg-item:hover {
    box-shadow: 0 8px 40px rgba(0, 80, 160, 0.30);
}

/* ── Fluid / WebGL canvas ──────────────────────────────────────────────────── */
.lfg-fluid-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: inherit;
    /* Canvas sits on top of the <img>; JS toggles visibility */
    z-index: 2;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s;
}

/* Once WebGL is ready, JS adds .lfg-webgl-ready and reveals canvas */
.lfg-item.lfg-webgl-ready .lfg-fluid-canvas {
    opacity: 1;
}

/* ── Actual image ──────────────────────────────────────────────────────────── */
.lfg-image {
    display: block;
    width: 100%;
    height: auto;
    border-radius: inherit;
    z-index: 1;
    position: relative;
    /* Image is the WebGL texture source; keep it rendered but behind canvas */
    -webkit-user-drag: none;
    user-select: none;
}

/* ── Reflection ────────────────────────────────────────────────────────────── */
.lfg-reflection {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    height: 60px;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
    border-radius: 0 0 6px 6px;
}

/* CSS gradient fallback (mobile / low-end) */
.lfg-reflection-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.lfg-reflection::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        to bottom,
        rgba(180, 210, 240, 0.35) 0%,
        rgba(180, 210, 240, 0.00) 100%
    );
    /* Blur softens the illusion */
    backdrop-filter: blur(2px);
}

/* ── Rain canvas ───────────────────────────────────────────────────────────── */
.lfg-rain-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    /* Rain canvas is transparent; particles are drawn directly */
}

/* ── CSS Wave animation (low-end fallback) ─────────────────────────────────── */
/* Applied by JS when it detects low-end device (lfg-css-waves class) */
.lfg-item.lfg-css-waves .lfg-image {
    animation: lfg-wave-css 3s ease-in-out infinite;
    transform-origin: center bottom;
}

@keyframes lfg-wave-css {
    0%,  100% { transform: scaleY(1.000) skewX(0deg); }
    25%        { transform: scaleY(1.005) skewX(0.3deg); }
    75%        { transform: scaleY(0.997) skewX(-0.3deg); }
}

/* Speed variants */
.lfg-item.lfg-css-waves[data-wave-speed="slow"]   .lfg-image { animation-duration: 5s;   }
.lfg-item.lfg-css-waves[data-wave-speed="normal"] .lfg-image { animation-duration: 3s;   }
.lfg-item.lfg-css-waves[data-wave-speed="fast"]   .lfg-image { animation-duration: 1.5s; }

/* ── Scroll-reactive wave intensification ──────────────────────────────────── */
/* JS adds/removes this class when page is scrolling fast */
.lfg-liquid-scene.lfg-scrolling .lfg-item.lfg-css-waves .lfg-image {
    animation-duration: 1s;
    transform: skewX(0.5deg) scaleY(1.01);
}

/* ── Click ripple burst (CSS complement to WebGL ripple) ────────────────────── */
@keyframes lfg-ripple-burst {
    from {
        opacity: 0.6;
        transform: scale(0.2);
    }
    to {
        opacity: 0;
        transform: scale(1.8);
    }
}

.lfg-ripple-burst {
    position: absolute;
    width: 80px;
    height: 80px;
    margin-left: -40px;
    margin-top: -40px;
    border-radius: 50%;
    border: 2px solid rgba(120, 180, 255, 0.8);
    pointer-events: none;
    z-index: 20;
    animation: lfg-ripple-burst 0.6s ease-out forwards;
}

/* ── Lightbox ──────────────────────────────────────────────────────────────── */
.lfg-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 15, 30, 0.88);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    backdrop-filter: blur(6px);
    animation: lfg-lightbox-in 0.35s ease forwards;
}

.lfg-lightbox[hidden] {
    display: none;
}

@keyframes lfg-lightbox-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.lfg-lightbox-inner {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
}

.lfg-lightbox-img {
    display: block;
    max-width: 90vw;
    max-height: 85vh;
    border-radius: 8px;
    box-shadow: 0 20px 80px rgba(0, 60, 120, 0.60);
    animation: lfg-lightbox-img-in 0.4s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes lfg-lightbox-img-in {
    from { transform: scale(0.88); opacity: 0; }
    to   { transform: scale(1.00); opacity: 1; }
}

.lfg-lightbox-close {
    position: absolute;
    top: -2.5rem;
    right: 0;
    background: none;
    border: none;
    color: #fff;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.lfg-lightbox-close:hover,
.lfg-lightbox-close:focus {
    opacity: 1;
    outline: 2px solid rgba(120,180,255,0.8);
    outline-offset: 2px;
    border-radius: 2px;
}

/* ── Audio mute button (injected by JS) ─────────────────────────────────────── */
.lfg-audio-btn {
    position: absolute;
    top: 0.6rem;
    right: 0.6rem;
    z-index: 30;
    background: rgba(0, 30, 60, 0.55);
    border: 1px solid rgba(120, 180, 255, 0.4);
    color: #b0d0ff;
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.lfg-audio-btn:hover {
    background: rgba(0, 60, 120, 0.75);
}

/* ── Accessibility – prefer reduced motion ──────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .lfg-item.lfg-css-waves .lfg-image,
    .lfg-liquid-scene.lfg-scrolling .lfg-item.lfg-css-waves .lfg-image {
        animation: none;
        transform: none;
    }

    .lfg-lightbox,
    .lfg-lightbox-img {
        animation: none;
    }

    .lfg-fluid-canvas {
        transition: none;
    }
}
