
/* Styles spécifiques au multijoueur */
#lobby-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--bg-color); z-index: 100;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 20px;
}
.lobby-box {
    background: var(--tile-bg); padding: 30px; border-radius: 10px;
    text-align: center; max-width: 400px; width: 100%;
    border: 1px solid var(--tile-border);
}
.lobby-btn {
    display: block; width: 100%; padding: 12px; margin: 10px 0;
    background: var(--key-bg); color: var(--text-color);
    border: none; border-radius: 5px; cursor: pointer; font-weight: bold;
    font-size: 1rem;
}
.lobby-btn:hover { opacity: 0.9; }
.lobby-input {
    width: 100%; padding: 12px; margin: 10px 0;
    background: var(--bg-color); border: 1px solid var(--tile-border);
    color: var(--text-color); border-radius: 5px; font-size: 1rem;
    text-transform: uppercase; text-align: center;
}
#opponents-container {
    display: flex; gap: 10px; justify-content: center; margin-bottom: 5px;
    flex-wrap: wrap;
}

/* Opponents Full Screen Mode (Global) */
body.opponents-open #opponents-container {
    display: flex !important; /* Force display even if hidden by media query */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    z-index: 1999;
    overflow-y: auto;
    flex-wrap: wrap;
    justify-content: center;
    align-content: flex-start;
    padding: 60px 20px 20px 20px;
    gap: 20px;
}

body.opponents-open #opponents-container .opponent-card {
    width: 45% !important;
    min-width: 140px;
    max-width: 200px;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    transform: scale(1.1);
    margin: 10px;
}

body.opponents-open .sidebar-toggle:not(#btn-toggle-opponents),
body.opponents-open .back-btn,
body.opponents-open .theme-switch {
    opacity: 0.2;
    pointer-events: none;
    transition: opacity 0.3s;
}

body.opponents-open #btn-toggle-opponents {
    background: var(--start-tile);
    color: white;
    border-color: white;
    box-shadow: 0 0 15px rgba(0,0,0,0.5);
}

/* Force display of opponents toggle button always */
/* #btn-toggle-opponents:not(.hidden) {
    display: flex !important;
} */

/* Mobile: Hide opponents by default */
@media (max-width: 900px) {
    #opponents-container {
        display: none;
    }
}

.opponent-card {
    background: var(--tile-bg); padding: 10px; border-radius: 8px;
    border: 1px solid var(--tile-border); width: 160px;
    transition: width 0.3s ease;
}

/* Dynamic Sizing based on opponent count */
/* 1 Opponent: Large */
#opponents-container.count-1 .opponent-card { width: 280px; }
#opponents-container.count-1 .mini-row { height: 28px; gap: 4px; }
#opponents-container.count-1 .opponent-name { font-size: 1.2rem; margin-bottom: 10px; }

/* 2 Opponents: Medium */
#opponents-container.count-2 .opponent-card { width: 200px; }
#opponents-container.count-2 .mini-row { height: 20px; gap: 3px; }
#opponents-container.count-2 .opponent-name { font-size: 1rem; }

/* 3+ Opponents: Small (Default) */
#opponents-container.count-3 .opponent-card,
#opponents-container.count-4 .opponent-card { width: 150px; }
#opponents-container.count-3 .mini-row,
#opponents-container.count-4 .mini-row { height: 15px; gap: 2px; }

.opponent-name { font-size: 0.8rem; font-weight: bold; margin-bottom: 5px; text-align: center; }
.mini-grid { display: grid; gap: 2px; }
.mini-row { display: grid; grid-template-columns: repeat(var(--mini-cols, 5), 1fr); gap: 2px; height: 15px; }
.mini-tile { 
    width: 100%; height: 100%; 
    background: var(--tile-bg); 
    border: 1px solid var(--tile-border); /* Ajout bordure pour visibilité */
    border-radius: 2px; 
}
.mini-tile.correct { background: var(--correct); border-color: var(--correct); }
.mini-tile.present { background: var(--present); border-color: var(--present); }
.mini-tile.absent { background: var(--absent); border-color: var(--absent); }
.mini-tile.filled { background: var(--filled-tile); border-color: var(--filled-tile); }
.typing-indicator { font-size: 0.7rem; color: var(--active-border); height: 1rem; text-align: center; }

.hidden { display: none !important; }

/* Séparateur Lobby */
.lobby-separator {
    width: 100%; height: 1px; background: var(--tile-border);
    margin: 20px 0; opacity: 0.5;
}
.lobby-section-title {
    font-size: 0.9rem; font-weight: bold; margin-bottom: 10px; 
    text-align: left; width: 100%; opacity: 0.8;
}

