@import url('https://fonts.googleapis.com/css2?family=Shojumaru&family=Roboto+Mono:wght@500;700&family=Poppins:wght@400;700&display=swap');

#gameCanvas {
    --nj-bg: #2c3e50;
    --nj-accent: #e74c3c;
    --nj-primary: #667eea;
    --nj-secondary: #764ba2;
    --nj-text: #ecf0f1;
    --nj-wood: #5d4037;
    --nj-target: #f1c40f;
    
    font-family: 'Poppins', sans-serif;
    /* Fond Ergo'Land */
    background: linear-gradient(135deg, #e0c3fc 0%, #8ec5fc 100%);
    display: flex; justify-content: center; align-items: center;
    width: 100%; padding: 20px;
    min-height: 650px;
}

#gameCanvas * { box-sizing: border-box; }

/* 1. WRAPPER EXTERNE */
#ninja-game-wrapper {
    position: relative; 
    width: 100%; max-width: 900px; 
    height: 600px; 
    background: transparent; 
    border-radius: 15px;
    display: flex; flex-direction: column;
}

/* 2. BOARD CONTAINER (CADRE JEU) */
#nj-board-container {
    width: 100%; height: 100%;
    position: relative;
    background-color: #333; /* Fond de base si tatami charge mal */
    border: 8px solid var(--nj-wood);
    border-radius: 15px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    overflow: hidden; 
    display: flex; flex-direction: column;
}

/* --- PLEIN ECRAN --- */
#ninja-game-wrapper:fullscreen {
    width: 100vw; height: 100vh;
    border-radius: 0; border: none;
    /* Fond Ergo'Land en plein écran */
    background: linear-gradient(135deg, #e0c3fc 0%, #8ec5fc 100%);
    display: flex; justify-content: center; align-items: center;
    padding: 0;
}
#ninja-game-wrapper:fullscreen #nj-board-container {
    width: 100%; height: 100%; max-width: 1200px; max-height: 900px;
    aspect-ratio: 4/3; box-shadow: 0 0 50px rgba(0,0,0,0.5); border: 8px solid var(--nj-wood);
}

/* HUD */
#nj-hud {
    height: 60px; width: 100%; flex-shrink: 0;
    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; border-bottom: 4px solid var(--nj-accent);
}
.nj-stat-box { display: flex; align-items: center; gap: 8px; font-weight: bold; }
.nj-icon { font-size: 1.2rem; }
.nj-label { text-transform: uppercase; font-size: 0.8rem; opacity: 0.8; }
#nj-score { color: var(--nj-target); font-size: 1.3rem; }

.nj-controls { display: flex; gap: 10px; }

/* BOUTONS RONDS */
.nj-round-btn {
    width: 36px; height: 36px; border-radius: 50%; border: 2px solid #bdc3c7;
    background: white; color: #2c3e50; font-size: 1rem; cursor: pointer;
    display: flex; justify-content: center; align-items: center;
    transition: all 0.2s; box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
.nj-round-btn:hover { transform: scale(1.1); border-color: var(--nj-target); color: var(--nj-accent); }

/* ZONE JEU + TATAMI FIX */
#nj-game-area { 
    flex-grow: 1; 
    position: relative; 
    width: 100%; 
    overflow: hidden;
    /* TATAMI APPLIQUÉ ICI */
    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;
}

/* DECOR SOL */
#nj-floor-zone {
    position: absolute; bottom: 0; left: 0; width: 100%; height: 60px;
    background-color: #3e2723;
    background-image: repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(255,255,255,0.05) 10px, rgba(255,255,255,0.05) 20px);
    border-top: 4px solid #281815; z-index: 5;
}

/* INPUT */
#nj-input-wrapper {
    position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
    width: 300px; z-index: 30;
}
#nj-input {
    width: 100%; padding: 12px; font-size: 1.5rem; text-align: center;
    background: rgba(255, 255, 255, 0.95); color: #2c3e50;
    border: 3px solid var(--nj-wood); border-radius: 12px;
    font-family: 'Roboto Mono', monospace; text-transform: uppercase; font-weight: bold;
    outline: none; box-shadow: 0 10px 20px rgba(0,0,0,0.3);
}
#nj-input:focus { border-color: var(--nj-accent); }
#nj-input.error { animation: shake 0.3s; background: #ffcccc; border-color: red; }

/* MOTS */
#gameCanvas .nj-word {
    position: absolute;
    background: white; color: #2c3e50; 
    padding: 6px 14px; border-radius: 4px;
    font-weight: bold; font-size: 1.2rem; font-family: 'Roboto Mono', monospace;
    border-left: 6px solid #95a5a6; 
    box-shadow: 3px 3px 6px rgba(0,0,0,0.2);
    z-index: 20; white-space: nowrap;
    /* Pas de transition CSS sur top pour éviter le lag en resize */
}
#gameCanvas .nj-word.targeted {
    background: #2c3e50; color: #fff; border-color: var(--nj-target);
    transform: scale(1.15); z-index: 25; box-shadow: 0 0 20px var(--nj-accent);
}
#gameCanvas .typed-char { color: var(--nj-target); }

