/* ==========================================================================
   SYSTÈME D'ANIMATIONS ÉLÉGANTES 60 FPS — MARIAGE ZAKI & CHAIMAE
   Fichier : assets/css/animations.css
   Optimisé GPU (transform / opacity), IntersectionObserver & Reduced Motion
   ========================================================================== */

:root {
    /* Paramètres globaux des animations (ajustables facilement) */
    --anim-ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --anim-ease-spring: cubic-bezier(0.34, 1.48, 0.64, 1);
    --anim-handwriting-duration: 1.85s;
    --anim-stagger-step: 0.13s;
    --anim-section-duration: 0.82s;
    --anim-shimmer-interval: 4.4s;
    --anim-wash-breathe-duration: 14s;
    --anim-petal-count-desktop: 20;
    --anim-petal-count-mobile: 11;
}

/* (La chorégraphie 3D de l'écran d'ouverture Enveloppe est isolée dans assets/css/envelope.css) */

/* ==========================================================================
   C. FOND AQUARELLE LÉGER (ZÉRO REPAINT INFINI POUR 60/120 FPS AU SCROLL)
   ========================================================================== */
.ambient-backdrop {
    contain: strict;
}

/* ==========================================================================
   D. TEXTES : EFFET "HANDWRITING" (PLUME CALLIGRAPHIQUE), "&" PULSÉ & STAGGER
   ========================================================================== */
.handwriting-name {
    position: relative;
    display: inline-block;
    padding: 0 0.08em;
}

body.js-anim-ready:not(.invitation-opened):not(.is-cinematic-reveal):not(.reveal-complete) .handwriting-name {
    clip-path: inset(-25% 100% -28% -8%);
    opacity: 0.2;
}

[dir="rtl"] body.js-anim-ready:not(.invitation-opened):not(.is-cinematic-reveal):not(.reveal-complete) .handwriting-name,
html[dir="rtl"] body.js-anim-ready:not(.invitation-opened):not(.is-cinematic-reveal):not(.reveal-complete) .handwriting-name {
    clip-path: inset(-25% -8% -28% 100%);
    opacity: 0.2;
}

body.invitation-opened:not(.is-cinematic-reveal):not(.reveal-complete) .handwriting-name {
    animation: calligraphyWrite var(--anim-handwriting-duration) cubic-bezier(0.35, 0, 0.25, 1) both;
    animation-delay: var(--write-delay, 0.35s);
}

html[dir="rtl"] body.invitation-opened:not(.is-cinematic-reveal):not(.reveal-complete) .handwriting-name {
    animation-name: calligraphyWriteRtl;
}

@keyframes calligraphyWriteRtl {
    0% {
        clip-path: inset(-25% -8% -28% 100%);
        opacity: 0.3;
    }
    100% {
        clip-path: inset(-25% -8% -28% -10%);
        opacity: 1;
    }
}

/* Petit éclat doré suivant la pointe de la plume pendant l'écriture */
body.invitation-opened:not(.is-cinematic-reveal):not(.reveal-complete) .handwriting-name::after {
    content: '✦';
    position: absolute;
    top: 42%;
    left: 0;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    color: var(--color-gold);
    text-shadow: 0 0 10px rgba(184, 146, 90, 0.85);
    pointer-events: none;
    opacity: 0;
    animation: nibSparkleFollow var(--anim-handwriting-duration) cubic-bezier(0.35, 0, 0.25, 1) both;
    animation-delay: var(--write-delay, 0.35s);
}

@keyframes calligraphyWrite {
    0% {
        clip-path: inset(-25% 100% -28% -8%);
        opacity: 0.3;
    }
    100% {
        clip-path: inset(-25% -10% -28% -8%);
        opacity: 1;
    }
}

@keyframes nibSparkleFollow {
    0% {
        transform: translate3d(0, -50%, 0) scale(0.5);
        opacity: 0;
    }
    12% {
        opacity: 0.95;
    }
    88% {
        opacity: 0.85;
    }
    100% {
        left: 98%;
        transform: translate3d(0, -50%, 0) scale(0.3);
        opacity: 0;
    }
}

