/* ========================================
   UI — Promo Modal — Roue de bienvenue

   Modale nouveau visiteur, une seule vue : formulaire email (Fluent Forms) à
   gauche, roue sur un plateau sombre à droite. L'envoi lance le tour, le
   résultat remplace le bloc d'introduction. Chargé seulement quand la modale
   est active (inc/promo-modal.php).

   États posés par le JS : .is-open sur la modale, .is-spinning puis
   .is-revealed sur la roue, body.has-promo-open pendant l'ouverture.
   Dépendances : styles.css (tokens), components-base.css (label),
   ui-buttons-links.css (.btn), ui-focus.css.
   Seuil : 768 px, aligné sur le reste du thème.

   Le disque et l'animation vivent dans promo-wheel.css.
   L'adaptation du plugin vit dans promo-form.css.
   ======================================== */

.promo-modal {
    --promo-wheel-size: 340px;
    --promo-modal-gutter: var(--spacing-lg);

    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--promo-modal-gutter);
}

/* L'attribut hidden doit primer sur tout display posé par le composant
   (modale, blocs) : le thème n'a pas de reset [hidden] global.
   Sans cette règle le fond couvre la page et bloque les clics. */
.promo-modal[hidden],
.promo-modal [hidden] {
    display: none;
}

body.has-promo-open {
    overflow: hidden;
}

/* Fond opaque plutôt que flou : un backdrop-filter se recalcule pendant le
   tour de roue, pour un rendu identique à l'œil. */
.promo-modal__backdrop {
    position: absolute;
    inset: 0;
    background: var(--overlay-vignette);
}

.promo-modal__dialog {
    position: relative;
    width: min(100%, 960px);
    max-height: calc(100vh - 2 * var(--promo-modal-gutter));
    max-height: calc(100dvh - 2 * var(--promo-modal-gutter));
    overflow: auto;
    overscroll-behavior: contain;
    background: var(--carbon-300);
    border: var(--border-subtle);
    border-radius: var(--border-radius-xl);
    box-shadow: var(--shadow-xl);
    transform: translateY(16px);
    opacity: 0;
    transition: transform var(--transition-normal), opacity var(--transition-normal);
}

.promo-modal.is-open .promo-modal__dialog {
    transform: translateY(0);
    opacity: 1;
}

/* L'aperçu connecté garde ses commandes sous la barre WordPress. */
.admin-bar .promo-modal__dialog {
    max-height: calc(100vh - 2 * var(--promo-modal-gutter) - var(--wp-admin--admin-bar--height, 32px));
    max-height: calc(100dvh - 2 * var(--promo-modal-gutter) - var(--wp-admin--admin-bar--height, 32px));
}

.promo-modal__close {
    position: absolute;
    top: var(--spacing-md);
    right: var(--spacing-md);
    z-index: var(--z-overlay);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--border-radius-pill);
    background: transparent;
    color: var(--gray-300);
    cursor: pointer;
    transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.promo-modal__close:hover {
    background: var(--color-white-10);
    border-color: var(--color-white-15);
    color: var(--white);
}

.promo-modal__close svg {
    width: 18px;
    height: 18px;
}

/* La casse capitalize des boutons du thème ne convient pas à une phrase. */
.promo-modal .btn,
.promo-modal .ff-btn-submit {
    text-transform: none;
}

/* ----------------------------------------
   Corps : texte à gauche, plateau de la roue à droite
   ---------------------------------------- */

.promo-modal__body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: stretch;
    min-height: 100%;
    overflow: hidden;
}

.promo-modal__text {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
    padding: var(--spacing-2xl) var(--spacing-xl) var(--spacing-2xl) 44px;
}

.promo-modal__intro,
.promo-result {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--spacing-md);
}

.promo-modal__text .label {
    margin-bottom: 0;
    font-size: calc(var(--font-size-label) - 1px);
}

