/* Gallery pages — scroll inside dedicated container (works on mobile + desktop) */
body.page-gallery {
  margin: 0;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  touch-action: pan-y;
}

.gallery-scroll {
  position: fixed;
  inset: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  scroll-behavior: smooth;
  scroll-padding-top: 88px;
  scrollbar-width: auto;
  scrollbar-color: #c4c4c4 #4a4a4a;
}

.gallery-scroll::-webkit-scrollbar {
  width: 16px;
}

.gallery-scroll::-webkit-scrollbar-track {
  background: #4a4a4a;
}

.gallery-scroll::-webkit-scrollbar-thumb {
  background: #c4c4c4;
  border: 2px solid #4a4a4a;
  border-radius: 8px;
}

.gallery-scroll::-webkit-scrollbar-thumb:hover {
  background: #dcdcdc;
}

.gallery-scroll::-webkit-scrollbar-button:single-button:vertical:decrement,
.gallery-scroll::-webkit-scrollbar-button:single-button:vertical:increment {
  display: block;
  height: 16px;
  background-color: #4a4a4a;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 8px 8px;
}

.gallery-scroll::-webkit-scrollbar-button:single-button:vertical:decrement {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'%3E%3Cpath fill='%23bdbdbd' d='M4 1.5 7 6.5H1Z'/%3E%3C/svg%3E");
}

.gallery-scroll::-webkit-scrollbar-button:single-button:vertical:increment {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'%3E%3Cpath fill='%23bdbdbd' d='M1 1.5h6L4 6.5Z'/%3E%3C/svg%3E");
}

body.page-gallery .header {
  position: sticky;
  top: 0;
  left: auto;
  right: auto;
}

.gallery-page {
  background: var(--black);
  color: var(--white);
  padding: 32px 32px 48px;
  min-height: auto;
}

@media (min-width: 1200px) {
  .gallery-page {
    padding-left: 32px;
  }
}

.gallery-page__header {
  max-width: var(--content-max);
  margin: 0 auto 40px;
}

.gallery-page__header h1 {
  font-size: clamp(28px, 4vw, 40px);
  font-weight: 800;
  margin-bottom: 12px;
}

.gallery-page__header p {
  color: var(--grey);
  max-width: 640px;
  line-height: 1.6;
}

.gallery-page__back {
  display: inline-block;
  margin-bottom: 24px;
  font-size: 13px;
  color: var(--grey);
  transition: color var(--transition);
}

.gallery-page__back:hover {
  color: var(--white);
}

.gallery-grid {
  max-width: var(--content-max);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}

.gallery-grid.gallery-grid--1 {
  grid-template-columns: 1fr;
  justify-items: center;
}

.gallery-grid.gallery-grid--1 .gallery-grid__item,
.gallery-grid.gallery-grid--1 .gallery-cat {
  width: min(760px, 100%);
  max-width: 760px;
  aspect-ratio: 4 / 3;
}

@media (min-width: 540px) {
  .gallery-grid.gallery-grid--2,
  .gallery-grid.gallery-grid--4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .gallery-grid.gallery-grid--6 {
    grid-template-columns: repeat(2, 1fr);
  }

  /* 3 items: inverted triangle — two on top, one centered below */
  .gallery-grid.gallery-grid--3 {
    grid-template-columns: repeat(2, 1fr);
  }

  .gallery-grid.gallery-grid--3 > :nth-child(3) {
    grid-column: 1 / -1;
    width: calc((100% - 20px) / 2);
    max-width: calc((100% - 20px) / 2);
    justify-self: center;
  }

  /* 5 items: pyramid — three on top, two centered below */
  .gallery-grid.gallery-grid--5 {
    grid-template-columns: repeat(6, 1fr);
  }

  .gallery-grid.gallery-grid--5 > :nth-child(1) {
    grid-column: 1 / 3;
  }

  .gallery-grid.gallery-grid--5 > :nth-child(2) {
    grid-column: 3 / 5;
  }

  .gallery-grid.gallery-grid--5 > :nth-child(3) {
    grid-column: 5 / 7;
  }

  .gallery-grid.gallery-grid--5 > :nth-child(4) {
    grid-column: 2 / 4;
  }

  .gallery-grid.gallery-grid--5 > :nth-child(5) {
    grid-column: 4 / 6;
  }
}

@media (min-width: 768px) {
  .gallery-grid.gallery-grid--6 {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Category cards (click to enter) */
.gallery-cat {
  position: relative;
  aspect-ratio: 4/3;
  overflow: hidden;
  border-radius: 4px;
  border: 1px solid var(--border);
  display: block;
  background: var(--dark-card);
  transition: border-color var(--transition), transform var(--transition);
}

.gallery-cat:hover {
  border-color: rgba(255, 255, 255, 0.35);
  transform: translateY(-3px);
}

.gallery-cat img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease, filter 0.5s ease;
  filter: brightness(0.75);
}

.gallery-cat:hover img {
  transform: scale(1.06);
  filter: brightness(0.9);
}

.gallery-cat__overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 20px;
  background: linear-gradient(transparent 30%, rgba(0, 0, 0, 0.92));
}

.gallery-cat__title {
  font-size: 15px;
  font-weight: 700;
  color: var(--white);
  width: 100%;
}

.gallery-cat__desc {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 6px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  width: calc(100% - 28px);
}

.gallery-cat__arrow {
  position: absolute;
  right: 20px;
  bottom: 20px;
  font-size: 20px;
  color: var(--white);
  opacity: 0;
  transform: translateX(-8px);
  transition: opacity var(--transition), transform var(--transition);
}

.gallery-cat:hover .gallery-cat__arrow {
  opacity: 1;
  transform: translateX(0);
}

/* Photo grid items */
.gallery-grid__item {
  position: relative;
  aspect-ratio: 4/3;
  overflow: hidden;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--dark-card);
  cursor: zoom-in;
}

.gallery-grid__item:focus-visible {
  outline: 2px solid var(--white);
  outline-offset: 2px;
}

.gallery-grid__item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease, filter 0.5s ease;
  filter: brightness(0.85);
}

.gallery-grid__item:hover img {
  transform: scale(1.06);
  filter: brightness(1);
}

.gallery-grid__caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 16px;
  background: linear-gradient(transparent, rgba(0,0,0,0.9));
  font-size: 13px;
  font-weight: 600;
  pointer-events: none;
}

/* Lightbox */
.gallery-lightbox {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.92);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.gallery-lightbox.is-open {
  opacity: 1;
  visibility: visible;
}

.gallery-lightbox__close {
  position: absolute;
  top: 20px;
  right: 24px;
  z-index: 2;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.5);
  color: var(--white);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.gallery-lightbox__close:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.45);
}

.gallery-lightbox__figure {
  max-width: min(1200px, 100%);
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.gallery-lightbox__figure img {
  max-width: 100%;
  max-height: calc(100vh - 120px);
  max-height: calc(100dvh - 120px);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

.gallery-lightbox__figure figcaption {
  color: var(--white);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  max-width: 720px;
  line-height: 1.5;
}

.gallery-lightbox__figure figcaption:empty {
  display: none;
}
