/* ==================== 1. BASE ==================== */
body { 
    font-family: 'Inter', sans-serif;
    -webkit-tap-highlight-color: transparent;
    margin: 0; padding: 0;
    background-color: #0a0f1a;
    overflow: hidden;
    width: 100vw; height: 100vh;
}

/* ==================== 2. CANVAS (FIXE & FONCTIONNEL) ==================== */
/* Le canvas est sorti du flux pour être en fond d'écran total */
#canvas-container {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100vw !important; 
    height: 100vh !important;
    z-index: 0; /* Au fond */
    background: #0a0f1a;
    /* CRUCIAL : On force la capture des événements souris pour le zoom JS */
    pointer-events: auto !important; 
    touch-action: none;
}

#weave-canvas {
    display: block;
    width: 100%; height: 100%;
    outline: none;
}

/* ==================== 3. INTERFACE (CALQUE FANTÔME) ==================== */
/* Ce conteneur se superpose mais laisse passer les clics */
#main-container {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 10;
    pointer-events: none; /* La souris traverse ce div */
    display: block; /* On casse le flexbox qui posait problème */
}

/* On réactive la souris UNIQUEMENT sur les éléments interactifs */
.header-minimal, footer, #words-panel, #stats-panel, 
#toggle-panel-button, #settings-modal, #qr-modal, .modal-content {
    pointer-events: auto;
}

/* ==================== 4. HEADER (TYPOGRAPHIE ÉLÉGANTE) ==================== */
.header-minimal {
    position: absolute;
    top: 1.5rem; left: 50%; transform: translateX(-50%);
    z-index: 50;
    min-width: 350px;
    
    background: rgba(20, 28, 45, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.15); 
    border-radius: 50px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4), 0 0 40px rgba(99, 102, 241, 0.1);
    backdrop-filter: blur(10px);
    
    padding: 1rem 2.5rem; text-align: center;
    transition: all 0.4s cubic-bezier(0.19, 1, 0.22, 1);
    overflow: hidden;
}

.header-minimal::before {
    content: '';
    position: absolute;
    top: 0; left: -100%;
    width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.05), transparent);
    transition: left 0.6s ease;
}

.header-minimal:hover::before {
    left: 100%;
}

.header-minimal:hover { 
    transform: translateX(-50%) translateY(-2px);
    border-color: rgba(99, 102, 241, 0.4);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 0 60px rgba(99, 102, 241, 0.2);
}

.title-minimal {
    font-family: 'Space Grotesk', 'Inter', sans-serif;
    font-size: 1.5rem; 
    font-weight: 700; 
    color: white; 
    margin: 0;
    display: flex; 
    align-items: center; 
    justify-content: center; 
    gap: 0.75rem;
    letter-spacing: 0.02em;
}

.title-word {
    position: relative;
    display: inline-block;
    animation: fadeInUp 0.8s ease forwards;
    opacity: 0;
}

.title-word:first-child {
    animation-delay: 0.1s;
    font-weight: 700;
    background: white;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.title-word:last-child {
    animation-delay: 0.3s;
    font-weight: 700;
    background: white;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.title-separator { 
    color: #818cf8;
    font-size: 1.2rem;
    font-weight: 300;
    opacity: 0.6;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.4; transform: scale(1); }
    50% { opacity: 0.8; transform: scale(5); }
}

.subtitle-minimal { 
    font-family: 'Cormorant Garamond', serif;
    font-size: 0.85rem; 
    font-weight: 300;
    color: rgba(255, 255, 255, 0.5); 
    margin-top: 0.35rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    animation: fadeIn 1s ease 0.5s forwards;
    opacity: 0;
}

@keyframes fadeIn {
    to { opacity: 1; }
}

.subtitle-minimal::before,
.subtitle-minimal::after {
    content: '◆';
    display: inline-block;
    margin: 0 0.5rem;
    font-size: 0.6rem;
    color: #818cf8;
    opacity: 0.4;
}

.line-decoration { display: none; }

/* ==================== 5. LISTE DES MOTS ==================== */
/* ==================== 5. LISTE DES MOTS (VITESSE UNIFIÉE) ==================== */
#words-panel {
    position: absolute;
    left: 2rem;
    top: 8rem;      
    bottom: 8rem;   
    width: 300px;
    z-index: 20;
    
    background: rgba(20, 28, 45, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    
    padding: 1.5rem;
    display: flex; flex-direction: column;
    
    /* Transformation fluide standard */
    transform: translateX(0);
    transition: transform 0.5s ease-in-out, opacity 0.5s ease-in-out;
}

#words-panel h2 {
    color: white; margin: 0 0 1rem 0; font-size: 1.2rem;
}

#words-list {
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 5px;
}

.word-item { 
    margin-bottom: 0.5rem; padding: 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px; border-left-width: 4px !important;
    color: white;
    /* Retour à la ligne forcé */
    word-wrap: break-word; 
    white-space: normal;
}
.word-item:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateX(2px);
}

/* Barre Recherche */
#word-filter {
    background: rgba(0, 0, 0, 0.4); border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px; color: white; padding: 0.7rem 1rem; width: 100%; 
    box-sizing: border-box; margin-bottom: 1rem; outline: none;
}
#word-filter:focus { border-color: #6366f1; }

/* État Caché */
#main-container.panel-hidden #words-panel {
    transform: translateX(-120%); opacity: 0; pointer-events: none;
}

