/* Before/after slider. Two layouts:

   - resting (no JavaScript, or before-after.js failed): both pictures side
     by side, each with its label. Complete, nothing hidden.
   - html.ba-js: stacked, with the BEFORE picture clipped at --pos.

   html.ba-js is set by a two-line script in <head> (see index.html), so the
   page never paints the side-by-side layout and then jumps. */

.ba { --pos: 50; margin: 0; }

.ba-frame { position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.ba-side { position: relative; margin: 0; }
.ba-side img { display: block; width: 100%; height: auto; aspect-ratio: var(--ratio, 3 / 2); object-fit: cover; border-radius: 8px; }
.ba-label {
  display: inline-block; margin-top: .4rem;
  font-weight: 600; font-size: .9rem;
}
.ba-handle, .ba-range { display: none; }
.ba figcaption { margin-top: .75rem; color: var(--ink-soft, inherit); }

/* ---- Slider layout ---------------------------------------------------- */

html.ba-js .ba-frame {
  display: block;
  aspect-ratio: var(--ratio, 3 / 2);
  border-radius: 8px; overflow: hidden;
  /* Vertical swipes still scroll the page on a phone; only sideways drags
     reach the slider. Without this, a full-width slider traps the thumb. */
  touch-action: pan-y;
  cursor: ew-resize;
  user-select: none; -webkit-user-select: none;
}
html.ba-js .ba-side { position: absolute; inset: 0; }
html.ba-js .ba-side img { width: 100%; height: 100%; border-radius: 0; -webkit-user-drag: none; }
html.ba-js .ba-before {
  z-index: 1;
  clip-path: inset(0 calc(100% - var(--pos) * 1%) 0 0);
}

/* Labels sit inside their own picture, so the divider clips them naturally
   as it passes. No fading logic needed. */
html.ba-js .ba-label {
  position: absolute; top: .75rem; margin: 0;
  padding: .3rem .7rem; border-radius: 999px;
  background: rgba(16, 20, 24, .72); color: #fff;
}
html.ba-js .ba-before .ba-label { left: .75rem; }
html.ba-js .ba-after  .ba-label { right: .75rem; }

html.ba-js .ba-handle {
  display: block; position: absolute; z-index: 2; top: 0; bottom: 0;
  left: calc(var(--pos) * 1%);
  width: 3px; margin-left: -1.5px; background: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .25);
  pointer-events: none;
}
.ba-knob {
  position: absolute; top: 50%; left: 50%;
  width: 48px; height: 48px; margin: -24px 0 0 -24px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .3);
  display: grid; place-items: center; color: #1e242b;
}
.ba-knob svg { width: 24px; height: 24px; }

/* The range itself: covers the picture so a screen reader's touch
   exploration finds it anywhere on the image, but is invisible and lets
   pointer events through to the frame. Keyboard focus shows on the knob. */
html.ba-js .ba-range {
  display: block; position: absolute; inset: 0; z-index: 3;
  width: 100%; height: 100%; margin: 0;
  opacity: 0; pointer-events: none;
}
html.ba-js .ba:has(.ba-range:focus-visible) .ba-knob {
  outline: 3px solid var(--focus, #2350c8); outline-offset: 3px;
}
