/* =====================================================================
   destruction.css : animation cinématique de destruction du cube (niveau 3)
   DESTINATION : FileZilla, racine du site
   À charger dans index.html (après style.css)
   ===================================================================== */

/* ---------- Overlay principal : couvre tout l'écran pendant la cinématique ---------- */
#destroy-overlay {
    position: fixed;
    inset: 0;
    z-index: 100000;
    pointer-events: none;
    display: none;
    background: radial-gradient(circle at center, rgba(0,0,0,0.15) 0%, rgba(0,0,0,0.85) 90%);
    opacity: 0;
    transition: opacity 0.3s ease-out;
}
#destroy-overlay.active {
    display: block;
    opacity: 1;
}

/* ---------- Freeze de l'écran pendant la cinématique : on bloque les inputs ---------- */
body.cinematic-active {
    overflow: hidden;
    user-select: none;
    cursor: not-allowed;
}
body.cinematic-active .cube,
body.cinematic-active #the-cube {
    cursor: not-allowed !important;
}

/* ---------- Le cube "source" qui va être cloné au centre de l'écran ---------- */
#destroy-clone-wrap {
    position: fixed;
    left: 50%;
    top: 50%;
    width: 200px;
    height: 200px;
    margin: -100px 0 0 -100px;
    perspective: 800px;
    z-index: 100001;
    pointer-events: none;
    transform-style: preserve-3d;
    transition: transform 1.2s cubic-bezier(.2,.7,.3,1);
}
#destroy-clone-wrap.zoomed {
    transform: scale(1.6);
}
#destroy-clone-wrap.shrunk {
    transform: scale(0.9);
}

/* Le cube cloné : identique au vrai cube pour la cohérence visuelle */
#destroy-clone {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transform: translateZ(-100px) rotateX(0deg) rotateY(0deg);
    animation: destroyRotate 4s linear infinite;
}
@keyframes destroyRotate {
    0%   { transform: translateZ(-100px) rotateX(0deg)   rotateY(0deg); }
    100% { transform: translateZ(-100px) rotateX(360deg) rotateY(360deg); }
}
#destroy-clone .face {
    position: absolute;
    width: 200px;
    height: 200px;
    background: hsla(var(--cube-hue, 355), 100%, 64%, 0.85);
    border: 2px solid #ffffff;
    box-sizing: border-box;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    /* Pendant la cinématique, on garde la couleur de la phase qui meurt */
}
#destroy-clone .face.front  { transform: rotateY(  0deg) translateZ(100px); }
#destroy-clone .face.right  { transform: rotateY( 90deg) translateZ(100px); }
#destroy-clone .face.back   { transform: rotateY(180deg) translateZ(100px); }
#destroy-clone .face.left   { transform: rotateY(-90deg) translateZ(100px); }
#destroy-clone .face.top    { transform: rotateX( 90deg) translateZ(100px); }
#destroy-clone .face.bottom { transform: rotateX(-90deg) translateZ(100px); }

/* ---------- Fissures qui apparaissent sur les faces du cube ---------- */
#destroy-clone .crack {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0;
    background:
        linear-gradient(125deg, transparent 42%, rgba(255,255,255,.95) 43%, transparent 44%),
        linear-gradient(35deg,  transparent 55%, rgba(255,255,255,.9)  56%, transparent 57%),
        linear-gradient(160deg, transparent 30%, rgba(255,255,255,.85) 31%, transparent 32%),
        linear-gradient(75deg,  transparent 65%, rgba(255,255,255,.9)  66%, transparent 67%),
        linear-gradient(10deg,  transparent 48%, rgba(255,255,255,.95) 49%, transparent 50%);
    filter: drop-shadow(0 0 4px rgba(255,80,80,.9));
    animation: crackIn 1.4s ease-out forwards;
}
@keyframes crackIn {
    0%   { opacity: 0; transform: scale(0.4); }
    30%  { opacity: 1; }
    100% { opacity: 1; transform: scale(1); }
}

/* ---------- Tremblement du cube pendant la phase de fissures ---------- */
#destroy-clone.shaking {
    animation: destroyRotate 4s linear infinite, destroyShake 0.08s infinite alternate;
}
@keyframes destroyShake {
    0%   { transform: translateZ(-100px) rotateX(0deg) rotateY(0deg) translate(0, 0); }
    100% { transform: translateZ(-100px) rotateX(0deg) rotateY(0deg) translate(3px, -3px); }
}

/* ---------- Flash blanc plein écran ---------- */
#destroy-flash {
    position: fixed;
    inset: 0;
    background: #ffffff;
    z-index: 100002;
    pointer-events: none;
    opacity: 0;
}
#destroy-flash.bang {
    animation: flashBang 0.45s ease-out forwards;
}
@keyframes flashBang {
    0%   { opacity: 0; }
    15%  { opacity: 1; }
    100% { opacity: 0; }
}

