/* Галерея поездки (stories.js). На компьютере — коллаж в своей колонке, клик открывает просмотр во весь экран
   в <dialog>; на телефоне — сторис прямо в потоке страницы: карточка 9:16, полоски сверху, автолистание.
   Разметку даёт макрос gallery в macros.njk; полоски, кнопки и диалог строит stories.js.
   Режим сторис — класс .is-stories на корне (сама галерея на телефоне или сцена диалога на компьютере). */

/* ---------- общее для всех режимов ---------- */
.gallery { position: relative; }
.gallery__list { list-style: none; margin: 0; padding: 0; }
.gallery__item { position: relative; margin: 0; }
.gallery__shot { position: absolute; inset: 0; margin: 0; overflow: hidden; }
.gallery__shot picture { display: block; width: 100%; height: 100%; }
.gallery__shot img { display: block; width: 100%; height: 100%; object-fit: cover; -webkit-user-drag: none; }
/* горизонтальный кадр в вертикальной карточке вписываем целиком, а не режем до узкой полосы */
.gallery__item.is-wide img { object-fit: contain; }
/* подпись снимка внизу на мягком затемнении (в коллаже скрыта — её покажет просмотр) */
.gallery__cap { position: absolute; z-index: 1; left: 0; right: 0; bottom: 0; margin: 0; padding: 72px 18px 20px; font: 600 15px/1.35 var(--body); color: var(--white); text-shadow: 0 1px 2px rgba(0, 0, 0, .4); background: linear-gradient(180deg, rgba(0, 0, 0, 0), rgba(0, 0, 0, .58)); pointer-events: none; transition: opacity .25s; }
.gallery__item--need .gallery__cap { padding-top: 20px; color: var(--muted); text-shadow: none; background: none; }
/* кадр-видео: ролик лежит поверх постера и проявляется, когда пошёл первый кадр (без чёрной вспышки) */
.gallery__video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .25s; pointer-events: none; }
.gallery__video.is-playing { opacity: 1; }
/* значок «видео» на постере: в коллаже и пока ролик не пошёл */
.gallery__play { position: absolute; z-index: 1; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(20, 24, 22, .5); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); pointer-events: none; transition: opacity .2s; }
.gallery__play::before { content: ""; position: absolute; left: 50%; top: 50%; margin: -10px 0 0 -6px; border-style: solid; border-width: 10px 0 10px 16px; border-color: transparent transparent transparent var(--white); }
.gallery__video.is-playing + .gallery__play { opacity: 0; }
/* ролик качается: вокруг значка бежит дуга, чтобы стоящая полоска не выглядела зависанием. Появляется через
   0,4 с — если ролик стартует быстро, кольцо не мигает */
.gallery__play::after { content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 2px solid transparent; border-top-color: var(--white); opacity: 0; transition: opacity .2s; }
.gallery__video.is-loading + .gallery__play::after { opacity: 1; transition-delay: .4s; animation: stories-spin .9s linear infinite; }
@keyframes stories-spin { to { transform: rotate(360deg); } }
/* заглушка «Нужно фото»: кремовая карточка с пунктирной рамкой, в ней написано, что снять */
.gallery__need { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 24px 20px; text-align: center; background: linear-gradient(160deg, var(--cream), var(--sand)); color: var(--ink); }
.gallery__need::before { content: ""; position: absolute; inset: 10px; border: 1.5px dashed rgba(139, 43, 43, .6); border-radius: 10px; pointer-events: none; }
.gallery__need .ic { width: 36px; height: 36px; margin-bottom: 4px; color: var(--accent); }
.gallery__need b { font: 700 16px/1.2 var(--body); }
.gallery__need span { max-width: 30ch; font-size: 14px; line-height: 1.4; color: var(--muted); }