/* Avatar Selector */
.avatar-selector {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-bottom: 15px;
}

.avatar-preview-container {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 3px solid var(--start-tile);
    overflow: hidden;
    background: var(--tile-bg);
    display: flex;
    align-items: center;
    justify-content: center;
}

.avatar-preview-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-nav-btn {
    background: var(--key-bg);
    color: var(--text-color);
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s;
}

.avatar-nav-btn:hover {
    transform: scale(1.1);
    background: var(--tile-border);
}

/* Game Mode Selector */
.game-mode-selector {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    justify-content: center;
}

.mode-option {
    padding: 8px 12px;
    border-radius: 20px;
    border: 1px solid var(--tile-border);
    background: var(--tile-bg);
    font-size: 0.8rem;
    cursor: pointer;
    opacity: 0.6;
    transition: all 0.2s;
    user-select: none;
    -webkit-user-select: none; /* Safari */
    -moz-user-select: none; /* Firefox */
    -ms-user-select: none; /* IE10+/Edge */
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

.mode-option:focus {
    outline: none;
}

.mode-option.selected {
    background: var(--start-tile);
    color: white;
    border-color: var(--start-tile);
    opacity: 1;
    font-weight: bold;
}

.mode-option.disabled {
    cursor: not-allowed;
    opacity: 0.3;
    text-decoration: line-through;
}

/* In-Game Room Info */
#room-info-bar {
    position: absolute; top: 20px; left: 50%; transform: translateX(-50%);
    display: flex; gap: 10px; align-items: center;
    background: var(--tile-bg); padding: 5px 15px; border-radius: 20px;
    border: 1px solid var(--tile-border);
    z-index: 50;
}
.room-code-display { font-weight: bold; letter-spacing: 2px; margin-right: 10px; }
.icon-btn {
    background: none; border: none; cursor: pointer; color: var(--text-color);
    padding: 5px; border-radius: 5px; display: flex; align-items: center;
}
.icon-btn:hover { background: var(--tile-border); }

/* Avatar & Crown */
.player-header { display: flex; align-items: center; justify-content: center; gap: 5px; margin-bottom: 5px; }
.avatar-icon { width: 20px; height: 20px; fill: var(--text-color); }
.crown-icon { font-size: 1rem; }

/* Custom Modal */
.custom-modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.7); z-index: 200;
    display: flex; align-items: center; justify-content: center;
}
.custom-modal-box {
    background: var(--bg-color); padding: 25px; border-radius: 10px;
    border: 1px solid var(--tile-border); text-align: center;
    max-width: 300px; width: 90%; box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}
.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; }
.btn-confirm { background: var(--correct); color: white; padding: 8px 16px; border-radius: 5px; }
.btn-cancel { background: var(--absent); color: white; padding: 8px 16px; border-radius: 5px; }

/* --- SIDEBAR RESPONSIVE --- */
.sidebar-toggle {
    position: fixed; /* Changed from absolute to fixed */
    top: 15px;
    left: 100px; /* Juste à côté du bouton retour */
    padding: 8px 12px;
    border-radius: 8px;
    background: var(--tile-bg);
    color: var(--text-color);
    border: 2px solid var(--tile-border);
    font-weight: 600;
    cursor: pointer;
    z-index: 2000; /* Au dessus de tout, même du lobby si besoin */
    display: none; /* Caché par défaut (desktop) */
    align-items: center;
    justify-content: center;
    font-size: 0.5rem;
    backdrop-filter: blur(5px);
}

/* Force display on mobile if not hidden */
@media (max-width: 900px) {
    .sidebar-toggle:not(.hidden) {
        display: flex !important;
    }
}

#ingame-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 220px;
    background: var(--bg-color);
    border-right: 1px solid var(--tile-border);
    padding: 20px;
    z-index: 1000; /* Au dessus de tout */
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    box-shadow: 2px 0 10px rgba(0,0,0,0.2);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--tile-border);
}

.room-code-pill {
    background: var(--tile-bg);
    padding: 4px 8px;
    border-radius: 4px;
    font-family: monospace;
    font-weight: bold;
    border: 1px solid var(--tile-border);
    font-size: 0.9rem;
}

#ingame-players-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ingame-player-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 8px;
    background: var(--tile-bg);
    border: 1px solid transparent;
    transition: background 0.2s;
}

.ingame-player-card.is-me {
    border-color: var(--correct);
    background: rgba(255, 255, 255, 0.05);
}

