:root {
  color-scheme: light;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: #202020;
  background: #faf9f6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 6px;
}

.gallery-content {
  --hex-width: 220px;
  --tracks: 8;
  container-type: inline-size;
  max-width: calc(var(--hex-width) * var(--tracks) / 2 + 48px);
  margin: 80px auto 0;
  padding: 0 24px;
}

.gallery-header {
  margin: 24px 32px 0;
}

h1,
.wordmark {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px;
  font-weight: 400;
  letter-spacing: -0.045em;
  line-height: 1.2;
}

h1 {
  margin: 0;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(var(--tracks), minmax(0, 1fr));
  /* Four quarter-height tracks per hex, three tracks between row centers. */
  grid-auto-rows: calc(100cqw / var(--tracks) / 1.7320508);
}

.thumbnail {
  grid-column: var(--column) / span 2;
  grid-row: var(--row) / span 4;
  display: block;
  min-width: 0;
  min-height: 0;
  margin: 4px;
  padding: 3px;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  scroll-margin-block: 32px;
}

.thumbnail:focus-visible {
  outline: none;
}

.thumbnail img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  transition:
    opacity 240ms ease-out,
    transform 240ms ease-out;
}

@media (hover: hover) {
  .thumbnail:hover img {
    opacity: 0.92;
    transform: scale(1.012);
  }

  .viewer-nav:hover,
  .viewer-close:hover {
    color: #202020;
  }
}

.thumbnail:focus-visible img {
  opacity: 0.7;
}

.viewer-page {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  height: 100svh;
  min-height: 320px;
  padding: 24px 32px;
}

.gallery-header,
.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
}

.viewer-close,
.viewer-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  color: #74706a;
}

.viewer-close svg,
.viewer-nav svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.viewer-stage {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  align-items: center;
  gap: 24px;
  min-height: 0;
  padding: 24px 0;
}

.viewer-artwork {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  margin: 0;
}

.viewer-artwork img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(80vh, calc(100svh - 184px));
  object-fit: contain;
}

.viewer-counter {
  margin: 0;
  padding-top: 16px;
  color: #74706a;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.12em;
  line-height: 1.5;
  text-align: center;
}

@media (width < 1000px) {
  .gallery-content {
    --tracks: 6;
  }

  .thumbnail {
    grid-column: var(--tablet-column) / span 2;
    grid-row: var(--tablet-row) / span 4;
  }
}

@media (width < 700px) {
  .gallery-content {
    --tracks: 5;
    margin-top: 56px;
  }

  .thumbnail {
    grid-column: var(--mobile-column) / span 2;
    grid-row: var(--mobile-row) / span 4;
  }

  .viewer-page {
    padding: 24px 16px 20px;
  }

  .viewer-header {
    margin-inline: 16px;
  }

  .viewer-stage {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: minmax(0, 1fr) 48px;
    gap: 12px;
    padding: 16px 0 0;
  }

  .viewer-artwork {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .viewer-artwork img {
    max-height: calc(100svh - 212px);
  }

  .viewer-nav {
    grid-row: 2;
  }

  .viewer-next {
    justify-self: end;
  }

  .viewer-counter {
    padding-top: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .thumbnail img {
    transition: none;
  }

  .thumbnail:hover img {
    transform: none;
  }
}
