/* Before/after image comparison slider — see layouts/shortcodes/compare.html */

.imgcmp-figure {
  margin: 2em 0;
}

.imgcmp {
  position: relative;
  overflow: hidden;
  border-radius: 6px;
  background: #0b0b0f;
  aspect-ratio: var(--ratio, 3 / 2);
  /* pinch-zoom stays available: people will want to zoom into a photo */
  touch-action: pan-y pinch-zoom;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none; /* no iOS "Save Image" sheet on a long press */
  cursor: ew-resize;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .18), 0 8px 24px rgba(0, 0, 0, .10);
}

/* Safari only got unprefixed aspect-ratio in iOS 15. Without a fallback the
   frame collapses to zero height and the slider vanishes entirely, so use the
   padding-bottom trick with a percentage worked out at build time. */
@supports not (aspect-ratio: 3 / 2) {
  .imgcmp {
    height: 0;
    padding-bottom: var(--pad, 66.667%);
  }
}

/* Doubled-up selector so this outranks the theme's `.post-content img`, whose
   margin-top would otherwise push both images 12px down inside the frame. */
.imgcmp .imgcmp__img {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  max-width: none; /* beat .post-content img */
  margin: 0;
  -webkit-user-drag: none;
  pointer-events: none;
}

/* fit="contain" letterboxes a mismatched image instead of cropping it */
.imgcmp[data-fit="contain"] .imgcmp__img {
  object-fit: contain;
}

.imgcmp__img--before {
  -webkit-clip-path: inset(0 calc(100% - var(--pos)) 0 0);
  clip-path: inset(0 calc(100% - var(--pos)) 0 0);
}

/* Divider + grip */
.imgcmp__divider {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--pos);
  width: 2px;
  margin-left: -1px;
  background: rgba(255, 255, 255, .9);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .28);
  pointer-events: none;
  z-index: 3;
}

.imgcmp__grip {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, .95);
  color: #111;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
  pointer-events: auto;
  cursor: ew-resize;
  transition: transform .12s ease;
}

.imgcmp__grip svg {
  width: 24px;
  height: 24px;
  display: block;
}

.imgcmp:hover .imgcmp__grip {
  transform: translate(-50%, -50%) scale(1.06);
}

.imgcmp.is-dragging {
  cursor: grabbing;
}

.imgcmp.is-dragging .imgcmp__grip {
  transform: translate(-50%, -50%) scale(.94);
}

/* Labels */
.imgcmp__label {
  position: absolute;
  top: 10px;
  z-index: 2;
  padding: 4px 9px;
  border-radius: 4px;
  background: rgba(10, 10, 14, .62);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  line-height: 1.4;
  pointer-events: none;
  transition: opacity .15s ease;
}

.imgcmp__label--before { left: 10px; }
.imgcmp__label--after  { right: 10px; }

/* Hide a label once its side is squeezed off screen */
.imgcmp[data-edge="left"]  .imgcmp__label--before,
.imgcmp[data-edge="right"] .imgcmp__label--after {
  opacity: 0;
}

/* Native range kept for keyboard + assistive tech; never captures pointers */
.imgcmp__range {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}

.imgcmp:focus-within {
  outline: 2px solid #1c7ed6;
  outline-offset: 3px;
}

.imgcmp__caption {
  margin-top: .6em;
  font-size: .85em;
  font-style: italic;
  color: #666;
  text-align: center;
}

@media screen and (max-width: 48em) {
  .imgcmp__grip { width: 40px; height: 40px; }
  .imgcmp__grip svg { width: 22px; height: 22px; }
  .imgcmp__label { font-size: 10px; top: 8px; }
  .imgcmp__label--before { left: 8px; }
  .imgcmp__label--after { right: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .imgcmp__grip,
  .imgcmp__label { transition: none; }
  .imgcmp:hover .imgcmp__grip { transform: translate(-50%, -50%); }
}