/* ==================== 6. BOUTON TOGGLE (MOTEUR GPU - ULTRA FLUIDE) ==================== */
#toggle-panel-button {
    position: fixed;
    z-index: 60;
    
    /* ON FIXE L'ORIGINE À 0,0 POUR TOUT GÉRER VIA TRANSFORM */
    top: 0;
    left: 0;
    
    width: 36px; height: 36px;
    border-radius: 50%;
    
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    
    /* --- ÉTAT OUVERT --- */
    /* Calcul précis : 2rem (marge) + 300px (liste) - 48px (bouton + écart) */
    /* Y = 9.5rem (Un peu sous le haut de la liste) */
    transform: translate3d(calc(2rem + 300px - 48px), 9rem, 0);
    
    /* C'est LE secret : on anime uniquement transform et les dimensions */
    transition: 
        transform 0.5s cubic-bezier(0.25, 1, 0.5, 1),
        width 0.3s ease,
        height 0.3s ease,
        background 0.3s ease;
        
    will-change: transform; /* Force l'accélération matérielle */
}

#toggle-panel-button:hover { 
    /* On garde la position calculée et on ajoute le scale */
    /* Note : L'effet de hover peut être simplifié pour éviter les conflits */
    background: rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
}

/* --- ÉTAT FERMÉ --- */
#main-container.panel-hidden #toggle-panel-button {
    width: 48px; height: 48px;
    
    background: #6366f1;
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
    
    /* --- POSITION FERMÉE --- */
    /* X = 1.5rem */
    /* Y = 50vh (milieu écran) - 24px (moitié hauteur bouton) */
    transform: translate3d(1.5rem, calc(50vh - 24px), 0);
}

#main-container.panel-hidden #toggle-panel-button:hover { 
    background: #818cf8;
    transform: translate3d(1.5rem, calc(50vh - 24px), 0) scale(1.1);
}

/* Animation de la flèche */
#main-container.panel-hidden #toggle-panel-button svg { 
    transform: rotate(180deg); 
    transition: transform 0.5s ease;
}

/* Mobile : Toujours caché */
@media (max-width: 767px) {
    #toggle-panel-button { display: none !important; }
}
/* ==================== 7. STATS ==================== */
#stats-panel {
    position: absolute;
    right: 2rem;
    top: 8rem; bottom: 8rem;
    width: 280px;
    z-index: 20;
    background: rgba(20, 28, 45, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    padding: 1.5rem;
    overflow-y: auto;
    color: white;
}

/* ==================== 8. FOOTER ==================== */
/* ==================== 8. FOOTER (COULEUR HARMONISÉE) ==================== */
footer {
    position: absolute; 
    bottom: 1.5rem; left: 50%; transform: translateX(-50%);
    z-index: 50; width: auto; max-width: 95%;
    
    /* Exactement la même teinte que #words-panel */
    background: rgba(20, 28, 45, 0.85);
    
    border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 24px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    
    padding: 0.75rem;
    display: flex; gap: 0.75rem; align-items: center;
}

footer button { transition: transform 0.2s ease; }
footer > div button {
    background: rgba(255, 255, 255, 0.05); 
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px; padding: 0.75rem;
}
footer > div button:hover {
    background: rgba(99, 102, 241, 0.5); transform: translateY(-2px);
}

#word-form button[type="submit"] {
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    border-radius: 12px; padding: 0 1.5rem; font-weight: 600;
}
#word-form button[type="submit"]:hover { transform: scale(1.02); }

#word-form { display: flex; gap: 0.5rem; }
#word-input {
    background: rgba(0, 0, 0, 0.6); 
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px; color: white; padding: 0.75rem 1rem; width: 250px;
    outline: none;
}
#word-input:focus { border-color: #6366f1; }

/* ==================== 9. MODALES ==================== */
#settings-modal, #qr-modal {
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 100;
    display: flex !important; align-items: center; justify-content: center;
}
#settings-modal.hidden, #qr-modal.hidden, #stats-panel.hidden { display: none !important; }

#settings-modal > div, #qr-modal > div {
    background: #1a1f2e !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    border-radius: 24px !important;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5) !important;
    color: white;
    width: 90%; max-width: 450px;
    max-height: 80vh; overflow-y: auto; 
    position: relative; margin: 0;
}

#close-settings-button, #close-modal-button {
    position: absolute; top: 1rem; right: 1rem;
    background: rgba(255,255,255,0.1); border-radius: 50%; padding: 4px;
    cursor: pointer; z-index: 10;
}

/* ==================== 10. MOBILE (NETTOYAGE) ==================== */
@media (max-width: 767px) {
    .header-minimal { top: 0.5rem; width: 90%; padding: 0.5rem 1rem; }
    .subtitle-minimal { display: none; }

    /* SUPPRESSION TOTALE DE LA LISTE SUR MOBILE */
    #words-panel, #toggle-panel-button { display: none !important; }

    /* Stats centrées */
    #stats-panel {
        width: 90%; left: 5%; right: 5%; top: 15%; bottom: auto; max-height: 60vh;
    }

    footer { width: 95%; bottom: 1rem; flex-wrap: wrap; justify-content: center; }
    #word-form { width: 100%; } #word-input { width: 100%; }
    footer > div { width: 100%; justify-content: space-between; display: flex; margin-top: 0.5rem; }
}

/* ==================== 11. SCROLLBAR & MISC ==================== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.2); border-radius: 10px; }
#color-picker-input { width: 50px; height: 50px; border: none; border-radius: 12px; padding: 0; }
#color-picker-input::-webkit-color-swatch-wrapper { padding: 0; }
#color-picker-input::-webkit-color-swatch { border: none; }