/* ==========================================================================
   Legal Evidence Gallery — Mobile Optimisation
   Lightbox overlay + responsive layout for screens < 640px
   ========================================================================== */

/* ---------- Lightbox overlay (all screen sizes) ---------- */

.gallery-lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.gallery-lightbox.is-open {
  visibility: visible;
  opacity: 1;
}

.gallery-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
}

.gallery-lightbox-close {
  position: absolute;
  top: var(--space-md, 1rem);
  right: var(--space-md, 1rem);
  z-index: 10;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s;
  touch-action: manipulation;
}

.gallery-lightbox-close:hover,
.gallery-lightbox-close:focus-visible {
  background: rgba(255, 255, 255, 0.3);
}

.gallery-lightbox-counter {
  position: absolute;
  top: var(--space-md, 1rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  font-family: var(--font-mono, monospace);
  font-size: var(--text-xs, 0.75rem);
  color: rgba(255, 255, 255, 0.7);
  padding: 0.25em 0.75em;
  background: rgba(0, 0, 0, 0.5);
  border-radius: var(--radius, 6px);
}

.gallery-lightbox-body {
  position: relative;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 90vw;
  max-height: 90vh;
  touch-action: pan-y;
  will-change: transform, opacity;
}

.gallery-lightbox-img-wrap {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
}

.gallery-lightbox-img {
  max-width: 90vw;
  max-height: 70vh;
  object-fit: contain;
  border-radius: var(--radius, 6px);
  user-select: none;
  -webkit-user-drag: none;
}

.gallery-lightbox-caption {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: var(--space-md, 1rem) var(--space-sm, 0.5rem);
  text-align: center;
  color: #fff;
  max-width: 600px;
}

.gallery-lightbox-nexis {
  font-family: var(--font-mono, monospace);
  font-size: var(--text-xs, 0.75rem);
  color: var(--accent-warm, #b8860b);
  font-weight: 600;
}

.gallery-lightbox-title {
  font-family: var(--font-display, serif);
  font-size: var(--text-base, 1rem);
  color: #fff;
  display: block;
}

.gallery-lightbox-desc {
  font-size: var(--text-sm, 0.875rem);
  color: rgba(255, 255, 255, 0.7);
  line-height: 1.5;
}

/* navigation arrows */
.gallery-lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s;
  touch-action: manipulation;
}

.gallery-lightbox-nav:hover,
.gallery-lightbox-nav:focus-visible {
  background: rgba(255, 255, 255, 0.25);
}

.gallery-lightbox-prev { left: var(--space-md, 1rem); }
.gallery-lightbox-next { right: var(--space-md, 1rem); }

/* swipe hint */
.gallery-lightbox-hint {
  position: absolute;
  bottom: var(--space-lg, 1.5rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  font-family: var(--font-body, sans-serif);
  font-size: var(--text-xs, 0.75rem);
  color: rgba(255, 255, 255, 0.5);
  padding: 0.3em 0.8em;
  background: rgba(0, 0, 0, 0.4);
  border-radius: var(--radius, 6px);
  transition: opacity 0.5s ease;
  pointer-events: none;
}

/* ---------- Mobile: screens < 640px ---------- */

@media (max-width: 639px) {

  /* 1. Single-column layout for both grids */
  #figureGrid,
  .legal-section > .container > div[style*="grid-template-columns"] {
    display: flex;
    flex-direction: column;
    gap: var(--space-md, 1rem);
  }

  /* 2. Full-width cards with larger tap targets */
  #figureGrid > .ground-card {
    width: 100%;
    padding: var(--space-md, 1rem);
  }

  #figureGrid > .ground-card > div[style*="cursor: pointer"],
  #figureGrid > .ground-card > div[role="button"] {
    min-height: 48px;
  }

  /* 3. Filter buttons: horizontal scroll, no wrap */
  .filter-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: var(--space-sm, 0.5rem);
    touch-action: pan-x;
  }

  .filter-bar::-webkit-scrollbar {
    display: none;
  }

  .filter-btn {
    flex-shrink: 0;
    white-space: nowrap;
    padding: 0.5em 1em;
    font-size: var(--text-sm, 0.875rem);
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  /* 4. Better captions on small screens */
  #figureGrid .ground-title {
    font-size: var(--text-base, 1rem);
    line-height: 1.4;
  }

  #figureGrid .ground-desc {
    font-size: var(--text-sm, 0.875rem);
    line-height: 1.6;
  }

  #figureGrid .nexis-code {
    font-size: var(--text-sm, 0.875rem);
  }

  #figureGrid .badge-category {
    font-size: var(--text-xs, 0.75rem);
  }

  /* 5. Lightbox mobile adjustments */
  .gallery-lightbox-img {
    max-width: 100vw;
    max-height: 55vh;
    border-radius: 0;
  }

  .gallery-lightbox-body {
    max-width: 100vw;
    max-height: 100vh;
    padding: 0 var(--space-sm, 0.5rem);
  }

  .gallery-lightbox-caption {
    padding: var(--space-sm, 0.5rem);
  }

  .gallery-lightbox-title {
    font-size: var(--text-sm, 0.875rem);
  }

  .gallery-lightbox-desc {
    font-size: var(--text-xs, 0.75rem);
  }

  /* hide desktop-style nav arrows on mobile (use swipe instead) */
  .gallery-lightbox-nav {
    display: none;
  }

  /* 6. Prevent accidental horizontal scrolling on the page body */
  .legal-wrapper {
    touch-action: pan-y;
    overflow-x: hidden;
  }

  #figureGrid {
    touch-action: pan-y;
  }

  /* hero adjustments */
  .legal-hero .subtitle {
    font-size: var(--text-base, 1rem);
  }

  /* primary exhibits grid also single column */
  .legal-section-title + div[style*="grid-template-columns"] {
    display: flex;
    flex-direction: column;
  }
}

/* ---------- Medium screens (640px - 1023px): 2-column grid ---------- */

@media (min-width: 640px) and (max-width: 1023px) {
  #figureGrid {
    grid-template-columns: repeat(2, 1fr);
  }
}