/* ---------- компьютер: коллаж ---------- */
@media (min-width: 901px) {
  /* 4 колонки: первый снимок 2×2, остальные 1×1 — видно до пяти; высота рядов идёт от пропорции 4:5 малых
     плиток, а плитки растянуты по ряду (align-self: stretch сильнее aspect-ratio), поэтому ряды ровные */
  .gallery .gallery__list { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; border-radius: 14px; overflow: hidden; }
  .gallery .gallery__item { align-self: stretch; aspect-ratio: 4 / 5; overflow: hidden; background: #D9D4C8; cursor: zoom-in; }
  .gallery .gallery__item:first-child { grid-column: span 2; grid-row: span 2; aspect-ratio: auto; }
  .gallery .gallery__item:nth-child(n + 6) { display: none; }
  /* один снимок — просто кадр 4:5 на всю колонку */
  .gallery .gallery__item:first-child:last-child { grid-column: 1 / -1; grid-row: auto; aspect-ratio: 4 / 5; }
  /* два снимка — два портрета рядом */
  .gallery .gallery__item:first-child:nth-last-child(2), .gallery .gallery__item:first-child:nth-last-child(2) ~ .gallery__item { grid-column: span 2; grid-row: span 2; aspect-ratio: 4 / 5; }
  /* три — большой и два горизонтальных друг под другом; четыре — последний горизонтальный, чтобы не было дыры */
  .gallery .gallery__item:first-child:nth-last-child(3) ~ .gallery__item, .gallery .gallery__item:first-child:nth-last-child(4) ~ .gallery__item:last-child { grid-column: span 2; aspect-ratio: 8 / 5; }
  .gallery .gallery__item.is-wide img { object-fit: cover; }
  .gallery .gallery__item img { transition: transform .7s cubic-bezier(.2, .7, .2, 1); }
  .gallery .gallery__item:hover img { transform: scale(1.035); }
  /* подпись плитки показываем при наведении (и при фокусе на кнопке «Все фото»); на плитке с «+N фото» её нет */
  .gallery .gallery__cap { --cap-dy: 6px; padding: 36px 12px 10px; font-size: 13px; line-height: 1.3; opacity: 0; transform: translateY(var(--cap-dy)); transition: opacity .25s, transform .25s; }
  .gallery .gallery__item:hover .gallery__cap, .gallery .gallery__item:focus-within .gallery__cap { opacity: 1; transform: none; }
  /* на плитке с круглой кнопкой подпись сверху, чтобы не ложиться на кнопку */
  .gallery .gallery__item:has(> .gallery__all:not(.gallery__all--more)) .gallery__cap { --cap-dy: -6px; top: 0; bottom: auto; padding: 10px 12px 36px; background: linear-gradient(180deg, rgba(0, 0, 0, .58), rgba(0, 0, 0, 0)); }
  .gallery .gallery__item--need:has(> .gallery__all:not(.gallery__all--more)) .gallery__cap { background: none; }
  .gallery .gallery__item:has(> .gallery__all--more) .gallery__cap { display: none; }
  .gallery .gallery__need { gap: 4px; padding: 16px; }
  .gallery .gallery__need::before { inset: 8px; }
  .gallery .gallery__need .ic { width: 28px; height: 28px; margin: 0; }
  .gallery .gallery__need b { font-size: 13px; }
  .gallery .gallery__need span { display: none; }
  /* на больших плитках (первая и обе при двух снимках) заглушка с описанием кадра */
  .gallery .gallery__item:first-child .gallery__need, .gallery .gallery__item:first-child:nth-last-child(2) ~ .gallery__item .gallery__need { gap: 8px; }
  .gallery .gallery__item:first-child .gallery__need .ic, .gallery .gallery__item:first-child:nth-last-child(2) ~ .gallery__item .gallery__need .ic { width: 36px; height: 36px; }
  .gallery .gallery__item:first-child .gallery__need b, .gallery .gallery__item:first-child:nth-last-child(2) ~ .gallery__item .gallery__need b { font-size: 16px; }
  .gallery .gallery__item:first-child .gallery__need span, .gallery .gallery__item:first-child:nth-last-child(2) ~ .gallery__item .gallery__need span { display: block; }
  /* кнопка «Все фото» в последней видимой плитке; если снимков больше пяти — поверх пятой «+N фото» */
  .gallery__all { position: absolute; z-index: 2; right: 10px; bottom: 10px; display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 14px; border: 0; border-radius: 999px; background: rgba(30, 42, 38, .84); color: var(--cream); font: 700 13px/1 var(--body); white-space: nowrap; cursor: pointer; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); transition: background .2s; }
  .gallery__all:hover { background: var(--ink); }
  /* надпись на узкой плитке (колонка 901–1100px даёт плитку ~100px) ужимается и при нужде переносится на две строки */
  .gallery__all--more { inset: 0; justify-content: center; padding: 0 6px; border-radius: 0; background: rgba(20, 24, 22, .52); color: var(--white); font: 800 clamp(14px, 1.7vw, 20px)/1.1 var(--display); text-align: center; white-space: normal; -webkit-backdrop-filter: none; backdrop-filter: none; }
  .gallery__all--more:hover { background: rgba(20, 24, 22, .64); }
  .gallery__all--more:focus-visible { outline-color: var(--white); outline-offset: -5px; }
  /* пятая плитка — заглушка: камеру и «Нужно фото» под оверлеем прячем, сам оверлей светлый с надписью цвета акцента */
  .gallery .gallery__item--need:has(> .gallery__all--more) .gallery__need > * { visibility: hidden; }
  .gallery .gallery__item--need > .gallery__all--more { background: rgba(139, 43, 43, .07); color: var(--accent); }
  .gallery .gallery__item--need > .gallery__all--more:hover { background: rgba(139, 43, 43, .14); }
  .gallery .gallery__item--need > .gallery__all--more:focus-visible { outline-color: var(--accent); }
  .gallery__all .stories__ic { width: 16px; height: 16px; }
  /* на плитке коллажа значок видео меньше */
  .gallery .gallery__play { width: 36px; height: 36px; margin: -18px 0 0 -18px; }
  .gallery .gallery__play::before { margin: -7px 0 0 -4px; border-width: 7px 0 7px 11px; }
  /* одна обложка вместо коллажа (data-tiles="1", карточка экскурсии): кадр 4:5, в углу плашка «N фото» */
  .gallery[data-tiles="1"] .gallery__list { grid-template-columns: minmax(0, 1fr); }
  .gallery[data-tiles="1"] .gallery__item:first-child { grid-column: auto; grid-row: auto; aspect-ratio: 4 / 5; }
  .gallery[data-tiles="1"] .gallery__item:nth-child(n + 2) { display: none; }
}