/* ---------- Fragments du cube projetés dans tous les sens ---------- */
#destroy-pieces {
    position: fixed;
    inset: 0;
    z-index: 100003;
    pointer-events: none;
    overflow: hidden;
}
.dpiece {
    position: absolute;
    width: 26px;
    height: 26px;
    border-radius: 3px;
    background: hsla(var(--cube-hue, 355), 100%, 64%, 0.95);
    box-shadow: 0 0 12px hsla(var(--cube-hue, 355), 100%, 64%, 0.75);
    will-change: transform, opacity;
    transform: translate3d(0,0,0) rotate(0deg);
}
.dpiece.trail::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: inherit;
    background: inherit;
    opacity: 0.4;
    filter: blur(6px);
}

/* ---------- Superposition "slow motion" : lignes de vitesse ---------- */
#destroy-speed {
    position: fixed;
    inset: 0;
    z-index: 100002;
    pointer-events: none;
    opacity: 0;
    background: repeating-conic-gradient(from 0deg, rgba(255,255,255,0.06) 0deg 2deg, transparent 2deg 6deg);
    mix-blend-mode: screen;
}
#destroy-speed.active {
    animation: speedFade 1.6s ease-out forwards;
}
@keyframes speedFade {
    0%   { opacity: 0; transform: scale(1); }
    20%  { opacity: 1; transform: scale(1.05); }
    100% { opacity: 0; transform: scale(1.4); }
}

/* ---------- Bandeau du pseudo du destructeur ---------- */
#destroy-winner {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.6);
    z-index: 100004;
    pointer-events: none;
    text-align: center;
    opacity: 0;
    color: #fff;
    font-family: 'Segoe UI', Tahoma, sans-serif;
    text-shadow: 0 0 30px rgba(255,80,80,0.9), 0 0 60px rgba(255,0,0,0.5);
}
#destroy-winner.show {
    animation: winnerIn 2.6s ease-out forwards;
}
#destroy-winner .small {
    display: block;
    font-size: 0.85rem;
    letter-spacing: 6px;
    text-transform: uppercase;
    color: #ffcc00;
    margin-bottom: 6px;
    opacity: 0.9;
}
#destroy-winner .big {
    display: block;
    font-size: clamp(2rem, 8vw, 4.5rem);
    font-weight: 900;
    letter-spacing: 2px;
    background: linear-gradient(90deg, #fff, #ffcc00, #ff4757, #fff);
    background-size: 300% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradientShift 2s linear infinite;
}
@keyframes gradientShift {
    0%   { background-position: 0% 50%; }
    100% { background-position: 200% 50%; }
}
@keyframes winnerIn {
    0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
    15%  { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
    25%  { transform: translate(-50%, -50%) scale(1); }
    75%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.05); }
}

/* ---------- Flash final de transition vers la nouvelle phase ---------- */
#destroy-fade {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 100005;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease-out;
}
#destroy-fade.in {
    opacity: 1;
}
#destroy-fade.out {
    opacity: 0;
}

/* ---------- Petite annonce en haut pendant la cinématique ---------- */
#destroy-caption {
    position: fixed;
    left: 50%;
    top: 8%;
    transform: translateX(-50%);
    z-index: 100006;
    pointer-events: none;
    padding: 8px 22px;
    border-radius: 20px;
    background: rgba(0,0,0,.7);
    border: 1px solid #ff4757;
    color: #fff;
    font-family: 'Segoe UI', Tahoma, sans-serif;
    font-weight: bold;
    font-size: 0.85rem;
    letter-spacing: 3px;
    text-transform: uppercase;
    opacity: 0;
    transition: opacity 0.3s;
}
#destroy-caption.show { opacity: 1; }

/* ---------- Mobile : on réduit un peu ---------- */
@media (max-width: 600px) {
    #destroy-clone-wrap { width: 150px; height: 150px; margin: -75px 0 0 -75px; }
    #destroy-clone .face { width: 150px; height: 150px; }
    #destroy-clone .face.front  { transform: rotateY(  0deg) translateZ(75px); }
    #destroy-clone .face.right  { transform: rotateY( 90deg) translateZ(75px); }
    #destroy-clone .face.back   { transform: rotateY(180deg) translateZ(75px); }
    #destroy-clone .face.left   { transform: rotateY(-90deg) translateZ(75px); }
    #destroy-clone .face.top    { transform: rotateX( 90deg) translateZ(75px); }
    #destroy-clone .face.bottom { transform: rotateX(-90deg) translateZ(75px); }
    #destroy-clone { transform: translateZ(-75px); }
    #destroy-clone.shaking {
        animation: destroyRotate 4s linear infinite, destroyShakeMobile 0.08s infinite alternate;
    }
    @keyframes destroyShakeMobile {
        0%   { transform: translateZ(-75px) rotateX(0deg) rotateY(0deg) translate(0, 0); }
        100% { transform: translateZ(-75px) rotateX(0deg) rotateY(0deg) translate(3px, -3px); }
    }
    .dpiece { width: 18px; height: 18px; }
}