/* Плитка фотографий и просмотрщик.
 *
 * Раскладку Тильды (t827) перекрываем своей CSS-сеткой: её скрипт при каждом
 * ресайзе пересчитывает ширину ячеек инлайном, поэтому все наши правила идут
 * с !important — обычное объявление в атрибуте style проигрывает !important
 * из таблицы стилей, и сетка остаётся нашей.
 *
 * Сами фотографии не трогаем: меняется только раскладка и поведение по клику.
 */

/* --- плитка ---------------------------------------------------------------- */

.t827__grid.theater-gallery {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    grid-auto-rows: 190px !important;
    grid-auto-flow: dense !important;      /* дырки от крупной плитки затягиваются */
    gap: 10px !important;
    height: auto !important;
    position: static !important;
}

.theater-gallery .t827__grid-item {
    width: auto !important;
    height: auto !important;
    position: static !important;
    left: auto !important;
    top: auto !important;
    margin: 0 !important;
    overflow: hidden;
    cursor: zoom-in;
    background-color: #ececec;
}

.theater-gallery .t827__grid-item img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
    display: block;
    transition: transform .35s ease;
}

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

.theater-gallery .t827__grid-item:hover img { transform: scale(1.04); }

/* Крупная плитка: вдвое шире и вдвое выше обычной. Колонку задаёт
   build/patch-gallery.mjs — она своя у каждого спектакля, но раз и навсегда. */
.theater-gallery .t827__grid-item_hero {
    grid-column: span 2 !important;
    grid-row: span 2 !important;
}
.theater-gallery .t827__grid-item_hero.theater-hero_1 { grid-column: 1 / span 2 !important; }
.theater-gallery .t827__grid-item_hero.theater-hero_2 { grid-column: 2 / span 2 !important; }
.theater-gallery .t827__grid-item_hero.theater-hero_3 { grid-column: 3 / span 2 !important; }

@media screen and (max-width: 960px) {
    .t827__grid.theater-gallery {
        grid-template-columns: repeat(2, 1fr) !important;
        grid-auto-rows: 160px !important;
    }
    /* На двух колонках крупная плитка занимает всю ширину — привязку к
       конкретной колонке снимаем, иначе сетка ломается. */
    .theater-gallery .t827__grid-item_hero,
    .theater-gallery .t827__grid-item_hero.theater-hero_1,
    .theater-gallery .t827__grid-item_hero.theater-hero_2,
    .theater-gallery .t827__grid-item_hero.theater-hero_3 {
        grid-column: 1 / span 2 !important;
    }
}

@media screen and (max-width: 560px) {
    .t827__grid.theater-gallery { grid-auto-rows: 130px !important; }
}

/* --- просмотрщик ----------------------------------------------------------- */

.theater-viewer {
    position: fixed;
    inset: 0;
    z-index: 100000;
    /* Плотный, а не полупрозрачный: сквозь 96% просвечивал светлый логотип
       в шапке — она зафиксирована и остаётся под просмотрщиком. */
    background: #100e12;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s ease, visibility .2s ease;
    font-family: 'Montserrat', Arial, sans-serif;
}

.theater-viewer_open { opacity: 1; visibility: visible; }

@media (prefers-reduced-motion: reduce) {
    .theater-viewer { transition: none; }
}

.theater-viewer__bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    color: #fff;
}

.theater-viewer__count {
    font-size: 13px;
    letter-spacing: .04em;
    opacity: .7;
    font-variant-numeric: tabular-nums;
    margin-right: auto;
}

.theater-viewer__btn {
    appearance: none;
    border: 1px solid rgba(255, 255, 255, .25);
    background: rgba(255, 255, 255, .06);
    color: #fff;
    border-radius: 3px;
    padding: 7px 12px;
    font: 500 12px/1.2 'Montserrat', Arial, sans-serif;
    letter-spacing: .04em;
    cursor: pointer;
    white-space: nowrap;
}

.theater-viewer__btn:hover { background: rgba(255, 255, 255, .16); }
.theater-viewer__btn:focus-visible { outline: 2px solid #e02d3c; outline-offset: 2px; }
.theater-viewer__btn[disabled] { opacity: .4; cursor: default; }
.theater-viewer__btn_done { border-color: #6fbf94; color: #6fbf94; }

.theater-viewer__stage {
    flex: 1 1 auto;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
}

.theater-viewer__img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
    transform-origin: center center;
    cursor: zoom-in;
}

.theater-viewer__img_zoomed { cursor: grab; }
.theater-viewer__img_dragging { cursor: grabbing; }

.theater-viewer__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, .25);
    background: rgba(20, 18, 22, .55);
    color: #fff;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theater-viewer__nav:hover { background: rgba(20, 18, 22, .85); }
.theater-viewer__nav:focus-visible { outline: 2px solid #e02d3c; outline-offset: 2px; }
.theater-viewer__nav_prev { left: 16px; }
.theater-viewer__nav_next { right: 16px; }
.theater-viewer__nav[hidden] { display: none; }

.theater-viewer__strip {
    flex: 0 0 auto;
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    overflow-x: auto;
    scrollbar-width: thin;
}

.theater-viewer__thumb {
    flex: 0 0 auto;
    width: 84px;
    height: 56px;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 2px;
    background: none;
    cursor: pointer;
    opacity: .5;
}

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

.theater-viewer__thumb_current { border-color: #e02d3c; opacity: 1; }
.theater-viewer__thumb:hover { opacity: 1; }
.theater-viewer__thumb:focus-visible { outline: 2px solid #e02d3c; outline-offset: 2px; }

@media screen and (max-width: 560px) {
    .theater-viewer__thumb { width: 64px; height: 44px; }
    .theater-viewer__nav { width: 42px; height: 42px; }
    .theater-viewer__btn { padding: 7px 9px; font-size: 11px; }
}

/* Пока просмотрщик открыт, страница под ним не прокручивается. */
body.theater-viewer-open { overflow: hidden; }