/* ---------- телефон: карточка 9:16 ---------- */
@media (max-width: 900px) {
  .gallery { width: min(100%, calc(78vh * 9 / 16)); width: min(100%, calc(78svh * 9 / 16)); aspect-ratio: 9 / 16; margin-inline: auto; border-radius: 16px; overflow: hidden; background: #15191B; box-shadow: 0 18px 40px rgba(20, 16, 12, .18); }
  /* пока не отработал скрипт (или без него): лента со снапом по одному кадру */
  .gallery .gallery__list { position: absolute; inset: 0; display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
  .gallery .gallery__list::-webkit-scrollbar { display: none; }
  .gallery .gallery__item { flex: 0 0 100%; scroll-snap-align: start; }
  .gallery__all { display: none; }
}

/* ---------- сторис: встроенные на телефоне и в диалоге на компьютере ---------- */
.is-stories { position: relative; overflow: hidden; background: #15191B; color: var(--white); touch-action: pan-y; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
.is-stories .gallery__list { position: absolute; inset: 0; display: block; overflow: hidden; }
.is-stories .gallery__item { display: none; position: absolute; inset: 0; }
.is-stories .gallery__item.is-active { display: block; animation: stories-in .2s ease-out; }
@keyframes stories-in { from { opacity: 0; } }
.is-stories .gallery__all { display: none; }
.stories__ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.stories__ic--fill { fill: currentColor; stroke: none; }
/* полоски: прошедшие залиты, текущая заполняется за --stories-dur, будущие пустые */
.stories__bars { position: absolute; z-index: 3; left: 10px; right: 10px; top: 10px; display: flex; gap: 4px; pointer-events: none; }
.stories__bar { flex: 1 1 0; height: 2.5px; border-radius: 2px; background: rgba(255, 255, 255, .35); overflow: hidden; }
.stories__fill { display: block; width: 100%; height: 100%; border-radius: inherit; background: var(--white); transform: scaleX(0); transform-origin: 0 50%; }
.stories__bar.is-done .stories__fill { transform: scaleX(1); }
.stories__bar.is-now .stories__fill { animation: stories-fill var(--stories-dur, 4.5s) linear forwards; will-change: transform; }
.is-stories.is-paused .stories__fill { animation-play-state: paused; }
/* без автолистания (один снимок или меньше движения) текущая полоска просто залита */
.is-stories.is-still .stories__bar.is-now .stories__fill { animation: none; transform: scaleX(1); }
@keyframes stories-fill { from { transform: scaleX(0); } to { transform: scaleX(1); } }
/* шапка карточки: затемнение, метка как ник в Instagram и кнопка паузы */
.stories__top { position: absolute; z-index: 2; left: 0; right: 0; top: 0; height: 120px; background: linear-gradient(180deg, rgba(0, 0, 0, .5), rgba(0, 0, 0, 0)); pointer-events: none; transition: opacity .2s; }
/* на заглушке (кремовый фон) затемнение не нужно: метка и кнопка паузы тёмные, полоски цвета акцента */
.is-stories.is-need .stories__top { opacity: 0; }
.is-stories.is-need .stories__label { color: var(--ink); text-shadow: none; }
.is-stories.is-need .stories__pause { background: rgba(30, 42, 38, .08); color: var(--ink); }
.is-stories.is-need .stories__avatar { box-shadow: 0 0 0 2px var(--white); }
.is-stories.is-need .stories__bar { background: rgba(30, 42, 38, .16); }
.is-stories.is-need .stories__fill { background: var(--accent); }
.stories__head { position: absolute; z-index: 3; left: 12px; right: 8px; top: 22px; display: flex; align-items: center; gap: 10px; pointer-events: none; transition: opacity .25s; }
.stories__avatar { flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--white); box-shadow: 0 0 0 2px rgba(255, 255, 255, .8); }
.stories__label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 700 14px/1.2 var(--body); text-shadow: 0 1px 2px rgba(0, 0, 0, .45); }
.stories__pause { flex: none; display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; background: rgba(0, 0, 0, .25); color: var(--white); cursor: pointer; pointer-events: auto; }
.stories__pause[hidden] { display: none; }
.stories__pause .sp-play, .is-stories.is-user-paused .stories__pause .sp-pause { display: none; }
.is-stories.is-user-paused .stories__pause .sp-play { display: block; }
/* при долгом удержании подписи прячутся, чтобы рассмотреть кадр */
.is-stories.is-held .stories__head, .is-stories.is-held .gallery__cap { opacity: 0; }
/* зоны тапа на всю высоту: левая треть — назад, правые две трети — вперёд */
.stories__zone { position: absolute; z-index: 2; top: 0; bottom: 0; margin: 0; padding: 0; border: 0; background: transparent; color: inherit; cursor: pointer; }
.stories__zone--prev { left: 0; width: 33.4%; }
.stories__zone--next { right: 0; width: 66.6%; }
.stories__zone:focus-visible { outline: 2px solid var(--white); outline-offset: -6px; border-radius: 12px; }
.stories__pause:focus-visible { outline-color: var(--white); outline-offset: 2px; }
.stories__status { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- компьютер: просмотр во весь экран ---------- */
.gallery-dialog { position: fixed; inset: 0; width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; padding: 0; border: 0; background: transparent; color: var(--white); overflow: visible; }
.gallery-dialog[open] { display: flex; align-items: center; justify-content: center; gap: clamp(12px, 2vw, 28px); animation: gallery-dialog-in .25s ease both; }
.gallery-dialog::backdrop { background: rgba(14, 18, 18, .9); }
@keyframes gallery-dialog-in { from { opacity: 0; } }
/* карточка 9:16 почти во всю высоту экрана, по бокам стрелки */
.gallery-dialog__stage { width: min(calc((100vh - 56px) * 9 / 16), calc(100vw - 180px)); aspect-ratio: 9 / 16; border-radius: 16px; outline: none; }
.gallery-dialog__stage:focus-visible { outline: 2px solid rgba(255, 255, 255, .7); outline-offset: 4px; }
.gallery-dialog__arrow, .gallery-dialog__close { display: grid; place-items: center; width: 48px; height: 48px; padding: 0; border: 1px solid rgba(255, 255, 255, .22); border-radius: 50%; background: rgba(255, 255, 255, .08); color: var(--white); cursor: pointer; transition: background .2s; }
.gallery-dialog__arrow:hover, .gallery-dialog__close:hover { background: rgba(255, 255, 255, .2); }
.gallery-dialog.is-single .gallery-dialog__arrow { visibility: hidden; }
.gallery-dialog__close { position: absolute; right: 20px; top: 20px; }
.gallery-dialog .gallery-dialog__arrow .stories__ic, .gallery-dialog__close .stories__ic { width: 22px; height: 22px; }
.gallery-dialog :focus-visible { outline-color: var(--white); }
html:has(.gallery-dialog[open]) { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  /* ролики сами не играют — значок не обещает видео, остаётся постер */
  .gallery__play { display: none; }
  .gallery__video { transition: none; }
  .stories__bar.is-now .stories__fill { animation: none; transform: scaleX(1); }
  .is-stories .gallery__item.is-active, .gallery-dialog[open] { animation: none; }
  .gallery .gallery__item img, .gallery__all, .stories__top, .stories__head, .gallery__cap, .gallery-dialog__arrow, .gallery-dialog__close { transition: none; }
}
