/**
 * Drift: Wipe
 *
 * Full-screen overlay played on load (entrance) and on internal link
 * click (exit), see wipe.js. Every style shares the same left/right
 * panel markup (printed on wp_body_open by the plugin). Single-panel
 * styles (fade, the slides, diagonal, circle) only animate the left
 * panel, full screen. "curtain" splits the panels left and right,
 * "shutter" splits them top and bottom.
 *
 * The entrance runs as a CSS animation the moment the overlay paints, so
 * there's no flash of uncovered content while the script loads. The exit
 * is triggered by the script adding .is-leaving, which swaps in the *Out
 * keyframes; changing the animation-name restarts it. Every duration is
 * multiplied by --drift-wipe-speed (the Speed setting). At speed 1, keep
 * every exit under the 900 ms safety timeout in wipe.js; the script
 * scales that timeout by the same multiplier.
 */

/* Lock scrolling during the entrance. wipe.js removes .has-drift-wipe
   when the entrance ends; if the script never runs (JS off, blocked or
   broken), the driftWipeUnlock animation lifts the lock after 1.5 s
   (scaled by the speed) anyway. It's on html, not body, so it can't
   replace a theme's own body animation. The scrollbar gutter is reserved only while locked, so the
   content width doesn't jump when the scrollbar comes back. Browsers
   without :has() simply don't lock. */
html:has(> body.has-drift-wipe) {
  overflow: hidden;
  scrollbar-gutter: stable;
  animation: driftWipeUnlock 0s calc(1.5s * var(--drift-wipe-speed, 1)) forwards;
}
@keyframes driftWipeUnlock {
  to { overflow: visible; }
}

.drift-wipe-overlay {
  position: fixed;
  inset: 0;
  z-index: 100000;
  pointer-events: none;
}

.drift-wipe-overlay.is-leaving {
  pointer-events: auto;
}

/* Once the entrance has finished, wipe.js takes the overlay out of the
   layout entirely. Safari tints its toolbar from fixed elements at the
   top of the page, and an invisible overlay can still set that tint. */
.drift-wipe-overlay.is-idle {
  display: none;
}

