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

/* ─── Tokens ─────────────────────────────────────────────── */
:root {
  --bg:          #F7F6F2;
  --text:        #1C1C1A;
  --text-muted:  rgba(28, 28, 26, 0.35);
  --gap:         5px;
  --header-h:    48px;
  --font:        -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --ease-out:    cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ─── Base ───────────────────────────────────────────────── */
html {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100dvh;
}

/* ─── Header ─────────────────────────────────────────────── */
.site-header {
  position: fixed;
  inset-block-start: 0;
  inset-inline: 0;
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding-inline: 18px;
  background: var(--bg);
  z-index: 10;
}

.site-title {
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: lowercase;
  color: var(--text);
  text-decoration: none;
  opacity: 0.55;
  transition: opacity 0.2s;
}

.site-title:hover {
  opacity: 1;
}

/* ─── Gallery ────────────────────────────────────────────── */
main {
  padding-top: calc(var(--header-h) + var(--gap));
}

.gallery {
  columns: 3 260px;
  gap: var(--gap);
  padding: var(--gap);
}

/* Empty / error state */
.gallery-empty {
  columns: unset;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

/* ─── Gallery items ──────────────────────────────────────── */
.gallery-item {
  break-inside: avoid;
  display: block;
  margin-bottom: var(--gap);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  /* remove default button/a styles if used */
  background: none;
  border: none;
  padding: 0;
  line-height: 0;
}

.gallery-item img {
  width: 100%;
  height: auto;
  display: block;
  opacity: 0;
  transition: opacity 0.4s var(--ease-out), transform 0.4s var(--ease-out);
  will-change: opacity;
  /* subtle warm bg while loading */
  background: #EEEDE9;
}

.gallery-item img.loaded {
  opacity: 1;
}

.gallery-item:hover img {
  opacity: 0.82;
}

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

/* ─── Lightbox ───────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 9, 0.97);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s var(--ease-out);
  /* prevent text select on rapid clicks */
  user-select: none;
  -webkit-user-select: none;
}

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

.lightbox-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: min(90vw, calc(100dvh * 2));
  max-height: 90dvh;
}

.lightbox-image {
  max-width: 90vw;
  max-height: 90dvh;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  opacity: 0;
  transition: opacity 0.3s var(--ease-out);
}

.lightbox-image.loaded {
  opacity: 1;
}

/* ─── Lightbox controls ──────────────────────────────────── */
.lightbox-close,
.lightbox-prev,
.lightbox-next {
  position: absolute;
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.45);
  padding: 14px;
  transition: color 0.2s;
  line-height: 0;
  z-index: 2;
}

.lightbox-close:hover,
.lightbox-prev:hover,
.lightbox-next:hover {
  color: rgba(255, 255, 255, 0.9);
}

.lightbox-close {
  top: 16px;
  right: 18px;
}

.lightbox-prev {
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
}

.lightbox-next {
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
}

.lightbox-counter {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  letter-spacing: 0.18em;
  color: rgba(255, 255, 255, 0.25);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ─── Spinner ────────────────────────────────────────────── */
.lightbox-spinner {
  position: absolute;
  width: 20px;
  height: 20px;
  border: 1.5px solid rgba(255, 255, 255, 0.12);
  border-top-color: rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.lightbox-spinner.visible {
  opacity: 1;
}

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

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 540px) {
  :root {
    --gap: 3px;
    --header-h: 44px;
  }

  .gallery {
    columns: 1;
  }

  .lightbox-prev,
  .lightbox-next {
    /* on mobile: swipe instead */
    display: none;
  }

  .lightbox-close {
    top: 12px;
    right: 14px;
  }
}

@media (max-width: 860px) and (min-width: 541px) {
  .gallery {
    columns: 2;
  }
}

/* Prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  .gallery-item img,
  .lightbox,
  .lightbox-image {
    transition: none;
  }

  .lightbox-spinner {
    animation: none;
  }
}
