/* ============================================================
   Adaptive picture gallery — no JavaScript required
   - Desktop (>= 769px): 5 columns
   - Mobile  (<= 768px): 2 columns
   - Rows adapt automatically to the viewport width
   - Thumbs are 30%-resolution files; lightbox shows the original
   ============================================================ */

:root {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #1a1e26;
  --text: #e8eaf0;
  --accent: #4f8cff;
  --gap: 12px;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---------- Grid ---------- */

.gallery {
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px;
}

.gallery h1 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0 0 16px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);   /* desktop: 5 columns */
  gap: var(--gap);
}

.item {
  display: block;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.item img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;      /* uniform cells; row count adapts to width */
  object-fit: cover;
  transition: transform 0.25s ease, filter 0.25s ease;
}

.item:hover img,
.item:focus-visible img {
  transform: scale(1.04);
  filter: brightness(1.1);
}

.item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Mobile: 2 columns ---------- */

@media (max-width: 768px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
  .gallery { padding: 12px; }
}

/* ---------- Lightbox (click to zoom to full resolution) ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 10, 14, 0.92);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0s linear 0.3s;
}

.lightbox:target {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.3s ease;
}

.lightbox__backdrop {
  position: absolute;
  inset: 0;
  cursor: zoom-out;
}

.lightbox__figure {
  position: relative;
  z-index: 1;
  margin: 0;
  max-width: 100%;
  max-height: 100%;
}

.lightbox__figure img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(100vh - 48px);          /* fit any screen */
  max-height: calc(100dvh - 48px);         /* mobile URL-bar safe */
  border-radius: var(--radius);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.55);

  /* zoom animation: starts at 30% (thumbnail scale) -> 100% full */
  transform: scale(0.3);
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.3s ease;
}

.lightbox:target .lightbox__figure img {
  transform: scale(1);
  opacity: 1;
}

.lightbox__close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(15, 17, 21, 0.8);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  text-decoration: none;
}

.lightbox__close:hover { background: var(--accent); }

/* Lock page scroll while a lightbox is open */
body:has(.lightbox:target) { overflow: hidden; }

/* ---------- Accessibility ---------- */

@media (prefers-reduced-motion: reduce) {
  .item img,
  .lightbox,
  .lightbox__figure img {
    transition: none;
    transform: none;
  }
}