/* =========================
   Gallery + Lightbox
   ========================= */

/* --- Tokens (fallbacks) --- */
:root{
  --gallery-radius: 6px;
  --gallery-gap: var(--space-sm, 18px);
  --gallery-shadow: 0 10px 24px rgba(0,0,0,.10);
}

/* =========================
   Lightbox
   ========================= */
.k-lightbox{
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.72);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease;
}

.k-lightbox.is-open{
  opacity: 1;
  pointer-events: auto;
}

.k-lightbox__panel{
  width: 90vw;
  height: min(90vh, 100vh);
  position: relative;
  transform: translateY(10px) scale(.98);
  transition: transform .22s ease;
}

.k-lightbox.is-open .k-lightbox__panel{
  transform: translateY(0) scale(1);
}

.k-lightbox__stage{
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  touch-action: pan-y;
}

.k-lightbox__img{
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: var(--gallery-radius);
  transform: translateX(0);
  transition: transform .26s ease;
  will-change: transform;
}

.k-lightbox__close{
  position: fixed;
  top: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 6px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  z-index: 10000;
}

.k-lightbox__close:hover{ background: rgba(0,0,0,0.70); }

.k-lightbox__prev,
.k-lightbox__next{
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: rgba(0,0,0,0.25);
  color: #fff;
  width: 64px;
  height: 64px;
  border-radius: 999px;
  cursor: pointer;
  padding: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
}

.k-lightbox__prev{ left: 16px; }
.k-lightbox__next{ right: 16px; }

.k-lightbox__prev:hover,
.k-lightbox__next:hover{
  background: rgba(0,0,0,0.40);
}

html.k-lightbox-open,
body.k-lightbox-open{ overflow: hidden; }

/* =========================
   Gallery
   ========================= */
.k-gallery{
  display: grid;
  gap: var(--gallery-gap);
}

.k-gallery__item{
  border-radius: var(--gallery-radius);
  overflow: hidden;
  display: block;
  position: relative;
  min-height: 200px;
  box-shadow: var(--gallery-shadow);
  border: 1px solid rgba(0,0,0,.06);
}

.k-gallery__item::before{
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--gallery-bg);
  background-size: cover;
  background-position: center;
  transform: scale(1);
  transition: transform .4s ease;
  will-change: transform;
}

@media (hover:hover){
  .k-gallery__item:hover::before{ transform: scale(1.06); }
}

/* Mobile: stack */
@media (max-width: 899px){
  .k-gallery{ grid-template-columns: 1fr; }
  .k-gallery__item{ height: clamp(220px, 43vw, 400px); }
}

