.expand-gallery {
  display: flex;
  gap: 6px;
  height: 420px;
}

.expand-gallery .expand-item {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 100%;
  overflow: hidden;
  border-radius: 16px;
  cursor: pointer;
  transition: flex 0.5s ease;
}

.expand-gallery .expand-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: grayscale(100%) brightness(80%);
  transition: filter 0.5s ease;
}

.expand-gallery .expand-item::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.6;
  mix-blend-mode: overlay;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

.expand-gallery .expand-item:hover {
  flex: 3;
}

.expand-gallery .expand-item:hover img {
  filter: grayscale(0%);
}

.expand-gallery .expand-item:hover::after {
  opacity: 0;
}

/* default-open item: expanded/colored at rest, but yields to normal
   hover behavior the moment any item in the gallery is hovered */
.expand-gallery:not(:hover) .expand-item--open {
  flex: 3;
}

.expand-gallery:not(:hover) .expand-item--open img {
  filter: grayscale(0%);
}

.expand-gallery:not(:hover) .expand-item--open::after {
  opacity: 0;
}

/* Loading skeleton: a soft shimmer in each tile until its image has loaded
   (the script adds .is-loaded). The tile at rest (open) keeps its image
   visible as soon as it paints — it's the largest element in the first view,
   so it must not wait for a script; the others fade in. Without JS the
   shortcode's <noscript> style turns all of this off. */
.expand-gallery.eg-js .expand-item {
  background: #e3e6ec;
}

.expand-gallery.eg-js .expand-item:not(.is-loaded)::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background-image: linear-gradient(100deg, rgba(255, 255, 255, 0) 20%, rgba(255, 255, 255, 0.6) 50%, rgba(255, 255, 255, 0) 80%);
  background-size: 200% 100%;
  background-repeat: no-repeat;
  animation: eg-shimmer 1.4s ease-in-out infinite;
}

.expand-gallery.eg-js .expand-item img {
  position: relative; /* paints above the shimmer layer */
}

.expand-gallery.eg-js .expand-item:not(.expand-item--open) img {
  opacity: 0;
  transition: filter 0.5s ease, opacity 0.4s ease;
}

.expand-gallery.eg-js .expand-item:not(.expand-item--open).is-loaded img {
  opacity: 1;
}

@keyframes eg-shimmer {
  from { background-position: 200% 0; }
  to { background-position: -100% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .expand-gallery.eg-js .expand-item:not(.is-loaded)::before {
    animation: none;
  }
}

/* Mobile: no reliable hover on touch, so tapping a tile moves the
   expand-item--open class instead (see the shortcode's inline script).
   The :not(:hover) rules above already make .expand-item--open show in
   color/no-grain here too, since .expand-gallery:hover basically never
   becomes true on a touch device — only the bigger grid span is new. */
@media (max-width: 768px) {
  .expand-gallery {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-auto-rows: 140px;
    gap: 8px;
    height: auto;
  }

  .expand-gallery .expand-item {
    height: auto;
    border-radius: 12px;
    order: 0;
  }

  .expand-gallery .expand-item--open {
    grid-column: 1 / -1;
    grid-row: span 2;
    order: -1;
  }
}
