.detail-gallery {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-auto-rows: 138px;
    gap: 8px;
}

.detail-gallery__figure { min-width: 0; margin: 0; }
.detail-gallery__figure:first-child { grid-column: span 2; grid-row: span 2; }

.detail-gallery__item {
    width: 100%;
    height: 100%;
    display: block;
    position: relative;
    overflow: hidden;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-accent-soft);
    padding: 0;
    cursor: zoom-in;
    color: #fff;
    font: inherit;
    text-decoration: none;
}

.detail-gallery__item img {
    width: 100%;
    height: 100%;
    min-height: 0;
    border: 0;
    border-radius: 0;
    object-fit: cover;
    transition: transform 180ms ease;
}

.detail-gallery__item:hover img { transform: scale(1.025); }
.detail-gallery__item:focus-visible { outline: 3px solid var(--color-accent); outline-offset: 2px; }
.detail-gallery__index,
.detail-gallery__open {
    position: absolute;
    border-radius: 6px;
    background: rgba(24, 32, 42, 0.78);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 7px;
}
.detail-gallery__index { top: 7px; left: 7px; min-width: 24px; text-align: center; }
.detail-gallery__open { right: 7px; bottom: 7px; }

.photo-viewer-open { overflow: hidden; }

.photo-viewer {
    width: min(1180px, calc(100vw - 32px));
    height: min(860px, calc(100vh - 32px));
    height: min(860px, calc(100dvh - 32px));
    max-width: none;
    max-height: none;
    overflow: hidden;
    border: 0;
    border-radius: 12px;
    background: #141a21;
    color: #fff;
    padding: 0;
    box-shadow: 0 24px 70px rgba(13, 18, 24, 0.42);
}

.photo-viewer::backdrop {
    background: rgba(12, 16, 22, 0.82);
    backdrop-filter: blur(3px);
}

.photo-viewer__frame {
    height: 100%;
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
}

.photo-viewer__header,
.photo-viewer__footer {
    min-height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: #202832;
    padding: 10px 14px;
}

.photo-viewer__header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.photo-viewer__header strong {
    font-size: 14px;
    letter-spacing: 0.01em;
}

.photo-viewer__close,
.photo-viewer__nav,
.photo-viewer__zoom button {
    display: inline-grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: #313c48;
    color: #fff;
    cursor: pointer;
    font: inherit;
}

.photo-viewer__close {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    font-size: 27px;
    line-height: 1;
}

.photo-viewer__stage {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr) 54px;
    align-items: stretch;
    background: #10151b;
}

.photo-viewer__viewport {
    min-width: 0;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    touch-action: pan-x pan-y pinch-zoom;
    scrollbar-color: #586777 #171e26;
}

.photo-viewer__canvas {
    min-width: 100%;
    min-height: 100%;
    position: relative;
}

.photo-viewer__canvas img {
    position: absolute;
    top: 50%;
    left: 50%;
    display: block;
    max-width: none;
    max-height: none;
    object-fit: contain;
    transform: translate(-50%, -50%);
    user-select: none;
    -webkit-user-drag: none;
}

.photo-viewer__nav {
    width: 42px;
    height: 56px;
    align-self: center;
    justify-self: center;
    border-radius: 10px;
    font-size: 36px;
    line-height: 1;
}

.photo-viewer__nav[hidden] {
    visibility: hidden;
    pointer-events: none;
}

.photo-viewer__footer {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.photo-viewer__zoom {
    display: inline-grid;
    grid-template-columns: 40px 70px 40px;
    gap: 6px;
}

.photo-viewer__zoom button {
    min-height: 38px;
    border-radius: 8px;
    font-size: 18px;
    font-weight: 700;
}

.photo-viewer__zoom button:nth-child(2) {
    font-size: 12px;
}

.photo-viewer__close:hover,
.photo-viewer__nav:hover,
.photo-viewer__zoom button:hover:not(:disabled) {
    border-color: rgba(255, 255, 255, 0.36);
    background: #43505e;
}

.photo-viewer__close:focus-visible,
.photo-viewer__nav:focus-visible,
.photo-viewer__zoom button:focus-visible {
    outline: 3px solid #efad91;
    outline-offset: 2px;
}

.photo-viewer__zoom button:disabled {
    cursor: default;
    opacity: 0.42;
}

.photo-viewer__hint {
    color: #bcc5ce;
    font-size: 12px;
    text-align: right;
}

@media (max-width: 700px) {
    .detail-gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: 112px; }
    .detail-gallery__figure:first-child { grid-column: span 2; grid-row: span 2; }

    .photo-viewer {
        width: calc(100vw - 12px);
        height: calc(100vh - 12px);
        height: calc(100dvh - 12px);
        border-radius: 10px;
    }

    .photo-viewer__header,
    .photo-viewer__footer {
        min-height: 54px;
        padding: 8px 10px;
    }

    .photo-viewer__stage {
        grid-template-columns: 42px minmax(0, 1fr) 42px;
    }

    .photo-viewer__nav {
        width: 34px;
        height: 52px;
        border-radius: 8px;
        font-size: 31px;
    }

    .photo-viewer__zoom {
        grid-template-columns: 38px 64px 38px;
        gap: 5px;
    }

    .photo-viewer__hint { display: none; }
}
