/* Before/after comparison slider — companion to before-after.js.
   Usage: see the header comment in before-after.js. Everything is scoped to .ba-slider.
   The whole component is driven by one custom property, --p (0–100, handle position
   as a percentage from the left). JS writes --p; all visuals derive from it in CSS.
   Without JS the component still renders a static 50/50 comparison with both labels. */

.ba-slider {
  --p: 50;                       /* handle position, 0–100 */
  --ba-focus: #2563eb;           /* focus ring colour — override per site */
  position: relative;
  overflow: hidden;
  touch-action: pan-y;           /* the browser keeps vertical scroll; we take horizontal */
  -webkit-user-select: none;
  user-select: none;
}

.ba-slider > img {
  display: block;
  width: 100%;
  height: auto;
}

/* Second image = "after", overlaid and clipped from the left by --p.
   clip-path is compositor-only: no layout, no repaint of the image, no jank. */
.ba-slider > img + img {
  position: absolute;
  inset: 0;
  height: 100%;
  object-fit: cover;
  clip-path: inset(0 0 0 calc(var(--p) * 1%));
}

/* Corner labels. Each fades out as the handle approaches its own edge. */
.ba-slider::before,
.ba-slider::after {
  position: absolute;
  top: 12px;
  z-index: 2;
  padding: 4px 10px;
  border-radius: 3px;
  background: rgba(17, 19, 24, 0.62);
  color: #fff;
  font: 600 12px/1.4 system-ui, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  pointer-events: none;
}
.ba-slider::before {
  content: "Before";
  left: 12px;
  opacity: clamp(0, calc((var(--p) - 12) / 12), 1);
}
.ba-slider::after {
  content: "After";
  right: 12px;
  opacity: clamp(0, calc((88 - var(--p)) / 12), 1);
}

/* The handle: an invisible 44px-wide touch target centred on the divider line. */
.ba-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--p) * 1%);
  z-index: 3;
  width: 44px;
  margin-left: -22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: ew-resize;
  touch-action: pan-y;
}
.ba-handle::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  margin-left: -1px;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.18);
}
.ba-grip {
  position: relative;
  z-index: 1;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  display: grid;
  place-items: center;
}
.ba-handle:focus-visible {
  outline: none;
}
.ba-handle:focus-visible .ba-grip {
  outline: 3px solid var(--ba-focus);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .ba-slider,
  .ba-slider * {
    transition: none !important;
    animation: none !important;
  }
}
