:root {
  color-scheme: dark;
  background: #141414;
  color: #f4f0e9;
  font-family: system-ui, sans-serif;
}

* { box-sizing: border-box; }

body { margin: 0; }

button {
  color: inherit;
  font: inherit;
  cursor: pointer;
}

button:focus-visible {
  outline: 2px solid #f1d5a0;
  outline-offset: 4px;
}

.album {
  width: min(100%, 1680px);
  margin-inline: auto;
  padding: clamp(22px, 5vw, 80px);
}

.album-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: clamp(18px, 3vw, 36px);
  border-bottom: 1px solid #43403c;
  margin-bottom: clamp(16px, 2vw, 28px);
}

h1 {
  margin: 0;
  font: 400 clamp(2rem, 5.8vw, 5.4rem)/1 Georgia, serif;
}

.album-count, .position {
  margin: 0;
  white-space: nowrap;
  color: #c9c3bb;
  font-size: .9rem;
  font-variant-numeric: tabular-nums;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(8px, 1.15vw, 18px);
  list-style: none;
  margin: 0;
  padding: 0;
}

.tile {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 4px;
  background: #242321;
}

.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

@media (hover: hover) {
  .tile:hover img { filter: brightness(1.13); }
}

#viewer {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  border: 0;
  background: #0c0c0c;
  color: #f4f0e9;
  overscroll-behavior: contain;
}

#viewer::backdrop {
  background: #0c0c0c;
  overflow: hidden;
  overscroll-behavior: contain;
}

#viewer[open] {
  display: grid;
  grid-template:
    "header header header" auto
    "prev stage next" minmax(0, 1fr) / auto minmax(0, 1fr) auto;
  gap: 12px;
}

.viewer-header {
  grid-area: header;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

.position { grid-column: 2; }
.viewer-header form { justify-self: end; }
.previous { grid-area: prev; }
.next { grid-area: next; }

.control {
  display: inline-grid;
  place-items: center;
  align-self: center;
  justify-self: center;
  width: 48px;
  height: 48px;
  padding: 0 0 4px;
  border: 1px solid #4c4945;
  border-radius: 50%;
  background: #1d1c1a;
  font: 400 2.2rem/1 system-ui, sans-serif;
}

.control:hover { background: #383632; }

#stage {
  grid-area: stage;
  overflow: hidden;
  display: grid;
  place-items: center;
  touch-action: pan-y pinch-zoom;
}

#stage img {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.load-error {
  position: absolute;
  align-self: end;
  justify-self: center;
  margin: 0 12px 20px;
  padding: 8px 12px;
  border-radius: 4px;
  background: #292624;
  color: #f4f0e9;
  text-align: center;
}

@media (max-width: 980px) {
  .gallery { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  #viewer[open] {
    grid-template:
      "header header" auto
      "stage stage" minmax(0, 1fr)
      "prev next" auto / 1fr 1fr;
  }

  .load-error { margin-bottom: 70px; }
}
