/* KHA Marine — gallery lightbox.
   Paired with kha-lightbox.js. The photo is deliberately sized with max-width /
   max-height and auto width/height rather than object-fit: contain — that way the
   <img> BOX is exactly the painted photo, which is what lets the JS measure it and
   fly it in and out of the grid tile accurately. object-fit would leave the element
   at full stage size with letterboxing inside it, and the zoom would land crooked. */

.kha-lb {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  /* the overlay owns every gesture: no page scroll behind it, no rubber-banding */
  touch-action: none;
  overscroll-behavior: contain;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
}
.kha-lb.is-open {
  display: block;
}

.kha-lb__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 8, 15, 0.94);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  opacity: 0;
  transition: opacity 420ms ease;
}
.kha-lb.is-in .kha-lb__backdrop {
  /* --kha-lb-fade is driven by the drag-to-dismiss gesture */
  opacity: var(--kha-lb-fade, 1);
}

.kha-lb__stage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: clamp(14px, 3vw, 56px);
  cursor: grab;
}
.kha-lb__stage:active {
  cursor: grabbing;
}
.kha-lb__img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border-radius: 10px;
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.6);
  will-change: transform, opacity;
  cursor: default;
  /* the browser's own image drag would fight the swipe */
  -webkit-user-drag: none;
  user-select: none;
}

/* ---- chrome: close, arrows, caption ---- */
.kha-lb__x,
.kha-lb__nav {
  position: absolute;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(9, 20, 34, 0.66);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: #eaf2fb;
  cursor: pointer;
  opacity: 0;
  transition:
    opacity 320ms ease 120ms,
    background 200ms ease,
    border-color 200ms ease,
    transform 200ms ease;
}
.kha-lb.is-in .kha-lb__x,
.kha-lb.is-in .kha-lb__nav,
.kha-lb.is-in .kha-lb__bar {
  opacity: var(--kha-lb-fade, 1);
}
.kha-lb__x:hover,
.kha-lb__nav:hover {
  background: rgba(20, 42, 68, 0.9);
  border-color: var(--kha-blue, #4a9eff);
  transform: scale(1.06);
}
.kha-lb__x svg,
.kha-lb__nav svg {
  width: 46%;
  height: 46%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.kha-lb__x {
  top: clamp(12px, 2vw, 26px);
  right: clamp(12px, 2vw, 26px);
  width: clamp(42px, 4vw, 52px);
  height: clamp(42px, 4vw, 52px);
}
.kha-lb__nav {
  top: 50%;
  width: clamp(42px, 4vw, 56px);
  height: clamp(42px, 4vw, 56px);
  margin-top: -26px;
}
.kha-lb__nav--prev {
  left: clamp(10px, 2vw, 30px);
}
.kha-lb__nav--next {
  right: clamp(10px, 2vw, 30px);
}
/* Arabic: previous on the right, next on the left, close button top-left */
html[dir="rtl"] .kha-lb__nav--prev {
  left: auto;
  right: clamp(10px, 2vw, 30px);
}
html[dir="rtl"] .kha-lb__nav--next {
  right: auto;
  left: clamp(10px, 2vw, 30px);
}
html[dir="rtl"] .kha-lb__nav svg {
  transform: scaleX(-1);
}
html[dir="rtl"] .kha-lb__x {
  right: auto;
  left: clamp(12px, 2vw, 26px);
}
html[dir="rtl"] .kha-lb__count {
  direction: ltr;
  unicode-bidi: isolate;
}

.kha-lb__bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 14px;
  padding: 40px clamp(16px, 4vw, 40px) clamp(16px, 2.4vw, 26px);
  background: linear-gradient(180deg, transparent, rgba(3, 8, 15, 0.86));
  opacity: 0;
  transition: opacity 320ms ease 120ms;
  pointer-events: none;
}
.kha-lb__cap {
  font-size: 0.92rem;
  color: #eaf2fb;
}
.kha-lb__count {
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  color: var(--kha-blue, #4a9eff);
}

/* the grid tiles are the entry point — say so */
.kha-gtile {
  cursor: zoom-in;
}

@media (max-width: 760px) {
  /* On a phone the arrows sit over the photo itself, so drop them to the bottom
     corners where a thumb reaches and the picture stays clear. Swiping is the
     primary gesture here; these are the fallback. */
  .kha-lb__nav {
    top: auto;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    margin-top: 0;
    width: 44px;
    height: 44px;
  }
  .kha-lb__bar {
    justify-content: center;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding-bottom: calc(74px + env(safe-area-inset-bottom, 0px));
  }
  .kha-lb__x {
    top: calc(12px + env(safe-area-inset-top, 0px));
  }
  .kha-lb__stage {
    padding: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .kha-lb__backdrop,
  .kha-lb__x,
  .kha-lb__nav,
  .kha-lb__bar {
    transition-duration: 1ms;
  }
  .kha-lb__img {
    transition: none !important;
  }
}
