/* Jenga Gallery - Base Styles */
.jenga-gallery {
    box-sizing: border-box;
}
.jenga-gallery *, .jenga-gallery *::before, .jenga-gallery *::after {
    box-sizing: inherit;
}

/* Elementor Outer Wrapper Overrides for Full Bleed Screen Overflow */
.elementor-widget-jenga-gallery {
    overflow: visible !important;
}
.elementor-widget-jenga-gallery .elementor-widget-container {
    overflow: visible !important;
    width: 100% !important;
    max-width: 100% !important;
}

/* Edge-to-Edge Screen Overflow Mode (Reference Style: images extend off screen) */
.jenga-gallery--overflow {
    width: var(--jg-overflow-width, 118vw) !important;
    max-width: var(--jg-overflow-width, 118vw) !important;
    position: relative !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

html, body {
    overflow-x: hidden !important;
}

.jenga-gallery__item {
    overflow: hidden;
    border-radius: var(--jg-radius, 12px);
    position: relative;
    /* Staggered load animation */
    animation: jg-item-appear 0.5s ease both;
}
.jenga-gallery__item:nth-child(1) { animation-delay: 0.05s; }
.jenga-gallery__item:nth-child(2) { animation-delay: 0.10s; }
.jenga-gallery__item:nth-child(3) { animation-delay: 0.15s; }
.jenga-gallery__item:nth-child(4) { animation-delay: 0.20s; }
.jenga-gallery__item:nth-child(5) { animation-delay: 0.25s; }
.jenga-gallery__item:nth-child(6) { animation-delay: 0.30s; }
.jenga-gallery__item:nth-child(7) { animation-delay: 0.35s; }
.jenga-gallery__item:nth-child(8) { animation-delay: 0.40s; }
.jenga-gallery__item:nth-child(9) { animation-delay: 0.45s; }
.jenga-gallery__item:nth-child(10) { animation-delay: 0.50s; }
.jenga-gallery__item:nth-child(11) { animation-delay: 0.55s; }
.jenga-gallery__item:nth-child(12) { animation-delay: 0.60s; }
.jenga-gallery__item:nth-child(n+13) { animation-delay: 0.60s; }

@keyframes jg-item-appear {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.jenga-gallery__link {
    display: block;
    overflow: hidden;
    border-radius: inherit;
    position: relative;
    height: 100%;
}

.jenga-gallery__img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.35s ease, filter 0.35s ease;
}

.jenga-gallery__overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    padding: 16px;
    transition: opacity 0.3s ease, background-color 0.3s ease;
    pointer-events: none;
}

.jenga-gallery__caption {
    color: #fff;
    font-size: 14px;
    line-height: 1.4;
    z-index: 2;
}

/* Layouts */

/* Masonry */
.jenga-gallery--masonry {
    column-count: var(--jg-columns, 3);
    column-gap: var(--jg-gap, 8px);
}
.jenga-gallery--masonry .jenga-gallery__item {
    break-inside: avoid;
    margin-bottom: var(--jg-gap, 8px);
    display: inline-block;
    width: 100%;
}
.jenga-gallery--masonry .jenga-gallery__img {
    height: auto;
}

/* Grid */
.jenga-gallery--grid {
    display: grid;
    grid-template-columns: repeat(var(--jg-columns, 3), 1fr);
    gap: var(--jg-gap, 8px);
}
.jenga-gallery--grid[data-ratio='1:1'] .jenga-gallery__item { aspect-ratio: 1/1; }
.jenga-gallery--grid[data-ratio='4:3'] .jenga-gallery__item { aspect-ratio: 4/3; }
.jenga-gallery--grid[data-ratio='3:4'] .jenga-gallery__item { aspect-ratio: 3/4; }
.jenga-gallery--grid[data-ratio='16:9'] .jenga-gallery__item { aspect-ratio: 16/9; }
.jenga-gallery--grid[data-ratio='3:2'] .jenga-gallery__item { aspect-ratio: 3/2; }
.jenga-gallery--grid .jenga-gallery__img {
    height: 100%;
    object-fit: cover;
}

