/* ============================================================
   BASE DU JEU
   ============================================================ */
body {
    background-color: #050505;
    margin: 0;
    overflow: hidden;
    touch-action: none; /* Empêche le défilement de la page sur mobile */
    font-family: Arial, sans-serif;
}


#game-container {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background-color: #050505;
    /* Dimensions gérées par JS (_fitCanvasToScreen) */
}

/* En plein écran, le container occupe tout l'espace et centre le canvas */
#game-container:fullscreen,
#game-container:-webkit-full-screen {
    top: 0; left: 0;
    transform: none;
    width: 100% !important;
    height: 100% !important;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Fallback fullscreen CSS pour iPhone/Safari (quand requestFullscreen n'est pas supporté) */
body[style*="position: fixed"] #game-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    transform: none;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

canvas {
    display: block;
    background-color: #000;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
    /* Sizing géré par JS (_fitCanvasToScreen) pour garantir le ratio 16:9 sur tous les écrans */
}

/* ============================================================
   CONTRÔLES MOBILES ET CLAVIER VIRTUEL
   ============================================================ */
#touch-controls {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
    z-index: 50;
    display: none; /* PATCH: Caché par défaut, JS l'active sur mobile */
}

/* Overlay choix de contrôles */
#ctrl-choice-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    display: none; align-items: center; justify-content: center;
    z-index: 200;
    pointer-events: auto;
}
#ctrl-choice-box {
    display: flex; flex-direction: column; align-items: center;
    gap: 16px; padding: 28px 24px;
    background: rgba(20,20,20,0.95);
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 16px;
}
#ctrl-choice-title {
    color: #fff; font-family: monospace; font-size: 18px;
    font-weight: bold; letter-spacing: 2px; margin: 0 0 8px;
}
#ctrl-choice-sub {
    color: #aaa; font-family: monospace; font-size: 12px;
    margin: -6px 0 6px; letter-spacing: 1px;
}
.ctrl-choice-btn {
    width: 180px; padding: 14px;
    background: rgba(255,255,255,0.12);
    border: 2px solid rgba(255,255,255,0.4);
    border-radius: 10px;
    color: #fff; font-size: 18px; font-weight: bold;
    cursor: pointer; touch-action: manipulation;
}
.ctrl-choice-btn:active { background: rgba(255,255,255,0.35); }

#dpad-area {
    --dpad-btn-size: 52px;
    --dpad-step: 52px;
    position: absolute;
    bottom: 30px; 
    left: 20px;
    width: 156px;
    height: 156px;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

#joystick-base {
    width: 138px;
    height: 138px;
    background: rgba(255, 255, 255, 0.1);
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
}

#joystick-stick {
    width: 60px;
    height: 60px;
    background: radial-gradient(circle, #666, #222);
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5), inset 0 0 12px rgba(0,0,0,0.6);
    transition: transform 0.05s linear;
    pointer-events: none;
}

/* Deadzone indicator ring */
#joystick-base::before {
    content: '';
    position: absolute;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px dashed rgba(255, 255, 255, 0.15);
    pointer-events: none;
}

#action-area {
    position: absolute;
    bottom: 20px; right: 20px;
    width: 168px; height: 128px;
    pointer-events: auto;
}

.touch-btn, .touch-btn-large, .touch-btn-small {
    position: absolute;
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    color: white;
    display: flex; justify-content: center; align-items: center;
    font-weight: bold; font-size: 16px;
    user-select: none; touch-action: none;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

/* Ripple wave animation on tap */
@keyframes btn-ripple {
    0%   { transform: scale(0); opacity: 0.5; }
    100% { transform: scale(2.5); opacity: 0; }
}

.touch-btn::after, .touch-btn-large::after, .touch-btn-small::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: radial-gradient(circle, rgba(255,255,255,0.6) 0%, transparent 70%);
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
}

/* PATCH #51: Ripple aussi sur .touch-pressed (pas seulement :active) */
.touch-btn:active::after, .touch-btn-large:active::after, .touch-btn-small:active::after,
.touch-btn.touch-pressed::after, .touch-btn-large.touch-pressed::after, .touch-btn-small.touch-pressed::after {
    animation: btn-ripple 0.4s ease-out forwards;
}

