/* Base styles */
:root {
    --primary-color: #4CAF50;
    --secondary-color: #2196F3;
    --accent-color: #FFD700;
    --bg-dark: #1a1a1a;
    --bg-light: #2d2d2d;
    --text-light: #ffffff;
    --text-dim: #a0a0a0;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Arial, sans-serif;
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-light) 100%);
    color: var(--text-light);
    min-height: 100vh;
    overscroll-behavior: contain;
}

/* Login Screen */
#login-screen {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
}

#login-form {
    background: rgba(255, 255, 255, 0.1);
    padding: 2.5rem;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

#login-form h2 {
    color: var(--accent-color);
    margin-bottom: 1.5rem;
    font-size: 2rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

#login-form input {
    padding: 12px;
    width: 250px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-light);
    font-size: 1rem;
    transition: all 0.3s ease;
}

#login-form input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 0 2px var(--accent-color);
}

#login-form button {
    padding: 12px 24px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#login-form button:hover {
    background: #45a049;
    transform: translateY(-2px);
}

/* Game Container */
#game-container {
    display: none;
    padding: 20px;
    height: 100vh;
    box-sizing: border-box;
}


/* Main Game Area */
.main-game {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 10px;
    height: 100%;
}

.canvas-container {
    position: relative;
    width: 100%;
    height: calc(100vh - 120px);
    max-width: 500px; /* Ajouter une largeur maximale */
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

#gameCanvas {
    width: auto;
    height: 100%;
    aspect-ratio: 1/2; /* Maintenir le ratio correct */
    display: block;
    image-rendering: pixelated;
    background-color: var(--bg-dark);
}

.game-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    width: 100%;
    padding: 10px;
    position: relative;
    z-index: 1;
}

.game-controls button {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    min-width: 100px;
}

.start-btn { background: var(--primary-color); color: white; }
.restart-btn { background: var(--secondary-color); color: white; }
.pause-btn { background: #FF9800; color: white; }
.exit-btn { background: #f44336; color: white; }

.game-controls button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.game-controls button:disabled {
    background: #666;
    cursor: not-allowed;
    opacity: 0.7;
}

.sound-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    color: white;
    transition: transform 0.2s;
}

.sound-btn:hover {
    transform: scale(1.1);
}

.sound-btn:active {
    transform: scale(0.95);
}

/* Scoreboard */
.scoreboard {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.8);
    border-radius: 8px;
    color: white;
    margin-left: 1rem;
    min-width: 300px;
}

.score-section {
    background: rgba(255, 255, 255, 0.1);
    padding: 1rem;
    border-radius: 4px;
}

.score-section h3 {
    margin: 0 0 0.5rem 0;
    color: #ffd700;
    font-size: 1.2rem;
}

