:root {
    --bg: #050505;
    --grid: #1a1a1a;
    --neon-cyan: #0ff;
    --neon-pink: #f0f;
}

body {
    background-color: var(--bg);
    /* Fond quadrillé style "Tech" */
    background-image: linear-gradient(#151515 1px, transparent 1px), 
                      linear-gradient(90deg, #151515 1px, transparent 1px);
    background-size: 30px 30px;
    
    color: white;
    font-family: 'Courier New', monospace;
    margin: 0;
    padding: 0;
    
    /* LE FIX MOBILE : On utilise dvh (Dynamic Viewport Height) */
    width: 100%;
    height: 100vh;      /* Fallback pour vieux navigateurs */
    height: 100dvh;     /* S'adapte à la barre d'adresse mobile */
    
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    touch-action: none; /* Empêche le rebond élastique sur iOS */
}

/* --- ACCUEIL --- */
#splash-screen {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px; /* Réduit un peu l'espace pour les petits écrans */
    animation: fadeIn 0.5s;
    width: 100%;
    height: 100%;
}

.neon-title {
    font-size: 2.5rem;
    margin: 10px 0;
    text-shadow: 0 0 15px var(--neon-cyan);
    line-height: 1;
}

.sub-title {
    color: var(--neon-pink);
    text-shadow: 0 0 15px var(--neon-pink);
    font-size: 3rem;
}

.stats-container {
    display: flex;
    gap: 40px;
    background: rgba(255,255,255,0.05);
    padding: 15px 30px;
    border-radius: 10px;
    border: 1px solid #333;
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.stat-label { font-size: 0.8rem; color: #888; }
.stat-value { font-size: 1.5rem; font-weight: bold; color: var(--neon-cyan); }

.btn-play {
    background: transparent;
    border: 2px solid var(--neon-cyan);
    color: var(--neon-cyan);
    padding: 15px 50px;
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 0 15px var(--neon-cyan);
    border-radius: 5px;
    transition: 0.2s;
    margin-top: 10px;
}

.btn-play:active { background: var(--neon-cyan); color: black; }

.install-hint { font-size: 0.7rem; color: #555; margin-top: 30px; opacity: 0.7; }

/* --- JEU --- */
#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.header {
    width: 320px; /* Valeur par défaut PC */
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.btn-small {
    background: transparent;
    border: 1px solid #666;
    color: #888;
    padding: 5px 15px;
    cursor: pointer;
    font-family: inherit;
}

.score-box {
    background: #222;
    padding: 5px 15px;
    border-radius: 5px;
    border: 1px solid var(--neon-pink);
    text-align: center;
    min-width: 80px;
}

.score-box span { display: block; font-size: 0.7rem; color: #aaa; }
.score-box strong { font-size: 1.2rem; color: white; }

#game-board {
    width: 320px;
    height: 320px;
    background: rgba(0,0,0,0.8);
    border: 2px solid #333;
    border-radius: 10px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 10px;
    padding: 10px;
    box-sizing: border-box;
    position: relative;
    box-shadow: 0 0 50px rgba(0,255,255,0.1);
}

.cell {
    background: rgba(255,255,255,0.05);
    border-radius: 5px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.tile {
    width: 100%; height: 100%;
    border-radius: 5px;
    display: flex; justify-content: center; align-items: center;
    font-size: 1.8rem; font-weight: bold;
    animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    /* Empêche la sélection de texte */
    user-select: none;
}

/* COULEURS */
.t-2 { border: 2px solid #0ff; color: #0ff; text-shadow: 0 0 5px #0ff; }
.t-4 { border: 2px solid #f0f; color: #f0f; text-shadow: 0 0 5px #f0f; }
.t-8 { border: 2px solid #ff0; color: #ff0; text-shadow: 0 0 5px #ff0; }
.t-16 { border: 2px solid #0f0; color: #0f0; text-shadow: 0 0 5px #0f0; }
.t-32 { background: #f00; color: white; box-shadow: 0 0 15px #f00; }
.t-64, .t-128, .t-256 { background: linear-gradient(45deg, #0ff, #f0f); color: black; box-shadow: 0 0 20px cyan; }
.t-512, .t-1024, .t-2048 { background: white; color: black; box-shadow: 0 0 30px white; animation: pulse 1s infinite; }

#game-over {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.9);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
    backdrop-filter: blur(5px);
    border-radius: 8px;
}

@keyframes popIn { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.8; } 100% { opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* --- MEDIA QUERIES (MOBILE) --- */
@media (max-width: 600px) {
    h1 { font-size: 2rem; }
    
    /* FORMULE MAGIQUE POUR CENTRAGE */
    /* On dit : la grille fait 90% de la largeur, MAIS ne doit pas dépasser 60% de la hauteur dispo */
    #game-board {
        width: min(90vw, 60vh);
        height: min(90vw, 60vh);
    }

    /* Le header suit la même largeur que le board */
    .header {
        width: min(90vw, 60vh);
    }
    
    .tile { font-size: 1.5rem; } /* Chiffres un peu plus petits sur mobile */
}

@media (max-height: 600px) {
    /* Pour les téléphones en mode paysage ou très petits */
    .neon-title { font-size: 1.5rem; }
    .sub-title { font-size: 1.8rem; }
    .btn-play { padding: 10px 30px; font-size: 1.2rem; }
    .stats-container { padding: 5px 20px; gap: 20px; }
}
