/* =================================
   TIVAN LE SERPENT - STYLES CSS V2
   Thème: Rétro-arcade pastel / pop-art / néon
   Mobile: Layout vertical optimisé
   ================================= */

/* Variables CSS */
:root {
    --bg-primary: #0B0F14;
    --text-primary: #ffffff;
    --text-secondary: #cccccc;
    --accent-yellow: #FED715;
    --accent-pink: #FE0879;
    --accent-blue: #0037B3;
    --accent-cyan: #00FFFF;
    --border-yellow: #FFD700;
    --success-green: #00FF41;
    --error-red: #FF0040;
}

/* Reset et base */
* {
    box-sizing: border-box;
}

.tivan-app {
    font-family: 'Courier New', monospace;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    position: relative;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Écrans */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease-in-out;
    padding: 20px;
}

.screen.active {
    opacity: 1;
    visibility: visible;
}

/* ===== ÉCRAN BIENVENUE ===== */
#tivan-screen-welcome {
    background: var(--bg-primary);
    text-align: center;
}

.welcome-content {
    max-width: 600px;
    width: 100%;
}

.title-section {
    margin-bottom: 40px;
}

.subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.main-title {
    font-size: 72px;
    font-weight: bold;
    color: var(--accent-yellow);
    margin: 20px 0;
    text-shadow: 4px 4px 0px var(--accent-pink), 8px 8px 0px var(--accent-blue);
    font-family: 'Arial Black', Arial, sans-serif;
    animation: pulse-title 2s ease-in-out infinite alternate;
}

@keyframes pulse-title {
    from { transform: scale(1); }
    to { transform: scale(1.05); }
}

.copyright {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 10px;
}

.game-description {
    margin-bottom: 40px;
}

.game-description p {
    font-size: 18px;
    line-height: 1.6;
    color: var(--text-primary);
    margin: 0;
}

.game-settings {
    margin-bottom: 40px;
    text-align: left;
}

.setting-group {
    margin-bottom: 20px;
}

.setting-group label {
    display: block;
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 8px;
    color: var(--accent-cyan);
}

.setting-group select,
.setting-group input {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px;
    background: var(--bg-primary);
    color: var(--accent-cyan);
    border: 2px solid var(--accent-cyan);
    border-radius: 8px;
    outline: none;
    transition: all 0.3s ease;
}

.setting-group select:focus,
.setting-group input:focus {
    border-color: var(--accent-yellow);
    box-shadow: 0 0 10px var(--accent-yellow);
    color: var(--accent-yellow);
}

.setting-group input::placeholder {
    color: var(--text-secondary);
}

.game-button {
    background: linear-gradient(45deg, var(--accent-pink), var(--accent-yellow));
    color: var(--bg-primary);
    border: none;
    padding: 16px 40px;
    font-size: 24px;
    font-weight: bold;
    border-radius: 12px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 2px;
    box-shadow: 0 6px 0 var(--accent-blue);
    transition: all 0.2s ease;
    font-family: inherit;
}

.game-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 0 var(--accent-blue);
}

.game-button:active {
    transform: translateY(2px);
    box-shadow: 0 4px 0 var(--accent-blue);
}

/* ===== ÉCRAN JEU ===== */
#tivan-screen-game {
    justify-content: flex-start;
    padding: 0;
}

.game-header {
    width: 100%;
    background: var(--bg-primary);
    padding: 12px 16px;
    border-bottom: 2px solid var(--accent-yellow);
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 5;
}

.scoreboard {
    display: flex;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}

.score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--accent-yellow);
    color: var(--bg-primary);
    padding: 8px 16px;
    border-radius: 6px;
    box-shadow: 2px 2px 0px var(--bg-primary);
    min-width: 70px;
    flex: 1;
    max-width: 120px;
}

.score-item .label {
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    margin-bottom: 2px;
}

.score-item .value {
    font-size: 18px;
    font-weight: bold;
    font-family: 'Courier New', monospace;
}