.score-section li {
    list-style: none;
    padding: 0.3rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.score-section li:last-child {
    border-bottom: none;
}

/* Player Stats */
.player-stats {
    margin: 1rem 0;
    padding: 0.8rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
}

.player-stats h3 {
    color: #4CAF50;
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}


.stat-item {
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 6px;
}

.stat-label {
    font-size: 0.8rem;
    color: #aaa;
    margin-bottom: 0.3rem;
}

.stat-value {
    font-size: 1.2rem;
    font-weight: bold;
    color: #fff;
}

/* Mobile Controls */
.mobile-controls {
    display: none;
}

@media (max-width: 768px) {
    .game-layout {
        display: grid;
        /* Réduire la taille des colonnes latérales */
        grid-template-columns: 250px auto 250px;
        gap: 10px; /* Réduire l'espace entre les colonnes */
        padding: 10px; /* Réduire le padding */
        max-width: 100vw;
        min-height: 100vh;
        background: var(--bg-dark);
    }
    
    .main-game {
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 0;
    }

    .canvas-container {
        position: relative;
        width: 100%;
        height: calc(100vh - 100px); /* Hauteur maximale moins l'espace pour les contrôles */
        margin: 0 auto;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .game-controls {
        width: 100%;
        max-width: 300px;
        display: flex;
        justify-content: center;
        gap: 10px;
        margin-bottom: 10px;
    }

    .game-controls button {
        padding: 8px 16px; /* Réduire la taille des boutons */
        min-width: 80px; /* Réduire la largeur minimale */
    }

    .mobile-controls {
        width: 100%;
        max-width: 300px;
        margin: 20px auto;
        display: flex;
        flex-direction: column;
        gap: 10px;
        padding: 10px;
    }

    .controls-row {
        display: flex;
        justify-content: center;
        gap: 20px;
    }

    .mobile-controls button {
        width: 60px;
        height: 60px;
        font-size: 24px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.1);
        border: 2px solid var(--accent-color);
        color: var(--text-light);
        display: flex;
        align-items: center;
        justify-content: center;
        touch-action: manipulation;
    }

    .mobile-controls button:active {
        background: rgba(255, 255, 255, 0.2);
        transform: scale(0.95);
    }

    #game-container {
        padding: 10px;
        height: 100vh;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .opponents-section, .scoreboard-section {
        display: none;
    }

    .scoreboard {
        margin-left: 0;
        margin-top: 1rem;
        min-width: auto;
        width: 100%;
    }
}


@media (max-width: 1600px) {
    .game-layout {
        grid-template-columns: 300px auto 300px;
        gap: 10px;
        padding: 10px;
    }
}

@media (max-width: 1200px) {
    .game-layout {
        grid-template-columns: 250px auto 250px;
    }
}

/* Version mobile */
@media (max-width: 992px) {
    .game-layout {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .game-info-section,
    .scoreboard-section {
        display: none;
    }
    
    .main-game {
        width: 100%;
        max-width: none;
    }
    
    .canvas-container {
        height: calc(100dvh - 180px);
        width: calc(100vw - 20px);
        margin: 10px;
    }
}

/* Paused Overlay */
.paused-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    color: var(--text-light);
    font-size: 2rem;
    font-weight: bold;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* Wait Message */
.wait-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    padding: 1rem 2rem;
    border-radius: 8px;
    text-align: center;
    z-index: 1000;
    border: 2px solid #ffd700;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 215, 0, 0.4);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(255, 215, 0, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(255, 215, 0, 0);
    }
}

/* Game Over Screen */
.game-over-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 999;
}

.game-over-screen {
    position: relative;
    background: rgba(20, 20, 20, 0.9);
    padding: 1.5rem;
    border-radius: 10px;
    text-align: center;
    color: white;
    width: 80%;
    max-width: 400px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    animation: fadeIn 0.3s ease-out;
}

.game-over-screen h2 {
    color: #ff4444;
    margin-bottom: 1rem;
    font-size: 2rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.top-scores {
    margin: 2rem 0;
}

.top-scores h3 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: #ffd700;
}

.score-list {
    max-height: 150px;
    overflow-y: auto;
    margin: 0.5rem 0;
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
}

.score-item.current-player {
    background: rgba(255, 215, 0, 0.1);
    color: #ffd700;
    font-weight: bold;
}

.current-player {
    animation: blink 1s infinite;
    color: #ffff00;
    font-weight: bold;
    background: rgba(255, 255, 0, 0.1);
    border-radius: 5px;
}

.restart-button {
    background: #4CAF50;
    border: none;
    padding: 0.8rem 1.5rem;
    margin-top: 1rem;
    color: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.1rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.3s ease;
}

.restart-button:hover {
    background: #45a049;
    transform: scale(1.05);
}


.score-item:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.score-item .rank {
    font-weight: bold;
    min-width: 25px;
}

