@import url('https://fonts.googleapis.com/css2?family=Shojumaru&family=Roboto+Mono:wght@500;700&display=swap');

#gameCanvas {
    --nj-bg: #2c3e50;
    --nj-accent: #c0392b;
    --nj-text: #ecf0f1;
    --nj-wood: #5d4037;
    --nj-target: #f1c40f;
    
    font-family: 'Roboto Mono', monospace;
    background-color: #1a252f;
    display: flex; justify-content: center; align-items: center;
    width: 100%; padding: 10px; min-height: 600px;
}

#gameCanvas * { box-sizing: border-box; }

#ninja-game-wrapper {
    position: relative; width: 100%; max-width: 900px; height: 600px;
    background-color: #fdf5e6;
    background-image: 
        linear-gradient(rgba(0,0,0,0.1) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0,0,0,0.1) 1px, transparent 1px);
    background-size: 50px 50px;
    border: 15px solid var(--nj-wood);
    border-radius: 5px;
    box-shadow: inset 0 0 50px rgba(0,0,0,0.5), 0 10px 30px rgba(0,0,0,0.3);
    overflow: hidden; display: flex; flex-direction: column;
}

#nj-floor-zone {
    position: absolute; bottom: 0; left: 0; width: 100%; height: 80px;
    background-color: #3e2723;
    background-image: repeating-linear-gradient(90deg, transparent, transparent 50px, rgba(0,0,0,0.3) 50px, rgba(0,0,0,0.3) 52px);
    border-top: 4px solid #281815;
    box-shadow: inset 0 10px 20px rgba(0,0,0,0.5); z-index: 5;
}

#nj-input-container {
    position: absolute; bottom: 15px; left: 50%; transform: translateX(-50%);
    width: 300px; z-index: 30;
}
#nj-input {
    width: 100%; padding: 12px; font-size: 1.4rem; text-align: center;
    background: rgba(255, 255, 255, 0.95); color: #2c3e50;
    border: 3px solid var(--nj-wood); border-radius: 8px;
    font-family: 'Roboto Mono', monospace; text-transform: uppercase;
    outline: none; box-shadow: 0 5px 15px rgba(0,0,0,0.5);
}
#nj-input:focus { border-color: var(--nj-accent); }
#nj-input.error { animation: shake 0.3s; background: #ffcccc; }

#nj-hud {
    height: 60px; width: 100%;
    background: rgba(44, 62, 80, 0.95);
    display: flex; justify-content: space-between; align-items: center;
    padding: 0 20px; color: var(--nj-text); font-size: 1.1rem;
    z-index: 40; /* Augmenté pour être au dessus de tout */
    border-bottom: 4px solid var(--nj-accent);
}
.nj-stat span { color: var(--nj-target); font-weight: bold; }

.nj-controls { display: flex; gap: 10px; }
.nj-icon-btn {
    background: transparent; border: 1px solid #7f8c8d; color: #bdc3c7;
    width: 35px; height: 35px; border-radius: 5px; cursor: pointer;
    display: flex; justify-content: center; align-items: center;
}
.nj-icon-btn:hover { border-color: white; color: white; }

#nj-game-area { flex-grow: 1; position: relative; width: 100%; overflow: hidden; }

/* MOTS (Z-Index augmenté pour passer DEVANT le Ninja) */
#gameCanvas .nj-word {
    position: absolute;
    background: rgba(255, 255, 255, 0.95);
    color: #2c3e50; padding: 8px 15px; border-radius: 4px;
    font-weight: bold; font-size: 1.2rem;
    border-left: 8px solid #95a5a6; 
    box-shadow: 3px 3px 8px rgba(0,0,0,0.2);
    white-space: nowrap; 
    z-index: 20; /* DEVANT le Ninja (qui est à 10) */
}
#gameCanvas .nj-word.targeted {
    background: #2c3e50; color: #fff; border-color: var(--nj-target);
    transform: scale(1.15); z-index: 25; box-shadow: 0 0 15px var(--nj-accent);
}
#gameCanvas .typed-char { color: var(--nj-target); }

/* NINJA (Z-Index réduit) */
#nj-ninja-guardian {
    position: absolute; bottom: 85px; left: 50%; transform: translateX(-50%);
    font-size: 5rem; z-index: 10; /* DERRIERE les mots */
    transition: transform 0.1s;
}
.ninja-attack { animation: ninjaJumpAttack 0.3s ease-out; }
@keyframes ninjaJumpAttack {
    0% { transform: translateX(-50%) scale(1); }
    50% { transform: translate(var(--tx), var(--ty)) scale(1.5) rotate(15deg); }
    100% { transform: translateX(-50%) scale(1); }
}

#nj-slash-effect {
    position: absolute; width: 200px; height: 5px;
    background: white; border-radius: 50%;
    box-shadow: 0 0 10px cyan, 0 0 20px blue;
    z-index: 30; pointer-events: none; transform-origin: center;
}
.slash-anim { animation: slash 0.2s forwards; }
@keyframes slash {
    0% { transform: scaleX(0) rotate(var(--rot)); opacity: 1; }
    100% { transform: scaleX(1.5) rotate(var(--rot)); opacity: 0; }
}

