* {
  box-sizing: border-box;
  position: relative;
}

img {
  max-width: 100%;
  height: auto;
  transform-origin: top left;
}

.gallery {
  /* https://tobiasahlin.com/blog/masonry-with-css/ */
  display: flex;
  flex-flow: column wrap;
  align-content: space-between;
  overflow: hidden;
  height: 310vw;
  /* Re-order items into rows */
  /* Force new columns */
}
.gallery .gallery-image {
  width: 33.3%;
}
.gallery .gallery-image[data-flipping] {
  opacity: 1;
  z-index: 3;
}
.gallery .gallery-image:nth-child(3n+1) {
  order: 1;
}
.gallery .gallery-image:nth-child(3n+2) {
  order: 2;
}
.gallery .gallery-image:nth-child(3n) {
  order: 3;
}
.gallery::before, .gallery::after {
  content: "";
  flex-basis: 100%;
  width: 0;
  order: 2;
}

.gallery-image {
  margin: 0;
  display: block;
  position: relative;
}
.gallery-image img {
  display: block;
  width: 100%;
}
.gallery-image figcaption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  color: #FFF;
  text-shadow: 0 0 1px #000;
  opacity: 0.8;
  padding: 1em;
  text-align: left;
  transition: opacity 0.4s linear;
  font-family: monospace;
}
.gallery-image:hover figcaption {
  opacity: 1;
}

.detail {
  z-index: 2;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(25, 25, 25, 0);
  box-shadow: 0 0 30px #000;
  display: flex;
  pointer-events: none;
  transition: background 0.3s linear;
}
.detail .gallery-image {
  padding: 5vmin;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.detail .gallery-image img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
}
.detail .gallery-image figcaption {
  display: none;
}

[data-state=detail] .detail {
  background: rgba(25, 25, 25, 0.85);
  pointer-events: auto;
}
[data-state=detail] .detail .gallery-image {
  opacity: 1;
}

[data-state=gallery] .detail .gallery-image {
  opacity: 0;
  transition: none;
}

/* ---------------------------------- */


#app {
  pointer-events: none;
}
#app .gallery .gallery-image {
  pointer-events: auto;
}

.gallery-image {
  transition: opacity 0.5s linear;
}

#app:hover .gallery .gallery-image {
  opacity: 0.3;
}
#app:hover .gallery .gallery-image[data-flipping],
#app:hover .gallery .gallery-image:hover {
  opacity: 1;
  transition-duration: 0.3s;
}