.equation-strip {
    text-align: center;
    padding: 8px 0;
}

.equation {
    font-size: 28px;
    font-weight: bold;
    color: var(--accent-yellow);
    text-shadow: 2px 2px 0px var(--accent-pink);
    animation: equation-pop 0.3s ease-out;
}

@keyframes equation-pop {
    0% { transform: scale(0.8); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

.game-area {
    position: relative;
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    background: var(--bg-primary);
    padding: 8px;
}

.countdown-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(11, 15, 20, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.countdown-overlay.active {
    opacity: 1;
    visibility: visible;
}

.countdown-number {
    font-size: 120px;
    font-weight: bold;
    color: var(--accent-yellow);
    text-shadow: 4px 4px 0px var(--accent-pink);
    animation: countdown-pulse 1s ease-in-out;
}

@keyframes countdown-pulse {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

#game-canvas {
    border: 3px solid var(--border-yellow);
    background: var(--bg-primary);
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.3);
    max-width: 100%;
    height: auto;
}

/* Contrôles mobiles optimisés */
.mobile-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(11, 15, 20, 0.95);
    padding: 16px;
    display: none;
    justify-content: center;
    align-items: center;
    gap: 24px;
    z-index: 100;
    border-top: 2px solid var(--accent-yellow);
}

.d-pad {
    display: grid;
    grid-template-areas: 
        ". up ."
        "left . right"
        ". down .";
    gap: 8px;
    width: 160px;
    height: 160px;
}

.d-pad-btn {
    background: var(--accent-blue);
    color: var(--text-primary);
    border: 3px solid var(--text-primary);
    border-radius: 12px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 48px;
    height: 48px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 0 var(--accent-blue);
}

.d-pad-btn.up { grid-area: up; }
.d-pad-btn.left { grid-area: left; }
.d-pad-btn.right { grid-area: right; }
.d-pad-btn.down { grid-area: down; }

.d-pad-btn:active {
    background: var(--accent-yellow);
    color: var(--bg-primary);
    transform: translateY(2px);
    box-shadow: 0 2px 0 var(--accent-blue);
}

.pause-btn {
    background: var(--accent-pink);
    color: var(--text-primary);
    border: 3px solid var(--text-primary);
    border-radius: 50%;
    width: 72px;
    height: 72px;
    font-size: 32px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 0 var(--accent-pink);
}

.pause-btn:active {
    background: var(--accent-yellow);
    color: var(--bg-primary);
    transform: translateY(2px);
    box-shadow: 0 2px 0 var(--accent-pink);
}

/* ===== ÉCRAN SCORE ===== */
#tivan-screen-score {
    background: var(--bg-primary);
    text-align: center;
}

.score-content {
    max-width: 600px;
    width: 100%;
}

.final-score-title {
    font-size: 48px;
    color: var(--accent-yellow);
    margin-bottom: 30px;
    text-shadow: 2px 2px 0px var(--accent-pink);
}

.final-score {
    font-size: 36px;
    font-weight: bold;
    color: var(--text-primary);
    margin-bottom: 40px;
}

.leaderboard {
    display: flex;
    flex-direction: column;
    gap: 30px;
    margin-bottom: 40px;
}

