body.gallery-page {
    --gallery-columns: 25;
    --gallery-rows: 5;
    --gallery-top: max(100px, 12vh);
    --gallery-bottom: max(64px, 8vh);
    --gallery-viewport: 100vh;
    display: block;
    min-height: var(--gallery-viewport);
    padding: var(--gallery-top) 4vw var(--gallery-bottom);
    font-family: "Source Code Pro", monospace;
}

body.notes-page {
    --gallery-columns: 13;
    --gallery-rows: 11;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(var(--gallery-columns), minmax(0, 1fr));
    grid-template-rows: repeat(var(--gallery-rows), minmax(0, 1fr));
    gap: clamp(3px, 0.45vw, 10px);
    height: calc(var(--gallery-viewport) - var(--gallery-top) - var(--gallery-bottom));
}

.gallery-item {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: none;
}

.gallery-item img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform 0.35s ease, opacity 0.35s ease;
}

.gallery-item:hover img,
.gallery-item:focus-visible img {
    transform: scale(1.025);
    opacity: 0.82;
}

.gallery-item:focus-visible {
    outline: 1px dotted currentColor;
    outline-offset: 3px;
}

.gallery-filename {
    position: fixed;
    z-index: 900;
    padding: 3px 6px;
    background: white;
    color: rgb(33, 33, 47);
    font-family: "Source Code Pro", monospace;
    font-size: 0.75rem;
    font-weight: 400;
    line-height: 1.4;
    white-space: nowrap;
    pointer-events: none;
}

.gallery-viewer[hidden],
.gallery-filename[hidden] {
    display: none;
}

.gallery-viewer {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    background: transparent;
    padding: 3vh 2vw;
}

.gallery-viewer-dialog {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: min(96vw, 1800px);
    height: 94vh;
    padding: 3rem 3.5rem;
}

.gallery-viewer-image {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.gallery-viewer-control {
    position: absolute;
    display: grid;
    place-items: center;
    width: 2.8rem;
    height: 2.8rem;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.75);
    border-radius: 50%;
    color: white;
    background: rgba(20, 20, 25, 0.35);
    font: inherit;
    font-size: 1.6rem;
    line-height: 1;
    cursor: none;
}

.gallery-viewer-control:hover,
.gallery-viewer-control:focus-visible {
    color: rgb(20, 20, 25);
    background: white;
    outline: 1px dotted currentColor;
    outline-offset: 3px;
}

.gallery-previous,
.gallery-next {
    top: 50%;
    transform: translateY(-50%);
}

.gallery-previous { left: 0.5rem; }
.gallery-next { right: 0.5rem; }
.gallery-close { top: 0.5rem; right: 0.5rem; }

.gallery-count {
    position: absolute;
    bottom: 0.75rem;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.8rem;
    letter-spacing: 0.08em;
    white-space: nowrap;
}

.gallery-page .inner-cursor,
.gallery-page .outer-cursor {
    z-index: 1100;
}

@supports (height: 100svh) {
    body.gallery-page {
        --gallery-top: max(100px, 12svh);
        --gallery-bottom: max(64px, 8svh);
        --gallery-viewport: 100svh;
    }

    .gallery-viewer-dialog { height: 94svh; }
}

@media (max-width: 700px) {
    body.gallery-page { padding-left: 5vw; padding-right: 5vw; }

    .gallery-grid {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: none;
        grid-auto-rows: auto;
        height: auto;
        gap: 2rem;
    }

    .gallery-item { height: auto; }
    .gallery-item img { height: auto; max-height: 80svh; }
    .gallery-viewer { padding: 2vh 1vw; }
    .gallery-viewer-dialog { width: 98vw; padding-left: 3rem; padding-right: 3rem; }
    .gallery-previous { left: 0; }
    .gallery-next { right: 0; }

    .gallery-page .fooot {
        position: static;
        margin-top: 3rem;
        text-align: right;
    }
}

@media (prefers-reduced-motion: reduce) {
    .gallery-item img { transition: none; }
}
