*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: #f5f5f5;
  color: #222;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ── Masonry grid (CSS columns) ─────────────────── */
#gallery {
  columns: 6;
  column-gap: 12px;
  padding: 12px;
}

@media (max-width: 1200px) { #gallery { columns: 5; } }
@media (max-width: 900px)  { #gallery { columns: 4; } }
@media (max-width: 600px)  { #gallery { columns: 3; } }
@media (max-width: 480px)  { #gallery { columns: 2; } }

/* ── Image tile component ───────────────────────── */
.image-tile {
  break-inside: avoid;
  margin-bottom: 12px;
  display: block;
  cursor: pointer;
  overflow: hidden;
  position: relative;
  border-radius: 4px;
  background: #e8e8e8;
}

/* ── Placeholder ─────────────────────────────────── */
.placeholder {
  position: absolute;
  inset: 0;
  background: #e8e8e8;
  z-index: 2;
  transition: opacity 0.35s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.placeholder.fade-out {
  opacity: 0;
  pointer-events: none;
}

/* ── Spinner ─────────────────────────────────────── */
.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid #ccc;
  border-top-color: #888;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.2s ease;
  animation: spin 0.6s linear infinite;
  pointer-events: none;
}

.spinner.visible {
  opacity: 1;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Image ───────────────────────────────────────── */
.image-tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.35s ease;
  position: absolute;
  inset: 0;
  z-index: 1;
}

.image-tile img.loaded {
  opacity: 1;
}

/* ── Hover dot ──────────────────────────────────────── */
.image-tile::after {
  content: "";
  position: absolute;
  bottom: 12px;
  right: 12px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  mix-blend-mode: difference;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
  z-index: 3;
}

.image-tile:hover::after {
  opacity: 1;
}

/* ── Reduced motion ──────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .image-tile img {
    transition: none;
  }
  .placeholder {
    transition: none;
  }
  .image-tile::after {
    transition: none;
  }
  .spinner {
    animation-duration: 1.5s;
  }
  .lb-image-inner img {
    transition: none;
  }
  .lb-image-inner .placeholder {
    transition: none;
  }
  .lb-image-inner .spinner {
    animation-duration: 1.5s;
  }
  #lightbox {
    transition: none;
  }

  #lightbox button {
    transition: none;
  }

  .icon {
    transition: none;
  }
}

/* ── Lightbox ────────────────────────────────────── */
#lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.25s ease;
}

/* ── Lightbox image container ────────────────────── */
.lb-image-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 100vw;
  height: 100dvh;
}

.lb-image-inner {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

.lb-image-inner .placeholder {
  position: absolute;
  inset: 0;
  background: #e8e8e8;
  z-index: 2;
  transition: opacity 0.35s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lb-image-inner .placeholder.fade-out {
  opacity: 0;
  pointer-events: none;
}

.lb-image-inner .spinner {
  width: 24px;
  height: 24px;
  border: 2px solid #ccc;
  border-top-color: #888;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.2s ease;
  animation: spin 0.6s linear infinite;
  pointer-events: none;
}

.lb-image-inner .spinner.visible {
  opacity: 1;
}

.lb-image-inner img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.lb-image-inner img.loaded {
  opacity: 1;
}

/* ── Icon buttons ──────────────────────────────── */
#lightbox button {
  position: absolute;
  background: none;
  border: none;
  color: #444;
  cursor: pointer;
  padding: 8px;
  line-height: 0;
  opacity: 0;
  transition: opacity 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

#lightbox:hover button {
  opacity: 0.4;
}

#lightbox button:hover,
#lightbox button:focus-visible {
  opacity: 1 !important;
}

/* Lightbox button specific styles */
#lb-close {
  top: 16px;
  right: 20px;
}
#lb-prev {
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
}
#lb-next {
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
}
#lb-share {
  bottom: 16px;
  right: 20px;
}

/* ── All icons ─────────────────────────────────── */
.icon {
  width: 18px;
  height: 18px;
  display: block;
  transition: opacity 0.2s ease;
}

/* ── Icon visibility toggles ───────────────────── */
#lb-share .icon-share {
  opacity: 1;
}

#lb-share .icon-copied {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

#lb-share.copied .icon-share {
  opacity: 0;
}

#lb-share.copied .icon-copied {
  opacity: 1;
  pointer-events: auto;
}
