/* Put the moving photos inside a fixed square so the section never reflows. */
.mirror-factory-gallery {
  --factory-gap: clamp(4px, 0.44vw, 7px);
  --factory-neighbor: clamp(3px, 0.45vw, 7px);
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: var(--factory-gap);
  width: 100%;
  aspect-ratio: 1;
  margin: 0 auto;
}

.mirror-factory-photo {
  position: relative;
  z-index: 0;
  min-width: 0;
  min-height: 0;
}

.mirror-factory-photo:nth-child(1),
.mirror-factory-photo:nth-child(2) { --factory-corner-y: 1; }
.mirror-factory-photo:nth-child(3),
.mirror-factory-photo:nth-child(4) { --factory-corner-y: -1; }
.mirror-factory-photo:nth-child(odd) { --factory-corner-x: 1; }
.mirror-factory-photo:nth-child(even) { --factory-corner-x: -1; }

body.elementor-kit-5 .mirror-factory-photo img,
.mirror-factory-photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 0;
  box-shadow: none;
}

body.elementor-kit-5 .mirror-factory-photo:nth-child(1) img,
.mirror-factory-photo:nth-child(1) img { border-top-left-radius: 12px; }
body.elementor-kit-5 .mirror-factory-photo:nth-child(2) img,
.mirror-factory-photo:nth-child(2) img { border-top-right-radius: 12px; }
body.elementor-kit-5 .mirror-factory-photo:nth-child(3) img,
.mirror-factory-photo:nth-child(3) img { border-bottom-left-radius: 12px; }
body.elementor-kit-5 .mirror-factory-photo:nth-child(4) img,
.mirror-factory-photo:nth-child(4) img { border-bottom-right-radius: 12px; }

@media (hover: hover) and (pointer: fine) and (min-width: 768px) and (prefers-reduced-motion: no-preference) {
  .mirror-factory-gallery {
    /* Give a 6.5% half-tile enlargement room at the outer frame edges. */
    width: 93.8%;
  }

  .mirror-factory-photo img {
    transition: transform 220ms ease, box-shadow 220ms ease;
  }

  .mirror-factory-photo:nth-child(1) img { transform-origin: bottom right; }
  .mirror-factory-photo:nth-child(2) img { transform-origin: bottom left; }
  .mirror-factory-photo:nth-child(3) img { transform-origin: top right; }
  .mirror-factory-photo:nth-child(4) img { transform-origin: top left; }

  .mirror-factory-photo:has(img:hover) {
    z-index: 1;
  }

  .mirror-factory-photo img:hover {
    transform: translate(var(--factory-center-x), var(--factory-center-y)) scale(1.065);
    box-shadow: 0 5px 18px #17263f30;
  }

  /* Move the neighbors away from the hovered corner while keeping their boxes fixed. */
  .mirror-factory-gallery:has(.mirror-factory-photo:nth-child(odd) img:hover) { --factory-push-x: 1; }
  .mirror-factory-gallery:has(.mirror-factory-photo:nth-child(even) img:hover) { --factory-push-x: -1; }
  .mirror-factory-gallery:has(.mirror-factory-photo:nth-child(-n+2) img:hover) { --factory-push-y: 1; }
  .mirror-factory-gallery:has(.mirror-factory-photo:nth-child(n+3) img:hover) { --factory-push-y: -1; }

  .mirror-factory-gallery:has(img:hover) {
    /* Offset all four visual boxes by half the difference between their two outer edges. */
    --factory-center-x: calc((3.25% - var(--factory-neighbor) / 2) * var(--factory-push-x));
    --factory-center-y: calc((3.25% - var(--factory-neighbor) / 2) * var(--factory-push-y));
  }

  .mirror-factory-gallery:has(img:hover) .mirror-factory-photo img:not(:hover) {
    transform: translate(
      calc(var(--factory-center-x) + var(--factory-neighbor) * (var(--factory-push-x) - var(--factory-corner-x)) / 2),
      calc(var(--factory-center-y) + var(--factory-neighbor) * (var(--factory-push-y) - var(--factory-corner-y)) / 2)
    );
  }
}