.leaderboard-section h3 {
    color: var(--accent-cyan);
    font-size: 20px;
    margin-bottom: 16px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.scores-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.score-entry {
    background: rgba(255, 255, 255, 0.1);
    padding: 12px 16px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 16px;
    border: 1px solid rgba(255, 215, 0, 0.3);
}

.score-entry.current-player {
    background: var(--accent-yellow);
    color: var(--bg-primary);
    font-weight: bold;
    border: 2px solid var(--accent-pink);
}

.player-ranking {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Effets visuels */
.pop-art-text {
    position: absolute;
    font-size: 48px;
    font-weight: bold;
    color: var(--accent-yellow);
    text-shadow: 2px 2px 0px var(--accent-pink);
    opacity: 0.5;
    pointer-events: none;
    animation: float-fade 0.6s ease-out;
    z-index: 15;
}

@keyframes float-fade {
    0% {
        transform: translateY(0) scale(0.8);
        opacity: 0.8;
    }
    100% {
        transform: translateY(-50px) scale(1);
        opacity: 0;
    }
}

/* Effet feux d'artifice 8-bit */
.fireworks-particle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: var(--accent-yellow);
    border-radius: 50%;
    pointer-events: none;
    animation: firework-burst 1.5s ease-out forwards;
}

.fireworks-particle.pink { background: var(--accent-pink); }
.fireworks-particle.blue { background: var(--accent-blue); }
.fireworks-particle.cyan { background: var(--accent-cyan); }

@keyframes firework-burst {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    100% {
        transform: scale(2) translate(var(--dx), var(--dy));
        opacity: 0;
    }
}

/* Responsive Mobile-First */
@media (max-width: 768px) {
    .tivan-app {
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height pour mobile */
    }

    .main-title {
        font-size: 36px;
    }

    .game-header {
        padding: 8px 12px;
    }

    .equation {
        font-size: 22px;
    }

    .mobile-controls {
        display: flex;
        padding-bottom: env(safe-area-inset-bottom); /* Support iPhone */
    }

    .game-area {
        padding-bottom: 180px; /* Espace pour les contrôles */
    }

    #game-canvas {
        width: 100%;
        max-width: 100vw;
        height: auto;
    }

    .countdown-number {
        font-size: 80px;
    }

    .leaderboard {
        gap: 20px;
    }

    .score-content {
        padding-bottom: 20px;
    }
}

@media (max-width: 480px) {
    .main-title {
        font-size: 28px;
    }

    .equation {
        font-size: 18px;
    }

    .score-item {
        padding: 6px 10px;
        min-width: 60px;
    }

    .score-item .value {
        font-size: 16px;
    }

    .d-pad {
        width: 140px;
        height: 140px;
    }

    .d-pad-btn {
        width: 42px;
        height: 42px;
        font-size: 24px;
    }

    .pause-btn {
        width: 60px;
        height: 60px;
        font-size: 28px;
    }
}

/* Orientation paysage sur mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .mobile-controls {
        position: fixed;
        bottom: 8px;
        right: 8px;
        left: auto;
        background: rgba(11, 15, 20, 0.9);
        border-radius: 12px;
        padding: 12px;
        border: 2px solid var(--accent-yellow);
    }

    .d-pad {
        width: 120px;
        height: 120px;
    }

    .game-area {
        padding-bottom: 20px;
        padding-right: 200px;
    }
}

/* États de focus pour l'accessibilité */
button:focus,
select:focus,
input:focus {
    outline: 3px solid var(--accent-yellow);
    outline-offset: 2px;
}

/* Animations des sprites (à utiliser dans JS) */
@keyframes snake-mouth-open {
    0% { transform: scaleX(1); }
    50% { transform: scaleX(1.2); }
    100% { transform: scaleX(1); }
}

@keyframes explosion-shake {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    10% { transform: translate(-2px, -2px) rotate(-1deg); }
    20% { transform: translate(2px, -2px) rotate(1deg); }
    30% { transform: translate(-2px, 2px) rotate(0deg); }
    40% { transform: translate(2px, 2px) rotate(1deg); }
    50% { transform: translate(-2px, -2px) rotate(-1deg); }
    60% { transform: translate(2px, -2px) rotate(0deg); }
    70% { transform: translate(-2px, 2px) rotate(-1deg); }
    80% { transform: translate(2px, 2px) rotate(1deg); }
    90% { transform: translate(-2px, -2px) rotate(0deg); }
}

/* Masquer le champ initiales si utilisateur connecté */
.tivan-app.logged-in #initials-group {
    display: none;
}