/**
 * Styles front : Tatoun Halloween (PrestaShop)
 * Habillage (toiles, citrouilles, chauves-souris) et fenêtre de code promo
 */

/* ========================================
   Conteneur plein écran
   ======================================== */
#tatoun-hw-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9990;
    overflow: hidden;
}

#tatoun-hw-wrapper svg {
    display: block;
    width: 100%;
    height: 100%;
}

/* ========================================
   Toiles d'araignées (coins)
   ======================================== */
.tatoun-hw-spiderweb {
    position: absolute;
    width: 90px;
    height: 90px;
    opacity: 0;
    pointer-events: none;
    animation: tatoun-hw-fade-in 2s ease-out forwards;
}

body.tatoun-hw-intensity-low .tatoun-hw-spiderweb {
    width: 70px;
    height: 70px;
}

body.tatoun-hw-intensity-high .tatoun-hw-spiderweb {
    width: 120px;
    height: 120px;
}

/* ========================================
   Citrouilles (côtés)
   ======================================== */
.tatoun-hw-pumpkin {
    position: absolute;
    width: 70px;
    height: 70px;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -50%);
    animation: tatoun-hw-pumpkin-appear 2.5s ease-out forwards;
    filter: drop-shadow(0 0 10px rgba(255, 122, 0, 0.45));
}

body.tatoun-hw-intensity-high .tatoun-hw-pumpkin {
    width: 85px;
    height: 85px;
}

@keyframes tatoun-hw-pumpkin-appear {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.4);
    }
    60% {
        opacity: 0.95;
        transform: translate(-50%, -50%) scale(1.08);
    }
    100% {
        opacity: 0.9;
        transform: translate(-50%, -50%) scale(1);
    }
}

/* ========================================
   Chauves-souris : base
   ======================================== */
.tatoun-hw-bat {
    position: absolute;
    width: 56px;
    height: 56px;
    pointer-events: none;
    --glow: #ff8c00;
}

.tatoun-hw-bat-inner {
    width: 100%;
    height: 100%;
}

/* Décoratives : plus petites et discrètes */
.tatoun-hw-bat.is-decor {
    width: 42px;
    height: 42px;
    opacity: 0.8;
}

body.tatoun-hw-intensity-low .tatoun-hw-bat.is-decor {
    width: 34px;
    height: 34px;
}

body.tatoun-hw-intensity-high .tatoun-hw-bat.is-decor {
    width: 48px;
    height: 48px;
}

/* ========================================
   Chauves-souris en vol (traversée)
   ======================================== */
.tatoun-hw-bat.is-flying {
    left: 0;
    animation-name: tatoun-hw-fly-ltr;
    animation-duration: 35s;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
}

.tatoun-hw-bat.is-flying.dir-rtl {
    animation-name: tatoun-hw-fly-rtl;
}

.tatoun-hw-bat.is-flying .tatoun-hw-bat-inner {
    animation: tatoun-hw-bob 3s ease-in-out infinite;
}

@keyframes tatoun-hw-fly-ltr {
    0%   { transform: translateX(-120px); }
    100% { transform: translateX(calc(100vw + 120px)); }
}

@keyframes tatoun-hw-fly-rtl {
    0%   { transform: translateX(calc(100vw + 120px)); }
    100% { transform: translateX(-120px); }
}

@keyframes tatoun-hw-bob {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-18px); }
}

/* ========================================
   Chauves-souris cliquables (code promo)
   ======================================== */
.tatoun-hw-bat.is-clickable {
    width: 72px;
    height: 72px;
    cursor: pointer;
    pointer-events: auto;
    filter: drop-shadow(0 0 8px var(--glow));
    transition: filter 0.3s ease;
}

.tatoun-hw-bat.is-clickable .tatoun-hw-bat-inner {
    transition: transform 0.25s ease;
}

.tatoun-hw-bat.is-clickable:hover,
.tatoun-hw-bat.is-clickable:focus-visible {
    filter: drop-shadow(0 0 16px var(--glow)) drop-shadow(0 0 4px var(--glow));
    outline: none;
}

.tatoun-hw-bat.is-clickable:hover .tatoun-hw-bat-inner,
.tatoun-hw-bat.is-clickable:focus-visible .tatoun-hw-bat-inner {
    transform: scale(1.2);
}