#nj-levelup-flash {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: white; opacity: 0; pointer-events: none; z-index: 40;
}
.flash-anim { animation: flash 0.5s ease-out; }
@keyframes flash { 0% { opacity: 0.5; } 100% { opacity: 0; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* ECRANS (Menu, Pause, Game Over) */
#gameCanvas .nj-screen {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.9); backdrop-filter: blur(5px);
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    z-index: 50; transition: opacity 0.3s;
}
#gameCanvas .nj-hidden { opacity: 0; pointer-events: none; }

#gameCanvas .nj-title { font-family: 'Shojumaru', cursive; font-size: 3.5rem; color: var(--nj-accent); text-shadow: 3px 3px 0 #fff; margin-bottom: 10px; }
#gameCanvas .nj-title-red { font-family: 'Shojumaru', cursive; font-size: 3rem; color: #e74c3c; margin-bottom: 10px; }
#gameCanvas p { color: #ecf0f1; font-size: 1.2rem; margin-bottom: 20px; }

/* Menu PAUSE redesigné */
#nj-pause-screen {
    background: rgba(44, 62, 80, 0.95);
    border: 4px solid var(--nj-wood);
}
#nj-pause-screen h2 {
    font-family: 'Shojumaru', cursive; font-size: 3rem; color: var(--nj-target);
    text-shadow: 2px 2px 0 #000; margin-bottom: 40px;
}
.nj-pause-buttons { display: flex; flex-direction: column; gap: 20px; width: 250px; }

.nj-player-name-box input {
    background: rgba(255,255,255,0.1); border: 2px solid #7f8c8d;
    padding: 10px; color: white; font-family: 'Roboto Mono'; font-size: 1.2rem;
    text-align: center; border-radius: 5px; margin-bottom: 20px; outline: none;
}
.nj-player-name-box input:focus { border-color: var(--nj-target); }

/* Game Over & Leaderboard */
.nj-game-over-content {
    display: flex; gap: 30px; margin-bottom: 30px;
    background: rgba(255,255,255,0.1); padding: 20px; border-radius: 10px;
    width: 90%; max-width: 600px; justify-content: space-around; flex-wrap: wrap;
}
.nj-current-result, .nj-leaderboard-box { flex: 1; min-width: 200px; text-align: center; }
.nj-big-score { font-size: 2.5rem; color: var(--nj-target); font-weight: bold; margin: 10px 0; }

.nj-leaderboard-box h3 { color: #bdc3c7; border-bottom: 1px solid #7f8c8d; padding-bottom: 5px; margin-bottom: 10px; }
#nj-leaderboard-list { list-style: none; padding: 0; margin: 0; text-align: left; }
#nj-leaderboard-list li { 
    display: flex; justify-content: space-between; 
    padding: 5px 10px; margin-bottom: 2px;
    background: rgba(0,0,0,0.3); border-radius: 4px; color: #aaa;
}
#nj-leaderboard-list li.new-record { 
    background: var(--nj-target); color: #2c3e50; font-weight: bold; animation: pulse 1s infinite; 
}
@keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.02); } 100% { transform: scale(1); } }

.nj-difficulty-selector { display: flex; gap: 15px; margin-bottom: 30px; }
.nj-btn-diff {
    background: transparent; border: 2px solid #fff; color: #fff;
    padding: 10px 20px; border-radius: 5px; cursor: pointer;
    font-family: 'Roboto Mono', monospace; font-weight: bold; transition: all 0.2s;
}
.nj-btn-diff.active, .nj-btn-diff:hover { background: var(--nj-accent); border-color: var(--nj-accent); }

.nj-btn-start {
    background: var(--nj-accent); color: #fff; border: none;
    padding: 15px 40px; font-size: 1.5rem; font-family: 'Shojumaru', cursive;
    cursor: pointer; border-radius: 5px; box-shadow: 0 5px 0 #922b21;
    transition: transform 0.1s;
}
.nj-btn-start:hover:not(:disabled) { transform: translateY(-3px); box-shadow: 0 8px 0 #922b21; }
.nj-btn-start:disabled { background: #7f8c8d; color: #bdc3c7; cursor: not-allowed; box-shadow: none; filter: grayscale(1); }

/* Bouton secondaire (Abandonner) */
.nj-btn-secondary {
    background: transparent; border: 2px solid #95a5a6; color: #95a5a6;
    padding: 12px 30px; font-size: 1.2rem; font-family: 'Roboto Mono';
    cursor: pointer; border-radius: 5px; transition: all 0.2s;
}
.nj-btn-secondary:hover { border-color: #fff; color: #fff; background: rgba(255,255,255,0.1); }

@media (max-width: 600px) {
    #gameCanvas .nj-title { font-size: 2.2rem; }
    #nj-input { width: 90%; font-size: 1.2rem; }
}