.gallery-filters {
    display: flex;
    align-items: end;
    gap: 1rem;
    padding: 1.5rem;
    background: #f4f1eb;
    border-radius: .4rem;
    margin-bottom: 3rem;
}

.gallery-filters>div {
    flex: 1;
    min-width: 0;
}

.gallery-filters label {
    margin-bottom: .5rem;
}

.gallery-album {
    margin: 3rem 0;
}

.gallery-album>header p {
    margin-bottom: .7rem;
}

.gallery-kicker {
    display: block;
    color: #417770;
    font-family: "Source Sans Pro", sans-serif;
    font-size: .8rem;
    font-weight: 900;
    letter-spacing: .13em;
    text-transform: uppercase;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: .35rem;
}

.gallery-card {
    margin: 0;
}

.gallery-photo {
    display: block;
    border: 0;
    overflow: hidden;
}

.gallery-photo img {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    display: block;
    transition: transform .2s;
}

.gallery-photo:hover img {
    transform: scale(1.025);
}

.gallery-empty,
.gallery-visit {
    padding: 2rem;
    text-align: center;
    border-top: 1px solid #e4e0d9;
}

.gallery-visit p,
.gallery-empty p {
    text-align: center;
}

.gallery-lightbox {
    width: min(1000px, 94vw);
    max-height: 94vh;
    padding: 1rem;
    border: 0;
    background: #fffdf8;
}

.gallery-lightbox::backdrop {
    background: rgb(0 0 0 / 85%);
}

.gallery-lightbox>img {
    display: block;
    width: 100%;
    height: min(65vh, 700px);
    object-fit: contain;
    margin-top: 1rem;
}

.gallery-lightbox-caption {
    text-align: center;
    margin: .8rem 0;
}

.gallery-lightbox-controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.gallery-lightbox-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.gallery-swipe-hint {
    display: none;
}

body.gallery-viewer-open {
    overflow: hidden;
    overscroll-behavior-x: none;
}

.gallery-lightbox>img {
    touch-action: pan-y pinch-zoom;
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
}

.gallery-lightbox {
    overscroll-behavior-x: none;
}

.gallery-editor {
    margin-top: 3rem;
    border-top: 1px solid #ddd;
    padding-top: 2rem;
}

.gallery-editor .fields {
    margin-top: 1rem;
}

.gallery-editor-photo {
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr) minmax(0, 180px) 90px;
    align-items: end;
    gap: .75rem;
    padding: .75rem;
    border-bottom: 1px solid #e4e0d9;
    font-family: "Source Sans Pro", Helvetica, Arial, sans-serif;
}

.gallery-editor-photo>div {
    min-width: 0;
}

.gallery-editor-photo,
.gallery-editor-photo * {
    box-sizing: border-box;
}

.gallery-editor-thumbnail {
    display: block;
    width: 56px;
    border: 0;
    cursor: zoom-in;
}

.gallery-editor-thumbnail img {
    display: block;
}

.gallery-editor-thumbnail:focus-visible {
    outline: 2px solid #417770;
    outline-offset: 3px;
}

.gallery-editor-photo img {
    width: 100%;
    height: 56px;
    object-fit: cover;
}

.gallery-editor-photo input[type="text"],
.gallery-editor-photo select {
    margin-bottom: 0;
    min-width: 0;
    max-width: 100%;
    width: 100%;
    height: 40px;
    padding-left: .65rem;
    font-family: inherit;
    font-size: 16px;
    line-height: normal;
    letter-spacing: normal;
    text-transform: none;
    background-color: #fff;
    margin-left: 0;
    margin-right: 0;
    border: 1px solid #c5ccc9;
    border-radius: 4px;
}

.gallery-admin-preview {
    box-sizing: border-box;
    width: min(960px, 94vw);
    max-height: 90vh;
    max-height: 90dvh;
    padding: 1rem;
    border: 0;
    border-radius: 8px;
    background: #fffdf8;
}

.gallery-admin-preview[open] {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.gallery-admin-preview::backdrop {
    background: rgb(0 0 0 / 80%);
}

.gallery-admin-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-shrink: 0;
}

.gallery-admin-preview-header h2 {
    margin: 0;
    font-size: 1rem;
}

.gallery-admin-preview>img {
    display: block;
    width: 100%;
    height: 60vh;
    height: 60svh;
    min-height: 0;
    object-fit: contain;
}

.gallery-admin-preview>p {
    margin: 0;
    max-height: 12vh;
    overflow-y: auto;
    text-align: center;
    font-family: "Source Sans Pro", Helvetica, Arial, sans-serif;
}

body.gallery-admin-preview-open {
    overflow: hidden;
}

.gallery-editor-photo select {
    padding-right: 2rem;
    background-position: calc(100% - .5rem) center;
}

.gallery-editor-photo label {
    margin-bottom: .25rem;
    font-size: .7rem;
    letter-spacing: .05em;
}

.gallery-photo-remove label {
    margin-bottom: 0;
}

.gallery-editor-photo .gallery-photo-remove {
    display: flex;
    align-items: center;
    gap: .5rem;
    min-height: 40px;
}

