/* ============================================================
   WMR Backgrounds — Stylesheet
   Supports dedicated hardware-accelerated .wmr-bg-canvas elements
   and legacy CSS :before pseudo-element with static fallbacks.
   ============================================================ */

/* ---------------------------------------------------------
   1. Backgrounds containers — wrapper or active body
   --------------------------------------------------------- */

.wmr-backgrounds-wrapper {
    position: relative;
    width: 100%;
    min-height: 100vh;          /* always fill the viewport */
    overflow-x: hidden;         /* prevent horizontal scroll from SVG */
    clip-path: inset(0);        /* clip fixed background layer strictly inside wrapper */
}

/* ---------------------------------------------------------
   2. Dedicated canvas element & fallback pseudo-element
   --------------------------------------------------------- */

.wmr-bg-canvas,
.wmr-backgrounds-wrapper::before,
body.wmr-backgrounds-active::before {
    content: "";
    position: fixed;            /* stays in viewport while scrolling */
    /* Viewport buffer: 20vh top and bottom headroom prevents empty gaps during parallax */
    top: -20vh;
    left: 0;
    width: 100vw;               /* full viewport width */
    height: 140vh;              /* 140vh provides a 20vh top & 20vh bottom scroll buffer */
    z-index: -1;                /* behind all page content */
    pointer-events: none;       /* prevent capturing clicks or touch events */

    /* Static CSS fallbacks for legacy browsers (IE11 / older Edge without CSS variables) */
    background-image: url("/assets/topo_mtns.svg");
    opacity: 0.4;
    transform: translate3d(0, 0, 0);

    /* Dynamic SVG and opacity via CSS custom properties */
    background-image: var(--wmr-bg-url, url("/assets/topo_mtns.svg"));
    opacity: var(--wmr-bg-opacity, 0.4);
    background-repeat: no-repeat;
    background-position: center center;
    background-size: cover;     /* covers the entire buffer area */

    /* Hardware-accelerated 3D transform */
    transform: translate3d(0, var(--wmr-parallax-y, 0px), 0);
    will-change: transform;

    transition: opacity 0.3s ease;

    /* Prevent flickering and maintain GPU compositing */
    -webkit-backface-visibility: hidden;
            backface-visibility: hidden;
}

/* Suppress fallback ::before pseudo-element when dedicated canvas exists */
body.wmr-backgrounds-active.has-wmr-canvas::before,
.wmr-backgrounds-wrapper.has-wmr-canvas::before {
    content: none !important;
    display: none !important;
}

/* ---------------------------------------------------------
   3. Mobile / responsive adjustments
   --------------------------------------------------------- */

@media ( max-width: 768px ) {
    .wmr-backgrounds-wrapper > *:not(.wmr-backgrounds-bg-content):not(.wmr-bg-canvas) {
        position: relative;
        z-index: 1;
    }
}

/* ---------------------------------------------------------
   4. Dark / light mode considerations (optional)
   --------------------------------------------------------- */

@media ( prefers-color-scheme: dark ) {
    .wmr-bg-canvas,
    .wmr-backgrounds-wrapper::before,
    body.wmr-backgrounds-active::before {
        /* filter: brightness(0.7); */
    }
}

/* ---------------------------------------------------------
   5. Reduced motion — respect user preferences (Recommendation 4)
   --------------------------------------------------------- */

@media ( prefers-reduced-motion: reduce ) {
    .wmr-bg-canvas,
    .wmr-backgrounds-wrapper::before,
    body.wmr-backgrounds-active::before {
        /* Disable parallax transform animation for users who prefer reduced motion */
        transform: none !important;
        -webkit-transform: none !important;
        --wmr-parallax-y: 0px !important;
        will-change: auto !important;
    }
}

/* ---------------------------------------------------------
   6. Print — hide the background entirely
   --------------------------------------------------------- */

@media print {
    .wmr-bg-canvas,
    .wmr-backgrounds-wrapper::before,
    body.wmr-backgrounds-active::before {
        display: none !important;
    }
}
