/**
 * Галерея и просмотр изображений (ТЗ §42–43; часть 4, §42).
 *
 * Компонент общий: полки галереи игры и просмотрщик, которым пользуется
 * и Wiki. Раньше `.lightbox` жил внутри `pages/wiki.css` — теперь лежит
 * здесь, потому что просмотр картинок нужен не одному разделу.
 *
 * Все значения — через переменные `tokens.css`.
 */

.gallery-shelf {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.gallery-shelf + .gallery-shelf {
    margin-top: var(--space-7);
}

.gallery-shelf__head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-2) var(--space-4);
}

.gallery-shelf__title {
    margin: 0;
    font-size: var(--fs-h4);
    font-weight: var(--fw-bold);
}

.gallery-shelf__hint {
    margin: 0;
    font-size: var(--fs-small);
    color: var(--text-secondary);
}

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--space-4);
}

.gallery__cell {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin: 0;
}

.gallery__item {
    display: block;
    overflow: hidden;
    border: 1px solid var(--border-card);
    border-radius: var(--radius-md);
    background: var(--bg-soft);
    aspect-ratio: 16 / 10;
}

.gallery__item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--t-base) var(--ease);
}

.gallery__item:hover img {
    transform: scale(1.04);
}

.gallery__caption {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-2);
    font-size: var(--fs-micro);
    color: var(--text-secondary);
}

.gallery__credit {
    color: var(--text-muted);
}

.gallery__credit a {
    color: var(--text-muted);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.gallery__credit a:hover {
    color: var(--primary);
}

/* ── Просмотр изображения ────────────────────────────────────────── */

.lightbox {
    position: fixed;
    inset: 0;
    z-index: var(--z-dialog);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    padding: var(--space-6);
    background: var(--bg-backdrop);
    backdrop-filter: blur(2px);
}

.lightbox[hidden] {
    display: none;
}

.lightbox__image {
    max-width: min(1100px, 92vw);
    max-height: 78vh;
    border-radius: var(--radius-card);
    background: var(--bg-card);
    object-fit: contain;
}

.lightbox__caption {
    max-width: 640px;
    margin: 0;
    color: var(--text-invert);
    font-size: var(--fs-small);
    text-align: center;
}

.lightbox__close,
.lightbox__nav {
    position: absolute;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    box-shadow: var(--shadow-pop);
}

.lightbox__close {
    top: var(--space-5);
    right: var(--space-5);
}

.lightbox__nav--prev {
    left: var(--space-4);
}

.lightbox__nav--next {
    right: var(--space-4);
}

@media (max-width: 768px) {
    .gallery {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: var(--space-3);
    }

    /* Листать на телефоне удобнее свайпом и по кадрам списка,
       а стрелки поверх картинки только закрывают её. */
    .lightbox__nav {
        display: none;
    }
}
