gallery {
    --dialog-width: 100vw;
    --dialog-height: 100%;
    /*--dialog-width: 65vw;*/
    /*--dialog-height: 90%;*/
    --dialog-background: black;

    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem;
}

gallery > img { /* immediate children of a <gallery> tag */
    flex: 1 1 auto;
    height: 10rem;

    object-fit: cover;
    border: 1px solid black;
    border-radius: 0.3rem;
    cursor: pointer;

    transition: transform 0.3s ease;
}

gallery > img:hover {
    transform: scale(1.03);
}

@keyframes galleryDialogFadeIn {
    from {
        scale: 0.95;
    }
    to {
        scale: 1;
    }
}

body:has(gallery > dialog[open]) { /* Prevents scrolling behind the open dialog */
    overflow: hidden;
}

gallery > dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    translate: -50% -50%;

    width: var(--dialog-width);
    height: var(--dialog-height);
    background: var(--dialog-background);

    border: 0.2rem solid rgba(255, 255, 255, 0.8);
    border-radius: 1rem;
    box-shadow: 0 0 1.5rem rgba(255, 255, 255, 0.7);

    animation: galleryDialogFadeIn 0.5s ease-out;
}

gallery > dialog:focus {
    outline: none;
}

gallery > dialog::backdrop {
    background: rgba(0, 0, 0, 0.8); /* Dimmed overlay behind the dialog */
}

gallery > dialog button {
    position: absolute;
    outline: none;
    padding: 0;
    margin: 0;
    border: 0;
    border-radius: 0.7rem;
    background: rgba(50, 50, 50, 0.5) center no-repeat;
    transition: background-color 0.4s ease;
    cursor: pointer;
}

gallery > dialog button:focus, gallery > dialog button:hover {
    background-color: rgba(50, 50, 50, 0.9);
}

gallery > dialog button.prev, gallery > dialog button.next {
    top: calc(50% - 2rem);
    width: 3rem;
    height: 4rem;
}

gallery > dialog button.prev {
    left: 1rem;
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 44 60" stroke-width="3" stroke="white" fill="transparent"><polyline points="30 10 10 30 30 50"/></svg>');
}

gallery > dialog button.next {
    right: 1rem;
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 44 60" stroke-width="3" stroke="white" fill="transparent"><polyline points="14 10 34 30 14 50"/></svg>');
}

gallery > dialog button.close {
    top: 1rem;
    right: 1rem;
    width: 2.5rem;
    height: 2.5rem;
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 44 44" stroke-width="3" stroke="white" fill="transparent"><line x1="10" y1="10" x2="34" y2="34"/><line x1="10" y1="34" x2="34" y2="10"/></svg>');
}

gallery > dialog div.slider {
    display: flex;    /* horizontal layout */
    width: 100%;
    height: 100%;
    overflow: hidden; /* disable manual scrolling*/
}

gallery > dialog div.slider::-webkit-scrollbar { /* hide scrollbars */
    width: 0;
    background: transparent;
}

gallery > dialog div.slider > div {
    flex: 0 0 100%;      /* do NOT shrink, width = 100% of frame */
    height: 100%;        /* match frame height */

    display: flex;
    justify-content: center;  /* horizontal */
    align-items: center;      /* vertical */
}

gallery > dialog div.slider > div > img {
    max-height: 100%;
}