/* En vol : se fige au survol pour être attrapée */
.tatoun-hw-bat.is-flying.is-clickable:hover,
.tatoun-hw-bat.is-flying.is-clickable:focus-visible {
    animation-play-state: paused;
}

.tatoun-hw-bat.is-flying.is-clickable:hover .tatoun-hw-bat-inner,
.tatoun-hw-bat.is-flying.is-clickable:focus-visible .tatoun-hw-bat-inner {
    animation-play-state: paused;
}

/* Perchée : suspendue sur les côtés, léger balancement */
.tatoun-hw-bat.is-perched {
    transform: translate(-50%, -50%);
    opacity: 0;
    animation: tatoun-hw-fade-in 1.5s ease-out forwards;
}

.tatoun-hw-bat.is-perched .tatoun-hw-bat-inner {
    animation: tatoun-hw-swing 4s ease-in-out infinite;
    transform-origin: 50% 0;
}

@keyframes tatoun-hw-swing {
    0%, 100% { transform: rotate(-5deg); }
    50%      { transform: rotate(5deg); }
}

/* Attrapée : s'envole et disparaît */
.tatoun-hw-bat.is-caught {
    pointer-events: none;
    animation-play-state: paused;
}

.tatoun-hw-bat.is-caught .tatoun-hw-bat-inner {
    animation: tatoun-hw-caught 0.9s ease-in forwards !important;
}

@keyframes tatoun-hw-caught {
    0%   { transform: scale(1.2) translateY(0); opacity: 1; }
    100% { transform: scale(0.3) translateY(-140px) rotate(25deg); opacity: 0; }
}

@keyframes tatoun-hw-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ========================================
   Fenêtre modale
   ======================================== */
.tatoun-hw-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 2, 20, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99900;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    padding: 16px;
    box-sizing: border-box;
}

.tatoun-hw-modal.active {
    opacity: 1;
    pointer-events: auto;
}

.tatoun-hw-modal-content {
    position: relative;
    background: linear-gradient(160deg, #2a1245 0%, #1b0b2e 60%, #120618 100%);
    color: #ffffff !important;
    padding: 40px 36px 32px;
    border-radius: 20px;
    border: 2px solid #ff7a00;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 40px rgba(255, 122, 0, 0.25);
    text-align: center;
    max-width: 520px;
    width: 100%;
    transform: scale(0.7);
    transition: transform 0.3s ease;
    font-family: inherit;
}

.tatoun-hw-modal.active .tatoun-hw-modal-content {
    transform: scale(1);
}

.tatoun-hw-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 34px;
    height: 34px;
    background: #ff7a00;
    border: none;
    border-radius: 50%;
    color: #1b0b2e !important;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease, background 0.3s ease;
    padding: 0;
}

.tatoun-hw-modal-close:hover {
    background: #ffa040;
    transform: rotate(90deg);
}

.tatoun-hw-modal-icon {
    font-size: 72px;
    line-height: 1;
    margin: 0 0 12px;
    animation: tatoun-hw-icon-bounce 1.4s ease-in-out infinite;
}

@keyframes tatoun-hw-icon-bounce {
    0%, 100% { transform: translateY(0) rotate(-6deg); }
    50%      { transform: translateY(-10px) rotate(6deg); }
}

.tatoun-hw-modal-title {
    font-size: 28px;
    line-height: 1.2;
    margin: 0 0 10px;
    /* Blanc, forcé : les thèmes imposent souvent une couleur sombre aux titres h2 */
    color: #ffffff !important;
    font-weight: 800;
}

.tatoun-hw-modal-subtitle {
    font-size: 16px;
    margin: 0 0 22px;
    color: #ffffff !important;
}

.tatoun-hw-modal.is-error .tatoun-hw-modal-subtitle {
    color: #ff8a8a !important;
}

.tatoun-hw-promo-code {
    background: #0c0314;
    border: 3px dashed #ff7a00;
    border-radius: 12px;
    padding: 18px;
    margin: 0 0 12px;
    font-size: 30px;
    font-weight: bold;
    color: #ffd166 !important;
    letter-spacing: 3px;
    font-family: 'Courier New', monospace;
    user-select: all;
    word-break: break-all;
}

