/* ==========================================================================
   L'Atelier Mähler — Animations & interactive components
   --------------------------------------------------------------------------
   Styles pour les classes injectées par :
     - inc/image-hover.php   → .am-hover-swap*
     - inc/image-popup.php   → .am-popup* + .am-popup-trigger
     - assets/js/fade-lines.js     → .am-fade-lines*
     - assets/js/parallax.js       → .am-parallax
     - assets/js/scroll-reveal-init.js → .am-reveal-grid (lib gère le reste)
   ========================================================================== */

/* ==========================================================================
   1. Image hover swap (inc/image-hover.php)
   --------------------------------------------------------------------------
   Markup :
     <figure class="wp-block-image am-hover-swap am-hover-swap--zoom"
             style="--am-hover-duration:450ms">
       <img src="primary.jpg" />
       <img class="am-hover-swap__alt" src="alternate.jpg" aria-hidden="true" />
     </figure>
   ========================================================================== */
.am-hover-swap {
    position: relative;
    overflow: hidden;
    --am-hover-duration: 450ms;
}

.am-hover-swap > img,
.am-hover-swap picture > img {
    transition: opacity var(--am-hover-duration) ease,
                transform var(--am-hover-duration) ease;
    backface-visibility: hidden;
}

.am-hover-swap__alt {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity var(--am-hover-duration) ease,
                transform var(--am-hover-duration) ease;
    pointer-events: none;
    backface-visibility: hidden;
}

.am-hover-swap:hover > img,
.am-hover-swap:hover picture > img {
    opacity: 0;
}

.am-hover-swap:hover .am-hover-swap__alt {
    opacity: 1;
}

/* Variant --zoom : léger scale sur l'image alternative au hover */
.am-hover-swap--zoom .am-hover-swap__alt {
    transform: scale(1.04);
}

.am-hover-swap--zoom:hover .am-hover-swap__alt {
    transform: scale(1);
}

@media (prefers-reduced-motion: reduce) {
    .am-hover-swap > img,
    .am-hover-swap picture > img,
    .am-hover-swap__alt {
        transition: opacity 0.001ms;
        transform: none !important;
    }
}

/* ==========================================================================
   2. Image popup (inc/image-popup.php)
   --------------------------------------------------------------------------
   Trigger :
     <figure class="wp-block-image am-popup-trigger" data-popup-id="am-popup-42"
             role="button" tabindex="0">
   Popup (rendu en footer, hidden au load) :
     <div class="am-popup" id="am-popup-42" hidden>
       <div class="am-popup__overlay"></div>
       <div class="am-popup__box">
         <button class="am-popup__close">×</button>
         <div class="am-popup__grid">
           <div class="am-popup__slider">
             <div class="am-popup__track">
               <figure class="am-popup__slide">…</figure>
             </div>
             <button class="am-popup__arrow am-popup__arrow--prev">‹</button>
             <button class="am-popup__arrow am-popup__arrow--next">›</button>
             <div class="am-popup__dots">
               <button class="am-popup__dot is-active"></button>
             </div>
           </div>
           <div class="am-popup__content">
             <h2 class="am-popup__title">…</h2>
             <div class="am-popup__body">…</div>
           </div>
         </div>
       </div>
     </div>
   ========================================================================== */
.am-popup-trigger {
    cursor: pointer;
    outline: none;
}

