/* ===========================================================================
   Responsive photo gallery — dark, justified grid + lightbox.
   No external dependencies.
   =========================================================================== */

:root {
  --bg:        #0d0d0f;
  --surface:   #161619;
  --text:      #f2f2f4;
  --muted:     #9a9aa2;
  --accent:    #e8b04b;
  --gap:       8px;
  --radius:    10px;
  --maxw:      1600px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

img { display: block; max-width: 100%; }

/* --- Header --------------------------------------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(13, 13, 15, 0.82);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.site-header__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 14px clamp(12px, 4vw, 28px);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.site-title {
  margin: 0;
  font-size: clamp(1.1rem, 2.6vw, 1.5rem);
  font-weight: 700;
  letter-spacing: 0.2px;
}
.site-tagline {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.btn-download-all {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--accent);
  color: #1a1206;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 0.15s ease, filter 0.15s ease;
}
.btn-download-all:hover { filter: brightness(1.08); }
.btn-download-all:active { transform: scale(0.96); }
.btn-download-all:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

@media (max-width: 480px) {
  .btn-download-all span { display: none; } /* icon-only on small screens */
  .btn-download-all { padding: 9px 11px; }
}

/* --- Gallery (justified rows; sizes set by JS) ---------------------------- */

main { max-width: var(--maxw); margin: 0 auto; }

.gallery {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
  padding: var(--gap) clamp(8px, 3vw, 24px) 40px;
  /* Avoid a flash of unstyled huge images before JS lays them out. */
  opacity: 0;
  transition: opacity 0.35s ease;
}
.gallery.ready { opacity: 1; }

.tile {
  position: relative;
  display: block;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface);
  cursor: zoom-in;
  /* Fallback sizing (used until JS runs / if JS disabled). */
  flex: 1 1 280px;
  aspect-ratio: var(--ar, 1);
  text-decoration: none;
  transform: translateZ(0);
}
.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.45s cubic-bezier(.2,.7,.3,1), opacity 0.4s ease;
}
.tile:hover img,
.tile:focus-visible img { transform: scale(1.05); }
.tile:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
/* Soft fade-in for each thumbnail as it decodes. */
.tile img[loading] { opacity: 0; }
.tile img.loaded   { opacity: 1; }

/* When JS has laid the grid out, drop the flex-grow fallback so explicit
   per-tile widths from the justified algorithm take over cleanly. */
.gallery.ready .tile { flex: 0 0 auto; aspect-ratio: auto; }

/* --- Empty state ---------------------------------------------------------- */

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--muted);
}
.empty-state__hint { font-size: 0.9rem; }
.empty-state code {
  background: var(--surface);
  padding: 2px 6px;
  border-radius: 5px;
  color: var(--accent);
}

/* --- Footer --------------------------------------------------------------- */

.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 28px 16px 40px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

/* --- Lightbox ------------------------------------------------------------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.lightbox.open { opacity: 1; }
.lightbox[hidden] { display: none; }

.lightbox__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 6, 8, 0.94);
}

.lightbox__stage {
  position: relative;
  margin: 0;
  max-width: 94vw;
  max-height: 82vh;
  display: grid;
  place-items: center;
}
.lightbox__img {
  max-width: 94vw;
  max-height: 82vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: opacity 0.2s ease;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-drag: none;
}
.lightbox__img.loaded { opacity: 1; }

.lightbox__spinner {
  position: absolute;
  width: 38px;
  height: 38px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: lb-spin 0.8s linear infinite;
  pointer-events: none;
}
.lightbox.loaded .lightbox__spinner { display: none; }
@keyframes lb-spin { to { transform: rotate(360deg); } }

.lb-btn {
  position: absolute;
  z-index: 2;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: none;
  cursor: pointer;
  border-radius: 50%;
  display: grid;
  place-items: center;
  transition: background 0.2s ease, transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.lb-btn:hover { background: rgba(255, 255, 255, 0.2); }
.lb-btn:active { transform: scale(0.92); }
.lb-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.lb-close {
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  width: 46px; height: 46px;
  font-size: 28px;
  line-height: 1;
}
.lb-prev, .lb-next {
  top: 50%;
  transform: translateY(-50%);
  width: 52px; height: 52px;
  font-size: 22px;
}
.lb-prev:active, .lb-next:active { transform: translateY(-50%) scale(0.92); }
.lb-prev { left: max(10px, env(safe-area-inset-left)); }
.lb-next { right: max(10px, env(safe-area-inset-right)); }

.lightbox__bar {
  position: absolute;
  left: 0; right: 0;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 0 16px;
}
.lightbox__counter {
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.lightbox__download {
  position: static;
  width: auto; height: auto;
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 0.85rem;
  text-decoration: none;
  font-weight: 600;
}

/* --- Motion / mobile tweaks ---------------------------------------------- */

@media (max-width: 600px) {
  .lb-prev, .lb-next { width: 44px; height: 44px; }
  :root { --gap: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
