﻿:root {
  /* slightly lighter overlay and surface so the modal isn't pure black */
  --lb-bg: rgba(0, 0, 0, 0);
  --lb-surface: #222;
  --lb-text: #f8f8f8;
  --lb-accent: #00a8ff;
  --lb-padding: 0px;
  /* caption sizing tokens */
  --lb-caption-size: 1.125rem;
  --lb-title-size: 1.25rem;
}

.lb-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 99999;
  /* Safe-area offsets are handled per-element (counter, close, prev/next, caption)
     so the overlay itself needs no padding. The dialog is position:fixed and
     ignores overlay padding anyway. */
  padding: 0;
  /* Prevent touch/scroll from affecting the page behind the overlay */
  overscroll-behavior: contain;
}

.lb-overlay[hidden] {
  display: none;
}

.lb-backdrop {
  position: absolute;
  inset: 0;
  background: var(--lb-bg);
  opacity: 1;
  transition: opacity var(--lb-animation, 200ms) ease;
}

/* Make the dialog use flex layout instead of grid to avoid row sizing issues */
.lb-dialog {
  /* fill viewport instead of a centered card */
  position: fixed;
  inset: 0;
  margin: 0;
  width: 100%;
  /* Use stable viewport units for mobile browsers (prevents cropping in landscape). */
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  box-sizing: border-box;
  background: var(--lb-surface);
  color: var(--lb-text);
  /* use flex column so middle area can flex and center content reliably */
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: var(--lb-padding);
  border-radius: 0;
  box-shadow: none;
  animation: lb-fade-in var(--lb-animation, 200ms) ease;
  outline: none;
  overflow: hidden;
}

/* Stage takes available space and centers media */
.lb-stage {
  position: relative;
  background: transparent;
  overflow: hidden;
  /* flex container centers its content */
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  /* allow the stage to shrink inside the container */
  min-height: 0;
  flex: 1 1 auto; /* make the stage grow/shrink to fill available space */
  /* allow JS to handle touch gestures (prevent browser pinch-zoom) */
  touch-action: none;
  -webkit-user-select: none;
  -ms-touch-action: none;
  user-select: none;
}

.lb-counter {
  position: absolute;
  top: max(10px, env(safe-area-inset-top, 0));
  left: max(10px, env(safe-area-inset-left, 0));
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.65);
  color: var(--lb-text);
  font-weight: 600;
  letter-spacing: 0.5px;
  z-index: 3;
  pointer-events: none;
}

/* When lightbox is open, lock document scrolling and hide native scrollbars */
html.lb-open,
body.lb-open,
html.lb-open body {
  overflow: hidden !important;
}

/* Compact mode: do not hide captions; only adjust controls presentation */
.lb-compact .lb-controls {
  opacity: 0.98;
  background: transparent;
}

/* Media fills the stage so media sizing can be relative to the available space
   (important when the caption becomes multi-line). */
