/* wd-gallery frontend layout, item, video, and lightbox theming. */

.dyn-gallery {
    max-width: var(--imp-container, 1200px);
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(var(--wd-gallery-cols, 4), 1fr);
    gap: 16px;
}

.dyn-gallery__item {
    position: relative;
    overflow: hidden;
    aspect-ratio: 1 / 1;
    background: var(--imp-color-bg-alt, #2a231d);
    border: 1px solid var(--imp-color-border, rgba(255, 255, 255, 0.08));
    text-decoration: none;
    color: inherit;
    display: block;
    cursor: pointer;
    transition: transform 0.4s ease, border-color 0.4s ease;
}

.dyn-gallery__item:hover {
    /*transform: translateY(-4px);*/
    border-color: var(--imp-color-primary, #c9a876);
}

.dyn-gallery__item--2x1 { grid-column: span 2; }
.dyn-gallery__item--1x2 { grid-row: span 2; }
.dyn-gallery__item--2x2 { grid-column: span 2; grid-row: span 2; }

.dyn-gallery__image,
.dyn-gallery__video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.6s ease;
}

.dyn-gallery__item:hover .dyn-gallery__image {
    transform: scale(1.05);
}

/* Clicks on the video element must pass through to its parent <a> so the
 * lightbox can open. Without this, browsers route clicks on the video frame
 * into the native <video> handler and the parent anchor never sees them. */
.dyn-gallery__item--video .dyn-gallery__video {
    pointer-events: none;
}

.dyn-gallery__play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--imp-color-primary, #c9a876);
    color: var(--imp-color-bg, #15100b);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    padding-left: 4px;
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
    z-index: 5;
}

.dyn-gallery__item--video .dyn-gallery__video[data-playing="true"] + .dyn-gallery__play-icon {
    opacity: 0;
}

/* Non-autoplay video tiles: video stays paused on its poster, so the play
 * indicator is the primary affordance telling the user "this is playable".
 * Slightly larger and with a soft ring + shadow so it reads from a distance. */
.dyn-gallery__item--no-autoplay .dyn-gallery__play-icon {
    width: 72px;
    height: 72px;
    font-size: 22px;
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.12), 0 6px 18px rgba(0, 0, 0, 0.35);
}

.dyn-gallery__item--no-autoplay:hover .dyn-gallery__play-icon {
    transform: translate(-50%, -50%) scale(1.08);
}

.dyn-gallery__overflow {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(var(--wd-gallery-cols, 4), 1fr);
    gap: 16px;
    margin-top: 16px;
}

.dyn-gallery--empty {
    padding: 64px 32px;
    text-align: center;
    color: var(--imp-color-text-muted, rgba(255, 255, 255, 0.6));
    background: var(--imp-color-bg-alt, #2a231d);
    border: 1px solid var(--imp-color-border, rgba(255, 255, 255, 0.08));
    display: block;
}

@media (max-width: 1024px) {
    .dyn-gallery,
    .dyn-gallery__overflow {
        grid-template-columns: repeat(min(var(--wd-gallery-cols, 4), 3), 1fr);
    }
}

@media (max-width: 768px) {
    .dyn-gallery,
    .dyn-gallery__overflow {
        grid-template-columns: repeat(min(var(--wd-gallery-cols, 4), 2), 1fr);
        gap: 12px;
    }
    .dyn-gallery__item--2x2 {
        grid-column: span 2;
        grid-row: span 1;
    }
}

/* ---- Mosaic render mode (row-justified, JS-driven) ---- */

.dyn-gallery--mosaic {
    display: block;
    position: relative;
    grid-template-columns: none;        /* override base grid rules */
    gap: 0;                              /* gap is per-item, set inline by JS */
}

.dyn-gallery--mosaic .dyn-gallery__item {
    aspect-ratio: auto;                  /* unset the 1/1 from base */
    grid-column: auto;
    grid-row: auto;
    /* Pre-JS state: inline-block with server-set aspect-ratio so the page
       has approximate height before JS runs. Once JS runs, items become
       absolutely positioned. */
    display: inline-block;
    vertical-align: top;
    width: 240px;                        /* approx, JS overrides */
    margin: 0 8px 8px 0;
}

/* JS sets this class on the container after first layout */
.dyn-gallery--mosaic.is-laid-out .dyn-gallery__item {
    position: absolute;
    margin: 0;                           /* gaps are positional, not margin */
    /* width and height set inline by JS */
}

.dyn-gallery--mosaic .dyn-gallery__image,
.dyn-gallery--mosaic .dyn-gallery__video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

@media (max-width: 768px) {
    /* Smaller default target on mobile. JS reads the actual data-target-height
       attribute, so to make this responsive at runtime, the JS halves the
       target on narrow viewports. CSS here only affects pre-JS sizing. */
    .dyn-gallery--mosaic .dyn-gallery__item {
        width: 160px;
        margin: 0 4px 4px 0;
    }
}
