:root {
  --bg: #07080b;
  --ink: #f4f6df;
  --muted: #6f7452;
  --paper: #e8ebe5;
  --olive: #666c4a;
  --charcoal: #171916;
  --gap: clamp(12px, 2.4vw, 20px);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 0%, rgba(105, 112, 76, 0.24), transparent 24rem),
    radial-gradient(circle at 88% 92%, rgba(86, 115, 104, 0.18), transparent 22rem),
    var(--bg);
  color: var(--ink);
  font-family: Inter, Arial, sans-serif;
}

.gallery-shell {
  --shell-pad-top: max(14px, env(safe-area-inset-top));
  --shell-pad-right: max(16px, env(safe-area-inset-right));
  --shell-pad-bottom: max(14px, env(safe-area-inset-bottom));
  --shell-pad-left: max(16px, env(safe-area-inset-left));
  position: relative;
  min-height: 100svh;
  overflow: hidden;
  padding: var(--shell-pad-top) var(--shell-pad-right) var(--shell-pad-bottom) var(--shell-pad-left);
  isolation: isolate;
}

.gallery-shell::before {
  content: "";
  position: fixed;
  inset: 4px;
  border: 1px solid rgba(244, 246, 223, 0.12);
  border-radius: 18px;
  pointer-events: none;
  z-index: 3;
}

.grain {
  position: fixed;
  inset: 0;
  opacity: 0.18;
  pointer-events: none;
  z-index: 1;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
  background-size: 23px 23px;
  mask-image: linear-gradient(to bottom, transparent, #000 10%, #000 92%, transparent);
}

.marquee-grid {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  gap: var(--gap);
  width: min(100%, 520px);
  height: calc(100svh - var(--shell-pad-top) - var(--shell-pad-bottom));
  margin: 0 auto;
  overflow: hidden;
  border-radius: 14px;
}

.column {
  position: relative;
  overflow: hidden;
}

.track {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-height: max-content;
  animation: roll-up var(--duration, 34s) linear infinite;
  will-change: transform;
}

.column[data-direction="down"] .track {
  animation-name: roll-down;
}

.tile {
  position: relative;
  aspect-ratio: 2409 / 3566;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--olive);
  box-shadow: 0 24px 46px rgba(0, 0, 0, 0.34);
}

.tile.photo {
  display: grid;
  align-items: stretch;
  cursor: zoom-in;
}

.tile.photo img {
  grid-area: 1 / 1;
}

.tile-backdrop {
  position: absolute;
  inset: -12%;
  width: 124%;
  height: 124%;
  object-fit: cover;
  filter: blur(22px) saturate(1.18) brightness(0.78);
  transform: scale(1.04);
}

.tile-image {
  position: relative;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  filter: saturate(0.94) contrast(0.98);
}

.tile[data-gallery-index] {
  cursor: zoom-in;
}

.tile[data-gallery-index]:focus-visible,
.icon-button:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(58px, 1fr) minmax(0, 1080px) minmax(58px, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  align-items: center;
  gap: 0;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  background: rgba(3, 4, 5, 0.28);
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: scale(1.01);
  transition: opacity 180ms ease, transform 180ms ease;
}

.lightbox::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 50% 48%, rgba(255, 255, 255, 0.16), transparent 34rem),
    rgba(4, 5, 5, 0.38);
}

.lightbox-backdrop {
  position: absolute;
  inset: -8%;
  z-index: -2;
  width: 116%;
  height: 116%;
  object-fit: cover;
  filter: blur(34px) saturate(1.25) brightness(0.66);
  transform: scale(1.04);
}

.lightbox.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}

.lightbox.is-open .lightbox-backdrop {
  animation: backdrop-bloom 300ms ease both;
}

.lightbox.is-open .lightbox-figure img {
  animation: photo-open 320ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.lightbox-top {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
}

.photo-count {
  display: grid;
  place-items: center;
  min-width: 68px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid rgba(244, 246, 223, 0.2);
  padding: 0 14px;
  background: rgba(10, 11, 12, 0.64);
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(244, 246, 223, 0.2);
  border-radius: 999px;
  background: rgba(10, 11, 12, 0.64);
  color: var(--ink);
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.icon-button svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-button {
  align-self: center;
  justify-self: center;
}

.prev-button {
  grid-column: 1;
  grid-row: 2;
}

.next-button {
  grid-column: 3;
  grid-row: 2;
}

.lightbox-figure {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  margin: 0;
  touch-action: pan-y;
}

.lightbox-figure img {
  display: block;
  max-width: 100%;
  max-height: calc(100svh - 104px);
  border-radius: 8px;
  object-fit: contain;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.54);
  user-select: none;
}

body.viewer-open .track {
  animation-play-state: paused;
}

@keyframes roll-up {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(-50%);
  }
}

@keyframes roll-down {
  from {
    transform: translateY(-50%);
  }
  to {
    transform: translateY(0);
  }
}

@keyframes photo-open {
  from {
    opacity: 0;
    transform: scale(0.94) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes backdrop-bloom {
  from {
    opacity: 0;
    transform: scale(1.1);
  }
  to {
    opacity: 1;
    transform: scale(1.04);
  }
}

@media (min-width: 760px) {
  .marquee-grid {
    width: min(72vw, 760px);
  }
}

@media (max-width: 430px) {
  .gallery-shell {
    padding-inline: max(14px, env(safe-area-inset-left));
  }

  .marquee-grid {
    grid-template-columns: repeat(3, minmax(78px, 1fr));
    gap: 10px;
    width: min(100%, 390px);
  }

}

@media (max-width: 560px) {
  .lightbox {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 12px;
  }

  .lightbox-figure {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .lightbox-figure img {
    max-height: calc(100svh - 150px);
  }

  .prev-button,
  .next-button {
    grid-row: 3;
    width: 52px;
    height: 52px;
  }

  .prev-button {
    grid-column: 1;
    justify-self: end;
  }

  .next-button {
    grid-column: 2;
    justify-self: start;
  }
}

@media (prefers-reduced-motion: reduce) {
  .track {
    animation-play-state: paused;
  }

  .lightbox.is-open .lightbox-backdrop,
  .lightbox.is-open .lightbox-figure img {
    animation: none;
  }
}