/* Sur-titre : pictogramme cadeau orange, filet et libellé du thème. */
.promo-modal__eyebrow {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.promo-modal__eyebrow-icon {
    display: inline-flex;
    width: 30px;
    height: 30px;
    color: var(--color-primary-light);
}

.promo-modal__eyebrow-icon svg {
    width: 100%;
    height: 100%;
}

.promo-modal__title {
    margin: 0;
    font-family: var(--font-display);
    font-size: clamp(1.75rem, 3vw, 2.375rem);
    font-weight: 600;
    line-height: var(--line-height-title);
    letter-spacing: var(--letter-spacing-title);
    color: var(--white);
    text-wrap: balance;
}

.promo-modal__desc {
    margin: 0;
    font-size: var(--font-size-body);
    line-height: var(--line-height-body);
    color: var(--gray-400);
}

.promo-modal__note,
.promo-result__note {
    margin: 0;
    font-size: var(--font-size-meta);
    line-height: var(--line-height-body);
    color: var(--gray-500);
}

/* Plateau : fond plus sombre et halos chauds, fixes pendant le tour.
   Le décor y est contenu : il ne crée jamais de défilement horizontal. */
.promo-modal__wheel-area {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 0;
    padding: 72px 60px 56px var(--spacing-2xl);
    overflow: hidden;
    background:
        radial-gradient(circle at 46% 48%, var(--color-primary-15) 0%, transparent 56%),
        radial-gradient(circle at 92% 96%, var(--color-primary-20) 0%, transparent 34%),
        var(--carbon-400);
    border-left: var(--border-subtle);
}

/* Décor : confettis, ruban, bannière et coffret. Sous la roue et le
   statut, sans interaction. */
.promo-modal__confetti,
.promo-modal__banner,
.promo-modal__gift {
    position: absolute;
    pointer-events: none;
    user-select: none;
}

.promo-modal__confetti {
    inset: 0;
    width: 100%;
    height: 100%;
}

.promo-modal__confetto {
    fill: var(--color-primary);
    opacity: 0.85;
}

.promo-modal__confetto--cream {
    fill: var(--neutral-200);
    opacity: 0.7;
}

.promo-modal__ribbon {
    fill: none;
    stroke: var(--color-primary);
    stroke-width: 5;
    stroke-linecap: round;
    opacity: 0.9;
}

/* Bannière pliée sous le bouton de fermeture : coupe en queue d'aronde à
   gauche, pli sombre à droite. */
.promo-modal__banner {
    top: 68px;
    right: -6px;
    z-index: var(--z-background);
    padding: 6px 22px 6px 28px;
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
    color: var(--white);
    background: linear-gradient(180deg, var(--color-primary-light), var(--color-primary));
    clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 12px 50%);
    box-shadow: var(--shadow-md);
    transform: rotate(14deg);
    transform-origin: right center;
}

.promo-modal__gift {
    right: 8px;
    bottom: 12px;
    z-index: var(--z-background);
    width: 190px;
    height: auto;
}

.promo-modal__wheel-area .promo-wheel,
.promo-modal__status {
    position: relative;
    z-index: var(--z-content);
}

/* Toujours rendu, même vide : une région aria-live masquée puis affichée
   n'est pas annoncée par tous les lecteurs d'écran. */
.promo-modal__status {
    max-width: var(--promo-wheel-size);
    /* Réserver la ligne avant le tour évite d'agrandir le plateau en cours de rotation. */
    min-height: 1lh;
    margin: var(--spacing-md) 0 0;
    font-size: var(--font-size-meta);
    line-height: var(--line-height-body);
    text-align: center;
    color: var(--gray-400);
}

/* ----------------------------------------
   Résultat : révélé à la fin du tour, il remplace l'introduction
   ---------------------------------------- */

/* Ces conteneurs reçoivent le focus pour annoncer le dialogue ou le gain.
   Les commandes et champs conservent leur propre repère de focus. */
.promo-result,
.promo-modal__dialog {
    outline: none;
}

.promo-result__message,
.promo-result__note {
    white-space: pre-line;
    overflow-wrap: anywhere;
}

.promo-result__message {
    color: var(--gray-300);
}

.promo-result__email {
    color: var(--color-primary-light);
    font-weight: 600;
    word-break: break-all;
}

.promo-result__action {
    margin-top: var(--spacing-sm);
    border-color: var(--color-white-15);
}

/* ----------------------------------------
   Responsive : formulaire d'abord, roue dessous
   ---------------------------------------- */

@media (max-width: 768px) {
    .promo-modal {
        --promo-wheel-size: min(240px, calc(100vw - 80px));
        --promo-modal-gutter: var(--spacing-md);

        align-items: flex-end;
    }

    .promo-modal__body {
        grid-template-columns: 1fr;
    }

    .promo-modal__text {
        padding: var(--spacing-xl) var(--spacing-lg) var(--spacing-lg);
    }

    .promo-modal__intro,
    .promo-result {
        gap: 12px;
    }

    .promo-modal__title {
        font-size: 1.75rem;
    }

    .promo-modal__wheel-area {
        padding: var(--spacing-lg) var(--spacing-lg) var(--spacing-lg) var(--spacing-md);
        border-left: 0;
        border-top: var(--border-subtle);
    }

    /* Décor compact : la bannière double le sur-titre, le coffret reste
       sous la roue, côté statut. */
    .promo-modal__banner {
        display: none;
    }

    .promo-modal__gift {
        right: 4px;
        bottom: 4px;
        width: 120px;
    }

    /* Le sur-titre partage la première ligne avec le bouton de fermeture. */
    .promo-modal__eyebrow {
        padding-right: 40px;
    }

    .promo-modal__eyebrow-icon {
        width: 26px;
        height: 26px;
    }

    .promo-result__action {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .promo-modal__dialog,
    .promo-modal__close {
        transition: none;
    }
}
