/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: #000;
    color: white;
    min-height: 100vh;
    overflow: hidden;
    position: relative;
}

/* Main layout */
main {
    padding: 0;
    height: 100vh;
    width: 100vw;
    position: relative;
}

.game-container {
    width: 100%;
    height: 100%;
    position: relative;
}

.game-area {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* Canvas layers */
#lightingCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 11;
    mix-blend-mode: screen;
}

/* Background container */
.background-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -10;
}

.background-container.distortion-active {
    filter: url(#distortionFilter);
    animation: backgroundDistortion 12s ease-in-out infinite;
}

/* Responsive */
@media (max-width: 768px) {
    .game-area {
        touch-action: none;
    }
}

/* Custom hand-drawn cursor */
.custom-cursor {
    position: fixed;
    width: 30px;
    height: 30px;
    pointer-events: none;
    z-index: 10000;
    /* transition: transform 0.1s ease-out; MODIFIÉ : Le mouvement est géré en JS via transform */
    mix-blend-mode: difference;

    /* --- OPTIMISATION --- */
    /* Prépare le curseur à être animé sur sa propre couche de composition,
       ce qui est crucial pour les mouvements fluides à chaque frame. */
    will-change: transform;
}

.custom-cursor::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: 50% 45% 55% 48%;
    filter: url(#distortionFilter);
}

.custom-cursor::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 4px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 48% 52% 47% 53%;
    animation: cursorCenterPulse 1.5s ease-in-out infinite;
}

/* Hide default cursor */
body.custom-cursor-active {
    cursor: none;
}

body.custom-cursor-active * {
    cursor: none !important;
}

/* Cursor states */
.custom-cursor.clicking::before {
    transform: translate(-50%, -50%) scale(0.8);
    border-color: rgba(255, 255, 255, 1);
    border-width: 3px;
}

.custom-cursor.hovering::before {
    transform: translate(-50%, -50%) scale(1.2);
    border-color: rgba(100, 200, 255, 0.9);
}

/* Cursor trail effect */
.cursor-trail {
    position: fixed;
    width: 15px;
    height: 15px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 45% 55% 48% 52%;
    pointer-events: none;
    z-index: 9999;
    animation: trailFade 1s ease-out forwards;
    filter: url(#distortionFilter);

    /* --- OPTIMISATION --- */
    /* Prépare également les particules du sillage pour des animations
       performantes de transformation et de fondu. */
    will-change: transform, opacity;
}

/* NOUVEAU: Règles pour le Mode Performance */

/* La classe .performance-mode-active sera ajoutée au body via JavaScript */

/* 1. Désactiver le filtre de distorsion PARTOUT */
body.performance-mode-active .distortion-active,
body.performance-mode-active [style*="url(#distortionFilter)"] {
    filter: none !important;
}

/* 2. Stopper les animations de fond coûteuses */
body.performance-mode-active .background-container {
    animation: none !important;
}

/* 3. Désactiver les animations subtiles mais gourmandes sur les zones */
body.performance-mode-active .clickable-zone::before {
    animation: none !important;
}
body.performance-mode-active .clickable-zone.permanently-activated {
    animation: none !important;
}

/* 4. Désactiver l'animation du curseur (le point central) */
body.performance-mode-active .custom-cursor::after {
    animation: none !important;
}

/* 5. Désactiver les animations de l'overlay d'histoire pour un affichage plus rapide */
body.performance-mode-active .story-text-container,
body.performance-mode-active .story-title,
body.performance-mode-active .story-close-button {
    animation: none !important;
    transform: none !important; /* Réinitialise les rotations/skew */
}

/*
   CORRECTION : Rendre les éléments visibles car leur animation d'apparition est désactivée.
   Le style original de .story-title et .story-close-button est "opacity: 0".
   L'animation les faisait passer à "opacity: 1". Sans animation, ils restent à 0.
   Nous devons donc forcer leur opacité à 1 en mode performance.
*/
body.performance-mode-active .story-title,
body.performance-mode-active .story-close-button {
    opacity: 1 !important;
}

/* 6. Réduire drastiquement le nombre de particules */
body.performance-mode-active .story-particle:nth-child(n+10) {
    display: none; /* Cache toutes les particules sauf les 10 premières */
}