/* ═══════════════════════════════════════════════════════════════
   Reusable interactive components — before/after slider, story
   carousel, lightbox gallery. Loaded on pages that use them.
   ═══════════════════════════════════════════════════════════════ */

/* ── before / after slider ───────────────────────────────────────
   No-JS fallback: --pos defaults to 50%, so the frame renders as a
   static half-and-half split — still legible as a comparison.
   touch-action:pan-y hands vertical swipes to the browser (page scroll)
   and horizontal ones to js/before-after.js. */
.ba{margin:0;}
.ba__frame{
  position:relative;aspect-ratio:var(--ba-ratio,4/3);
  border-radius:var(--radius);overflow:hidden;
  --pos:50%;
  cursor:ew-resize;touch-action:pan-y;
  user-select:none;-webkit-user-select:none;-webkit-touch-callout:none;
  background:var(--paper-2);
}
.ba__img{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;display:block;pointer-events:none;}
.ba__img--after{clip-path:inset(0 0 0 var(--pos));}
.ba__divider{
  position:absolute;top:0;bottom:0;left:var(--pos);
  width:2px;background:#fff;transform:translateX(-1px);
  box-shadow:0 0 0 1px rgba(21,25,26,.25);
  pointer-events:none;
}
.ba__handle{
  position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);
  width:46px;height:46px;border-radius:50%;
  background:#fff;color:var(--ink);box-shadow:0 4px 14px rgba(21,25,26,.3);
  display:flex;align-items:center;justify-content:center;
  pointer-events:auto;cursor:ew-resize;
  font-size:1.2rem;font-weight:700;line-height:1;
}
.ba__handle::before{content:"\2039\2002\203A";transform:translateY(-1px);}
@media (pointer:coarse){ .ba__handle{width:52px;height:52px;} }
.ba--js .ba__handle{transition:box-shadow var(--ease),transform var(--ease);}
.ba--js .ba__frame.is-dragging .ba__handle{box-shadow:0 6px 22px rgba(21,25,26,.45);transform:translate(-50%,-50%) scale(1.08);}
.ba__frame:not(.is-dragging) .ba__divider,
.ba__frame:not(.is-dragging) .ba__img--after{transition:left .5s var(--ease-slow),clip-path .5s var(--ease-slow);}

.ba__tag{
  position:absolute;top:12px;z-index:3;
  padding:.4rem .75rem;border-radius:999px;
  font-size:.72rem;font-weight:700;letter-spacing:.1em;text-transform:uppercase;
  background:rgba(21,25,26,.72);color:#fff;pointer-events:none;
}
.ba__tag--before{left:12px;}
.ba__tag--after{right:12px;}

.ba__hint{
  display:flex;align-items:center;gap:.5rem;margin-top:.8rem;
  font-size:.85rem;color:var(--body-dim);
}
.ba__hint svg{flex:0 0 auto;}
/* Say "drag" to touch users; mention the keyboard only where there is one. */
.ba__hint-mouse{display:none;}
@media (hover:hover) and (pointer:fine){
  .ba__hint-touch{display:none;}
  .ba__hint-mouse{display:inline;}
}

/* ── story carousel ──────────────────────────────────────────────
   The track runs edge to edge so the next slide peeks in from the screen
   edge; --story-inset lines the first slide up with the page content on any
   width (the gutter on phones, the centred container edge on wide screens).
   Place .story outside .container. */
.story{position:relative;--story-inset:max(var(--gutter), calc((100% - var(--container)) / 2 + var(--gutter)));}
.story__track{
  display:flex;align-items:flex-start;gap:1rem;
  overflow-x:auto;overscroll-behavior-x:contain;
  scroll-snap-type:x mandatory;
  padding:0 var(--story-inset) .5rem;scroll-padding-inline:var(--story-inset);
  scrollbar-width:none;
}
.story__track::-webkit-scrollbar{display:none;}
/* Guarantees trailing space after the last slide in engines that ignore
   inline-end padding on a scrolling flex container. */