.score-item .player {
    flex-grow: 1;
    margin: 0 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.score-item .score {
    font-weight: bold;
    color: #ffd700;
}

/* Style spécial pour le top 3 */
.score-item:nth-child(1) {
    background-color: rgba(255, 215, 0, 0.2);
}

.score-item:nth-child(2) {
    background-color: rgba(192, 192, 192, 0.2);
}

.score-item:nth-child(3) {
    background-color: rgba(205, 127, 50, 0.2);
}

/* Ajoutez ces styles dans votre fichier CSS */
.scoreboard-container {
    --gold-bg: rgba(255, 215, 0, 0.15);
    --silver-bg: rgba(192, 192, 192, 0.15);
    --bronze-bg: rgba(205, 127, 50, 0.15);
    --normal-bg: rgba(255, 255, 255, 0.05);
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.scoreboard-title {
    text-align: center;
    color: #ffd700;
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.title-icon {
    font-size: 1.2rem;
}

.scores-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.score-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.score-item:hover {
    transform: translateX(5px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.rank-medal {
    font-size: 1.2rem;
}

.rank-number {
    font-size: 0.9rem;
    color: #aaa;
}


.player-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 1;
    min-width: 0; /* Important pour gérer le débordement */
}

.player-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 10px;
    flex: 1;
}

.rank-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 60px; /* Largeur fixe pour la partie rang */
    flex-shrink: 0; /* Empêche la compression */
}

.score-container {
    display: flex;
    align-items: baseline;
    gap: 0.25rem;
    flex-shrink: 0; /* Empêche la compression du score */
}

.score-value {
    font-size: 1.2rem;
    font-weight: bold;
    color: #ffd700;
}

.score-label {
    font-size: 0.8rem;
    color: #aaa;
}

.no-scores {
    text-align: center;
    padding: 2rem;
    color: #aaa;
}

.no-scores-icon {
    font-size: 2rem;
    margin-bottom: 1rem;
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.animate-fade-in {
    animation: fadeIn 0.5s ease-out forwards;
    opacity: 0;
}

/* Ajoutez ces styles à la fin du fichier */
.game-layout {
    display: grid;
    grid-template-columns: 300px auto 300px; /* Fixer la largeur des colonnes latérales */
    gap: 20px;
    padding: 20px;
    height: 100vh;
    box-sizing: border-box;
    background: var(--bg-dark);
}

.scoreboard-section {
    background: rgba(0, 0, 0, 0.8);
    border-radius: 12px;
    padding: 20px;
    height: fit-content;
}

@media (max-width: 768px) {
    /* Layout mobile */
    .game-layout {
        grid-template-columns: 1fr;
        gap: 0;
        height: 100dvh;
    }

    .game-controls {
        position: fixed;
        bottom: 10px;
        left: 0;
        right: 0;
        padding: 5px;
        background: rgba(0,0,0,0.8);
        z-index: 100;
    }

    .canvas-container {
        position: relative;
        width: 100%;
        height: calc(100vh - 120px);
        max-width: 500px; /* Ajouter une largeur maximale */
        margin: 0 auto;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    #gameCanvas {
        width: 100%;
        height: 100%;
        aspect-ratio: auto;
    }
    
    /* Contrôles mobiles améliorés */
    .mobile-controls {
        display: flex;
        position: fixed;
        bottom: 70px;
        left: 0;
        right: 0;
        padding: 10px;
        background: rgba(0,0,0,0.6);
        backdrop-filter: blur(5px);
        z-index: 99;
    }

    .mobile-controls-left,
    .mobile-controls-right {
        flex: 1;
        display: flex;
        justify-content: center;
        gap: 20px;
    }

    .mobile-controls button {
        width: 50px;
        height: 50px;
        font-size: 20px;
        background: rgba(255,255,255,0.15);
        border: 2px solid var(--accent-color);
        border-radius: 50%;
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-controls button:active {
        background: rgba(255,255,255,0.25);
        transform: scale(0.95);
    }
}

.game-info-section, .scoreboard-section {
    background: rgba(0, 0, 0, 0.8);
    border-radius: 12px;
    padding: 20px;
    height: calc(100vh - 40px); /* Hauteur fixe avec marge */
    overflow-y: auto; /* Permettre le défilement si nécessaire */
}

.current-game-info h2 {
    color: var(--accent-color);
    margin-bottom: 1.5rem;
    font-size: 1.8rem;
    text-align: center;
}

.game-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.stat-box {
    background: rgba(255, 255, 255, 0.1);
    padding: 10px;
    border-radius: 8px;
    text-align: center;
}

.stat-box h3 {
    color: var(--text-dim);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.stat-box div {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-light);
}

.players-list {
    margin-bottom: 2rem;
}

.players-list h3 {
    color: var(--accent-color);
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.active-players {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 0.5rem;
}

.player-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.player-item:last-child {
    border-bottom: none;
}

.player-item.current {
    background: rgba(var(--accent-color), 0.2);
}

.player-name {
    color: var(--text-light);
    font-weight: 500;
}

.player-score {
    color: var(--accent-color);
    font-weight: bold;
}

.game-statistics {
    margin-top: 2rem;
}

.game-statistics h3 {
    color: var(--accent-color);
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.stat-item {
    background: rgba(255, 255, 255, 0.05);
    padding: 0.75rem;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    color: var(--text-dim);
    font-size: 0.8rem;
    margin-bottom: 0.25rem;
}

.stat-value {
    color: var(--text-light);
    font-size: 1.2rem;
    font-weight: bold;
}

@media (max-width: 768px) {
    .game-info-section {
        display: none;
    }
    
    .game-layout {
        grid-template-columns: 1fr;
    }
}

.mini-displays {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* Affichage sur 2 colonnes */
    gap: 10px;
    margin-top: 20px;
    max-height: 50vh;
    overflow-y: auto;
    padding: 10px;
}

.mini-display-container {
    width: 120px; /* Réduire encore la largeur */
    height: 240px; /* Garder le ratio 1:2 */
    background: rgba(0, 0, 0, 0.3);
    padding: 5px;
    border-radius: 8px;
    margin: 0 auto;
}

.mini-display-container canvas {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
}

/* Ajuster le texte du nom du joueur */
.player-label {
    text-align: center;
    margin-top: 3px;
    color: var(--text-light);
    font-size: 0.7rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.game-status {
    background: rgba(255, 255, 255, 0.1);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    text-align: center;
}

.status-box {
    margin: 0.5rem 0;
    color: var(--text-light);
}

.status-box span {
    font-weight: bold;
    color: var(--accent-color);
}

/* Style spécial quand une partie est en cours */
.game-in-progress {
    color: #FFD700 !important;
}

/* Ajouter à la fin du fichier */
@keyframes fadeInOut {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
    20% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
}

/* Style pour la bordure brillante */
.level-notification {
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
    border: 2px solid rgba(255, 215, 0, 0.5);
}

.game-over-notification {
    box-shadow: 0 0 30px rgba(255, 68, 68, 0.3);
    border: 2px solid rgba(255, 68, 68, 0.5);
    backdrop-filter: blur(5px);
}

/* Ajouter ces styles */
html {
    overscroll-behavior: none; /* Empêche le rebond sur iOS */
    touch-action: manipulation; /* Améliore la réactivité tactile */
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overscroll-behavior: none;
}

/* Pour éviter la sélection de texte sur mobile */
* {
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* Optimiser le rendu du canvas */
#gameCanvas {
    backface-visibility: hidden;
    transform: translateZ(0);
    perspective: 1000;
}

.connected-players {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 1rem;
    margin: 1rem 0;
}

.player-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* Styles pour l'interface mobile */
.mobile-game-root {
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-dark);
    touch-action: none;
}

.mobile-game-root canvas {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    border: 2px solid var(--accent-color);
}

.mobile-game-root button {
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.mobile-game-root button:active {
    transform: scale(0.95);
}

/* Ajustements pour les contrôles mobiles */
@media (max-width: 768px) {
    #game-container {
        padding: 0;
        margin: 0;
        height: 100vh;
        width: 100vw;
        display: flex;
        flex-direction: column;
    }

    #gameCanvas {
        margin: auto;
        max-height: calc(100vh - 200px);
    }
}