/* Esperluette "&" avec pulsation dorée délicate */
body.js-anim-ready:not(.invitation-opened):not(.is-cinematic-reveal):not(.reveal-complete) .couple-ampersand {
    opacity: 0;
    transform: scale(0.6);
}

body.invitation-opened:not(.is-cinematic-reveal):not(.reveal-complete) .couple-ampersand {
    animation:
        ampRevealPop 0.75s var(--anim-ease-spring) 1.05s both,
        ampGoldenPulse 4.2s ease-in-out 2s infinite;
}

@keyframes ampRevealPop {
    0% { opacity: 0; transform: scale(0.55) rotate(-8deg); }
    100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

@keyframes ampGoldenPulse {
    0%, 100% {
        transform: scale(1);
        text-shadow: 0 0 0 rgba(184, 146, 90, 0);
    }
    50% {
        transform: scale(1.09);
        text-shadow: 0 0 16px rgba(184, 146, 90, 0.42);
    }
}

/* Apparition séquentielle (stagger fade-up) des éléments de la carte d'accueil */
body.js-anim-ready:not(.invitation-opened):not(.is-cinematic-reveal):not(.reveal-complete) .hero-stagger {
    opacity: 0;
    transform: translate3d(0, 18px, 0);
}

body.invitation-opened:not(.is-cinematic-reveal):not(.reveal-complete) .hero-stagger {
    animation: staggerFadeUp 0.8s var(--anim-ease-out) both;
    animation-delay: calc(0.18s + var(--stagger, 0) * var(--anim-stagger-step));
}

@keyframes staggerFadeUp {
    from {
        opacity: 0;
        transform: translate3d(0, 18px, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

/* ==========================================================================
   E. SECTIONS AU SCROLL : TRAITS DORÉS PROGRESSIFS & REBOND DES ICÔNES
   ========================================================================== */
.gold-divider .divider-line {
    transform-origin: center;
    transition: transform 0.95s var(--anim-ease-out);
}

body.js-anim-ready:not(.invitation-opened):not(.is-cinematic-reveal):not(.reveal-complete) .hero-arch .gold-divider .divider-line,
body.js-anim-ready .reveal-on-scroll:not(.is-visible) .gold-divider .divider-line {
    transform: scaleX(0);
}

body.invitation-opened:not(.is-cinematic-reveal) .hero-arch .gold-divider .divider-line,
.reveal-on-scroll.is-visible .gold-divider .divider-line {
    transform: scaleX(1);
    transition-delay: 0.45s;
}

/* Traits du bloc date & rebond doux des icônes dorées */
.date-wing {
    position: relative;
}

body.invitation-opened:not(.is-cinematic-reveal):not(.reveal-complete) .gold-icon-wrap {
    animation: iconGentleBounce 0.9s var(--anim-ease-spring) 0.35s both;
}

@keyframes iconGentleBounce {
    0% {
        opacity: 0;
        transform: translate3d(0, 14px, 0) scale(0.72);
    }
    65% {
        opacity: 1;
        transform: translate3d(0, -4px, 0) scale(1.08);
    }
    100% {
        opacity: 1;
        transform: translate3d(0, 0, 0) scale(1);
    }
}

/* ==========================================================================
   F. COMPTE À REBOURS : EFFET FLIP / GLISSEMENT 3D À CHAQUE SECONDE
   ========================================================================== */
.countdown-arch {
    perspective: 500px;
    position: relative;
    overflow: hidden;
}

.countdown-value {
    display: inline-block;
    transform-origin: 50% 50%;
    backface-visibility: hidden;
    will-change: transform, opacity;
}

.countdown-value.is-flipping {
    animation: digitFlipTick 0.46s var(--anim-ease-out);
}

@keyframes digitFlipTick {
    0% {
        opacity: 0.25;
        transform: translate3d(0, -10px, 0) rotateX(68deg) scale(0.92);
    }
    65% {
        opacity: 1;
        transform: translate3d(0, 2px, 0) rotateX(-8deg) scale(1.03);
    }
    100% {
        opacity: 1;
        transform: translate3d(0, 0, 0) rotateX(0deg) scale(1);
    }
}

/* ==========================================================================
   G. BOUTONS DORÉS : SHIMMER TRAVERSANT, LIFT & RIPPLE AU CLIC
   ========================================================================== */
.btn-gold,
.btn-outline-gold {
    position: relative;
    overflow: hidden;
    isolation: isolate;
}

/* Brillance dorée diagonale (shimmer) */
.btn-gold::after,
.btn-outline-gold::after {
    content: '';
    position: absolute;
    top: -30%;
    left: -45%;
    width: 36%;
    height: 160%;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.42) 50%,
        transparent 100%
    );
    transform: translate3d(-120%, 0, 0) rotate(22deg);
    pointer-events: none;
    animation: btnGoldenShimmer var(--anim-shimmer-interval) ease-in-out infinite;
}

.btn-outline-gold::after {
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(184, 146, 90, 0.24) 50%,
        transparent 100%
    );
}

@keyframes btnGoldenShimmer {
    0%, 68% {
        transform: translate3d(-140%, 0, 0) rotate(22deg);
    }
    100% {
        transform: translate3d(420%, 0, 0) rotate(22deg);
    }
}

.btn-gold:active:not(:disabled),
.btn-outline-gold:active:not(:disabled) {
    transform: translateY(0) scale(0.98);
}

/* Onde tactile / clic (Ripple) */
.btn-ripple-wave {
    position: absolute;
    border-radius: 50%;
    transform: scale(0);
    background: rgba(255, 253, 249, 0.48);
    pointer-events: none;
    animation: btnRippleExpand 0.62s ease-out forwards;
}

.btn-outline-gold .btn-ripple-wave {
    background: rgba(184, 146, 90, 0.25);
}

@keyframes btnRippleExpand {
    to {
        transform: scale(3.4);
        opacity: 0;
    }
}

/* ==========================================================================
   H. FORMULAIRE RSVP : LABELS FLOTTANTS, SLIDE-DOWN, SHAKE & CÉLÉBRATION
   ========================================================================== */
.floating-group {
    position: relative;
    margin-bottom: 20px;
}

.floating-group .form-control {
    padding: 20px 15px 8px;
}

.floating-group .floating-label {
    position: absolute;
    left: 15px;
    top: 16px;
    max-width: calc(100% - 30px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--color-text-muted);
    pointer-events: none;
    transform-origin: left top;
    transition: transform 0.22s var(--anim-ease-out), color 0.22s ease, background-color 0.22s ease;
    padding: 0 4px;
    border-radius: 4px;
}

[dir="rtl"] .floating-group .floating-label {
    left: auto;
    right: 15px;
    transform-origin: right top;
}

.floating-group .form-control:focus ~ .floating-label,
.floating-group .form-control:not(:placeholder-shown) ~ .floating-label {
    transform: translate3d(-3px, -23px, 0) scale(0.78);
    color: var(--color-gold-dark);
    font-weight: 600;
    background: var(--color-ivory-pure);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

[dir="rtl"] .floating-group .form-control:focus ~ .floating-label,
[dir="rtl"] .floating-group .form-control:not(:placeholder-shown) ~ .floating-label {
    transform: translate3d(3px, -23px, 0) scale(0.84);
    letter-spacing: 0;
    text-transform: none;
}

/* Apparition slide-down fluide des blocs accompagnants */
.conditional-block:not([hidden]),
.companions-details:not([hidden]) {
    animation: slideDownSmooth 0.38s var(--anim-ease-out);
}

@keyframes slideDownSmooth {
    from {
        opacity: 0;
        transform: translate3d(0, -10px, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

/* Micro-animation shake léger en cas d'erreur de validation */
.is-invalid-shake {
    animation: fieldGentleShake 0.42s ease;
    border-color: var(--color-danger) !important;
}

@keyframes fieldGentleShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

/* Confirmation RSVP : tracé animé coche/cœur + explosion douce de pétales */
.rsvp-success-box {
    position: relative;
    overflow: visible;
}

.rsvp-success-box:not([hidden]) .success-check-path {
    stroke-dasharray: 60;
    stroke-dashoffset: 60;
    animation: drawSuccessStroke 0.75s var(--anim-ease-out) 0.2s forwards;
}

.rsvp-success-box:not([hidden]) .success-circle-path {
    stroke-dasharray: 190;
    stroke-dashoffset: 190;
    animation: drawSuccessStroke 0.85s var(--anim-ease-out) forwards;
}

@keyframes drawSuccessStroke {
    to {
        stroke-dashoffset: 0;
    }
}

.celebration-burst-petal {
    position: absolute;
    left: 50%;
    top: 42px;
    width: 11px;
    height: 15px;
    border-radius: 75% 15% 75% 15%;
    pointer-events: none;
    z-index: 10;
    animation: burstPetalFly 1.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes burstPetalFly {
    0% {
        opacity: 1;
        transform: translate3d(-50%, -50%, 0) scale(0.4) rotate(0deg);
    }
    100% {
        opacity: 0;
        transform: translate3d(var(--bx, 0px), var(--by, -80px), 0) scale(1.05) rotate(var(--brot, 220deg));
    }
}

/* ==========================================================================
   I. GALERIE EN CASCADE & TRANSITION DOUCE DE LA LIGHTBOX
   ========================================================================== */
body.js-anim-ready #galerie:not(.is-visible) .gallery-thumb-item {
    opacity: 0;
    transform: translate3d(0, 20px, 0) scale(0.96);
}

#galerie.is-visible .gallery-thumb-item {
    animation: galleryCascadeIn 0.65s var(--anim-ease-out) both;
    animation-delay: calc(0.12s + var(--item-idx, 0) * 0.08s);
}

@keyframes galleryCascadeIn {
    from {
        opacity: 0;
        transform: translate3d(0, 20px, 0) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0) scale(1);
    }
}

.lightbox-img.is-transitioning {
    animation: lightboxSlideTransition 0.32s var(--anim-ease-out);
}

@keyframes lightboxSlideTransition {
    from {
        opacity: 0.35;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ==========================================================================
   J. BOUTON MUSIQUE : ONDES SONORES CONCENTRIQUES DORÉES
   ========================================================================== */
.music-toggle.is-playing::before,
.music-toggle.is-playing::after {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    border: 1px solid rgba(184, 146, 90, 0.55);
    pointer-events: none;
    animation: musicSoundWaveRing 2.2s ease-out infinite;
}

.music-toggle.is-playing::after {
    animation-delay: 1.1s;
}

@keyframes musicSoundWaveRing {
    0% {
        transform: scale(1);
        opacity: 0.75;
    }
    100% {
        transform: scale(1.62);
        opacity: 0;
    }
}

/* ==========================================================================
   3. PERFORMANCE & ACCESSIBILITÉ : PAUSE HORS-ÉCRAN / ONGLET CACHÉ & REDUCED MOTION
   ========================================================================== */
body.tab-hidden *,
body.tab-hidden *::before,
body.tab-hidden *::after,
.is-offscreen-paused,
.is-offscreen-paused *,
.is-offscreen-paused *::before,
.is-offscreen-paused *::after {
    animation-play-state: paused !important;
}

@media (prefers-reduced-motion: reduce) {
    .falling-petal-node,
    .butterflies-stage,
    .handwriting-name::after,
    .btn-gold::after,
    .btn-outline-gold::after,
    .music-toggle::before,
    .music-toggle::after {
        display: none !important;
    }

    body.js-anim-ready .handwriting-name,
    body.js-anim-ready .hero-stagger,
    body.js-anim-ready .svg-petal,
    body.js-anim-ready .garland-grow-stem {
        clip-path: none !important;
        stroke-dashoffset: 0 !important;
        opacity: 1 !important;
        transform: none !important;
        animation: none !important;
    }

    .svg-branch,
    .watercolor-wash {
        animation: none !important;
    }
}