.touch-btn:active, .touch-btn-large:active, .touch-btn-small:active,
.touch-btn.touch-pressed, .touch-btn-large.touch-pressed, .touch-btn-small.touch-pressed {
    background: rgba(255, 255, 255, 0.45);
    transform: scale(0.92);
    box-shadow: 0 0 18px rgba(255, 255, 255, 0.35);
    transition: transform 0.06s ease, background 0.06s ease, box-shadow 0.06s ease;
}

/* Positions D-PAD (cachés par défaut, affichés si mode dpad) */
#btn-up, #btn-down, #btn-left, #btn-right { display: none; }
#btn-up,
#btn-down,
#btn-left,
#btn-right {
    width: var(--dpad-btn-size);
    height: var(--dpad-btn-size);
}
#btn-up    { top: 0; left: calc(50% - (var(--dpad-btn-size) / 2)); }
#btn-down  { bottom: 0; left: calc(50% - (var(--dpad-btn-size) / 2)); }
#btn-left  { top: calc(50% - (var(--dpad-btn-size) / 2)); left: calc(50% - (var(--dpad-btn-size) / 2) - var(--dpad-step)); }
#btn-right { top: calc(50% - (var(--dpad-btn-size) / 2)); left: calc(50% - (var(--dpad-btn-size) / 2) + var(--dpad-step)); }

/* Positions ACTIONS */
#btn-attack { bottom: 0; right: 0; width: 60px; height: 60px; border-radius: 12px; font-size: 11px;}
#btn-j { bottom: 70px; right: 10px; width: 45px; height: 45px; }
#btn-d { bottom: 10px; right: 70px; width: 45px; height: 45px; }
#btn-fury { bottom: 70px; right: 118px; width: 40px; height: 40px; border-color: #ffaa00; color: #ffaa00;}
#btn-block { bottom: 72px; right: 70px; width: 40px; height: 40px; border-color: #66aaff; color: #66aaff; background: rgba(80, 140, 255, 0.18); }
#btn-striker { display: none; bottom: 125px; right: 55px; width: 50px; height: 50px; border-color: #ffdd00; color: #ffdd00; background: rgba(255, 221, 0, 0.2); font-size: 18px; }
@keyframes striker-pulse {
    0%, 100% { background: rgba(255,221,0,0.2); box-shadow: 0 0 10px rgba(255,221,0,0.4); transform: scale(1); }
    50% { background: rgba(255,221,0,0.6); box-shadow: 0 0 25px rgba(255,221,0,0.9); transform: scale(1.1); }
}
#btn-striker.available { animation: striker-pulse 1s infinite; }

#btn-pause { top: 20px; right: 20px; width: 40px; height: 40px; border-radius: 8px; pointer-events: auto; z-index: 100; cursor: pointer; }

/* Bouton plein écran */
#btn-fullscreen {
    position: absolute;
    top: 20px; left: 20px;
    background: rgba(0,0,0,0.5);
    color: white;
    border: 2px solid #fff;
    border-radius: 8px;
    width: 40px; height: 40px;
    font-size: 20px;
    cursor: pointer;
    z-index: 400;
    display: flex; justify-content: center; align-items: center;
}

/* Clavier virtuel pour les scores */
#mobile-keyboard {
    position: absolute;
    bottom: 10px; left: 50%; transform: translateX(-50%);
    width: 95%; max-width: 600px;
    background: rgba(0,0,0,0.85);
    padding: 10px; border-radius: 10px;
    z-index: 200; display: none;
}
#mobile-name-input {
    width: calc(100% - 8px);
    margin: 0 4px 8px 4px;
    height: 36px;
    border-radius: 7px;
    border: 1px solid rgba(255,255,255,0.45);
    background: rgba(0,0,0,0.72);
    color: #ffffff;
    text-align: center;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
}
#mobile-name-input:focus {
    outline: 2px solid rgba(124,217,255,0.8);
    outline-offset: 1px;
}
.kb-row { display: flex; justify-content: center; margin-bottom: 6px; gap: 4px; }
.kb-key {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.4);
    color: white; border-radius: 5px;
    width: 35px; height: 40px;
    font-size: 16px; font-weight: bold;
    display: flex; justify-content: center; align-items: center;
    cursor: pointer; user-select: none; touch-action: none;
}
.kb-key.wide { min-width: 60px; font-size: 13px; }
.kb-key:active { background: rgba(255,255,255,0.6); color: black; }


