/* 
 * BLUNAPRESS EDITORIAL MOSAIC GRID (v1.9 - ASPECT-LOCKED)
 */

/* 1. THE GRID ENGINE */
.blunapress-mosaic-grid,
.blunapress-mosaic-grid > .wp-block-group__inner-container,
.wp-block-group.blunapress-mosaic-grid > .block-editor-inner-blocks > .block-editor-block-list__layout {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    grid-auto-flow: dense !important;
    gap: 15px !important;
    margin: 40px 0 !important;
    width: 100% !important;
    max-width: none !important;
}

/* 2. ITEM RESET - FIXED HEIGHT FOR EDITORIAL LOOK */
.blunapress-mosaic-grid .wp-block-image,
.blunapress-mosaic-grid .wp-block-group,
.blunapress-mosaic-grid .wp-block-video,
.blunapress-mosaic-grid .block-editor-block-list__block {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: none !important;
    height: 400px !important; /* Fixed height for all tiles in a row */
    display: block !important;
}

/* 3. THE SPAN LOGIC (Frontend + Backend) */

/* Span 2 Left */
.blunapress-mosaic-grid > *:has(.is-style-span-2-left),
.blunapress-mosaic-grid .is-style-span-2-left,
.wp-block-group.blunapress-mosaic-grid .block-editor-block-list__block:has(.is-style-span-2-left) {
    grid-column: span 2 !important;
}

/* Span 2 Right */
.blunapress-mosaic-grid > *:has(.is-style-span-2-right),
.blunapress-mosaic-grid .is-style-span-2-right,
.wp-block-group.blunapress-mosaic-grid .block-editor-block-list__block:has(.is-style-span-2-right) {
    grid-column: 2 / span 2 !important;
}

/* Full Span (3 Cols) */
.blunapress-mosaic-grid > *:has(.is-style-span-3),
.blunapress-mosaic-grid .is-style-span-3,
.wp-block-group.blunapress-mosaic-grid .block-editor-block-list__block:has(.is-style-span-3) {
    grid-column: span 3 !important;
}

/* Double Height (Optional - override the 400px) */
.blunapress-mosaic-grid > *:has(.is-style-row-2),
.blunapress-mosaic-grid .is-style-row-2,
.wp-block-group.blunapress-mosaic-grid .block-editor-block-list__block:has(.is-style-row-2) {
    grid-row: span 2 !important;
    height: 815px !important; /* (400px * 2) + 15px gap */
}

/* 4. IMAGE FITTING */
.blunapress-mosaic-grid img,
.blunapress-mosaic-grid video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    display: block !important;
}

/* 5. CAPTION OVERLAY */
.mosaic-caption {
    position: absolute !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    background: rgba(255, 255, 255, 0.9) !important;
    backdrop-filter: blur(10px);
    padding: 20px !important;
    margin: 0 !important;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 10;
    color: #000 !important;
}

.blunapress-mosaic-grid *:hover > .mosaic-caption {
    opacity: 1;
}

/* 6. MOBILE */
@media (max-width: 768px) {
    .blunapress-mosaic-grid {
        display: block !important;
    }
    .blunapress-mosaic-grid .wp-block-image,
    .blunapress-mosaic-grid .wp-block-group {
        height: 300px !important;
        margin-bottom: 15px !important;
    }
}

/* 7. LIGHTBOX (Postcard Style) */
#mosaic-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

#mosaic-lightbox.is-active {
    opacity: 1;
    visibility: visible;
}

.lightbox-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(5px);
}

.lightbox-container {
    position: relative;
    max-width: 1000px;
    width: 90%;
    background: #fff;
    padding: 15px; /* The \"Postcard\" border */
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

#mosaic-lightbox.is-active .lightbox-container {
    transform: translateY(0);
}

.lightbox-image {
    width: 100%;
    height: auto;
    display: block;
}

.lightbox-close {
    position: absolute;
    top: -40px;
    right: 0;
    color: #fff;
    font-size: 35px;
    cursor: pointer;
    line-height: 1;
}

.blunapress-mosaic-grid img {
    cursor: zoom-in;
}

/* 8. LIGHTBOX NAVIGATION */
.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    cursor: pointer;
    z-index: 100;
    transition: background 0.3s ease;
    border-radius: 50%;
}

.lightbox-nav:hover {
    background: #fff;
}

.lightbox-prev {
    left: -70px;
}

.lightbox-next {
    right: -70px;
}

@media (max-width: 1200px) {
    .lightbox-prev { left: 10px; }
    .lightbox-next { right: 10px; }
    .lightbox-nav { background: rgba(255,255,255,0.5); }
}