.ingame-player-avatar {
    width: 32px;
    height: 32px;
    background: var(--key-bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.9rem;
}

.ingame-player-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.ingame-player-name {
    font-weight: bold;
    font-size: 0.9rem;
}

.ingame-player-status {
    font-size: 0.7rem;
    opacity: 0.7;
}

/* Responsive Adjustments */
@media (max-width: 900px) {
    /* Mobile: Sidebar en bas (Bottom Sheet) */
    #ingame-sidebar {
        transform: translateY(100%); /* Caché en bas */
        width: 100%;
        height: auto;
        max-height: 60vh; /* Max 60% de l'écran */
        top: auto;
        bottom: 0;
        left: 0;
        border-right: none;
        border-top: 1px solid var(--tile-border);
        border-radius: 20px 20px 0 0; /* Coins arrondis en haut */
        padding: 20px;
        box-shadow: 0 -5px 20px rgba(0,0,0,0.3);
    }

    #ingame-sidebar.open {
        transform: translateY(0);
    }

    /* Afficher le bouton toggle */
    .sidebar-toggle {
        display: flex;
    }
    
    /* Force display on mobile if not hidden */
    .sidebar-toggle:not(.hidden) {
        display: flex !important;
    }
    
    /* Reset game container margins */
    .game-container {
        margin-left: 0 !important;
        margin-top: 0 !important;
        width: 100% !important;
        padding-bottom: 80px; /* Espace pour éviter que le clavier soit caché par le bouton toggle si en bas */
        padding-top: 70px; /* Espace pour éviter l'overlap avec les boutons du haut */
        justify-content: flex-start; /* Sur mobile, on aligne en haut pour éviter les soucis de centrage */
    }

    /* Overlay quand la sidebar est ouverte */
    #sidebar-overlay {
        position: fixed; top: 0; left: 0; width: 100%; height: 100%;
        background: rgba(0,0,0,0.5); z-index: 999;
        display: none;
        backdrop-filter: blur(2px);
    }
    #sidebar-overlay.visible { display: block; }
}

@media (min-width: 901px) {
    /* Desktop: Sidebar en bas (Bottom Bar) */
    #ingame-sidebar {
        transform: none;
        top: auto;
        bottom: 0;
        left: 0;
        width: 100%;
        height: auto;
        min-height: 80px;
        border-right: none;
        border-top: 1px solid var(--tile-border);
        flex-direction: row;
        align-items: center;
        padding: 10px 30px;
        box-shadow: 0 -5px 20px rgba(0,0,0,0.1);
    }

    .sidebar-header {
        margin-bottom: 0;
        padding-bottom: 0;
        border-bottom: none;
        border-right: 1px solid var(--tile-border);
        padding-right: 20px;
        margin-right: 20px;
        height: 100%;
    }

    #ingame-players-content {
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 20px;
        overflow-y: hidden;
        overflow-x: auto;
        padding-bottom: 5px; /* Scrollbar space */
    }

    /* Cacher le bouton toggle */
    .sidebar-toggle {
        display: none !important;
    }

    /* Adjust game container */
    .game-container {
        margin-left: 0;
        width: 100%;
        padding-bottom: 120px; /* Espace pour la barre du bas */
        justify-content: center;
    }
}

/* Avatar Styles */
.ingame-player-avatar-img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--tile-border);
    background: var(--tile-bg);
}

.ingame-player-card.is-me .ingame-player-avatar-img {
    border-color: var(--start-tile);
}

/* --- REACTIONS --- */
.sidebar-reactions {
    display: flex;
    gap: 10px;
    padding: 10px;
    justify-content: center;
    border-top: 1px solid var(--tile-border);
    margin-top: auto; /* Push to bottom if flex column */
}

/* Desktop adjustment */
@media (min-width: 901px) {
    .sidebar-reactions {
        border-top: none;
        border-left: 1px solid var(--tile-border);
        margin-top: 0;
        margin-left: auto; /* Push to right */
        padding: 0 0 0 20px;
    }
}

.reaction-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
}
.reaction-btn:hover {
    transform: scale(1.25);
    filter: drop-shadow(0 0 8px rgba(255,255,255,0.3));
}
.reaction-btn:active {
    transform: scale(0.9);
}

/* Better SVG styling inside buttons */
.reaction-btn svg {
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
    width: 100%;
    height: 100%;
}

.floating-reaction {
    position: fixed;
    width: 60px;
    height: 60px;
    pointer-events: none;
    animation: floatReaction 2.5s ease-out forwards;
    z-index: 2000;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.3));
}

@keyframes floatReaction {
    0% { transform: translateY(0) scale(0); opacity: 0; }
    15% { transform: translateY(-20px) scale(1.2); opacity: 1; }
    50% { transform: translateY(-60px) scale(1); opacity: 1; }
    100% { transform: translateY(-120px) scale(0.8); opacity: 0; }
}