.am-popup-trigger:focus-visible {
    outline: 2px solid var(--wp--preset--color--blue-text, #10547f);
    outline-offset: 4px;
}

/* Container — full screen overlay */
.am-popup {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 280ms ease;
}

.am-popup[hidden] {
    display: none;
}

.am-popup.is-open {
    opacity: 1;
}

.am-popup__overlay {
    position: absolute;
    inset: 0;
    background: rgba(10, 22, 40, 0.72);
    cursor: pointer;
}

/* Box — content container */
.am-popup__box {
    position: relative;
    width: min(1200px, 92vw);
    max-height: 90vh;
    background: var(--wp--preset--color--white, #fff);
    overflow: hidden;
    transform: scale(0.98);
    transition: transform 280ms ease;
    display: flex;
    flex-direction: column;
}

.am-popup.is-open .am-popup__box {
    transform: scale(1);
}

/* Close button — top right */
.am-popup__close {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 3;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--wp--preset--color--blue-text, #10547f);
    color: var(--wp--preset--color--blue-text, #10547f);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    line-height: 1;
    padding: 0;
    transition: background 0.2s;
}

.am-popup__close:hover {
    background: var(--wp--preset--color--cream, #f3eee5);
}

.am-popup__close span {
    display: block;
    margin-top: -2px;
}

/* Grid — slider à gauche, contenu à droite */
.am-popup__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    overflow: hidden;
    flex: 1;
    min-height: 0;
}

/* Slider */
.am-popup__slider {
    position: relative;
    overflow: hidden;
    background: var(--wp--preset--color--cream, #f3eee5);
    min-height: 480px;
}

.am-popup__track {
    display: flex;
    width: 100%;
    height: 100%;
    transition: transform 360ms cubic-bezier(0.22, 1, 0.36, 1);
    will-change: transform;
}

.am-popup__slide {
    flex: 0 0 100%;
    margin: 0;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.am-popup__slide img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.am-popup__slide figcaption {
    position: absolute;
    bottom: 16px;
    left: 16px;
    right: 16px;
    color: #fff;
    font-family: var(--wp--preset--font-family--heading, Optima);
    font-size: 13px;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

/* Slider arrows */
.am-popup__arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border: 1px solid var(--wp--preset--color--blue-text, #10547f);
    background: rgba(255, 255, 255, 0.92);
    color: var(--wp--preset--color--blue-text, #10547f);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    font-size: 22px;
    line-height: 1;
    padding: 0;
    transition: background 0.2s, opacity 0.28s ease, transform 0.28s ease;
}

.am-popup__arrow:hover {
    background: var(--wp--preset--color--cream, #f3eee5);
}

.am-popup__arrow--prev { left: 12px; }
.am-popup__arrow--next { right: 12px; }

.am-popup__arrow.is-hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-50%) translateX(-6px);
}

/* Dots */
.am-popup__dots {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 2;
}

.am-popup__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 1px solid var(--wp--preset--color--blue-text, #10547f);
    background: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    padding: 0;
    transition: background 0.3s;
}

.am-popup__dot.is-active {
    background: var(--wp--preset--color--blue-text, #10547f);
}

/* Content — texte à droite */
.am-popup__content {
    padding: 48px 40px;
    overflow-y: auto;
    color: var(--wp--preset--color--blue-text, #10547f);
    font-family: var(--wp--preset--font-family--heading, Optima);
}

.am-popup__title {
    font-family: var(--wp--preset--font-family--heading, Optima);
    font-size: clamp(22px, 2.2vw, 32px);
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin: 0 0 24px;
    line-height: 1.2;
}

.am-popup__body {
    font-size: 15px;
    line-height: 1.6;
}

.am-popup__body p {
    margin: 0 0 1em;
}

.am-popup__body p:last-child {
    margin-bottom: 0;
}

/* Body lock quand popup ouvert */
html.am-popup-lock,
body.am-popup-lock {
    overflow: hidden;
}

/* Responsive — passe le grid en colonnes empilées sous 768px */
@media (max-width: 768px) {
    .am-popup__box {
        width: 96vw;
        max-height: 94vh;
    }

    .am-popup__grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
        overflow-y: auto;
    }

    .am-popup__slider {
        min-height: 320px;
        aspect-ratio: 1 / 1;
    }

    .am-popup__content {
        padding: 28px 24px;
    }

    .am-popup__close {
        top: 8px;
        right: 8px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .am-popup,
    .am-popup__box,
    .am-popup__track,
    .am-popup__arrow {
        transition: none !important;
    }
}

/* ==========================================================================
   3. Fade lines (assets/js/fade-lines.js)
   --------------------------------------------------------------------------
   Le JS split le texte en .am-fade-lines__word et ajoute :
     - .am-fade-lines--ready (état initial : mots cachés)
     - .is-revealed (déclenche l'animation, animation-delay sur chaque mot)
   ========================================================================== */
.am-fade-lines--ready .am-fade-lines__word {
    display: inline-block;
    opacity: 0;
    transform: translateY(0.6em);
    will-change: opacity, transform;
}

.am-fade-lines.is-revealed .am-fade-lines__word {
    animation: amFadeLineUp 900ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes amFadeLineUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .am-fade-lines--ready .am-fade-lines__word {
        opacity: 1;
        transform: none;
        animation: none;
    }
}

/* ==========================================================================
   4. Parallax (assets/js/parallax.js)
   --------------------------------------------------------------------------
   Le JS pose translate3d via inline style. Pas de transition CSS (le lerp JS
   fait tout le smoothing). On hint juste le GPU et on protège le layout.
   ========================================================================== */
.am-parallax {
    will-change: transform;
    backface-visibility: hidden;
}

/* ==========================================================================
   5. ScrollReveal grid (assets/js/scroll-reveal-init.js)
   --------------------------------------------------------------------------
   La lib ScrollReveal pose elle-même opacity:0 + transform sur les items.
   Default CSS : items visibles (fallback si la lib échoue à charger).
   Aucun style spécifique nécessaire ici.
   ========================================================================== */
.am-reveal-grid figure {
    will-change: transform, opacity;
}