/* Justified */
.jenga-gallery--justified {
    display: flex;
    flex-wrap: wrap;
    gap: var(--jg-gap, 8px);
}
.jenga-gallery--justified::after {
    content: '';
    flex-grow: 999;
}
.jenga-gallery--justified .jenga-gallery__item {
    flex-grow: 1;
    height: 280px;
}
.jenga-gallery--justified .jenga-gallery__img {
    height: 100%;
    width: 100%;
    object-fit: cover;
}

/* Mosaic */
.jenga-gallery--mosaic {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--jg-gap, 8px);
    grid-auto-flow: dense;
}
.jenga-gallery--mosaic .jenga-gallery__item:nth-child(5n+1) {
    grid-column: span 2;
    grid-row: span 2;
}
.jenga-gallery--mosaic .jenga-gallery__item:nth-child(7n+4) {
    grid-row: span 2;
}
.jenga-gallery--mosaic .jenga-gallery__img {
    height: 100%;
    object-fit: cover;
}

/* Marquee Infinite Ticker Layout */
.jenga-gallery {
    --jg-image-gap: 12px;
    --jg-row-gap: 16px;
}

.jenga-gallery--marquee {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    overflow: hidden !important;
    column-count: auto !important;
    grid-template-columns: none !important;
    gap: var(--jg-row-gap, 16px) !important;
}

.jenga-gallery__marquee-row {
    display: flex !important;
    flex-direction: row !important;
    width: 100vw !important;
    max-width: 100vw !important;
    position: relative !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    overflow: hidden !important;
    user-select: none !important;
    gap: var(--jg-image-gap, 12px) !important;
    margin: 0 0 var(--jg-row-gap, 16px) 0 !important;
}

.jenga-gallery__marquee-track {
    display: flex !important;
    flex-direction: row !important;
    flex-shrink: 0 !important;
    gap: var(--jg-image-gap, 12px) !important;
    align-items: center !important;
    min-width: max-content !important;
    will-change: transform !important;
    animation: jg-marquee-left var(--jg-marquee-speed, 45s) linear infinite !important;
}

.jenga-gallery__marquee-row--right .jenga-gallery__marquee-track {
    animation-name: jg-marquee-right !important;
}

/* Pause on Hover Modes */

/* Mode 1: Pause Entire Gallery when hovering anywhere inside widget */
.jenga-gallery[data-marquee-pause="entire"]:hover .jenga-gallery__marquee-track,
.jenga-gallery[data-marquee-pause="yes"]:hover .jenga-gallery__marquee-track {
    animation-play-state: paused !important;
}

/* Mode 2: Pause Hovered Row Only (Only the specific row under cursor pauses) */
.jenga-gallery[data-marquee-pause="row"] .jenga-gallery__marquee-row:hover .jenga-gallery__marquee-track {
    animation-play-state: paused !important;
}

.jenga-gallery--marquee .jenga-gallery__item {
    flex: 0 0 auto !important;
    height: var(--jg-marquee-height, 260px) !important;
    width: auto !important;
    animation: none !important; /* Prevent load animation from causing vertical shift */
    margin: 0 !important;
    display: block !important;
}

.jenga-gallery--marquee .jenga-gallery__img {
    height: 100% !important;
    width: auto !important;
    object-fit: cover !important;
}

@keyframes jg-marquee-left {
    0% { transform: translate3d(0, 0, 0); }
    100% { transform: translate3d(calc(-50% - (var(--jg-image-gap, 12px) / 2)), 0, 0); }
}

@keyframes jg-marquee-right {
    0% { transform: translate3d(calc(-50% - (var(--jg-image-gap, 12px) / 2)), 0, 0); }
    100% { transform: translate3d(0, 0, 0); }
}

/* Hover Effects */
.jenga-gallery--hover-none .jenga-gallery__link {
    cursor: pointer;
}

