body.gallery-page {
    overflow-y: auto;
    min-height: 100vh;
}

body.gallery-page .content {
    justify-content: flex-start;
    padding-bottom: 4rem;
}

.gallery-container {
    position: relative;
    z-index: 2;
    margin-top: 1.5rem;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
    align-items: start;
    min-height: 160px;
}

.gallery-item {
    position: relative;
    display: flex;
    flex-direction: column;
    cursor: zoom-in;
}

.item-content {
    position: relative;
    width: 100%;
    overflow: hidden;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--glass-surface-sunken);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    transition: border-color var(--transition-fast);
}

.gallery-item:hover .item-content {
    border-color: var(--glass-border-focus);
}

.gallery-item.with-video .item-content {
    aspect-ratio: var(--media-ratio, 9 / 16);
    min-height: 0;
    background: var(--overlay-strong);
}

.item-content img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.item-content video {
    width: 100%;
    height: 100%;
    max-height: none;
    object-fit: cover;
    display: block;
    background: var(--bg-base);
}

.item-meta {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 7px;
    font-family: var(--font-mono);
    font-size: 9px;
    text-transform: uppercase;
    color: var(--text-secondary);
    background: var(--glass-surface-elevated);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    pointer-events: none;
}

.item-overlay {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 1.2rem;
    background: linear-gradient(to top, var(--overlay-strong), transparent);
    color: var(--text-primary);
    transform: translateY(100%);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    z-index: 5;
    pointer-events: none;
}

.gallery-item.show-fact .item-overlay {
    transform: translateY(0);
}

.item-overlay h3 {
    font-size: 12px;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--crystal-blue);
    margin-bottom: 6px;
}

.item-overlay p {
    font-size: 12px;
    line-height: 1.45;
    color: var(--text-secondary);
}

.gallery-message {
    grid-column: 1 / -1;
    padding: 2rem;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 1px;
    color: var(--text-muted);
    background: var(--glass-surface);
    border: 1px dashed var(--glass-border);
    border-radius: var(--radius-lg);
}

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 4000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: var(--overlay-strong);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-smooth);
}

.lightbox.open {
    opacity: 1;
    pointer-events: auto;
}

.lightbox img,
.lightbox video {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
}

.lightbox-close {
    position: absolute;
    top: 18px;
    right: 18px;
    padding: 8px 12px;
    background: var(--glass-surface-elevated);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 10px;
    letter-spacing: 1px;
    cursor: pointer;
}

.lightbox-close:hover,
.lightbox-close:focus-visible {
    border-color: var(--glass-border-focus);
    outline: none;
}

@media (max-width: 720px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 8px;
    }
}

.gallery-grid {
    display: block;
    column-width: 240px;
    column-gap: 1rem;
}

.gallery-item {
    display: inline-block;
    width: 100%;
    margin: 0 0 1rem;
    break-inside: avoid;
    vertical-align: top;
}

.item-content {
    aspect-ratio: auto;
    min-height: 0;
}

.item-content img {
    height: auto;
}

.gallery-item.with-video .item-content {
    min-height: 0;
    aspect-ratio: var(--media-ratio, 9 / 16);
}

.gallery-message {
    display: block;
    width: 100%;
    column-span: all;
}

@media (max-width: 720px) {
    .gallery-grid {
        column-width: 150px;
        column-gap: 8px;
    }

    .gallery-item {
        margin-bottom: 8px;
    }
}

dialog.lightbox {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 2rem;
    border: 0;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

dialog.lightbox:not([open]) {
    display: none;
}

dialog.lightbox[open] {
    display: flex;
}

dialog.lightbox::backdrop {
    background: var(--overlay-strong);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
}
