/**
 * Gallery + lightbox – one component for the feature block ("Bildergalerie + Text")
 * and the escape room pages (template-parts/content/gallery.php, JS in main.js).
 */

/* Gallery: one large + two or three small, opens the lightbox */
.aw-gallery {
  position: relative;
  display: grid;
  grid-template-columns: 2fr 1fr;
  grid-template-rows: repeat(3, 1fr);
  gap: 6px;
  aspect-ratio: 5 / 4;
}
.aw-gallery--wide { aspect-ratio: 16 / 9; }   /* Full width (escape rooms) */
/* Colour glow behind the images */
.aw-gallery::before {
  content: "";
  position: absolute;
  inset: 8% -6% -10% 10%;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--c) 45%, transparent), transparent);
  filter: blur(50px);
}
.aw-gallery__item {
  position: relative;
  display: block;
  overflow: hidden;
  border-radius: var(--aw-radius-s);
  background: var(--aw-ink);
  cursor: zoom-in;
}
.aw-gallery__item:first-child { grid-row: 1 / -1; }
.aw-gallery--3 { grid-template-rows: repeat(2, 1fr); }
.aw-gallery--1 { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.aw-gallery__item img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.aw-gallery__item::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 3px;
  background: var(--c);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--aw-dur) var(--aw-ease-out);
}
/* Zoom on hover only with a mouse: on touch screens it would stick after a tap */
@media (hover: hover) {
  .aw-gallery__item img { transition: transform 1s var(--aw-ease-out); }
  .aw-gallery__item:hover img { transform: scale(1.06); }
  .aw-gallery__item:hover::after { transform: none; }
}
.aw-gallery__item:focus-visible img { transform: scale(1.06); }
.aw-gallery__item:focus-visible::after { transform: none; }
.aw-gallery__item:focus-visible { outline-offset: -3px; }

/* Entrance: when the gallery comes into view, its photos fade in one after the other
   (each waits for its file; JS loads them all early, so swiping never waits) */
.js .aw-gallery__item {
  opacity: 0;
  translate: 0 14px;
  transition: opacity .8s var(--aw-ease-out), translate .8s var(--aw-ease-out);
  transition-delay: calc(var(--i, 0) * .1s);
}
.js .aw-gallery__item.is-in { opacity: 1; translate: none; }

@media (max-width: 900px) {
  /* Mobile: swipeable row, like the v1 carousel. Photos line up with the page edge, the next one peeks in. */
  .aw-gallery {
    display: flex;
    aspect-ratio: auto;
    gap: 8px;
    margin-inline: calc(-1 * var(--aw-gutter));
    padding-inline: var(--aw-gutter);
    scroll-padding-inline: var(--aw-gutter);
    overflow: auto hidden;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
  }
  .aw-gallery::-webkit-scrollbar { display: none; }
  .aw-gallery::before { display: none; }   /* Blurred glow inside a scrolling row repaints on every swipe */
  .aw-gallery__item { flex: 0 0 86%; aspect-ratio: 5 / 4; scroll-snap-align: start; }
  .js .aw-gallery__item:not(:first-child) { transition-delay: 0s; }   /* Off screen anyway */
}

/* Lightbox ---------------------------------------------------------------- */
/* A swipe track with all photos of the gallery: swipe or arrows to browse, swipe down,
   Esc, × or a tap beside the photo to close. Fades in and out; the page behind is locked. */
html.aw-lightbox-open { overflow: hidden; }
.aw-lightbox {
  --dy: 0px;
  width: 100vw; height: 100dvh;
  max-width: none; max-height: none;
  margin: 0; padding: 0;
  border: 0;
  overflow: hidden;
  overscroll-behavior: contain;
  background: rgb(0 0 0 / .94);
  color: var(--aw-white);
  opacity: 0;
  transition: opacity .4s var(--aw-ease-out), background-color .3s;
}
.aw-lightbox.is-open { opacity: 1; }
.aw-lightbox::backdrop { background: transparent; }
.aw-lightbox[open] { display: block; }
.aw-lightbox__track {
  display: flex;
  height: 100%;
  overflow: auto hidden;
  overscroll-behavior: contain;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  touch-action: pan-x pinch-zoom;   /* Vertical drags are ours: swipe down closes */
  translate: 0 var(--dy);
  transition: translate .35s var(--aw-ease-out);
}
.aw-lightbox__track::-webkit-scrollbar { display: none; }
.aw-lightbox__slide {
  flex: 0 0 100%;
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  padding: 4.5rem 5.5rem;
  scroll-snap-align: center;
  scroll-snap-stop: always;
}
.aw-lightbox__slide img {
  max-width: min(100%, 1400px);
  max-height: 100%;
  width: auto; height: auto;
  border-radius: var(--aw-radius-s);
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  scale: .96;
  transition: scale .5s var(--aw-ease-out);
}
.aw-lightbox.is-open .aw-lightbox__slide img { scale: 1; }
.aw-lightbox.is-dragging { background-color: rgb(0 0 0 / .6); }
.aw-lightbox.is-dragging .aw-lightbox__track { transition: none; }

.aw-lightbox__btn {
  position: absolute;
  z-index: 1;
  display: grid; place-items: center;
  width: 52px; height: 52px;
  border: 1px solid var(--aw-line);
  border-radius: 50%;
  background: rgb(0 0 0 / .5);
  color: var(--aw-white);
  cursor: pointer;
  transition: background var(--aw-dur-fast), color var(--aw-dur-fast), opacity var(--aw-dur-fast);
}
.aw-lightbox__btn svg { width: 22px; height: 22px; }
.aw-lightbox__btn:disabled { opacity: .3; cursor: default; }
@media (hover: hover) {
  .aw-lightbox__btn:not(:disabled):hover { background: var(--aw-white); color: var(--aw-black); }
}
.aw-lightbox__close { top: max(1rem, env(safe-area-inset-top)); right: max(1rem, env(safe-area-inset-right)); }
/* Arrows at the sides, centred on the photo */
.aw-lightbox__prev,
.aw-lightbox__next { top: 50%; translate: 0 -50%; }
.aw-lightbox__prev { left: max(1rem, env(safe-area-inset-left)); }
.aw-lightbox__next { right: max(1rem, env(safe-area-inset-right)); }
.aw-lightbox__count {
  position: absolute; left: 50%; bottom: max(1.5rem, env(safe-area-inset-bottom)); translate: -50% 0;
  color: var(--aw-mute);
  font-size: var(--aw-step--1);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.aw-lightbox--single :is(.aw-lightbox__prev, .aw-lightbox__next, .aw-lightbox__count) { display: none; }

/* Touch screens: swipe instead of arrows, photo uses the full width */
@media (hover: none) and (pointer: coarse), (max-width: 700px) {
  .aw-lightbox__slide { padding: 4.25rem .75rem 4.5rem; }
}
@media (hover: none) and (pointer: coarse) {
  .aw-lightbox__prev, .aw-lightbox__next { display: none; }
}
