:root {
  --bg: #cfcccc;
  --fg: #f5f5f5;
  --muted: #9a9a9a;
  --maxw: 1200px;
  --gap: 12px;
  --radius: 14px;
  --accent: #e8e8e8;
  --ink: #000000;
  --elev: 0 8px 24px rgba(0,0,0,0.28);
  --elev-sm: 0 2px 10px rgba(0,0,0,0.22);
  --ring: 0 0 0 3px rgba(255,255,255,0.18);
}

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

html,
body {
  height: 100%;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color-scheme: dark;
  text-rendering: optimizeLegibility;
}

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

main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(16px, 3vw, 32px);
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: #000;
  backdrop-filter: saturate(1.2) blur(6px);
  border-bottom: 1px solid rgba(0,0,0,0.06);
  box-shadow: 1px 1px 6px rgba(0,0,0,0.12);
}

header > p {
  margin: 0;
  color: #fff;
  letter-spacing: .7rem;
  text-transform: uppercase;
}

header a {
  display: inline-grid;
  place-items: center;
  height: 36px;
  width: 36px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.25);
  color: #fff;
  opacity: 0.9;
  text-decoration: none;
  transition: background .2s ease, border-color .2s ease, opacity .2s ease, transform .15s ease;
}

header a:hover {
  opacity: 1;
  border-color: rgba(255,255,255,0.35);
}

header a:active {
  transform: scale(0.96);
}

header a:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(0,0,0,0.12);
}

#masonry {
  column-width: 320px;
  column-gap: var(--gap);
  padding: var(--gap);
}

#masonry > img {
  display: block;
  width: 100%;
  height: auto;                 /* keep original aspect ratio */
  margin: 0 0 var(--gap);
  border-radius: var(--radius);
  background: #111;
  break-inside: avoid;
  -webkit-column-break-inside: avoid;
  box-shadow: 0 1px 0 rgba(255,255,255,0.04) inset,
              0 8px 24px rgba(0,0,0,0.22);
  transition: transform .25s ease, box-shadow .25s ease, opacity .25s ease;
  opacity: 0.98;
  content-visibility: auto;
}

#masonry > img:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 2px 0 rgba(255,255,255,0.05) inset,
              0 14px 36px rgba(0,0,0,0.32);
  opacity: 1;
}

#lightbox {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto 1fr auto;
  align-items: center;
  justify-items: center;
  background: rgba(0, 0, 0, 0.9);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease;
  z-index: 50;
}

#lightbox[aria-hidden="false"] {
  opacity: 1;
  visibility: visible;
}

#lightbox figure {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  max-width: min(92vw, 1400px);
  max-height: 86vh;
}

#lb-image {
  max-width: 100%;
  max-height: 82vh;
  object-fit: contain;
  border-radius: 10px;
}

#lb-caption {
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
}

#btn-close,
#btn-prev,
#btn-next {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  font-size: 28px;
  color: var(--fg);
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  cursor: pointer;
  opacity: 0.9;
  backdrop-filter: saturate(1.1) blur(2px);
  transition: background .2s ease, border-color .2s ease, transform .15s ease, opacity .2s ease;
}

#btn-close:hover,
#btn-prev:hover,
#btn-next:hover {
  opacity: 1;
  border-color: rgba(255, 255, 255, 0.5);
}

#btn-close:active,
#btn-prev:active,
#btn-next:active {
  transform: scale(0.96);
}

#btn-close:focus-visible,
#btn-prev:focus-visible,
#btn-next:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

#btn-close {
  grid-column: 3;
  grid-row: 1;
  margin: 16px;
}

#btn-prev {
  grid-column: 1;
  grid-row: 2;
  margin-left: 16px;
}

#btn-next {
  grid-column: 3;
  grid-row: 2;
  margin-right: 16px;
}

@media (prefers-reduced-motion: reduce) {
  #masonry img,
  #lightbox {
    transition: none;
  }
}

@media (max-width: 720px) {
  main {
    padding: 16px;
  }
  #masonry {
    column-width: 220px;
  }
  #btn-close,
  #btn-prev,
  #btn-next {
    width: 40px;
    height: 40px;
    font-size: 24px;
  }
}

::selection {
  background: rgba(255,255,255,0.16);
  color: #fff;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: #0e0e0e;
}

*::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.22);
  border-radius: 10px;
  border: 2px solid #0e0e0e;
}

*::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.32);
}