/* ============================================================
   OVERLAYS RÉANIMATION & VIDÉOS (MODERNISÉS ET RESPONSIVE)
   ============================================================ */

/* PATCH: #revive-menu styles (migrés depuis inline) */
#revive-menu {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.75);
    display: none; flex-direction: column; align-items: center; justify-content: center;
    z-index: 100; font-family: Arial, sans-serif;
}
/* Garantie : .hidden masque toujours, même si display:flex est forcé ailleurs. */
#revive-menu.hidden { display: none !important; }
#revive-menu-title { color: #ffdd00; font-size: 28px; margin-bottom: 8px; text-shadow: 0 0 12px #ff6600; }
#revive-menu-subtitle { color: #fff; font-size: 16px; margin-bottom: 18px; }
#reviveTimerDisplay { font-size: 36px; font-weight: bold; color: #ff4444; margin-bottom: 18px; }
#btnRevive { background: #cc0000; color: #fff; border: none; padding: 14px 32px; font-size: 18px; border-radius: 6px; cursor: pointer; margin-bottom: 12px; font-family: Arial, sans-serif; }
#btnSkipRevive { background: #333; color: #aaa; border: none; padding: 10px 24px; font-size: 14px; border-radius: 6px; cursor: pointer; font-family: Arial, sans-serif; }
#revive-menu-hint { color: #888; font-size: 12px; margin-top: 14px; }
/* Partage social pendant le revive vidéo */
#revive-share-row { margin: 8px 0 12px; padding: 8px 10px; background: rgba(0,0,0,0.32); border: 1px solid rgba(255,221,68,0.25); border-radius: 8px; }
#revive-share-label { color: #ffcc55; font-size: 12px; margin: 0 0 8px; letter-spacing: .5px; }
#revive-share-buttons { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 520px; }
.revive-share-btn { color: #fff; border: none; padding: 11px 22px; font-size: 15px; border-radius: 6px; cursor: pointer; font-family: Arial, sans-serif; font-weight: bold; transition: transform .1s, filter .1s; }
.revive-share-btn:hover { transform: translateY(-2px); filter: brightness(1.15); }
.revive-share-btn:active { transform: translateY(0); }
#btnShareX { background: #000; border: 1px solid #555; }
#btnShareWhatsApp { background: #25d366; color: #062e16; }
#btnShareFacebook { background: #1877f2; }
#btnShareInstagram { background: linear-gradient(135deg, #f58529, #dd2a7b, #8134af, #515bd4); }
#btnShareTikTok { background: #111; border: 1px solid #26f4ee; color: #26f4ee; }

/* Popup d'apparition du bouton "Revivre" */
.revive-popup {
    display: none; /* C'EST ÇA QUI MANQUAIT (écrasé par les bugs) */
    position: absolute;
    left: 50%;
    top: 65%;
    transform: translate(-50%, -50%);
    z-index: 210; /* PATCH: Au-dessus de ctrl-choice-overlay (200) */
    text-align: center;
    width: 90%;
    max-width: 450px;
}

/* Style global des gros boutons (Play, Cancel) */
.game-btn {
    padding: 15px 20px;
    font-size: 18px;
    font-weight: bold;
    text-transform: uppercase;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.1s ease;
    border: 3px solid;
    box-shadow: 0 5px 0 rgba(0,0,0,0.6);
    width: 100%;
    display: block;
    margin: 0 auto;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.game-btn:active {
    transform: translateY(5px);
    box-shadow: 0 0px 0 rgba(0,0,0,0.6);
}

/* Bouton d'action principal (Rouge/Orange) */
.game-btn.primary {
    background: linear-gradient(180deg, #ff4444 0%, #cc0000 100%);
    border-color: #ffaa00;
    color: white;
    text-shadow: 1px 1px 2px black;
}

.game-btn.primary:hover {
    background: linear-gradient(180deg, #ff6666 0%, #ee0000 100%);
    box-shadow: 0 5px 15px rgba(255, 170, 0, 0.4);
}

/* Bouton secondaire (Abandon) */
.game-btn.secondary {
    background: linear-gradient(180deg, #444 0%, #222 100%);
    border-color: #777;
    color: #ddd;
    margin-top: 25px;
}

.game-btn.secondary:hover {
    background: linear-gradient(180deg, #555 0%, #333 100%);
    color: white;
}

/* PATCH: .revive-hint-box supprimé — l'élément utilise .warning-text */

/* L'arrière-plan de la fenêtre de choix */
.game-modal {
    display: none; /* C'EST ÇA QUI MANQUAIT (écrasé par les bugs) */
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 300;
    align-items: center;
    justify-content: center;
    padding: 10px;
    box-sizing: border-box;
    overflow-y: auto;
}

/* La fenêtre en elle-même */
.modal-content {
    background: #111;
    border: 3px solid #ffdd44;
    border-radius: 12px;
    padding: 20px;
    max-width: 800px;
    width: 100%;
    max-height: 98%;
    overflow-y: auto;
    text-align: center;
    box-shadow: 0 0 40px rgba(255, 221, 68, 0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.neon-title {
    margin: 0 0 10px 0;
    font-size: 32px;
    text-transform: uppercase;
    text-shadow: 0 0 15px rgba(255, 221, 68, 0.5);
}
.text-yellow { color: #ffdd44; }

.modal-subtitle {
    color: #ccc;
    font-size: 16px;
    margin-bottom: 25px;
}

/* Grille des vidéos Youtube */
.video-grid {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 20px;
    width: 100%;
}

.video-choice-btn {
    background: #222;
    border: 2px solid #555;
    color: white;
    padding: 10px;
    cursor: pointer;
    border-radius: 8px;
    transition: transform 0.2s ease, border-color 0.2s ease;
    width: 150px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 4px 6px rgba(0,0,0,0.5);
}

.video-choice-btn:hover {
    background: #333;
    border-color: #ffdd44;
    transform: translateY(-4px);
    box-shadow: 0 8px 15px rgba(255, 221, 68, 0.3);
}

.video-choice-thumb {
    width: 100%;
    height: auto;
    aspect-ratio: 16/9;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 8px;
    background: #000;
}

.video-choice-btn span {
    font-size: 13px;
    line-height: 1.3;
    color: #eee;
    font-weight: bold;
}

/* Conteneur du lecteur vidéo */
.video-wrapper {
    display: none;
    width: 100%;
    max-width: 640px;
    aspect-ratio: 16 / 9;
    background: black;
    border: 2px solid #ffdd44;
    border-radius: 8px;
    overflow: hidden;
    margin: 0 auto;
    box-shadow: 0 0 20px rgba(255, 221, 68, 0.4);
}

#revive-hint { display: none; }

.warning-text {
    color: #ff4444;
    margin-top: 20px;
    font-weight: bold;
    font-size: 18px;
}

/* Animations communes */
.pulse-anim {
    animation: pulse 1s infinite alternate;
}

@keyframes pulse { 
    0% { transform: scale(1); } 
    100% { transform: scale(1.04); } 
}

/* --- ADAPTATION MOBILE EXTRÊME --- */
@media (max-width: 600px) {
    .modal-content { padding: 15px; border-width: 2px; }
    .neon-title { font-size: 24px; }
    .video-grid { gap: 10px; }
    .video-choice-btn { width: 46%; padding: 8px; }
    .video-choice-btn span { font-size: 11px; }
    .game-btn { font-size: 14px; padding: 12px 15px; }
}

/* ===== ÉCRAN SÉLECTION PERSONNAGE ===== */
#character-select-screen {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(5, 5, 20, 0.97);
    z-index: 200;
    display: none; /* PATCH: Caché par défaut, JS l'active */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-sizing: border-box;
    padding: 10px 16px;
}

#char-select-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

#char-select-mode-badge {
    font-family: monospace;
    font-size: 12px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 3px;
    padding: 3px 12px;
    border-radius: 4px;
    border: 1px solid currentColor;
}

#char-select-mode-badge.god-mode {
    color: #00ffff;
    border-color: #00ffff;
    text-shadow: 0 0 8px rgba(0, 255, 255, 0.8);
    box-shadow: 0 0 8px rgba(0, 255, 255, 0.3);
}

#char-select-mode-badge.mosh-pit {
    color: #ff6600;
    border-color: #ff6600;
    text-shadow: 0 0 8px rgba(255, 100, 0, 0.8);
    box-shadow: 0 0 8px rgba(255, 100, 0, 0.3);
}

#char-select-title {
    margin: 0;
    font-size: 22px;
    text-transform: uppercase;
    color: #ffdd44;
    text-shadow: 0 0 18px rgba(255, 221, 68, 0.7);
    letter-spacing: 4px;
    font-family: monospace;
}

#char-vignettes {
    display: flex;
    flex-direction: row;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.char-vignette {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    border: 2px solid #333;
    border-radius: 8px;
    padding: 10px 8px;
    width: 150px;
    background: rgba(20, 20, 20, 0.9);
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
    filter: grayscale(60%) brightness(0.7);
    box-sizing: border-box;
    /* Reset button defaults (#58) */
    font: inherit;
    color: inherit;
    text-align: center;
    -webkit-appearance: none;
    appearance: none;
    outline-offset: 2px;
}

.char-vignette:hover {
    filter: grayscale(20%) brightness(0.9);
    border-color: #666;
    transform: translateY(-2px);
}

.char-vignette.selected {
    border-color: #ff44ff;
    box-shadow: 0 0 14px rgba(255, 68, 255, 0.6), inset 0 0 8px rgba(255, 68, 255, 0.1);
    filter: grayscale(0%) brightness(1);
    transform: translateY(-4px);
}

.char-vignette img {
    width: 120px;
    height: 120px;
    object-fit: contain;
    image-rendering: pixelated;
}

.char-name {
    font-family: monospace;
    font-size: 13px;
    font-weight: bold;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.char-vignette.selected .char-name {
    color: #ff44ff;
    text-shadow: 0 0 8px rgba(255, 68, 255, 0.8);
}

.char-desc {
    font-family: monospace;
    font-size: 10px;
    color: #ffdd44;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.8;
}

/* --- DIFFICULTY SECTION --- */
#char-difficulty-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.diff-label {
    font-family: monospace;
    font-size: 11px;
    color: #888;
    letter-spacing: 2px;
    text-transform: uppercase;
}

#diff-options {
    display: flex;
    flex-direction: row;
    gap: 8px;
}

.diff-btn {
    font-family: monospace;
    font-size: 12px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 6px 14px;
    border: 2px solid #444;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.04);
    color: #888;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.diff-btn:hover {
    border-color: #aaa;
    color: #ccc;
    transform: translateY(-1px);
}

.diff-btn[data-diff="EASY"].selected   { border-color: #44ff44; color: #44ff44; box-shadow: 0 0 8px rgba(68,255,68,0.5); }
.diff-btn[data-diff="NORMAL"].selected { border-color: #ffdd44; color: #ffdd44; box-shadow: 0 0 8px rgba(255,221,68,0.5); }
.diff-btn[data-diff="HARD"].selected   { border-color: #ff4444; color: #ff4444; box-shadow: 0 0 8px rgba(255,68,68,0.5); }
.diff-btn[data-diff="OHD"].selected    { border-color: #ff0000; color: #ff0000; box-shadow: 0 0 12px rgba(255,0,0,0.7); }

/* --- CONFIRM BUTTON --- */
#char-confirm-btn {
    font-family: monospace;
    font-size: 18px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 3px;
    padding: 10px 36px;
    border: 3px solid #44ff88;
    border-radius: 6px;
    background: rgba(68, 255, 136, 0.1);
    color: #44ff88;
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
    box-shadow: 0 0 12px rgba(68, 255, 136, 0.3);
}

#char-confirm-btn:hover {
    background: rgba(68, 255, 136, 0.25);
    box-shadow: 0 0 22px rgba(68, 255, 136, 0.6);
    transform: scale(1.04);
}

#char-select-hint {
    font-family: monospace;
    font-size: 10px;
    color: #555;
    letter-spacing: 1px;
    text-transform: uppercase;
}