.lb-media {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  min-height: 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Media should scale to fit the viewport while leaving room for captions and controls */
.lb-media img,
.lb-media video,
.lb-media iframe {
  /* Constrain to the available stage area (no hard-coded vh math) */
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  transition: transform 160ms ease;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

/* Videos and posters should always fully fit within the stage (no cropping),
   including on short-height landscape mobile viewports. */
.lb-media > * {
  min-width: 0;
  min-height: 0;
}

/* Only actual lightbox images should show the zoom cursor (video posters are also <img>). */
.lb-media img.lb-image {
  cursor: zoom-in;
  /* Enable hardware acceleration for smooth panning/zooming */
  will-change: transform;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}

/* Cursor states for zoomed images */
.lb-media img.lb-image[style*='scale(1)'] {
  cursor: zoom-in;
}

/* When zoomed, show zoom-out cursor by default (JS will update this) */
.lb-media img.lb-image.zoomed {
  cursor: zoom-out;
}

/* During active drag/pan, show grabbing cursor */
.lb-media img.lb-image.panning {
  cursor: grabbing !important;
  transition: none; /* Disable transitions during pan for responsiveness */
}

/* Touch devices: show grab cursor when zoomed */
@media (hover: none) and (pointer: coarse) {
  .lb-media img.lb-image.zoomed {
    cursor: grab;
  }
}

/* Caption sits below the media */
.lb-caption {
  font-size: var(--lb-caption-size);
  line-height: 1;
  color: #e8e8e8;
  padding-top: 2px;
  padding-bottom: 2px;
  /* center the caption/title under the media */
  text-align: center;
  max-width: 1000px;
  margin-left: auto;
  margin-right: auto;
  /* Allow multi-line captions with no scrollbar; the media area above shrinks as needed. */
  flex: 0 0 auto;
  max-height: none;
  overflow: visible;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.lb-title {
  font-weight: 700;
  font-size: var(--lb-title-size);
  margin: 0 auto 8px;
}

/* Controls row: previous/next and zoom items */
.lb-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  /* allow buttons to wrap to next line on narrow screens so they're always visible */
  flex-wrap: wrap;
  padding: 4px 0;
}

/* Buttons styling */
.lb-controls button,
.lb-close,
.lb-fullscreen {
  background: rgba(28, 28, 28, 0.8);
  color: var(--lb-text);
  border: 1px solid rgba(42, 42, 42, 0.6);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition:
    background 120ms ease,
    transform 120ms ease;
  box-sizing: border-box;
}

/* Close button at top-right inside the dialog */
.lb-close {
  position: absolute;
  top: max(10px, env(safe-area-inset-top, 0));
  right: max(10px, env(safe-area-inset-right, 0));
  font-size: 20px;
  line-height: 1;
  width: 36px;
  height: 36px;
  padding: 0; /* override inherited padding for proper centering */
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

/* Fullscreen button positioned left of close button */
.lb-fullscreen {
  position: absolute;
  top: max(10px, env(safe-area-inset-top, 0));
  right: calc(
    max(10px, env(safe-area-inset-right, 0)) + 44px
  ); /* 44px = 36px close button + 8px gap */
  font-size: 20px;
  line-height: 1;
  width: 36px;
  height: 36px;
  padding: 0; /* override inherited padding for proper centering */
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  /* Better visibility on black background */
  background: rgba(60, 60, 60, 0.9);
  border: 1.5px solid rgba(120, 120, 120, 0.7);
}

.lb-controls button:focus,
.lb-close:focus,
.lb-controls button:hover,
.lb-close:hover {
  outline: 2px solid var(--lb-accent);
  outline-offset: 2px;
  background: rgba(36, 36, 36, 0.95);
}

/* Fullscreen button states - better visibility */
.lb-fullscreen:hover {
  background: rgba(80, 80, 80, 0.95);
  border-color: rgba(160, 160, 160, 0.9);
  outline: 2px solid var(--lb-accent);
  outline-offset: 2px;
}

.lb-fullscreen:focus {
  outline: 2px solid var(--lb-accent);
  outline-offset: 2px;
  background: rgba(80, 80, 80, 0.95);
  border-color: rgba(160, 160, 160, 0.9);
}

/* Fullscreen active state (when in fullscreen mode) */
.lb-fullscreen-active .lb-fullscreen {
  background: rgba(0, 168, 255, 0.2);
  border-color: var(--lb-accent);
  color: var(--lb-accent);
}

/* allow prev/next buttons to shrink on small screens */
.lb-prev,
.lb-next {
  /* make these overlay navigation buttons positioned center-left and center-right */
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 56px;
  height: 56px;
  min-width: initial;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  z-index: 3;
}

.lb-prev {
  left: max(12px, env(safe-area-inset-left, 0));
}

.lb-next {
  right: max(12px, env(safe-area-inset-right, 0));
}

/* Mobile (portrait + landscape): place arrows inline with caption at bottom. */
@media (max-width: 1000px) {
  .lb-dialog {
    padding: 8px;
  }

  .lb-counter {
    top: max(10px, env(safe-area-inset-top, 0));
    left: max(10px, env(safe-area-inset-left, 0));
  }

  .lb-prev,
  .lb-next {
    position: absolute;
    top: auto;
    transform: none;
    bottom: max(8px, env(safe-area-inset-bottom, 0));
    width: 48px;
    height: 44px;
    min-width: 48px;
    display: grid;
    place-items: center;
    box-shadow: none;
    z-index: 4;
  }

  .lb-prev {
    left: max(10px, env(safe-area-inset-left, 0));
  }

  .lb-next {
    right: max(10px, env(safe-area-inset-right, 0));
  }

  .lb-caption {
    position: absolute;
    left: calc(max(10px, env(safe-area-inset-left, 0)) + 56px);
    right: calc(max(10px, env(safe-area-inset-right, 0)) + 56px);
    bottom: max(8px, env(safe-area-inset-bottom, 0));
    margin: 0;
    max-width: none;
    text-align: center;
    background: rgba(0, 0, 0, 0.55);
    padding: 6px 0;
    z-index: 3;
  }

  .lb-title {
    margin: 0 auto 4px;
  }

  .lb-caption.lb-caption-empty {
    display: none;
  }

  .lb-controls {
    padding: 0;
    margin: 0;
    height: 0;
  }

  /* reduce caption size on small screens */
  :root {
    --lb-caption-size: 1rem;
    --lb-title-size: 1.125rem;
  }
}

/* Mobile landscape: flush elements to edges (literal 0) to avoid double-counting
   the safe-area inset that the browser already accounts for. */
@media (max-width: 1000px) and (orientation: landscape) {
  .lb-dialog {
    gap: 0;
    padding: 8px 0;
  }

  .lb-counter {
    top: 0;
    left: 0;
  }

  .lb-prev {
    left: 0;
    bottom: 0;
  }

  .lb-next {
    right: 0;
    bottom: 0;
  }

  .lb-caption {
    left: 56px;
    right: 56px;
    bottom: 0;
  }
}

/* Video: keep the poster and the <video> itself fully visible (no cropping).
   This follows the same "fit within stage" sizing rules as images. */
.lb-video-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
}

.lb-video-wrap img.lb-video-poster {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.lb-video-wrap video.lb-video {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* Short-height landscape: reduce spacing so the stage has enough room. */
@media (orientation: landscape) and (max-height: 480px) and (min-width: 1001px) {
  .lb-dialog {
    gap: 0;
    padding: 8px 0;
  }

  /* Flush counter to the left edge in landscape (literal zero to avoid double-counting)
     — some browsers already restrict the viewport to the safe area when
     viewport-fit=cover is not used; using env() here can add the inset twice. */
  .lb-counter {
    left: 0;
  }

  /* Flush prev button to the left edge in landscape */
  .lb-prev {
    left: 0;
  }

  /* Flush next button to the right edge in landscape */
  .lb-next {
    right: 0;
  }

  /* Let the media stage occupy the available vertical space, and overlay captions
     on top of the image at the bottom with a subtle background. */
  .lb-caption {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    max-width: none;
    text-align: center;
    background: rgba(0, 0, 0, 0.55);
  }

  /* Hide caption bar when empty in landscape */
  .lb-caption.lb-caption-empty {
    display: none;
  }

  .lb-title {
    margin: 0 auto 4px;
  }

  /* The prev/next buttons are absolutely positioned; remove the controls bar
     from the flex flow so it doesn't steal vertical space. */
  .lb-controls {
    padding: 0;
    margin: 0;
    height: 0;
  }
}

@keyframes lb-fade-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.998);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Remove default focus outline on stage and media to avoid thin white border after navigation */
.lb-stage:focus {
  outline: none;
}
.lb-stage *:focus {
  outline: none;
  box-shadow: none;
}
.lb-media img:focus,
.lb-media video:focus,
.lb-media iframe:focus,
.lb-video-wrap:focus {
  outline: none;
  box-shadow: none;
}

/* Prevent tap highlight on mobile */
.lb-overlay,
.lb-dialog,
.lb-stage,
.lb-media,
.lb-video-wrap {
  -webkit-tap-highlight-color: transparent;
}

/* iOS fallback fullscreen mode */
.lb-ios-fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh; /* dynamic viewport height on iOS */
}

/* Fullscreen active: ensure caption stays at bottom in landscape */
.lb-fullscreen-active .lb-caption,
.lb-ios-fullscreen .lb-caption {
  /* Remove bottom offset that was pushing caption up */
  bottom: 0;
}

/* Hide empty captions in fullscreen landscape */
.lb-fullscreen-active .lb-caption.lb-caption-empty,
.lb-ios-fullscreen .lb-caption.lb-caption-empty {
  display: none;
}
