/**
 * Image Comparison Component Styles
 */

.image-comparison-container {
  margin: 0 0 2.5rem;
}

.image-comparison-wrapper {
  --image-comparison-max-height: min(600px, 70vh);
  position: relative;
  display: block;
  width: 100%;
  /* Narrow the slider so the full image fits within the max height. */
  max-width: calc(var(--image-comparison-max-height) * var(--image-comparison-ratio));
  aspect-ratio: var(--image-comparison-ratio);
  margin: 0 auto;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: pan-y;
  background-color: #f5f5f5;
  /* Lets the overlay image match the wrapper width via cqw units. */
  container-type: inline-size;
}

.image-comparison-wrapper img {
  display: block;
  width: 100%;
  height: auto;
}

.image-comparison-wrapper .image-comparison-after {
  width: 100%;
  height: 100%;
  max-height: var(--image-comparison-max-height);
  object-fit: contain;
  display: block;
}

.image-comparison-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  height: 100%;
  overflow: hidden;
}

/* Extra specificity beats page rules such as `.node--type-projects .images img`. */
.image-comparison-wrapper .image-comparison-overlay .image-comparison-before {
  /* Match the after image size so both line up. Cover fills the whole
     slider, so the after image never shows through when the two images
     have different aspect ratios. */
  width: 100cqw;
  max-width: none;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-comparison-handle {
  position: absolute;
  top: 0;
  left: 50%;
  width: 2px;
  height: 100%;
  background: #fff;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
  cursor: ew-resize;
  transform: translateX(-50%);
  z-index: 10;
  outline: none;
}

/* Keyboard-only focus indicator; no frame on mouse or touch. */
.image-comparison-handle:focus-visible .image-comparison-handle-icon {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.6), 0 0 4px rgba(0, 0, 0, 0.3);
}

.image-comparison-handle-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
  box-sizing: border-box;
  border: 3px solid #fff;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
}

.image-comparison-handle-icon::before,
.image-comparison-handle-icon::after {
  content: '';
  width: 0;
  height: 0;
  border-style: solid;
}

.image-comparison-handle-icon::before {
  border-width: 6px 7px 6px 0;
  border-color: transparent #fff transparent transparent;
  margin-right: 3px;
}

.image-comparison-handle-icon::after {
  border-width: 6px 0 6px 7px;
  border-color: transparent transparent transparent #fff;
  margin-left: 3px;
}

.image-comparison-caption {
  margin-top: 1rem;
  font-size: 14px;
  color: #666;
  font-style: italic;
  line-height: 1.5;
}

/* Responsive Design */
@media (max-width: 768px) {
  .image-comparison-container {
    margin: 0 0 1.25rem;
  }

  .image-comparison-handle-icon {
    width: 38px;
    height: 38px;
  }

  .image-comparison-handle-icon::before {
    border-width: 5px 6px 5px 0;
  }

  .image-comparison-handle-icon::after {
    border-width: 5px 0 5px 6px;
  }
}