.drift-wipe-overlay__panel {
  position: absolute;
  inset: 0;
  background-color: var(--drift-wipe-colour, #111111);
}

/* Only Curtain and Shutter use the right panel; every other style
   animates the left panel, full screen. Styles added through the
   drift_wipe_styles filter can show it the same way. */
.drift-wipe-overlay__panel--right {
  display: none;
}
.drift-wipe-overlay[data-wipe-style="curtain"] .drift-wipe-overlay__panel--right,
.drift-wipe-overlay[data-wipe-style="shutter"] .drift-wipe-overlay__panel--right {
  display: block;
}

/* ---------- Fade ---------- */
.drift-wipe-overlay[data-wipe-style="fade"] .drift-wipe-overlay__panel--left {
  animation: driftWipeFadeIn calc(.6s * var(--drift-wipe-speed, 1)) ease forwards;
}
.drift-wipe-overlay[data-wipe-style="fade"].is-leaving .drift-wipe-overlay__panel--left {
  animation: driftWipeFadeOut calc(.5s * var(--drift-wipe-speed, 1)) ease forwards;
}
@keyframes driftWipeFadeIn {
  from { opacity: 1; visibility: visible; }
  to   { opacity: 0; visibility: hidden; }
}
@keyframes driftWipeFadeOut {
  from { opacity: 0; visibility: visible; }
  to   { opacity: 1; visibility: visible; }
}

/* ---------- Slide Up ----------
   Enters from the bottom on exit, leaves off the top on entrance. */
.drift-wipe-overlay[data-wipe-style="slide-up"] .drift-wipe-overlay__panel--left {
  animation: driftWipeSlideIn calc(.7s * var(--drift-wipe-speed, 1)) cubic-bezier(.65, 0, .35, 1) forwards;
}
.drift-wipe-overlay[data-wipe-style="slide-up"].is-leaving .drift-wipe-overlay__panel--left {
  animation: driftWipeSlideOut calc(.6s * var(--drift-wipe-speed, 1)) cubic-bezier(.65, 0, .35, 1) forwards;
}
@keyframes driftWipeSlideIn {
  from { transform: translateY(0); visibility: visible; }
  to   { transform: translateY(-100%); visibility: hidden; }
}
@keyframes driftWipeSlideOut {
  from { transform: translateY(100%); visibility: visible; }
  to   { transform: translateY(0); visibility: visible; }
}

/* ---------- Slide Down ----------
   Enters from the top on exit, leaves off the bottom on entrance. */
.drift-wipe-overlay[data-wipe-style="slide-down"] .drift-wipe-overlay__panel--left {
  animation: driftWipeSlideDownIn calc(.7s * var(--drift-wipe-speed, 1)) cubic-bezier(.65, 0, .35, 1) forwards;
}
.drift-wipe-overlay[data-wipe-style="slide-down"].is-leaving .drift-wipe-overlay__panel--left {
  animation: driftWipeSlideDownOut calc(.6s * var(--drift-wipe-speed, 1)) cubic-bezier(.65, 0, .35, 1) forwards;
}
@keyframes driftWipeSlideDownIn {
  from { transform: translateY(0); visibility: visible; }
  to   { transform: translateY(100%); visibility: hidden; }
}
@keyframes driftWipeSlideDownOut {
  from { transform: translateY(-100%); visibility: visible; }
  to   { transform: translateY(0); visibility: visible; }
}

/* ---------- Slide Left ----------
   Enters from the right on exit, leaves off the left on entrance. */
.drift-wipe-overlay[data-wipe-style="slide-left"] .drift-wipe-overlay__panel--left {
  animation: driftWipeSlideLeftIn calc(.7s * var(--drift-wipe-speed, 1)) cubic-bezier(.65, 0, .35, 1) forwards;
}
.drift-wipe-overlay[data-wipe-style="slide-left"].is-leaving .drift-wipe-overlay__panel--left {
  animation: driftWipeSlideLeftOut calc(.6s * var(--drift-wipe-speed, 1)) cubic-bezier(.65, 0, .35, 1) forwards;
}
@keyframes driftWipeSlideLeftIn {
  from { transform: translateX(0); visibility: visible; }
  to   { transform: translateX(-100%); visibility: hidden; }
}
@keyframes driftWipeSlideLeftOut {
  from { transform: translateX(100%); visibility: visible; }
  to   { transform: translateX(0); visibility: visible; }
}

/* ---------- Slide Right ----------
   Enters from the left on exit, leaves off the right on entrance. */
.drift-wipe-overlay[data-wipe-style="slide-right"] .drift-wipe-overlay__panel--left {
  animation: driftWipeSlideRightIn calc(.7s * var(--drift-wipe-speed, 1)) cubic-bezier(.65, 0, .35, 1) forwards;
}
.drift-wipe-overlay[data-wipe-style="slide-right"].is-leaving .drift-wipe-overlay__panel--left {
  animation: driftWipeSlideRightOut calc(.6s * var(--drift-wipe-speed, 1)) cubic-bezier(.65, 0, .35, 1) forwards;
}
@keyframes driftWipeSlideRightIn {
  from { transform: translateX(0); visibility: visible; }
  to   { transform: translateX(100%); visibility: hidden; }
}
@keyframes driftWipeSlideRightOut {
  from { transform: translateX(-100%); visibility: visible; }
  to   { transform: translateX(0); visibility: visible; }
}

/* ---------- Curtain ---------- */
.drift-wipe-overlay[data-wipe-style="curtain"] .drift-wipe-overlay__panel--left {
  right: 50%;
  animation: driftWipeCurtainLeftIn calc(.8s * var(--drift-wipe-speed, 1)) cubic-bezier(.65, 0, .35, 1) forwards;
}
.drift-wipe-overlay[data-wipe-style="curtain"] .drift-wipe-overlay__panel--right {
  left: 50%;
  animation: driftWipeCurtainRightIn calc(.8s * var(--drift-wipe-speed, 1)) cubic-bezier(.65, 0, .35, 1) forwards;
}
.drift-wipe-overlay[data-wipe-style="curtain"].is-leaving .drift-wipe-overlay__panel--left {
  animation: driftWipeCurtainLeftOut calc(.6s * var(--drift-wipe-speed, 1)) cubic-bezier(.65, 0, .35, 1) forwards;
}
.drift-wipe-overlay[data-wipe-style="curtain"].is-leaving .drift-wipe-overlay__panel--right {
  animation: driftWipeCurtainRightOut calc(.6s * var(--drift-wipe-speed, 1)) cubic-bezier(.65, 0, .35, 1) forwards;
}
@keyframes driftWipeCurtainLeftIn {
  from { transform: translateX(0); visibility: visible; }
  to   { transform: translateX(-100%); visibility: hidden; }
}
@keyframes driftWipeCurtainRightIn {
  from { transform: translateX(0); visibility: visible; }
  to   { transform: translateX(100%); visibility: hidden; }
}
@keyframes driftWipeCurtainLeftOut {
  from { transform: translateX(-100%); visibility: visible; }
  to   { transform: translateX(0); visibility: visible; }
}
@keyframes driftWipeCurtainRightOut {
  from { transform: translateX(100%); visibility: visible; }
  to   { transform: translateX(0); visibility: visible; }
}

/* ---------- Shutter ----------
   Curtain turned on its side: the left panel is the top half, the right
   panel the bottom half. */
.drift-wipe-overlay[data-wipe-style="shutter"] .drift-wipe-overlay__panel--left {
  bottom: 50%;
  animation: driftWipeShutterTopIn calc(.8s * var(--drift-wipe-speed, 1)) cubic-bezier(.65, 0, .35, 1) forwards;
}
.drift-wipe-overlay[data-wipe-style="shutter"] .drift-wipe-overlay__panel--right {
  top: 50%;
  animation: driftWipeShutterBottomIn calc(.8s * var(--drift-wipe-speed, 1)) cubic-bezier(.65, 0, .35, 1) forwards;
}
.drift-wipe-overlay[data-wipe-style="shutter"].is-leaving .drift-wipe-overlay__panel--left {
  animation: driftWipeShutterTopOut calc(.6s * var(--drift-wipe-speed, 1)) cubic-bezier(.65, 0, .35, 1) forwards;
}
.drift-wipe-overlay[data-wipe-style="shutter"].is-leaving .drift-wipe-overlay__panel--right {
  animation: driftWipeShutterBottomOut calc(.6s * var(--drift-wipe-speed, 1)) cubic-bezier(.65, 0, .35, 1) forwards;
}
@keyframes driftWipeShutterTopIn {
  from { transform: translateY(0); visibility: visible; }
  to   { transform: translateY(-100%); visibility: hidden; }
}
@keyframes driftWipeShutterBottomIn {
  from { transform: translateY(0); visibility: visible; }
  to   { transform: translateY(100%); visibility: hidden; }
}
@keyframes driftWipeShutterTopOut {
  from { transform: translateY(-100%); visibility: visible; }
  to   { transform: translateY(0); visibility: visible; }
}
@keyframes driftWipeShutterBottomOut {
  from { transform: translateY(100%); visibility: visible; }
  to   { transform: translateY(0); visibility: visible; }
}

/* ---------- Diagonal ----------
   A slanted band sweeping left to right, drawn with clip-path. The
   polygon is a parallelogram whose bottom edge sits 30% left of its top
   edge; at full cover it overhangs both sides so no corner shows. Both
   directions move the same way: on exit the leading edge crosses the
   screen, on entrance the trailing edge follows it off. */
.drift-wipe-overlay[data-wipe-style="diagonal"] .drift-wipe-overlay__panel--left {
  animation: driftWipeDiagonalIn calc(.7s * var(--drift-wipe-speed, 1)) cubic-bezier(.65, 0, .35, 1) forwards;
}
.drift-wipe-overlay[data-wipe-style="diagonal"].is-leaving .drift-wipe-overlay__panel--left {
  animation: driftWipeDiagonalOut calc(.6s * var(--drift-wipe-speed, 1)) cubic-bezier(.65, 0, .35, 1) forwards;
}
@keyframes driftWipeDiagonalIn {
  from { clip-path: polygon(0 0, 130% 0, 100% 100%, -30% 100%); visibility: visible; }
  to   { clip-path: polygon(130% 0, 130% 0, 100% 100%, 100% 100%); visibility: hidden; }
}
@keyframes driftWipeDiagonalOut {
  from { clip-path: polygon(0 0, 0 0, -30% 100%, -30% 100%); visibility: visible; }
  to   { clip-path: polygon(0 0, 130% 0, 100% 100%, -30% 100%); visibility: visible; }
}

/* ---------- Circle Reveal ----------
   On exit a circle grows from the click point (--drift-wipe-x / -y, set
   by wipe.js; centre if unset, as in the settings preview). On entrance
   it shrinks to the centre. A 150% radius covers the screen from any
   point, corners included. */
.drift-wipe-overlay[data-wipe-style="circle"] .drift-wipe-overlay__panel--left {
  animation: driftWipeCircleIn calc(.7s * var(--drift-wipe-speed, 1)) cubic-bezier(.65, 0, .35, 1) forwards;
}
.drift-wipe-overlay[data-wipe-style="circle"].is-leaving .drift-wipe-overlay__panel--left {
  animation: driftWipeCircleOut calc(.7s * var(--drift-wipe-speed, 1)) cubic-bezier(.65, 0, .35, 1) forwards;
}
@keyframes driftWipeCircleIn {
  from { clip-path: circle(150% at 50% 50%); visibility: visible; }
  to   { clip-path: circle(0 at 50% 50%); visibility: hidden; }
}
@keyframes driftWipeCircleOut {
  from { clip-path: circle(0 at var(--drift-wipe-x, 50%) var(--drift-wipe-y, 50%)); visibility: visible; }
  to   { clip-path: circle(150% at var(--drift-wipe-x, 50%) var(--drift-wipe-y, 50%)); visibility: visible; }
}

@media (prefers-reduced-motion: reduce) {
  .drift-wipe-overlay {
    display: none;
  }
  html:has(> body.has-drift-wipe) {
    overflow: visible;
    animation: none;
  }
}