/* Desktop layouts (900px+) */
@media (min-width: 900px){

  /* 1 */
  .k-gallery--1{ grid-template-columns: 1fr; }
  .k-gallery--1 .k-gallery__item{ min-height: clamp(420px, 45vw, 720px); }

  /* 2 */
  .k-gallery--2{ grid-template-columns: 2fr 1fr; }
  .k-gallery--2 .k-gallery__item{ min-height: clamp(420px, 45vw, 720px); }

  /* 3 */
  .k-gallery--3{
    grid-template-columns: 2fr 1fr;
    grid-template-rows: repeat(2, clamp(200px, 18vw, 320px));
  }
  .k-gallery--3 .k-gallery__item:nth-child(1){ grid-row: 1 / span 2; }

  /* 4 */
  .k-gallery--4{
    grid-template-columns: 2fr 1fr 1fr;
    grid-template-rows: repeat(2, clamp(200px, 27vw, 420px));
  }
  .k-gallery--4 .k-gallery__item:nth-child(1){ grid-column: 1; grid-row: 1 / span 2; }
  .k-gallery--4 .k-gallery__item:nth-child(2){ grid-column: 2 / span 2; grid-row: 1; }
  .k-gallery--4 .k-gallery__item:nth-child(3){ grid-column: 2; grid-row: 2; }
  .k-gallery--4 .k-gallery__item:nth-child(4){ grid-column: 3; grid-row: 2; }

  /* 5 */
  .k-gallery--5{
    grid-template-columns: 2fr 1fr 1fr;
    grid-template-rows: repeat(3, clamp(160px, 24vw, 300px));
  }
  .k-gallery--5 .k-gallery__item:nth-child(1){ grid-column: 1; grid-row: 1 / span 3; }
  .k-gallery--5 .k-gallery__item:nth-child(2){ grid-column: 2 / span 2; grid-row: 1; }
  .k-gallery--5 .k-gallery__item:nth-child(3){ grid-column: 2; grid-row: 2; }
  .k-gallery--5 .k-gallery__item:nth-child(4){ grid-column: 3; grid-row: 2; }
  .k-gallery--5 .k-gallery__item:nth-child(5){ grid-column: 2 / span 2; grid-row: 3; }

  /* 6 */
  .k-gallery--6{
    grid-template-columns: 2fr 1fr 1fr;
    grid-template-rows: repeat(3, clamp(160px, 22vw, 400px));
  }
  .k-gallery--6 .k-gallery__item:nth-child(1){ grid-column: 1; grid-row: 1 / span 2; }
  .k-gallery--6 .k-gallery__item:nth-child(2){ grid-column: 2 / span 2; grid-row: 1; }
  .k-gallery--6 .k-gallery__item:nth-child(3){ grid-column: 2; grid-row: 2; }
  .k-gallery--6 .k-gallery__item:nth-child(4){ grid-column: 3; grid-row: 2; }
  .k-gallery--6 .k-gallery__item:nth-child(5){ grid-column: 1; grid-row: 3; }
  .k-gallery--6 .k-gallery__item:nth-child(6){ grid-column: 2 / span 2; grid-row: 3; }

  /* 7 */
  .k-gallery--7{
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(3, clamp(160px, 22vw, 382px));
  }
  .k-gallery--7 .k-gallery__item:nth-child(1){ grid-column: 1 / span 2; grid-row: 1 / span 2; }
  .k-gallery--7 .k-gallery__item:nth-child(2){ grid-column: 1; grid-row: 3; }
  .k-gallery--7 .k-gallery__item:nth-child(3){ grid-column: 2; grid-row: 3; }
  .k-gallery--7 .k-gallery__item:nth-child(4){ grid-column: 3 / span 2; grid-row: 1; }
  .k-gallery--7 .k-gallery__item:nth-child(5){ grid-column: 3; grid-row: 2; }
  .k-gallery--7 .k-gallery__item:nth-child(6){ grid-column: 4; grid-row: 2; }
  .k-gallery--7 .k-gallery__item:nth-child(7){ grid-column: 3 / span 2; grid-row: 3; }

  /* 8 */
  .k-gallery--8{
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, clamp(140px, 21vw, 440px));
  }
  .k-gallery--8 .k-gallery__item:nth-child(1){ grid-column: 1 / span 2; grid-row: 1 / span 2; }
  .k-gallery--8 .k-gallery__item:nth-child(2){ grid-column: 3; grid-row: 1 / span 2; }
  .k-gallery--8 .k-gallery__item:nth-child(3){ grid-column: 4; grid-row: 1 / span 2; }
  .k-gallery--8 .k-gallery__item:nth-child(4){ grid-column: 1; grid-row: 3; }
  .k-gallery--8 .k-gallery__item:nth-child(5){ grid-column: 2; grid-row: 3; }
  .k-gallery--8 .k-gallery__item:nth-child(6){ grid-column: 3 / span 2; grid-row: 3; }
  .k-gallery--8 .k-gallery__item:nth-child(7){ grid-column: 1 / span 2; grid-row: 4; }
  .k-gallery--8 .k-gallery__item:nth-child(8){ grid-column: 3 / span 2; grid-row: 4; }
}

section.k-section.k-section--gallery.is-last {
    padding-bottom: 35px;
}