.tatoun-hw-modal-desc {
    font-size: 15px;
    margin: 0 0 20px;
    color: #ffffff !important;
    min-height: 1em;
}

.tatoun-hw-modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.tatoun-hw-btn {
    /* Couleurs forcées : les thèmes redéfinissent souvent fond et texte des boutons */
    border: none !important;
    padding: 12px 24px;
    font-size: 15px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    font-family: inherit;
}

.tatoun-hw-btn:hover:not(:disabled) {
    transform: translateY(-2px);
}

.tatoun-hw-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

.tatoun-hw-btn-copy {
    background: #ff7a00 !important;
    color: #1b0b2e !important;
}

.tatoun-hw-btn-copy:hover:not(:disabled) {
    box-shadow: 0 6px 16px rgba(255, 122, 0, 0.45);
}

.tatoun-hw-btn-copy.copied {
    background: #3ddc84 !important;
}

.tatoun-hw-btn-apply {
    background: transparent !important;
    color: #ffd166 !important;
    border: 2px solid #ffd166 !important;
    padding: 10px 22px;
}

.tatoun-hw-btn-apply:hover:not(:disabled) {
    background: rgba(255, 209, 102, 0.12) !important;
}

.tatoun-hw-btn-apply.applied {
    background: #3ddc84 !important;
    border-color: #3ddc84 !important;
    color: #0c2b18 !important;
}

.tatoun-hw-feedback {
    font-size: 14px;
    margin-top: 14px;
    min-height: 1.2em;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.tatoun-hw-feedback.show {
    opacity: 1;
}

.tatoun-hw-feedback.is-success {
    color: #3ddc84 !important;
}

.tatoun-hw-feedback.is-error {
    color: #ff8a8a !important;
}

.tatoun-hw-cart-link {
    color: #ffd166 !important;
    text-decoration: underline;
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 1024px) {
    .tatoun-hw-spiderweb { width: 70px; height: 70px; }
    .tatoun-hw-pumpkin { width: 58px; height: 58px; }
    .tatoun-hw-bat.is-clickable { width: 64px; height: 64px; }
}

@media (max-width: 768px) {
    .tatoun-hw-spiderweb { width: 56px; height: 56px; opacity: 0.8; }
    .tatoun-hw-pumpkin { width: 48px; height: 48px; }
    .tatoun-hw-bat.is-decor { width: 30px; height: 30px; }
    .tatoun-hw-bat.is-clickable { width: 58px; height: 58px; }

    .tatoun-hw-modal-content { padding: 32px 20px 24px; }
    .tatoun-hw-modal-title { font-size: 22px; }
    .tatoun-hw-modal-icon { font-size: 56px; }
    .tatoun-hw-promo-code { font-size: 22px; padding: 14px; letter-spacing: 2px; }
}

@media (max-width: 480px) {
    .tatoun-hw-spiderweb { width: 44px; height: 44px; }
    .tatoun-hw-pumpkin { width: 40px; height: 40px; }
    .tatoun-hw-bat.is-clickable { width: 52px; height: 52px; }

    .tatoun-hw-modal-content { padding: 28px 14px 20px; }
    .tatoun-hw-modal-title { font-size: 19px; }
    .tatoun-hw-promo-code { font-size: 18px; padding: 12px; letter-spacing: 1px; }
    .tatoun-hw-btn { padding: 10px 18px; font-size: 14px; }
}

/* ========================================
   Accessibilité : mouvement réduit
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    .tatoun-hw-bat.is-flying,
    .tatoun-hw-bat-inner,
    .tatoun-hw-modal-icon,
    .tatoun-hw-pumpkin,
    .tatoun-hw-spiderweb,
    .tatoun-hw-bat.is-perched {
        animation: none !important;
        opacity: 1;
    }
}

/* ========================================
   Diagnostic du fond (?thw_debug=1)
   ======================================== */
.tatoun-hw-debug {
    position: fixed;
    left: 12px;
    bottom: 12px;
    z-index: 99950;
    max-width: min(560px, calc(100vw - 24px));
    max-height: 45vh;
    overflow: auto;
    padding: 12px 14px;
    background: #1b0b2e;
    color: #f6ecff;
    border: 2px solid #ff7a00;
    border-radius: 10px;
    font: 13px/1.5 monospace;
    white-space: pre-wrap;
    word-break: break-word;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
