.media-gallery {
    --thumb-height: 320px;

    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    gap: 8px;

    max-width: 1600px;
    margin: 0 auto;
    padding: 8px;
}

.media-tile {
    flex: 0 0 auto;

    /* The key organic-gallery rule */
    width: calc(var(--thumb-height) * var(--media-w) / var(--media-h));
    height: var(--thumb-height);

    position: relative;
    display: block;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    overflow: hidden;
    appearance: none;
}

.media-tile img,
.media-tile video {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Only the clicked item becomes a full-width row */
.media-tile.is-active {
    width: 100vw;
    height: 100vh;
    aspect-ratio: var(--media-w) / var(--media-h);
}

.media-tile.is-active img,
.media-tile.is-active video {
    position: absolute;
    inset: 0;
}

/* Optional visual indication that this clip has sound when opened */
.media-tile--audio::after {
    content: "Sound";
    position: absolute;
    right: 8px;
    bottom: 8px;
    z-index: 2;
    padding: 4px 6px;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    font: 12px/1 system-ui, sans-serif;
    pointer-events: none;
}

.media-tile--audio.is-active::after {
    display: none;
}

/* Full-width individual pieces only on a narrow phone */
@media (max-width: 700px) {
    .media-gallery {
        display: grid;
        grid-template-columns: 1fr;
        gap: 6px;
        padding: 6px;
    }

    .media-tile,
    .media-tile.is-active {
        width: 100%;
        height: auto;
        aspect-ratio: var(--media-w) / var(--media-h);
    }
}