.story__track::after{content:"";flex:0 0 1px;}
.story__slide{scroll-snap-align:start;flex:0 0 auto;width:min(80vw,420px);margin:0;}
@media (min-width:56rem){ .story__slide{width:min(38vw,460px);} }
/* Sized by aspect-ratio, not height:100% — percentage height inside the
   stretched flex item made each image fill the whole slide and pushed its
   caption into the track's hidden overflow, so no caption ever showed. */
.story__slide img{
  display:block;width:100%;height:auto;aspect-ratio:4/5;object-fit:cover;
  border-radius:var(--radius);background:var(--ink-2);
}
.story__slide figcaption{margin-top:.85rem;}
.story__slide figcaption p{margin:0;}
.story__step{font-size:.75rem;font-weight:700;letter-spacing:.14em;text-transform:uppercase;color:var(--jade-ink);}
.story__slide .story__step-title{font-weight:700;font-size:1.04rem;line-height:1.35;color:var(--ink);margin-top:.25rem;}
.story__slide .story__step-title--on-dark{color:var(--on-dark);}
.story__step--on-dark{color:var(--jade-bright);}

.story__nav{
  display:flex;align-items:center;justify-content:space-between;gap:1rem;
  margin-top:1.25rem;padding-inline:var(--story-inset);
}
.story__dots{display:flex;}
/* 24x24 tap target, 8px dot drawn inside it. */
.story__dot{
  width:24px;height:24px;padding:0;border:none;background:transparent;cursor:pointer;
  display:flex;align-items:center;justify-content:center;
}
.story__dot::before{
  content:"";width:8px;height:8px;border-radius:4px;background:var(--line);
  transition:width var(--ease),background var(--ease);
}
.story__dot.is-active::before{width:20px;background:var(--jade-ink);}
.band--dark .story__dot::before{background:rgba(244,244,242,.28);}
.band--dark .story__dot.is-active::before{background:var(--jade-bright);}

/* Phones get a counter and a progress line instead of a row of dots. */
.story__progress{display:none;align-items:center;gap:.75rem;flex:1;min-width:0;}
.story__count{font-size:.85rem;font-weight:700;font-variant-numeric:tabular-nums;color:var(--ink);white-space:nowrap;}
.band--dark .story__count{color:var(--on-dark);}
.story__bar{position:relative;flex:1;height:2px;max-width:9rem;background:var(--line);border-radius:2px;overflow:hidden;}
.band--dark .story__bar{background:rgba(244,244,242,.2);}
.story__bar span{position:absolute;inset:0 auto 0 0;width:0;background:var(--jade-ink);transition:width .35s var(--ease-slow);}
.band--dark .story__bar span{background:var(--jade-bright);}
@media (max-width:39.99rem){
  .story__dots{display:none;}
  .story__progress{display:flex;}
}

.story__arrows{display:flex;gap:.5rem;flex:0 0 auto;}
.story__prev,.story__next{
  width:44px;height:44px;border-radius:50%;border:1px solid var(--line);background:#fff;color:var(--ink);
  display:flex;align-items:center;justify-content:center;cursor:pointer;
  font-size:1.35rem;line-height:1;
  transition:border-color var(--ease),opacity var(--ease),transform var(--ease);
}
.band--dark .story__prev,.band--dark .story__next{background:transparent;border-color:rgba(244,244,242,.3);color:var(--on-dark);}
@media (hover:hover){ .story__prev:hover,.story__next:hover{border-color:var(--jade-ink);} }
.story__prev:active,.story__next:active{transform:scale(.94);}
.story__prev:disabled,.story__next:disabled{opacity:.35;cursor:default;transform:none;}
.story__prev:focus-visible,.story__next:focus-visible,.story__dot:focus-visible{outline:2px solid var(--jade);outline-offset:2px;}

