/* Minimal styles for layout only */
:root {
  --gap-row: 16px; /* vertical gap */
  --gap-col: 16px; /* horizontal gap */
  --tile-min: 220px;
  --tile-max: 220px;
}

/* Center the gallery and hard-cap at 4 columns without media queries */
.gallery {
  display: grid;
  gap: var(--gap-row) var(--gap-col);
  grid-template-columns: repeat(auto-fit, minmax(var(--tile-min), var(--tile-max)));
  /* Cap max width to 4 columns + gaps */
  max-width: calc(4 * var(--tile-min) + 3 * var(--gap-col));
  margin: 0 auto; /* centers horizontally */
  padding: 0;
  justify-content: center;
}

.gallery img {
  width: 100%;
  height: 100%;     /* stretch to fill the fixed figure box */
  display: block;
  object-fit: fill; /* allow distortion to match 3:4 box */
}

.gallery figure {
  margin: 0;
  position: relative;
  aspect-ratio: 3 / 4; /* force uniform 4:3 portrait (width:height = 3:4) */
  overflow: hidden;     /* keep caption inside the reserved area */
}

.gallery figcaption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 33.333%;
  background-color: rgba(128, 128, 128, 0.6); /* grey-transparent */
  color: #fff;
  overflow: hidden; /* ensure text stays within the reserved area */
  display: flex;
  align-items: center;    /* vertical centering */
  justify-content: center;/* horizontal centering */
  text-align: center;     /* center multiline text */
}

.gallery figcaption,
.modal__counter {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.3;
  font-weight: 500;
}

/* Modal (minimal) */
.modal[hidden] { display: none; }
.modal { 
  position: fixed;
  inset: 0;
  z-index: 9999;    /* Raise the whole modal above everything */
}

.modal__overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 1;
}

.modal__stage {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
}

.modal__img {
  max-width: 90vw; max-height: 80vh; display: block;
  object-fit: contain;
}

/* Controls */
.modal__close { position: absolute; top: 8px; right: 8px; }
.modal__prev { position: absolute; top: 50%; left: 8px; transform: translateY(-50%); }
.modal__next { position: absolute; top: 50%; right: 8px; transform: translateY(-50%); }

/* Prevent background scroll when modal is open */
body.modal-open { overflow: hidden; }

/* Hide prev/next buttons ONLY on small touch devices.
   Keep them visible on large touch laptops/desktops. */
@media (pointer: coarse) and (max-width: 768px),
       (hover: none) and (max-width: 768px) {
  .swipe-supported .modal__prev,
  .swipe-supported .modal__next {
    display: none;
  }
}

/* (If not already present) allow vertical pan while capturing horizontal swipes */
.modal__stage { touch-action: pan-y; }

/* Bigger, white, transparent modal controls */
.modal__close,
.modal__prev,
.modal__next {
  background: transparent;
  border: 0;
  color: #fff;
  font-size: 36px;   /* bigger glyphs: ×, ‹, › */
  line-height: 1;
  padding: 8px 12px; /* increases tap/click target */
  min-width: 44px;   /* recommended minimum touch target */
  min-height: 44px;
  cursor: pointer;
}

.modal__close   { z-index: 3; }

/* Accessible focus outline (minimal) */
.modal__close:focus-visible,
.modal__prev:focus-visible,
.modal__next:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* Hover pop-up only on devices that support hover + fine pointer (e.g., mouse) */
@media (hover: hover) and (pointer: fine) {
  .gallery figure {
    transition: transform 120ms ease-out;
    transform-origin: center;
  }
  .gallery figure:hover {
    transform: scale(1.03);
    z-index: 1; /* sit above neighbors during the pop-up */
  }
}

/* Viewport fills the frame; slider fills the viewport */
.modal__viewport {
  width: 100%;
  height: 100%;
  overflow: hidden;
  margin: 0;
}

/* Track with exactly two slides; animate its translateX */
.modal__slider {
  display: flex;
  width: 200%;                  /* 2 slides side-by-side */
  height: 100%;
  transform: translateX(0);     /* 0% = show first slot */
  transition: transform 0.5s ease-in-out;
}

/* Each slide = one viewport's width; center its content */
.modal__slide {
  flex: 0 0 50%;              /* 2 slides => each is half of the 200% track */
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;    /* centers smaller images instead of stretching */
}

/* Image scales up/down to fill available space, keeps aspect ratio */
.modal__img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Reduced motion: disable the slide animation */
@media (prefers-reduced-motion: reduce) {
  .modal__slider { transition: none; }
}

/* Frame: 50% viewport on larger screens; 90% on small/touch */
.modal__frame {
  position: relative;
  width: 50vw;
  height: 50vh;
  z-index: 2;
}

/* Small/touch screens */
@media (max-width: 768px), (hover: none) and (pointer: coarse) {
  .modal__frame { width: 90vw; height: 90vh; }
}

/* Photo counter in the modal */
.modal__counter {
  position: absolute;
  right: 8px;
  bottom: 8px;
  background: #fff;
  color: #000;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1;
  z-index: 3; /* same as close button */
}
