/**
 * Then & Now — before/after image comparison slider.
 * Paired with the [then_now] shortcode (inc/then-now.php) and wh-then-now.js.
 *
 * The "now" image sits in normal flow and sets the box height; the "then" image
 * overlays it and is revealed by clip-path driven by the --wh-tn-pos variable.
 */

.wh-tn-figure {
    margin: 1.75rem 0;
}

.wh-tn-figure__title {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0 0 0.55rem;
    font-family: "DM Sans", system-ui, -apple-system, sans-serif;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: #65bab0;
}

.wh-tn-figure__title svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

/* Match the theme's standard image captions (.wp-caption-text / figcaption). */
.wh-tn-figure__caption {
    margin: 0;
    padding: 0.6rem 0;
    border-bottom: 1px solid #eee;
    font-size: 0.9rem;
    font-style: italic;
    letter-spacing: 0.01em;
    line-height: 1.4;
    color: #777;
}

.wh-tn {
    --wh-tn-pos: 50%;
    position: relative;
    width: 100%;
    margin: 0;
    overflow: hidden;
    background: #33363b;
    /* Single accent border on the container, not the individual images. */
    border-bottom: 3px solid var(--wh-accent, #d24d33);
    box-shadow: 0 6px 26px rgba(51, 54, 59, 0.18);
    line-height: 0;
    cursor: ew-resize;
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
}

/* The "now" image — in flow, establishes the box height/ratio.
   Scoped via .wh-tn to beat the theme's .entry-content img rules (border,
   radius, height:auto) that would otherwise distort the comparison. */
.wh-tn .wh-tn__base {
    display: block;
    width: 100%;
    height: auto;
    border: none;
    border-radius: 0;
}

/* The "then" image — overlaid and clipped from the right edge inwards. */
.wh-tn__overlay {
    position: absolute;
    inset: 0;
    clip-path: inset(0 calc(100% - var(--wh-tn-pos)) 0 0);
    -webkit-clip-path: inset(0 calc(100% - var(--wh-tn-pos)) 0 0);
    will-change: clip-path;
}

.wh-tn .wh-tn__overlay-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: cover;
    border: none;
    border-radius: 0;
}

/* Corner labels. */
.wh-tn__label {
    position: absolute;
    top: 14px;
    z-index: 3;
    padding: 5px 12px;
    font-family: "DM Sans", system-ui, -apple-system, sans-serif;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    line-height: 1.2;
    text-transform: uppercase;
    color: #fff;
    border-radius: 999px;
    pointer-events: none;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: opacity 0.2s ease;
}

.wh-tn__label--then {
    left: 14px;
    background: rgba(51, 54, 59, 0.62);
}

.wh-tn__label--now {
    right: 14px;
    background: rgba(101, 186, 176, 0.92);
}

/* Vertical divider line, tracks the divider position. */
.wh-tn__divider {
    position: absolute;
    top: 0;
    bottom: 0;
    left: var(--wh-tn-pos);
    z-index: 4;
    width: 0;
    pointer-events: none;
}

.wh-tn__divider::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 3px;
    transform: translateX(-50%);
    background: #fff;
    box-shadow: 0 0 0 1px rgba(51, 54, 59, 0.12), 0 2px 8px rgba(0, 0, 0, 0.25);
}

/* Grab handle. */
.wh-tn__handle {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 46px;
    height: 46px;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: #fff;
    color: #33363b;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    cursor: ew-resize;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translate(-50%, -50%);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    touch-action: none;
}

.wh-tn__handle svg {
    width: 22px;
    height: 22px;
    display: block;
}

.wh-tn__handle:hover {
    transform: translate(-50%, -50%) scale(1.07);
}

.wh-tn--dragging .wh-tn__handle,
.wh-tn__handle:active {
    transform: translate(-50%, -50%) scale(0.97);
}

.wh-tn__handle:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(101, 186, 176, 0.95), 0 2px 12px rgba(0, 0, 0, 0.3);
}

/* "Drag to compare" hint — auto-fades, and hides once interacted with. */
.wh-tn__hint {
    position: absolute;
    left: 50%;
    bottom: 16px;
    z-index: 5;
    padding: 6px 14px;
    font-family: "DM Sans", system-ui, -apple-system, sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 1.2;
    color: #33363b;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 999px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transform: translateX(-50%);
    animation: wh-tn-hint 5s ease forwards;
}

@keyframes wh-tn-hint {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(6px);
    }
    14%, 68% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateX(-50%) translateY(0);
    }
}

.wh-tn--touched .wh-tn__hint {
    animation: none;
    opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
    .wh-tn__hint {
        animation: none;
        opacity: 1;
    }
    .wh-tn--touched .wh-tn__hint {
        opacity: 0;
    }
    .wh-tn__handle {
        transition: none;
    }
}

@media (max-width: 575px) {
    .wh-tn__handle {
        width: 42px;
        height: 42px;
    }
    .wh-tn__label {
        font-size: 0.66rem;
        padding: 4px 10px;
    }
}
