/* =========================================
   1. VARIABLES & CONFIGURATION GLOBALE
   ========================================= */
:root {
    --bg-dark: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --card-border: rgba(255, 255, 255, 0.1);
    --primary: #6366f1; /* Indigo */
    --primary-glow: rgba(99, 102, 241, 0.5);
    --accent: #ec4899; /* Pink */
    --success: #10b981; /* Green */
    --danger: #ef4444; /* Red */
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --font-main: 'Inter', sans-serif;
}

* {
    box-sizing: border-box; /* Crucial pour la mise en page */
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-dark);
    color: var(--text-main);
    margin: 0;
    height: 100vh;
    overflow: hidden;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.05'/%3E%3C/svg%3E");
}

/* --- Arrière-plan Animé --- */
.background-blobs { position: fixed; inset: 0; z-index: -1; pointer-events: none; }
.blob { position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.5; animation: float 15s infinite ease-in-out alternate; }
.blob-1 { top: -10%; left: -10%; width: 50vw; height: 50vw; background: var(--primary); }
.blob-2 { bottom: -10%; right: -10%; width: 50vw; height: 50vw; background: var(--accent); animation-delay: -5s; }
@keyframes float { 0% { transform: translate(0, 0) scale(1); } 100% { transform: translate(30px, 50px) scale(1.1); } }

/* =========================================
   2. LAYOUT PRINCIPAL (GRID + CHAT)
   ========================================= */
.app-container {
    display: flex; flex-direction: column; height: 100vh;
}

.main-layout {
    display: flex;
    flex: 1; /* Prend tout l'espace restant sous le header */
    overflow: hidden; /* Empêche le scroll global */
    position: relative;
}

/* =========================================
   3. HEADER & INDICATEURS
   ========================================= */
.glass-header {
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--card-border);
    padding: 10px 20px;
    display: flex; justify-content: space-between; align-items: center;
    z-index: 50; box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.brand h1 {
    font-size: 1.5rem; font-weight: 800; margin: 0;
    background: linear-gradient(135deg, #fff, #94a3b8);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.badge { background: linear-gradient(90deg, var(--primary), var(--accent)); color: white; padding: 2px 8px; border-radius: 12px; font-size: 0.7rem; vertical-align: middle; }

/* Badge de Tour */
.turn-badge {
    display: inline-block; padding: 5px 12px; border-radius: 20px;
    font-size: 0.85rem; margin-left: 15px; font-weight: bold;
    animation: fadeIn 0.5s;
}
.my-turn { background: rgba(16, 185, 129, 0.15); color: var(--success); border: 1px solid var(--success); }
.opponent-turn { background: rgba(239, 68, 68, 0.15); color: var(--danger); border: 1px solid var(--danger); }

.controls { display: flex; gap: 20px; align-items: center; }
.counter-badge { text-align: right; }
.counter-badge span:first-child { font-size: 1.2rem; font-weight: 800; color: white; }
.counter-badge .label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; }
.counter-badge.opponent { border-left: 1px solid var(--card-border); padding-left: 15px; }

.actions { display: flex; gap: 10px; }

/* =========================================
   4. PLATEAU DE JEU (GRILLE)
   ========================================= */
.grid-wrapper {
    flex: 1; /* Prend l'espace restant à gauche du chat */
    overflow-y: auto; /* Scroll uniquement ici */
    padding: 20px;
    scrollbar-width: thin; scrollbar-color: var(--primary) transparent;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 15px;
    padding-bottom: 80px;
    max-width: 1400px; margin: 0 auto;
}

/* =========================================
   5. CARTES & ANIMATIONS
   ========================================= */
.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 8px;
    position: relative;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.card:hover {
    transform: translateY(-5px) scale(1.02);
    border-color: var(--primary);
    box-shadow: 0 10px 20px rgba(0,0,0,0.3), 0 0 15px var(--primary-glow);
    z-index: 10;
}

.img-box {
    width: 100%; aspect-ratio: 1/1; border-radius: 8px;
    overflow: hidden; margin-bottom: 8px; background: #1e293b;
}

.card img { width: 100%; height: 100%; object-fit: cover; transition: 0.3s; }
.card h3 { margin: 5px 0; font-size: 0.9rem; text-align: center; color: #e2e8f0; }

/* Bouton Guess */
.btn-guess-card {
    width: 100%; padding: 6px 0;
    background: rgba(99, 102, 241, 0.15); color: var(--primary);
    border: 1px solid rgba(99, 102, 241, 0.3); border-radius: 6px;
    font-size: 0.75rem; transition: 0.2s; opacity: 0.9; cursor: pointer;
}
.card:hover .btn-guess-card { opacity: 1; background: var(--primary); color: white; }

/* --- ÉTAT ÉLIMINÉ --- */
.card.eliminated {
    animation: shake 0.4s ease-in-out;
    transform: scale(0.95);
    background: #0f1115; border-color: #333; opacity: 0.6;
    box-shadow: none;
}
.card.eliminated img { filter: grayscale(100%) contrast(1.2) brightness(0.5); }
.card.eliminated h3 { text-decoration: line-through; color: #555; }
.card.eliminated .btn-guess-card { display: none; }
.card.eliminated::before {
    content: "✖"; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -100%);
    font-size: 3rem; color: var(--danger); z-index: 20; opacity: 0.8; pointer-events: none;
}

@keyframes shake {
    0%, 100% { transform: translateX(0) scale(0.95); }
    25% { transform: translateX(-3px) scale(0.95); }
    75% { transform: translateX(3px) scale(0.95); }
}

/* =========================================
   6. SIDEBAR CHAT (NOUVEAU)
   ========================================= */
.chat-sidebar {
    width: 320px;
    background: rgba(15, 23, 42, 0.95);
    border-left: 1px solid var(--card-border);
    display: flex; flex-direction: column;
    z-index: 40; backdrop-filter: blur(10px);
}

.chat-header { padding: 15px; background: rgba(0,0,0,0.2); font-weight: bold; border-bottom: 1px solid var(--card-border); font-size: 0.9rem; }
.chat-messages { flex: 1; padding: 15px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; font-size: 0.9rem; }

.msg { padding: 8px 12px; border-radius: 8px; max-width: 90%; word-wrap: break-word; line-height: 1.4; }
.my-msg { align-self: flex-end; background: var(--primary); color: white; border-bottom-right-radius: 2px; }
.opp-msg { align-self: flex-start; background: #334155; color: #e2e8f0; border-bottom-left-radius: 2px; }
.system-msg { align-self: center; font-style: italic; color: #64748b; font-size: 0.75rem; margin: 10px 0; }

.chat-input-area { padding: 15px; border-top: 1px solid var(--card-border); display: flex; gap: 8px; }
.chat-input-area input { flex: 1; padding: 10px; border-radius: 8px; border: 1px solid #334155; background: #0f172a; color: white; outline: none; }
.chat-input-area input:focus { border-color: var(--primary); }

/* =========================================
   7. MODALES & INPUTS
   ========================================= */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.85);
    backdrop-filter: blur(5px); z-index: 100;
    display: flex; justify-content: center; align-items: center;
    animation: fadeIn 0.3s ease;
}
.hidden { display: none !important; }

.modal-content {
    background: rgba(30, 41, 59, 0.95);
    border: 1px solid var(--card-border);
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
    padding: 30px; border-radius: 20px;
    text-align: center; max-width: 500px; width: 90%;
    position: relative;
}
.modal-content::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px;
    background: linear-gradient(90deg, var(--primary), var(--accent));
}

.modal-content h2 { margin-top: 0; margin-bottom: 20px; font-size: 1.5rem; color: white; }

/* STYLE DES INPUTS (CORRECTION "UGLY INPUT") */
.modal-content input {
    width: 100%;
    padding: 12px 15px;
    margin-bottom: 15px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    color: white; font-size: 1rem; text-align: center;
    display: block; outline: none; transition: 0.2s;
}
.modal-content input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }

/* CORRECTIF SCROLL SÉLECTION */
#selection-screen .modal-content {
    width: 1100px; max-width: 95%; max-height: 85vh;
    overflow-y: auto !important; overflow-x: hidden; display: block;
}
#selection-grid { padding: 10px; padding-bottom: 50px; }