.jenga-gallery--hover-zoom .jenga-gallery__item:hover .jenga-gallery__img {
    transform: scale(1.08);
}

.jenga-gallery--hover-overlay .jenga-gallery__item:hover .jenga-gallery__overlay {
    opacity: 1;
    background-color: rgba(0, 0, 0, 0.4); 
}

.jenga-gallery--hover-grayscale .jenga-gallery__img {
    filter: grayscale(100%);
}
.jenga-gallery--hover-grayscale .jenga-gallery__item:hover .jenga-gallery__img {
    filter: grayscale(0%);
}

.jenga-gallery--hover-blur .jenga-gallery__item:hover .jenga-gallery__img {
    filter: blur(3px);
}

.jenga-gallery--hover-shine .jenga-gallery__link::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(to right, transparent 0%, rgba(255,255,255,0.3) 50%, transparent 100%);
    transform: rotate(25deg) translateX(-150%);
    transition: transform 0.6s ease;
    pointer-events: none;
    z-index: 1;
}
.jenga-gallery--hover-shine .jenga-gallery__item:hover .jenga-gallery__link::after {
    transform: rotate(25deg) translateX(150%);
}

/* Lightbox Styles */
.jenga-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999999;
}
.jenga-lightbox[aria-hidden='true'] {
    display: none;
}
.jenga-lightbox[aria-hidden='false'] {
    display: flex;
    align-items: center;
    justify-content: center;
}

.jenga-lightbox__backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.jenga-lightbox__close {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 10;
    color: white;
    font-size: 36px;
    background: none;
    border: none;
    cursor: pointer;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, color 0.2s;
    padding: 0;
    line-height: 1;
}
.jenga-lightbox__close:hover {
    transform: scale(1.1);
    color: #ff6b6b;
}

.jenga-lightbox__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: white;
    font-size: 24px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    z-index: 10;
    padding: 0;
    line-height: 1;
}
.jenga-lightbox__nav:hover {
    background: rgba(255,255,255,0.2);
}
.jenga-lightbox__nav--prev {
    left: 20px;
}
.jenga-lightbox__nav--next {
    right: 20px;
}

.jenga-lightbox__stage {
    position: relative;
    z-index: 2;
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.jenga-lightbox__img {
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.jenga-lightbox__caption {
    position: absolute;
    bottom: -40px;
    left: 0;
    right: 0;
    text-align: center;
    color: rgba(255,255,255,0.8);
    font-size: 14px;
}

.jenga-lightbox__counter {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255,255,255,0.5);
    font-size: 13px;
    letter-spacing: 2px;
    z-index: 10;
}

/* Lightbox Animations */
.jenga-lightbox--fade .jenga-lightbox__img {
    animation: jg-fade-in 0.3s ease;
}
.jenga-lightbox--zoom .jenga-lightbox__img {
    animation: jg-zoom-in 0.3s ease;
}
.jenga-lightbox--slide .jenga-lightbox__img {
    animation: jg-slide-in 0.3s ease;
}

@keyframes jg-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes jg-zoom-in {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}
@keyframes jg-slide-in {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes jg-slide-out-left {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(-30px); }
}
@keyframes jg-slide-out-right {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(30px); }
}

/* Responsive Fallbacks */
@media (max-width: 1024px) {
    .jenga-gallery--justified .jenga-gallery__item {
        height: 220px;
    }
}
@media (max-width: 767px) {
    .jenga-gallery--justified .jenga-gallery__item {
        height: 180px;
    }
    
    .jenga-lightbox__nav {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }
    .jenga-lightbox__nav--prev { left: 10px; }
    .jenga-lightbox__nav--next { right: 10px; }
    
    .jenga-lightbox__stage {
        max-width: 100vw;
        padding: 0 15px;
    }
    .jenga-lightbox__close {
        top: 10px;
        right: 10px;
        width: 36px;
        height: 36px;
        font-size: 28px;
    }
}
