:root {
  --bg: #ffffff;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --tile-bg: #ececec;
  --focus: #2b6cff;
  --page-pad: 16px;
}

@media (min-width: 640px) {
  :root {
    --page-pad: 24px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --text: #f1f1f1;
    --muted: #a0a0a0;
    --tile-bg: #242424;
    --focus: #7aa2ff;
  }
}

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

html {
  /* Keep the container width the same whether or not the page scrolls, so the
     scrollbar appearing never triggers a second layout. */
  scrollbar-gutter: stable;
}

html.lightbox-open {
  overflow: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

.page {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 var(--page-pad) 64px;
}

.page-title {
  margin: 0;
  padding: 40px 0 24px;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* --- Gallery ------------------------------------------------------------- */

/* gallery.js sets this element's height and every tile's left/top/width/height.
   Nothing here depends on the photos, so nothing shifts as they load. */
.gallery {
  position: relative;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tile {
  position: absolute;
  margin: 0;
  overflow: hidden;
  background: var(--tile-bg);
}

.tile-link {
  display: block;
  width: 100%;
  height: 100%;
}

.tile-link:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: -3px;
}

.tile-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 50%; /* gallery.js overrides this per photo from `focal` */
  opacity: 0;
  transition: opacity 0.5s ease, transform 0.6s ease;
}

.tile-img.is-loaded {
  opacity: 1;
}

.tile.is-broken .tile-img {
  opacity: 0;
}

@media (hover: hover) {
  .tile-link:hover .tile-img {
    transform: scale(1.04);
  }
}

/* --- Load more ----------------------------------------------------------- */

.gallery-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding-top: 32px;
}

.gallery-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.gallery-more {
  min-height: 44px;
  padding: 0 24px;
  border: 1px solid currentColor;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.gallery-more[hidden] {
  display: none;
}

.gallery-more:hover {
  background: var(--text);
  color: var(--bg);
}

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

/* --- Lightbox ------------------------------------------------------------ */

.lightbox {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: rgba(0, 0, 0, 0.92);
  color: #fff;
}

.lightbox[open] {
  display: grid;
}

.lightbox::backdrop {
  background: transparent;
}

.lightbox-figure {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  justify-items: center;
  margin: 0;
  padding: 56px 64px 16px;
  min-height: 0;
}

.lightbox-img {
  max-width: 100%;
  max-height: 100%;
  min-height: 0;
  margin: auto;
  object-fit: contain;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.lightbox-img.is-loaded {
  opacity: 1;
}

.lightbox-caption {
  padding-top: 12px;
  font-size: 0.875rem;
  text-align: center;
}

.lightbox-count {
  opacity: 0.6;
}

.lightbox-btn {
  position: absolute;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.lightbox-btn:hover {
  background: rgba(255, 255, 255, 0.24);
}

.lightbox-btn:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.lightbox-close {
  top: 8px;
  right: 8px;
}

.lightbox-prev,
.lightbox-next {
  top: 50%;
  transform: translateY(-50%);
}

.lightbox-prev {
  left: 8px;
}

.lightbox-next {
  right: 8px;
}

@media (max-width: 639px) {
  .lightbox-figure {
    padding: 56px 8px 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile-img,
  .lightbox-img {
    transition: opacity 0.15s linear;
  }

  .tile-link:hover .tile-img {
    transform: none;
  }
}
