main {
  display: block;
  box-sizing: border-box;
  padding: 0 1rem;
  width: 100%;
  column-count: 3;
  column-gap: 16px;
}

@media (min-width: 1800px) { main { column-count: 4; } }
@media (min-width: 2400px) { main { column-count: 5; } }
@media (min-width: 3000px) { main { column-count: 6; } }

main > h1,
main > h2,
main > h3,
main > p,
main > ul,
main > ol,
main > blockquote {
  column-span: all;
  display: block;
  max-width: 72ch;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 24px;
}

main > .gallery {
  column-span: none;
  display: inline-block;
  width: 100%;
  break-inside: avoid;
  margin: 0 0 16px 0;
  vertical-align: top;
}

.gallery p {
  margin: 0;
  line-height: 0;
  display: block;
}

main.large-image {
  display: flex;
  column-count: auto;
  flex-direction: column;
  align-items: center;
}

main.large-image > h1,
main.large-image > h2,
main.marge-image > :not(.gallery) {
  aligh-self: flex-start;
  width: 100%;
}

main.large-image > .gallery {
  width: fit-content;
  margin: 0 auto 40px auto;
}

.image-widget {
  position: relative;
  display: block;
  width: 100%;
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  border-radius: 8px;
}

.hover-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  color: #ffffff;
  padding: 10px;
  box-sizing: border-box;
  text-align: center;
  opacity: 0;
  transition: opacity 0.2s ease-in-out;
  pointer-events: none;
}

.image-widget img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  cursor: pointer;
  transition: opacity 0.3s ease;
  max-height: 90vh;
  object-fit: contain;
}

html:has(main.large-image) {
  scroll-snap-type: y proximity;
  scroll-behavior: smooth;
}

main.large-image > .gallery {
  scroll-snap-align: center;
  scroll-snap-stop: always;
}

main.large-image > h1, main.large-image > h2 {
  scroll-snap-align: start;
}

.image-widget:hover .hover-caption {
  opacity: 1;
}

.image-widget.is-active .hover-caption {
  opacity: 0;
}

.image-widget .overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.image-widget.is-active .overlay {
  opacity: 1;
  pointer-events: auto;
}

.image-widget.is-active img {
  opacity: 0.4;
}

.overlay-menu, .hover-caption {
  line-height: 1.4;
}

.overlay-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: center;
  width: 80%;
  max-width: 250px;
}

.menu-title {
  color: #a1a1aa;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 12px;
}

.menu-caption {
  color: #a1a1aa;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 12px;
}

.menu-title:first-child {
  margin-top: 0;
}

.menu-btn {
  color: #ffffff;
  text-decoration: none;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  transition: background 0.2s ease, transform 0.1s ease;
}

.menu-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.menu-btn:active {
  transform: scale(0.98);
}

@media (max-width: 768px) {
  main {
    column-gap: 2px;
    padding: 0 2px;
  }

  main > .gallery {
    margin-bottom: 2px;
  }

  main.large-image > .gallery {
    margin-bottom: 24px;
  }
}