/* =========================================
   8. BOUTONS GÉNÉRAUX
   ========================================= */
button { padding: 10px 20px; border-radius: 10px; cursor: pointer; border: none; font-weight: 600; font-family: inherit; transition: 0.2s; }
.btn-primary { background: linear-gradient(135deg, var(--primary), #4f46e5); color: white; box-shadow: 0 4px 15px var(--primary-glow); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 20px var(--primary-glow); }
.btn-secondary { background: rgba(255,255,255,0.1); color: white; border: 1px solid #475569; }
.btn-secondary:hover { background: rgba(255,255,255,0.2); }
.btn-warning { background: var(--accent); color: white; box-shadow: 0 0 10px var(--accent-glow); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* =========================================
   9. RESPONSIVE MOBILE
   ========================================= */
@media (max-width: 768px) {
    .glass-header { flex-direction: column; gap: 10px; height: auto; align-items: stretch; }
    .controls { justify-content: space-between; flex-wrap: wrap; }
    .brand { display: flex; justify-content: space-between; align-items: center; }
    .turn-badge { margin: 0; font-size: 0.75rem; }

    /* Layout vertical : Grille en haut, Chat en bas */
    .main-layout { flex-direction: column; }
    
    .grid-wrapper { height: 60%; padding: 10px; }
    .grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; padding-bottom: 40px; }
    
    .chat-sidebar {
        width: 100%; height: 40%;
        border-left: none; border-top: 1px solid var(--card-border);
    }
    
    .modal-content { padding: 20px; }
}

#secret-card-display .img-box {
    width: 200px;         /* Taille fixe raisonnable */
    height: 200px;
    margin: 0 auto 15px auto; /* Centré horizontalement */
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 10px 20px rgba(0,0,0,0.5);
    border: 2px solid var(--primary);
}

#secret-card-display h3 {
    font-size: 1.5rem;
    color: white;
    margin: 0;
}