:root {
  --bg: #212121;
  --bg-elevated: #171a21;
  --bg-card: #1c2029;
  --border: #2a2f3a;
  --text: #e7e9ee;
  --text-muted: #9aa1ad;
  --accent: #e7353c;
  --accent-soft: rgba(231, 53, 60, 0.15);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

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

/* ---------- Header ---------- */
.site-header {
  padding: 1rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 900px;
  margin: 0 auto;
}
.site-title {
  margin: 0;
  font-size: clamp(1.5rem, 5vw, 2rem);
  letter-spacing: 0.5px;
  font-weight: 700;
}
.site-subtitle {
  margin: 12px 0 0;
  color: var(--text-muted);
  font-size: clamp(1rem, 2vw, 1.15rem);
}

/* ---------- Category nav ---------- */
.category-nav {
  position: static;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  padding: 14px 16px;
  background: #212121;
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.category-nav a {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  white-space: nowrap;
  transition: all 0.18s ease;
}
.category-nav a:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.category-nav a .count {
  color: var(--accent);
  font-weight: 600;
  margin-left: 4px;
}

/* ---------- Gallery ---------- */
.gallery {
  max-width: 1320px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

.category-block {
  margin-bottom: 56px;
  scroll-margin-top: 80px;
}

.category-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.category-head h2 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
}
.category-head .badge {
  font-size: 0.8rem;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(231, 53, 60, 0.3);
  padding: 2px 10px;
  border-radius: 999px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.tile {
  position: relative;
  display: block;
  width: 100%;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  aspect-ratio: 1 / 1;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
}
.tile:hover,
.tile:focus-visible {
  transform: translateY(-4px);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.55);
  outline: none;
}
.tile:hover img,
.tile:focus-visible img {
  transform: scale(1.06);
}
.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.35s ease;
  background: #11131a;
}
.tile .tile-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 18px 10px 8px;
  font-size: 0.75rem;
  color: #fff;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.75), transparent);
  opacity: 0;
  transition: opacity 0.2s ease;
}
.tile:hover .tile-label,
.tile:focus-visible .tile-label {
  opacity: 1;
}

/* ---------- Scroll to top ---------- */
.scroll-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 50;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition:
    opacity 0.25s ease,
    transform 0.25s ease,
    background 0.18s ease;
}
.scroll-top.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.scroll-top:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

@media (max-width: 600px) {
  .scroll-top {
    right: 14px;
    bottom: 14px;
  }
}

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(8, 9, 12, 0.94);
  padding: 24px;
}
.lightbox.open {
  display: flex;
}

.lb-figure {
  margin: 0;
  max-width: 92vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.lb-image {
  max-width: 92vw;
  max-height: 82vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
  transition: filter 0.3s ease;
}
/* While the full-res original loads, the upscaled thumbnail is shown blurred. */
.lightbox.loading .lb-image {
  filter: blur(8px);
}

/* Spinner shown over the image while the original downloads. */
.lb-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 48px;
  height: 48px;
  margin: -24px 0 0 -24px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  animation: lb-spin 0.8s linear infinite;
}
.lightbox.loading .lb-spinner {
  opacity: 1;
}
@keyframes lb-spin {
  to {
    transform: rotate(360deg);
  }
}
.lb-caption {
  margin-top: 14px;
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
}
.lb-caption strong {
  color: var(--text);
}

.lb-close,
.lb-nav {
  position: absolute;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background 0.18s ease,
    transform 0.18s ease;
}
.lb-close:hover,
.lb-nav:hover {
  background: rgba(231, 53, 60, 0.35);
}

.lb-close {
  top: 20px;
  right: 24px;
  width: 46px;
  height: 46px;
  font-size: 1.8rem;
  line-height: 1;
}
.lb-nav {
  top: 50%;
  transform: translateY(-50%);
  width: 54px;
  height: 54px;
  font-size: 1.4rem;
}
.lb-nav:hover {
  transform: translateY(-50%) scale(1.08);
}
.lb-prev {
  left: 20px;
}
.lb-next {
  right: 20px;
}

@media (max-width: 600px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
  }
  .lb-close {
    top: 12px;
    right: 12px;
  }
  .lb-prev {
    left: 8px;
  }
  .lb-next {
    right: 8px;
  }
}
