/* ==========================================================================
   GALLERY
   --------------------------------------------------------------------------
   Click-through image slideshow with a fullscreen viewer.

   Markup is just a div and some images. Everything else is added by
   gallery.js at load:

     <div class="gallery">
       <img src="images/first.webp"  alt="...">
       <img src="images/second.webp" alt="...">
     </div>

   With JavaScript off, the first image shows and the rest stay hidden, so
   the page still reads correctly. No library, no build step.
   ========================================================================== */

.gallery {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: var(--surface-hi);
}

.gallery img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* No-JS and pre-init: show the first, hide the rest. */
.gallery img + img { display: none; }

.gallery.is-ready img {
  display: block;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.gallery.is-ready img.is-active {
  opacity: 1;
  pointer-events: auto;
  cursor: zoom-in;
}

/* ---- Arrows ---- */
.g-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 34px;
  height: 46px;
  border: 0;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.82);
  color: var(--text);
  font-family: var(--sans);
  font-size: 18px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.2s ease, background 0.2s ease;
}

.gallery:hover .g-arrow,
.g-arrow:focus-visible { opacity: 1; }
.g-arrow:hover { background: #fff; }
.g-arrow.prev { left: 0; }
.g-arrow.next { right: 0; }

/* Touch has no hover, so never hide the arrows there. */
@media (hover: none) {
  .g-arrow { opacity: 1; }
}

/* ---- Dots ---- */
.g-dots {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  z-index: 2;
  display: flex;
  justify-content: center;
  gap: 7px;
}

.g-dots button {
  width: 8px;
  height: 8px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.g-dots button[aria-current="true"] { background: var(--accent); }

/* ---- Count badge ---- */
.g-count {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  background: rgba(255, 255, 255, 0.85);
  color: var(--text);
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 3px 8px;
}

/* ---- Focus ring for keyboard users opening an image ---- */
.gallery img:focus-visible,
.gallery-grid img:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

/* ---- Grid layout ----
   Every image visible at once as a thumbnail. auto-fill packs as many
   columns as fit, so it reflows from five across on desktop to two on a
   phone with no breakpoints to maintain. */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
}

.gallery-grid img {
  width: 100%;
  height: auto;            /* the height="1200" attribute must not win */
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  background: var(--surface-hi);
  cursor: zoom-in;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.gallery-grid img:hover { opacity: 0.86; }

@media (max-width: 480px) {
  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }
}

/* ---- Fullscreen viewer ---- */
.g-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 12, 14, 0.94);
  padding: 3rem 1rem;
}

.g-lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.g-lightbox .g-arrow {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  opacity: 1;
  width: 48px;
  height: 64px;
  font-size: 24px;
}
.g-lightbox .g-arrow:hover { background: rgba(255, 255, 255, 0.34); }
.g-lightbox .g-arrow.prev { left: 1rem; }
.g-lightbox .g-arrow.next { right: 1rem; }

.g-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 2;
  width: 44px;
  height: 44px;
  border: 0;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-family: var(--sans);
  font-size: 22px;
  line-height: 1;
}
.g-close:hover { background: rgba(255, 255, 255, 0.34); }

.g-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 1rem;
  text-align: center;
  color: #e8eaec;
  font-family: var(--sans);
  font-size: 0.85rem;
  padding: 0 4rem;
}

body.g-open { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  .gallery.is-ready img { transition: none; }
}

/* A gallery is a web control. On paper, print the first frame only. */
@media print {
  .g-arrow, .g-dots, .g-count { display: none !important; }
  .gallery { aspect-ratio: auto; }
  .gallery.is-ready img { display: none !important; }
  .gallery.is-ready img.is-active {
    display: block !important;
    position: static;
    opacity: 1;
    height: auto;
  }
}
