:root {
  --bg: #f5f2ed;
  --surface: #edeae4;
  --border: #d8d3cb;
  --text-primary: #1a1714;
  --text-muted: #7a746b;
  --accent: #8b6f47;
  --accent-light: #c4a882;
  --white: #fdfcfa;
  --shadow-sm: 0 2px 12px rgba(26, 23, 20, .08);
  --shadow-md: 0 8px 40px rgba(26, 23, 20, .18);
  --shadow-lg: 0 20px 80px rgba(26, 23, 20, .35);
  --radius: 4px;
  --transition: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  scroll-behavior: smooth;
}

body {
  background-color: var(--bg);
  color: var(--text-primary);
  font-family: 'Josefin Sans', sans-serif;
  font-weight: 300;
  min-height: 100vh;
  /* Subtle grain texture */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
}

/* ── HEADER ─────────────────────────────────────────────── */
header {
  text-align: center;
  padding: 64px 24px 48px;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(3rem, 8vw, 6rem);
  font-weight: 300;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-primary);
  line-height: 1;
}

.subtitle {
  margin-top: 10px;
  font-size: 0.72rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ── GALLERY GRID ────────────────────────────────────────── */
main {
  padding: 48px 32px 80px;
  max-width: 1400px;
  margin: 0 auto;
}

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

/* ── GALLERY ITEM ────────────────────────────────────────── */
.gallery-item {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  aspect-ratio: 4 / 3;

  /* Staggered entrance animation */
  opacity: 0;
  transform: translateY(20px);
  animation: fadeUp 0.6s forwards;
}

/* Stagger delays for first 12 items */
.gallery-item:nth-child(1) {
  animation-delay: 0.05s;
}

.gallery-item:nth-child(2) {
  animation-delay: 0.10s;
}

.gallery-item:nth-child(3) {
  animation-delay: 0.15s;
}

.gallery-item:nth-child(4) {
  animation-delay: 0.20s;
}

.gallery-item:nth-child(5) {
  animation-delay: 0.25s;
}

.gallery-item:nth-child(6) {
  animation-delay: 0.30s;
}

.gallery-item:nth-child(7) {
  animation-delay: 0.35s;
}

.gallery-item:nth-child(8) {
  animation-delay: 0.40s;
}

.gallery-item:nth-child(9) {
  animation-delay: 0.45s;
}

.gallery-item:nth-child(10) {
  animation-delay: 0.50s;
}

.gallery-item:nth-child(11) {
  animation-delay: 0.55s;
}

.gallery-item:nth-child(12) {
  animation-delay: 0.60s;
}

@keyframes fadeUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform var(--transition);
}

.gallery-item:hover img {
  transform: scale(1.06);
}

/* ── OVERLAY ─────────────────────────────────────────────── */
.overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top,
      rgba(26, 23, 20, 0.65) 0%,
      rgba(26, 23, 20, 0.0) 55%);
  display: flex;
  align-items: flex-end;
  padding: 18px 20px;
  opacity: 0;
  transition: opacity var(--transition);
}

.gallery-item:hover .overlay {
  opacity: 1;
}

.overlay span {
  font-size: 0.68rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--white);
  font-weight: 400;
}

/* ── LIGHTBOX BACKDROP ───────────────────────────────────── */
.lightbox-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 9, 8, 0.92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 900;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.lightbox-backdrop.active {
  opacity: 1;
  pointer-events: all;
}

/* ── LIGHTBOX ────────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 32px 16px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.lightbox.active {
  opacity: 1;
  pointer-events: all;
}

/* ── LIGHTBOX IMAGE CONTENT ──────────────────────────────── */
.lightbox-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: calc(100vw - 160px);
  max-height: calc(100vh - 64px);
}

.lightbox-content img {
  max-width: 100%;
  max-height: calc(100vh - 130px);
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: block;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.lightbox-content img.switching {
  opacity: 0;
  transform: scale(0.97);
}

/* ── LIGHTBOX CAPTION & COUNTER ──────────────────────────── */
.lightbox-caption {
  margin-top: 14px;
  font-size: 0.68rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgba(253, 252, 250, 0.6);
  text-align: center;
  min-height: 16px;
}

.lightbox-counter {
  margin-top: 6px;
  font-size: 0.62rem;
  letter-spacing: 0.22em;
  color: rgba(253, 252, 250, 0.35);
  text-align: center;
}

/* ── LIGHTBOX NAV BUTTONS ────────────────────────────────── */
.lightbox-nav {
  background: none;
  border: 1px solid rgba(253, 252, 250, 0.2);
  border-radius: 50%;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--white);
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
  align-self: center;
}

.lightbox-nav svg {
  width: 22px;
  height: 22px;
}

.lightbox-nav:hover {
  background: rgba(253, 252, 250, 0.12);
  border-color: rgba(253, 252, 250, 0.45);
  transform: scale(1.08);
}

.lightbox-nav:active {
  transform: scale(0.96);
}

/* ── LIGHTBOX CLOSE BUTTON ───────────────────────────────── */
.lightbox-close {
  position: fixed;
  top: 24px;
  right: 28px;
  background: none;
  border: 1px solid rgba(253, 252, 250, 0.2);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  color: var(--white);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
  z-index: 1010;
}

.lightbox-close:hover {
  background: rgba(253, 252, 250, 0.12);
  border-color: rgba(253, 252, 250, 0.45);
  transform: rotate(90deg);
}

/* ── RESPONSIVE ──────────────────────────────────────────── */
@media (max-width: 768px) {
  main {
    padding: 32px 16px 60px;
  }

  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
  }

  .lightbox {
    gap: 12px;
    padding: 20px 8px;
  }

  .lightbox-content {
    max-width: calc(100vw - 100px);
  }

  .lightbox-nav {
    width: 40px;
    height: 40px;
  }

  .lightbox-nav svg {
    width: 18px;
    height: 18px;
  }
}

@media (max-width: 480px) {
  .lightbox-content {
    max-width: calc(100vw - 80px);
  }

  .lightbox-nav {
    width: 36px;
    height: 36px;
  }
}