/**
 * WeXchange Processus Puzzle Stylesheet
 * Interlocking puzzle process cards for Elementor — WeXchange 2026.
 *
 * Géométrie unifiée : la languette (knob) et l'encoche (notch) sont calculées
 * à partir des MÊMES variables (gap, rayon, col, jeu). La tête de la languette
 * est donc toujours parfaitement centrée dans son encoche, quel que soit
 * l'espacement entre les pièces.
 *
 *   --wex-puzzle-gap        espacement horizontal entre pièces
 *   --wex-puzzle-vgap       espacement vertical (disposition empilée)
 *   --wex-puzzle-knob-r     rayon de la tête
 *   --wex-puzzle-knob-d     distance bord de la pièce suivante -> centre de la tête
 *   --wex-puzzle-knob-neck  demi-hauteur du col
 *   (les images d'encoche sont générées côté PHP avec le jeu « seam »)
 */

:root {
    --wex-puzzle-font: 'Gotham', 'Montserrat', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --wex-puzzle-title-color: #6a6399;
    --wex-puzzle-grad-start: #389eb0;
    --wex-puzzle-grad-end: #57c7be;
    --wex-puzzle-radius: 12px;
}

/* ==========================================================================
   Global Wrapper
   ========================================================================== */
.wex-puzzle-process-wrapper {
    --wex-puzzle-gap: 14px;
    --wex-puzzle-vgap: 18px;
    --wex-puzzle-knob-r: 10px;
    --wex-puzzle-knob-d: 13px;
    --wex-puzzle-knob-neck: 6px;
    --wex-puzzle-stagger: 160ms;
    position: relative;
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

.wex-puzzle-process-wrapper *,
.wex-puzzle-process-wrapper *::before,
.wex-puzzle-process-wrapper *::after {
    box-sizing: border-box;
}

/* Section Header */
.wex-puzzle-header {
    font-family: var(--wex-puzzle-font);
    font-size: 38px;
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: -0.5px;
    color: var(--wex-puzzle-title-color);
    margin: 0 0 35px 0;
    padding: 0;
    transition: color 0.25s ease;
}

/* ==========================================================================
   Puzzle Container (horizontal par défaut)
   ========================================================================== */
.wex-puzzle-container {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    justify-content: space-between;
    gap: var(--wex-puzzle-gap);
    width: 100%;
    position: relative;
}

/* ==========================================================================
   Puzzle Card
   ========================================================================== */
.wex-puzzle-card {
    position: relative;
    flex: 1 1 0;
    min-width: 0;
    min-height: 190px;
    display: flex;
    flex-direction: column;
    text-decoration: none;
    outline: none !important;
    -webkit-tap-highlight-color: transparent !important;
    transition: transform 0.3s cubic-bezier(0.2, 0, 0.2, 1), box-shadow 0.3s ease, filter 0.3s ease;
}

.wex-puzzle-card:focus,
.wex-puzzle-card:focus-visible,
.wex-puzzle-card:active {
    outline: none !important;
}

.wex-puzzle-card:hover {
    z-index: 10;
}

.wex-puzzle-hover-lift:hover {
    transform: translateY(-5px);
}

.wex-puzzle-hover-scale:hover {
    transform: scale(1.025);
}

.wex-puzzle-hover-glow:hover .wex-puzzle-card-body {
    box-shadow: 0 12px 30px rgba(56, 158, 176, 0.35);
}

/* Card Body (fond, texte & encoche) */
.wex-puzzle-card-body {
    position: relative;
    width: 100%;
    height: 100%;
    flex: 1;
    border-radius: var(--wex-puzzle-radius);
    background: linear-gradient(180deg, var(--wex-puzzle-grad-start) 0%, var(--wex-puzzle-grad-end) 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 24px 20px;
    color: #ffffff;
    box-shadow: 0 6px 18px rgba(56, 158, 176, 0.12);
    transition: background 0.35s ease, box-shadow 0.3s ease;
    overflow: visible;
}

/* ==========================================================================
   Géométrie horizontale (desktop)
   ========================================================================== */

/* Encoche (pièces 2..N) — forme générée en PHP, centrée verticalement */
.wex-puzzle-style-interlocking .wex-puzzle-has-notch .wex-puzzle-card-body {
    -webkit-mask: var(--wex-puzzle-notch-img) left 0 top 50% / var(--wex-puzzle-notch-w) var(--wex-puzzle-notch-h) no-repeat,
                  linear-gradient(#000 0 0);
    -webkit-mask-composite: destination-out;
    mask: var(--wex-puzzle-notch-img) left 0 top 50% / var(--wex-puzzle-notch-w) var(--wex-puzzle-notch-h) no-repeat,
          linear-gradient(#000 0 0);
    mask-composite: exclude;
}

/* Languette (pièces 1..N-1) :
   l'élément couvre toute la hauteur de la carte => son dégradé est
   strictement identique à celui des cartes ; un masque dessine col + tête. */
.wex-puzzle-tab {
    --wex-k-cx: calc(1px + var(--wex-puzzle-gap) + var(--wex-puzzle-knob-d));
    position: absolute;
    top: 0;
    bottom: 0;
    left: calc(100% - 1px);
    width: calc(var(--wex-k-cx) + var(--wex-puzzle-knob-r) + 1px);
    background: linear-gradient(180deg, var(--wex-puzzle-grad-start) 0%, var(--wex-puzzle-grad-end) 100%);
    -webkit-mask:
        radial-gradient(circle at var(--wex-k-cx) 50%, #000 calc(var(--wex-puzzle-knob-r) - 0.5px), transparent calc(var(--wex-puzzle-knob-r) + 0.5px)) 0 0 / 100% 100% no-repeat,
        linear-gradient(#000 0 0) 0 50% / var(--wex-k-cx) calc(2 * var(--wex-puzzle-knob-neck)) no-repeat;
    mask:
        radial-gradient(circle at var(--wex-k-cx) 50%, #000 calc(var(--wex-puzzle-knob-r) - 0.5px), transparent calc(var(--wex-puzzle-knob-r) + 0.5px)) 0 0 / 100% 100% no-repeat,
        linear-gradient(#000 0 0) 0 50% / var(--wex-k-cx) calc(2 * var(--wex-puzzle-knob-neck)) no-repeat;
    transform-origin: left center;
    z-index: 3;
    pointer-events: none;
    transition: transform 0.3s ease;
}

/* ==========================================================================
   Card Content (Title, Description, Badge)
   ========================================================================== */
.wex-puzzle-card-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 88%;
    margin: 0 auto;
    z-index: 2;
    box-sizing: border-box;
}

.wex-puzzle-step-badge {
    display: inline-block;
    font-family: var(--wex-puzzle-font);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.2);
    padding: 3px 8px;
    border-radius: 20px;
    margin-bottom: 8px;
}

.wex-puzzle-card-title {
    font-family: var(--wex-puzzle-font);
    font-size: 19px;
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: -0.2px;
    color: #ffffff;
    margin: 0 0 10px 0;
    padding: 0;
    text-align: center;
    transition: color 0.25s ease;
}

.wex-puzzle-card-desc {
    font-family: var(--wex-puzzle-font);
    font-size: 13px;
    font-weight: 400;
    line-height: 1.45;
    color: #ffffff;
    opacity: 0.95;
    margin: 0;
    padding: 0;
    text-align: center;
    word-break: normal;
    overflow-wrap: break-word;
    hyphens: none;
    transition: opacity 0.25s ease, color 0.25s ease;
}

.wex-puzzle-card-link-overlay {
    position: absolute;
    inset: 0;
    z-index: 5;
    text-indent: -9999px;
    border-radius: var(--wex-puzzle-radius);
}

/* ==========================================================================
   Clean Cards Mode (sans languettes)
   ========================================================================== */
.wex-puzzle-style-clean_cards .wex-puzzle-tab {
    display: none !important;
}

.wex-puzzle-style-clean_cards .wex-puzzle-card-body {
    -webkit-mask: none !important;
    mask: none !important;
}

/* ==========================================================================
   Animation d'entrée : les pièces apparaissent une à une puis s'emboîtent
   (classes ajoutées par JS uniquement — sans JS tout reste visible)
   ========================================================================== */
.wex-puzzle-process-wrapper.is-armed .wex-puzzle-header {
    opacity: 0;
    transform: translate3d(0, 16px, 0);
}

.wex-puzzle-process-wrapper.is-armed .wex-puzzle-card {
    opacity: 0;
    transform: translate3d(-22px, 18px, 0) scale(0.94);
}

.wex-puzzle-process-wrapper.is-armed .wex-puzzle-tab {
    transform: scaleX(0);
}

.wex-puzzle-process-wrapper.is-armed.is-playing .wex-puzzle-header {
    opacity: 1;
    transform: none;
    transition: opacity 0.6s ease, transform 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

.wex-puzzle-process-wrapper.is-armed.is-playing .wex-puzzle-card {
    opacity: 1;
    transform: none;
    transition: opacity 0.55s ease, transform 0.8s cubic-bezier(0.22, 1, 0.36, 1);
    transition-delay: calc(var(--wex-puzzle-i, 0) * var(--wex-puzzle-stagger) + 150ms);
}

.wex-puzzle-process-wrapper.is-armed.is-playing .wex-puzzle-tab {
    transform: none;
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    transition-delay: calc(var(--wex-puzzle-i, 0) * var(--wex-puzzle-stagger) + 520ms);
}

/* ==========================================================================
   Responsive : disposition empilée (Puzzle vertical)
   - .wex-puzzle-bp-tablet  : ≤ 991px
   - .wex-puzzle-bp-mobile  : ≤ 767px
   ========================================================================== */
@media (max-width: 991px) {
    .wex-puzzle-bp-tablet .wex-puzzle-container.wex-puzzle-layout-vertical_puzzle {
        flex-direction: column;
        gap: var(--wex-puzzle-vgap) !important;
        max-width: 520px;
        margin: 0 auto;
    }

    .wex-puzzle-bp-tablet .wex-puzzle-layout-vertical_puzzle .wex-puzzle-card {
        min-height: auto;
        width: 100%;
    }

    /* Encoche en HAUT, centrée horizontalement */
    .wex-puzzle-bp-tablet.wex-puzzle-style-interlocking .wex-puzzle-layout-vertical_puzzle .wex-puzzle-has-notch .wex-puzzle-card-body {
        -webkit-mask: var(--wex-puzzle-notch-v-img) top 0 left 50% / var(--wex-puzzle-notch-h) var(--wex-puzzle-notch-w) no-repeat,
                      linear-gradient(#000 0 0);
        -webkit-mask-composite: destination-out;
        mask: var(--wex-puzzle-notch-v-img) top 0 left 50% / var(--wex-puzzle-notch-h) var(--wex-puzzle-notch-w) no-repeat,
              linear-gradient(#000 0 0);
        mask-composite: exclude;
        padding-top: calc(var(--wex-puzzle-knob-d) + var(--wex-puzzle-knob-r) + 14px);
    }

    /* Languette en BAS, pointant vers la pièce suivante */
    .wex-puzzle-bp-tablet .wex-puzzle-layout-vertical_puzzle .wex-puzzle-card .wex-puzzle-tab {
        --wex-k-cy: calc(1px + var(--wex-puzzle-vgap) + var(--wex-puzzle-knob-d));
        top: calc(100% - 1px);
        bottom: auto;
        left: 0;
        right: 0;
        width: auto;
        height: calc(var(--wex-k-cy) + var(--wex-puzzle-knob-r) + 1px);
        background: linear-gradient(180deg, var(--wex-puzzle-grad-end) 0%, var(--wex-puzzle-grad-start) 100%);
        -webkit-mask:
            radial-gradient(circle at 50% var(--wex-k-cy), #000 calc(var(--wex-puzzle-knob-r) - 0.5px), transparent calc(var(--wex-puzzle-knob-r) + 0.5px)) 0 0 / 100% 100% no-repeat,
            linear-gradient(#000 0 0) 50% 0 / calc(2 * var(--wex-puzzle-knob-neck)) var(--wex-k-cy) no-repeat;
        mask:
            radial-gradient(circle at 50% var(--wex-k-cy), #000 calc(var(--wex-puzzle-knob-r) - 0.5px), transparent calc(var(--wex-puzzle-knob-r) + 0.5px)) 0 0 / 100% 100% no-repeat,
            linear-gradient(#000 0 0) 50% 0 / calc(2 * var(--wex-puzzle-knob-neck)) var(--wex-k-cy) no-repeat;
        transform-origin: center top;
        z-index: 5;
    }

    .wex-puzzle-bp-tablet.is-armed .wex-puzzle-layout-vertical_puzzle .wex-puzzle-card .wex-puzzle-tab {
        transform: scaleY(0);
    }
    .wex-puzzle-bp-tablet.is-armed.is-playing .wex-puzzle-layout-vertical_puzzle .wex-puzzle-card .wex-puzzle-tab {
        transform: none;
    }
    .wex-puzzle-bp-tablet.is-armed .wex-puzzle-layout-vertical_puzzle .wex-puzzle-card {
        transform: translate3d(0, 24px, 0) scale(0.96);
    }

    /* Tablette : cartes verticales épurées */
    .wex-puzzle-bp-tablet .wex-puzzle-container.wex-puzzle-layout-vertical_clean {
        flex-direction: column;
        gap: 14px !important;
        max-width: 520px;
        margin: 0 auto;
    }

    /* Tablette : défilement horizontal */
    .wex-puzzle-bp-tablet .wex-puzzle-container.wex-puzzle-layout-horizontal_scroll {
        overflow-x: auto;
        padding-bottom: 16px;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
    }
    .wex-puzzle-bp-tablet .wex-puzzle-container.wex-puzzle-layout-horizontal_scroll .wex-puzzle-card {
        flex: 0 0 240px;
        scroll-snap-align: start;
    }

    /* Sans languettes dans les modes épuré / défilement */
    .wex-puzzle-bp-tablet .wex-puzzle-layout-vertical_clean .wex-puzzle-tab,
    .wex-puzzle-bp-tablet .wex-puzzle-layout-horizontal_scroll .wex-puzzle-tab {
        display: none !important;
    }
    .wex-puzzle-bp-tablet .wex-puzzle-layout-vertical_clean .wex-puzzle-card-body,
    .wex-puzzle-bp-tablet .wex-puzzle-layout-horizontal_scroll .wex-puzzle-card-body {
        -webkit-mask: none !important;
        mask: none !important;
    }
}

@media (max-width: 767px) {
    .wex-puzzle-process-wrapper {
        --wex-puzzle-vgap: 14px;
    }

    .wex-puzzle-header {
        font-size: 26px;
        margin-bottom: 20px;
        text-align: center;
    }

    /* Puzzle vertical (tous breakpoints) */
    .wex-puzzle-container.wex-puzzle-layout-vertical_puzzle {
        flex-direction: column !important;
        gap: var(--wex-puzzle-vgap) !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 auto !important;
    }

    .wex-puzzle-container.wex-puzzle-layout-vertical_puzzle .wex-puzzle-card {
        min-height: auto !important;
        width: 100% !important;
        flex: 1 1 auto;
    }

    .wex-puzzle-style-interlocking .wex-puzzle-layout-vertical_puzzle .wex-puzzle-has-notch .wex-puzzle-card-body {
        -webkit-mask: var(--wex-puzzle-notch-v-img) top 0 left 50% / var(--wex-puzzle-notch-h) var(--wex-puzzle-notch-w) no-repeat,
                      linear-gradient(#000 0 0);
        -webkit-mask-composite: destination-out;
        mask: var(--wex-puzzle-notch-v-img) top 0 left 50% / var(--wex-puzzle-notch-h) var(--wex-puzzle-notch-w) no-repeat,
              linear-gradient(#000 0 0);
        mask-composite: exclude;
        padding-top: calc(var(--wex-puzzle-knob-d) + var(--wex-puzzle-knob-r) + 10px) !important;
    }

    .wex-puzzle-layout-vertical_puzzle .wex-puzzle-card .wex-puzzle-tab {
        --wex-k-cy: calc(1px + var(--wex-puzzle-vgap) + var(--wex-puzzle-knob-d));
        top: calc(100% - 1px);
        bottom: auto;
        left: 0;
        right: 0;
        width: auto;
        height: calc(var(--wex-k-cy) + var(--wex-puzzle-knob-r) + 1px);
        background: linear-gradient(180deg, var(--wex-puzzle-grad-end) 0%, var(--wex-puzzle-grad-start) 100%);
        -webkit-mask:
            radial-gradient(circle at 50% var(--wex-k-cy), #000 calc(var(--wex-puzzle-knob-r) - 0.5px), transparent calc(var(--wex-puzzle-knob-r) + 0.5px)) 0 0 / 100% 100% no-repeat,
            linear-gradient(#000 0 0) 50% 0 / calc(2 * var(--wex-puzzle-knob-neck)) var(--wex-k-cy) no-repeat;
        mask:
            radial-gradient(circle at 50% var(--wex-k-cy), #000 calc(var(--wex-puzzle-knob-r) - 0.5px), transparent calc(var(--wex-puzzle-knob-r) + 0.5px)) 0 0 / 100% 100% no-repeat,
            linear-gradient(#000 0 0) 50% 0 / calc(2 * var(--wex-puzzle-knob-neck)) var(--wex-k-cy) no-repeat;
        transform-origin: center top;
        z-index: 5;
    }

    .is-armed .wex-puzzle-layout-vertical_puzzle .wex-puzzle-card .wex-puzzle-tab {
        transform: scaleY(0);
    }
    .is-armed.is-playing .wex-puzzle-layout-vertical_puzzle .wex-puzzle-card .wex-puzzle-tab {
        transform: none;
    }
    .is-armed .wex-puzzle-layout-vertical_puzzle .wex-puzzle-card {
        transform: translate3d(0, 24px, 0) scale(0.96);
    }

    /* Cartes verticales épurées */
    .wex-puzzle-container.wex-puzzle-layout-vertical_clean {
        flex-direction: column !important;
        gap: 12px !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 auto !important;
    }

    /* Défilement horizontal */
    .wex-puzzle-container.wex-puzzle-layout-horizontal_scroll {
        overflow-x: auto !important;
        padding-bottom: 16px !important;
        -webkit-overflow-scrolling: touch !important;
        scroll-snap-type: x mandatory !important;
        gap: 12px !important;
    }
    .wex-puzzle-container.wex-puzzle-layout-horizontal_scroll .wex-puzzle-card {
        flex: 0 0 240px !important;
        scroll-snap-align: start !important;
        min-height: 160px !important;
    }

    .wex-puzzle-layout-vertical_clean .wex-puzzle-tab,
    .wex-puzzle-layout-horizontal_scroll .wex-puzzle-tab {
        display: none !important;
    }
    .wex-puzzle-layout-vertical_clean .wex-puzzle-card-body,
    .wex-puzzle-layout-horizontal_scroll .wex-puzzle-card-body {
        -webkit-mask: none !important;
        mask: none !important;
    }

    .wex-puzzle-card-body {
        padding: 18px 18px 20px;
        border-radius: 12px;
        box-shadow: 0 4px 14px rgba(56, 158, 176, 0.12);
    }

    .wex-puzzle-card-content {
        max-width: 95% !important;
    }

    .wex-puzzle-card-title {
        font-size: 18px !important;
        font-weight: 700 !important;
        margin: 0 0 6px 0 !important;
        letter-spacing: -0.2px !important;
    }

    .wex-puzzle-card-desc {
        font-size: 13.5px !important;
        line-height: 1.45 !important;
        opacity: 0.95 !important;
    }

    .wex-puzzle-step-badge {
        font-size: 11px !important;
        margin-bottom: 6px !important;
    }
}

@media (max-width: 360px) {
    .wex-puzzle-card-title {
        font-size: 16.5px !important;
    }

    .wex-puzzle-card-desc {
        font-size: 12.5px !important;
        line-height: 1.4 !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .wex-puzzle-process-wrapper.is-armed .wex-puzzle-header,
    .wex-puzzle-process-wrapper.is-armed .wex-puzzle-card,
    .wex-puzzle-process-wrapper.is-armed .wex-puzzle-tab {
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
    }
}