.gallery-editor-photo .gallery-photo-remove input[type="checkbox"] {
    appearance: auto;
    display: inline-block;
    float: none;
    opacity: 1;
    width: 18px;
    height: 18px;
    margin: 0;
    flex-shrink: 0;
    z-index: auto;
    accent-color: #417770;
}

.gallery-editor-photo .gallery-photo-remove input[type="checkbox"]+label {
    padding: 0;
    font-family: inherit;
    font-size: .85rem;
    line-height: 1.5;
    font-weight: 400;
    letter-spacing: normal;
    white-space: nowrap;
}

.gallery-editor-photo .gallery-photo-remove input[type="checkbox"]+label::before {
    display: none;
}

.gallery-editor-photo input:focus-visible {
    outline: 2px solid #417770;
    outline-offset: 2px;
}

.gallery-photo-editor {
    margin-top: 1rem;
    border: 1px solid #e4e0d9;
}

.gallery-photo-editor summary {
    cursor: pointer;
    padding: 1rem;
    font-weight: bold;
    background: #f4f1eb;
    font-family: "Source Sans Pro", Helvetica, Arial, sans-serif;
    font-size: 1rem;
    line-height: 1.5;
    text-transform: none;
    letter-spacing: normal;
}

.gallery-editor-photos {
    max-height: 28rem;
    overflow-y: auto;
    scrollbar-gutter: stable;
}

.gallery-editor-photos:focus-visible {
    outline: 2px solid #417770;
    outline-offset: 2px;
}

.gallery-editor-toolbar {
    position: sticky;
    top: 5rem;
    z-index: 10;
    padding: .75rem;
    background: #fffdf8;
    border: 1px solid #e4e0d9;
    box-shadow: 0 3px 8px rgb(0 0 0 / 8%);
}

.gallery-editor-toolbar .gallery-upload-feedback {
    margin-top: .75rem;
}

.gallery-editor input[type="file"] {
    max-width: 100%;
}

.gallery-editor button[type="submit"] {
    max-width: 100%;
    height: auto;
    min-height: 3.25rem;
    padding: .75rem 1.25rem;
    line-height: 1.5;
    white-space: normal;
}

.gallery-upload-feedback {
    margin-top: 1.5rem;
    padding: 1rem;
    background: #f4f1eb;
    border: 1px solid #417770;
}

.gallery-upload-feedback p {
    margin-bottom: .7rem;
    text-align: left;
}

.gallery-upload-feedback progress {
    display: block;
    width: 100%;
    height: 1.25rem;
    accent-color: #417770;
    margin-bottom: 1rem;
}

.gallery-upload-feedback [hidden] {
    display: none;
}

@media (max-width: 980px) {
    .gallery-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 600px) {
    .gallery-editor-toolbar {
        top: .5rem;
    }

    .gallery-editor-photo {
        grid-template-columns: 40px minmax(0, 1fr);
        gap: .5rem .75rem;
    }

    .gallery-editor-photo img {
        height: 40px;
    }

    .gallery-editor-thumbnail {
        width: 40px;
    }

    .gallery-photo-category {
        grid-column: 2;
    }

    .gallery-photo-remove {
        grid-column: 2;
    }

    .gallery-editor-photos {
        max-height: 24rem;
    }

    .gallery-filters {
        flex-direction: column;
        align-items: stretch;
        padding: 1rem;
    }

    .gallery-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 3px;
    }

    .gallery-photo img {
        aspect-ratio: 1;
    }

    .gallery-page #main>.post {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .gallery-visit {
        padding: 2rem 0;
    }
}

@media (max-width: 980px) {
    .gallery-lightbox {
        position: fixed;
        inset: 0;
        margin: 0;
        width: 100%;
        max-width: none;
        box-sizing: border-box;
        height: 100svh;
        height: var(--gallery-viewer-height, 100dvh);
        max-height: var(--gallery-viewer-height, 100dvh);
        padding: calc(.75rem + env(safe-area-inset-top)) max(.75rem, env(safe-area-inset-right)) calc(1rem + env(safe-area-inset-bottom)) max(.75rem, env(safe-area-inset-left));
        background: #101010;
        color: #fff;
        overflow: hidden;
    }

    .gallery-lightbox[open] {
        display: flex;
        flex-direction: column;
        gap: .75rem;
    }

    .gallery-lightbox>img {
        flex: 1 1 0;
        height: 0;
        min-width: 0;
        min-height: 0;
        margin: 0;
    }

    .gallery-lightbox-caption {
        flex: 0 1 auto;
        max-height: 18vh;
        overflow-y: auto;
        margin: 0;
        font-size: .95rem;
        line-height: 1.5;
    }

    .gallery-lightbox .button {
        color: #fff !important;
        box-shadow: inset 0 0 0 1px #777;
        min-height: 44px;
        padding: 0 1rem;
    }

    .gallery-lightbox .button:focus-visible {
        outline: 2px solid #40e0d0;
        outline-offset: 3px;
    }

    .gallery-lightbox-controls {
        flex: 0 0 auto;
        min-height: 44px;
        align-items: center;
        justify-content: space-between;
        gap: .5rem;
    }

    .gallery-lightbox-header {
        flex: 0 0 auto;
    }

    .gallery-swipe-hint {
        display: inline;
        font-size: .75rem;
        color: #ccc;
    }
}

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