/* ── gallery grid + lightbox ────────────────────────────────────── */
.gallery{display:grid;gap:.6rem;grid-template-columns:repeat(2,1fr);}
@media (min-width:40rem){ .gallery{gap:.85rem;grid-template-columns:repeat(3,1fr);} }
.gallery__item{
  display:block;padding:0;border:none;background:var(--paper-2);
  border-radius:var(--radius-sm);overflow:hidden;cursor:zoom-in;aspect-ratio:1;
  position:relative;transition:transform var(--ease);
}
.gallery__item img{width:100%;height:100%;object-fit:cover;transition:transform 400ms var(--ease);}
.gallery__item:focus-visible{outline:2px solid var(--jade);outline-offset:2px;}
.gallery__item::after{content:"";position:absolute;inset:0;background:rgba(21,25,26,0);transition:background var(--ease);}
@media (hover:hover){
  .gallery__item:hover img{transform:scale(1.06);}
  .gallery__item:hover::after{background:rgba(21,25,26,.08);}
}
.gallery__item:active{transform:scale(.97);}

.lightbox{
  position:fixed;inset:0;z-index:200;
  background:rgba(10,12,12,.95);
  display:flex;align-items:center;justify-content:center;
  padding:calc(3.5rem + env(safe-area-inset-top)) clamp(1rem,4vw,3rem) calc(3.5rem + env(safe-area-inset-bottom));
  overscroll-behavior:contain;
}
.lightbox[hidden]{display:none;}
.lightbox__img{max-width:min(1100px,100%);max-height:100%;object-fit:contain;border-radius:4px;}
.lightbox__caption{
  position:absolute;left:1rem;right:1rem;bottom:calc(1.1rem + env(safe-area-inset-bottom));
  margin:0;text-align:center;color:var(--on-dark-dim);font-size:.9rem;
}
.lightbox__caption[hidden]{display:none;}
.lightbox__counter{
  position:absolute;top:calc(1.3rem + env(safe-area-inset-top));left:1.25rem;color:var(--on-dark-dim);
  font-size:.82rem;font-variant-numeric:tabular-nums;letter-spacing:.05em;
}
.lightbox__close,.lightbox__prev,.lightbox__next{
  position:absolute;background:rgba(244,244,242,.1);border:1px solid rgba(244,244,242,.2);
  color:#fff;border-radius:50%;cursor:pointer;
  display:flex;align-items:center;justify-content:center;line-height:1;
  transition:background var(--ease),border-color var(--ease);
}
@media (hover:hover){
  .lightbox__close:hover,.lightbox__prev:hover,.lightbox__next:hover{background:rgba(244,244,242,.18);border-color:rgba(244,244,242,.4);}
}
.lightbox__close{top:calc(.75rem + env(safe-area-inset-top));right:1rem;width:44px;height:44px;font-size:1.4rem;}
.lightbox__prev,.lightbox__next{top:50%;transform:translateY(-50%);width:48px;height:48px;font-size:1.6rem;}
.lightbox__prev{left:clamp(.5rem,2vw,1.5rem);}
.lightbox__next{right:clamp(.5rem,2vw,1.5rem);}
.lightbox__close:focus-visible,.lightbox__prev:focus-visible,.lightbox__next:focus-visible{outline:2px solid var(--jade);outline-offset:2px;}
/* Phones: arrows move off the photo to the bottom corners, where thumbs are;
   swiping the photo works too. */
@media (max-width:39.99rem){
  .lightbox{padding-inline:.5rem;}
  .lightbox__prev,.lightbox__next{top:auto;bottom:calc(.5rem + env(safe-area-inset-bottom));transform:none;width:48px;height:48px;}
  .lightbox__prev{left:.75rem;}
  .lightbox__next{right:.75rem;}
  .lightbox__caption{left:4.5rem;right:4.5rem;bottom:calc(1.3rem + env(safe-area-inset-bottom));font-size:.82rem;}
}

@media (prefers-reduced-motion:reduce){
  .ba__frame .ba__divider,.ba__frame .ba__img--after,.ba__handle,
  .story__dot::before,.story__bar span,.gallery__item,.gallery__item img{transition:none !important;}
}