/* NINJA */
#nj-ninja-guardian {
    position: absolute; bottom: 65px; left: 50%; transform: translateX(-50%);
    font-size: 5rem; z-index: 10; transition: transform 0.1s;
}
.ninja-attack { animation: ninjaJumpAttack 0.2s ease-out; }
@keyframes ninjaJumpAttack {
    0% { transform: translateX(-50%) scale(1); }
    50% { transform: translate(var(--tx), var(--ty)) scale(1.2) rotate(10deg); }
    100% { transform: translateX(-50%) scale(1); }
}

#nj-slash-effect {
    position: absolute; width: 200px; height: 5px;
    background: white; border-radius: 50%;
    box-shadow: 0 0 15px cyan; z-index: 30; pointer-events: none;
}
.slash-anim { animation: slash 0.15s forwards; }
@keyframes slash {
    0% { transform: scaleX(0) rotate(var(--rot)); opacity: 1; }
    100% { transform: scaleX(1.5) rotate(var(--rot)); opacity: 0; }
}

/* Text Flottant */
#nj-feedback-text {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    font-size: 3rem; font-weight: bold; color: #2ecc71; text-shadow: 0 0 10px white;
    z-index: 45; pointer-events: none;
}
.pop-up-anim { animation: popUpFade 1s forwards; }
@keyframes popUpFade { 0% { opacity: 0; transform: translate(-50%, 0); } 20% { opacity: 1; transform: translate(-50%, -30px); } 100% { opacity: 0; transform: translate(-50%, -80px); } }

/* ECRANS */
#gameCanvas .nj-screen {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.85); backdrop-filter: blur(5px);
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    z-index: 50; animation: fadeIn 0.3s ease;
}
.nj-hidden { display: none !important; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.nj-card {
    background: white; padding: 40px; border-radius: 20px;
    width: 90%; max-width: 600px; text-align: center;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    color: #2c3e50; border: 4px solid var(--nj-wood);
}
.nj-title { font-family: 'Shojumaru', cursive; font-size: 2.5rem; color: var(--nj-accent); margin-bottom: 5px; }
.nj-title-red { font-family: 'Shojumaru', cursive; font-size: 2.5rem; color: #c0392b; margin-bottom: 20px; }
.nj-desc { color: #7f8c8d; margin-bottom: 20px; font-size: 0.9rem; }

.nj-difficulty-selector { display: flex; gap: 10px; justify-content: center; margin-bottom: 25px; flex-wrap: wrap; }
.nj-btn-diff {
    background: #ecf0f1; border: none; padding: 10px 20px; border-radius: 8px;
    cursor: pointer; font-weight: bold; color: #7f8c8d; transition: 0.2s;
}
.nj-btn-diff:hover, .nj-btn-diff.active { background: var(--nj-accent); color: white; transform: translateY(-2px); }

/* BOUTONS */
.nj-btn-primary {
    background: var(--nj-accent); color: white; border: none;
    padding: 12px 35px; border-radius: 50px; font-size: 1.1rem; font-weight: bold;
    cursor: pointer; box-shadow: 0 5px 0 #922b21; transition: transform 0.1s;
    font-family: 'Shojumaru', cursive;
}
.nj-btn-primary:active { transform: translateY(5px); box-shadow: none; }
.nj-btn-primary:disabled { background: #bdc3c7; box-shadow: none; cursor: not-allowed; }

.nj-btn-secondary {
    background: transparent; border: 2px solid #7f8c8d; color: #7f8c8d;
    padding: 10px 25px; border-radius: 50px; font-weight: bold; cursor: pointer; margin-top: 10px;
}
.nj-btn-secondary:hover { border-color: var(--nj-accent); color: var(--nj-accent); }

/* LEADERBOARD */
.nj-results-grid { display: flex; gap: 20px; text-align: left; margin-bottom: 20px; flex-wrap: wrap; }
.nj-result-box { flex: 1; text-align: center; background: #f9f9f9; padding: 15px; border-radius: 10px; min-width: 150px; }
.nj-leaderboard-box { flex: 1.5; background: #f9f9f9; padding: 15px; border-radius: 10px; min-width: 200px; }
.nj-big-score { font-size: 2.2rem; color: var(--nj-accent); font-weight: bold; }
#nj-leaderboard-list { list-style: none; padding: 0; margin: 0; font-size: 0.9rem; }
#nj-leaderboard-list li { display: flex; justify-content: space-between; border-bottom: 1px solid #eee; padding: 5px 0; }
#nj-leaderboard-list li.new-record { color: var(--nj-accent); font-weight: bold; }

@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

@media (max-width: 600px) {
    .nj-results-grid { flex-direction: column; }
    .nj-title { font-size: 1.8rem; }
    #nj-input { width: 90%; font-size: 1.2rem; }
}