/* style.css */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;800&display=swap');

:root {
    /* Thème COLORÉ (Défaut) */
    --bg-color: #004678;
    --text-color: #fff;
    --tile-border: #ffffff50;
    --tile-bg: #ffffff20;
    --key-bg: #005694;
    --correct: #ff3d4e;
    --start-tile: #0c9eff;
    --present: #ffc800;
    --absent: #0060a5;
    --active-border: transparent;
    --filled-tile: rgba(255, 255, 255, 0.6);
}

body.sombre {
    /* Thème NUIT */
    --bg-color: #121213;
    --text-color: #ffffff;
    --tile-border: #3a3a3c;
    --tile-bg: #121213;
    --key-bg: #818384;
    --correct: #538d4e;
    --present: #b59f3b;
    --absent: #3a3a3c;
    --start-tile: #058ae3;
    --active-border: #565758;
    --filled-tile: #565758;
}

body.claire {
    /* Thème JOUR */
    --bg-color: #f0f2f5;
    --text-color: #1a1a1b;
    --tile-border: #d3d6da;
    --tile-bg: #ffffff;
    --key-bg: #d3d6da;
    --correct: #6aaa64;
    --present: #c9b458;
    --absent: #787c7e;
    --start-tile: #058ae3;
    --active-border: #878a8c;
    --filled-tile: #878a8c;
}

* { box-sizing: border-box; margin: 0; padding: 0; touch-action: manipulation; }

body {
    background: var(--bg-color);
    color: var(--text-color);
    font-family: 'Poppins', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    transition: background 0.4s ease, color 0.4s ease;
}

/* --- UI COMPONENTS --- */
button {
    cursor: pointer;
    border: none;
    font-family: inherit;
}

.theme-switch {
    position: fixed; /* Changed from absolute to fixed */
    top: 15px;
    right: 15px;
    padding: 8px 12px; /* Slightly smaller padding */
    border-radius: 8px;
    background: var(--tile-bg);
    color: var(--text-color);
    border: 2px solid var(--tile-border);
    font-weight: 600;
    font-size: 0.8rem; /* Smaller font */
    transition: transform 0.2s;
    z-index: 2000; /* High z-index to stay on top */
    backdrop-filter: blur(5px); /* Nice effect */
}
.theme-switch:hover { transform: translateY(-2px); box-shadow: 0 6px 12px rgba(0,0,0,0.06); }

/* Bouton Retour: couleurs similaires aux tuiles, discret pour ne pas inciter au départ */
.back-btn {
    position: fixed; /* Changed from absolute to fixed */
    left: 15px;
    top: 15px;
    padding: 8px 12px;
    border-radius: 8px;
    background: var(--tile-bg);
    color: var(--text-color);
    border: 2px solid var(--tile-border);
    font-weight: 600;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.12s, box-shadow 0.12s;
    z-index: 2000; /* Ensure it's clickable and on top */
    backdrop-filter: blur(5px);
}

/* Score Popup Animation */
.score-popup {
    position: absolute;
    font-weight: bold;
    font-size: 1.2rem;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    pointer-events: none;
    animation: floatUp 1.5s ease-out forwards;
    z-index: 50;
}

@keyframes floatUp {
    0% { transform: translateY(0) scale(1); opacity: 1; }
    50% { transform: translateY(-20px) scale(1.2); opacity: 1; }
    100% { transform: translateY(-40px) scale(1); opacity: 0; }
}

.row-highlight-eco {
    animation: highlightEco 1s ease-in-out;
}

@keyframes highlightEco {
    0% { background-color: transparent; }
    50% { background-color: rgba(255, 215, 0, 0.3); } /* Gold tint */
    100% { background-color: transparent; }
}

.big-score-popup {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    font-weight: 800;
    color: #FFD700;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
    animation: popIn 1s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    z-index: 60;
}

@keyframes popIn {
    0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
    50% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}
.back-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 12px rgba(0,0,0,0.06); }

/* Bouton Retour Lobby */
.lobby-back-btn {
    position: absolute;
    left: 20px;
    top: 20px;
    padding: 10px 20px;
    border-radius: 8px;
    background: var(--tile-bg);
    color: var(--text-color);
    border: 2px solid var(--tile-border);
    font-weight: 600;
    text-decoration: none;
    font-size: 1rem;
    transition: transform 0.2s, box-shadow 0.2s;
    z-index: 1001;
}

.lobby-back-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}

/* --- PAGE D'ACCUEIL --- */
.home-container {
    text-align: center;
    margin-top: 15vh;
    animation: fadeIn 1s ease;
}

h1 { font-size: 4rem; margin-bottom: 2rem; letter-spacing: 2px; }

.menu-btn {
    display: block;
    width: 300px;
    padding: 1.5rem;
    margin: 1rem auto;
    font-size: 1.2rem;
    font-weight: bold;
    border-radius: 12px;
    background: var(--correct);
    color: white;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    transition: transform 0.2s, box-shadow 0.2s;
    text-decoration: none;
}

.menu-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.2);
}

.btn-secondary { background: var(--present); }
.btn-tertiary { background: var(--absent); }

/* Bouton Désactivé (Coming Soon) */
.btn-disabled {
    opacity: 0.5;
    cursor: not-allowed;
    position: relative;
    filter: grayscale(0.3);
}

.btn-disabled:hover {
    transform: none !important;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1) !important;
}

.coming-soon-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgb(0, 0, 0);
    backdrop-filter: blur(10px);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

/* --- JEU (GRID) --- */
.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px; /* Reduced from 50px to fit everything on screen */
    height: 100%;
    width: 100%;
    /* max-width: 500px; Removed to allow wider grids for long words */
    padding: 10px;
    margin: 0 auto;
}

.grid {
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: auto; /* Let it shrink to content size */
    margin: 0 auto;
    align-items: center;
}

.row {
    display: flex;
    gap: 5px;
    justify-content: center; /* Center tiles in row */
    position: relative; /* For timer positioning */
}

.timer-display {
    position: absolute;
    right: -60px; /* Adjust based on layout */
    top: 50%;
    transform: translateY(-50%);
    background: #ff4444;
    color: white;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2rem;
    animation: pulse 1s infinite;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    z-index: 10;
}

@keyframes pulse {
    0% { transform: translateY(-50%) scale(1); }
    50% { transform: translateY(-50%) scale(1.1); }
    100% { transform: translateY(-50%) scale(1); }
}

.tile.skipped {
    background-color: var(--absent) !important;
    border-color: var(--absent) !important;
    opacity: 0.5;
}

.tile {
    width: 62px;
    max-width: calc(90vw / var(--cols, 5)); /* Responsive based on word length */
    aspect-ratio: 1 / 1;
    border: 2px solid var(--tile-border);
    background: var(--tile-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: 800;
    text-transform: uppercase;
    user-select: none;
    transition: transform 0.2s, background-color 0.5s, border-color 0.5s;
}

/* --- CLAVIER --- */
.keyboard { 
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px; 
    width: 100%; 
    max-width: 500px;
    margin: 0 auto;
}
.key-row { display: flex; justify-content: center; gap: 6px; }
.key {
    background: var(--key-bg);
    color: var(--text-color);
    padding: 16px 18px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 18px;
    text-transform: uppercase;
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: manipulation;
}
.key.large { flex: 1.5; font-size: 16px; }
.key.correct {
    background-color: var(--correct);
    color: white;
}

.key.present {
    background-color: var(--present);
    color: white;
}

.key.absent {
    background-color: var(--absent);
    /* Default behavior for non-clear themes: slightly translucent to deemphasize */
    color: white;
    opacity: 0.3;
    filter: none;
}

/* Override for light/"claire" theme: keep text readable and only dim background */
body.claire .key.absent {
    color: var(--text-color);
    opacity: 1; /* no global translucency so text stays visible */
    filter: brightness(0.9);
}


/* --- ANIMATIONS --- */
.tile[data-state="active"] {
    border-color: var(--active-border);
    animation: pop 0.1s;
}

.tile.flip {
    animation: flip 0.6s ease forwards;
}

.tile.shake {
    animation: shake 0.5s;
}

@keyframes pop { 50% { transform: scale(1.1); } }
@keyframes flip {
    0% { transform: rotateX(0); }
    50% { transform: rotateX(90deg); }
    100% { transform: rotateX(0); }
}
@keyframes shake {
    10%, 90% { transform: translateX(-1px); }
    20%, 80% { transform: translateX(2px); }
    30%, 50%, 70% { transform: translateX(-4px); }
    40%, 60% { transform: translateX(4px); }
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* Couleurs des tuiles validées */
.tile.correct { background: var(--correct) !important; border-color: var(--correct) !important; color: white; }
.tile.present { background: var(--present) !important; border-color: var(--present) !important; color: white; }
.tile.absent { background: var(--absent) !important; border-color: var(--absent) !important; color: white; }

/* Tuile de départ (première lettre fournie) */
.start-tile {
    background: var(--start-tile) !important;
    border-color: rgba(0,0,0,0.15) !important;
    color: white !important;
}

/* Dans style.css */

/* 1. Alignement parfait de l'icône et du texte */
.menu-btn {
    display: flex;
    align-items: center; /* Centre verticalement */
    justify-content: center; /* Centre horizontalement si tu veux que tout le bloc soit centré */
    gap: 12px; /* Espace plus élégant entre l'icône et le texte */
    /* ... tes autres styles existants ... */
}

/* 2. S'assurer que l'icône ne se déforme pas sur petits écrans */
.menu-btn svg {
    flex-shrink: 0;
}

/* --- MODAL (End Screen) --- */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: var(--bg-color);
    padding: 2rem;
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    text-align: center;
    max-width: 90%;
    width: 400px;
    border: 1px solid var(--tile-border);
    transform: scale(1);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal.hidden .modal-content {
    transform: scale(0.9);
}

.modal h2 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
}

.modal p {
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    opacity: 0.8;
}

.word-reveal {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: 2px;
    margin: 1rem 0 2rem;
    padding: 10px;
    background: var(--tile-bg);
    border-radius: 8px;
    border: 2px dashed var(--tile-border);
    color: var(--text-color);
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.action-btn {
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: transform 0.1s, opacity 0.2s;
}

.action-btn:hover { transform: translateY(-2px); }
.action-btn:active { transform: translateY(0); }

.action-btn.share {
    background: var(--start-tile);
    color: white;
}

.action-btn.restart {
    background: var(--tile-bg);
    color: var(--text-color);
    border: 2px solid var(--tile-border);
}

/* Victory/Defeat specific styles */
.modal.victory h2 { color: #6aaa64; } /* Force Green */
.modal.defeat h2 { color: var(--present); } /* Or red if preferred */


/* In-Game Player List (Skribbl Style) */
#ingame-players-list {
    position: fixed;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    width: 200px;
    background: var(--tile-bg);
    border: 1px solid var(--tile-border);
    border-radius: 10px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 40;
    max-height: 80vh;
    overflow-y: auto;
}

.ingame-player-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: rgba(0,0,0,0.1);
    border-radius: 5px;
    border: 1px solid transparent;
}

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

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

.ingame-player-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.ingame-player-name {
    font-size: 0.9rem;
    font-weight: bold;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

/* Responsive: Hide on small screens or move to bottom */
@media (max-width: 1000px) {
    #ingame-players-list {
        display: none; /* Or move to a drawer */
    }
}

/* Sidebar Styles */
#ingame-sidebar {
    position: fixed;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    width: 220px;
    background: var(--tile-bg);
    border: 1px solid var(--tile-border);
    border-radius: 10px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    z-index: 40;
    max-height: 80vh;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

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

.room-code-box {
    display: flex;
    flex-direction: column;
}

.sidebar-actions {
    display: flex;
    gap: 5px;
}

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

/* Hide sidebar on mobile */
@media (max-width: 1000px) {
    #ingame-sidebar {
        display: none;
    }
}

/* Bounce Animation for Share Buttons */
@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {transform: translateY(0);}
    40% {transform: translateY(-5px);}
    60% {transform: translateY(-3px);}
}

.bounce {
    animation: bounce 0.5s;
}

/* --- MOBILE OPTIMIZATIONS --- */
@media (max-width: 600px) {
    h1 {
        font-size: 2.5rem; /* Reduce title size for mobile */
        margin-bottom: 1rem;
        word-break: break-word; /* Ensure it doesn't overflow */
    }

    body {
        overflow-y: auto; /* Allow scrolling */
        padding-top: 0;
        justify-content: flex-start;
    }

    .game-container {
        height: auto; /* Allow container to grow */
        min-height: 100vh;
        justify-content: flex-start; /* Stack from top */
        padding-top: 60px;
        padding-bottom: 20px;
        gap: 10px;
        width: 100%;
        max-width: 100%;
        overflow: visible; /* Allow content to flow */
    }

    /* Grid Adjustments */
    .grid {
        gap: 3px;
        flex-shrink: 1; /* Allow shrinking */
        max-height: 55vh; /* Limit height to leave room for keyboard */
        width: 100%;
        justify-content: center;
        padding: 0 5px; /* Add some padding */
    }

    .row {
        gap: 3px;
        width: 100%;
        justify-content: center;
    }

    .tile {
        /* Dynamic sizing based on column count to prevent overflow */
        /* 90vw total width / number of columns, minus gap approximation */
        width: calc((100vw - 20px) / var(--cols, 5) - 4px);
        height: calc((100vw - 20px) / var(--cols, 5) - 4px);
        
        /* Cap max size for larger mobile screens */
        max-width: 55px;
        max-height: 55px;
        
        font-size: 1.5rem;
        border-width: 2px;
    }

    /* Keyboard Adjustments */
    .keyboard {
        width: 100%;
        padding: 0 2px;
        gap: 4px;
        margin-bottom: 5px;
        flex-shrink: 0; /* Don't shrink keyboard */
    }

    .key-row {
        gap: 3px;
        width: 100%;
        justify-content: center;
    }

    .key {
        padding: 0;
        height: 52px; /* Taller touch targets */
        font-size: 1.1rem;
        border-radius: 4px;
        flex: 1; /* Distribute space evenly */
    }

    .key.large {
        font-size: 0.8rem;
        flex: 1.5;
    }

    /* Adjust Top Buttons */
    .theme-switch {
        top: 10px;
        right: 10px;
        padding: 6px 10px;
        font-size: 0.75rem;
    }

    .back-btn, .lobby-back-btn {
        top: 10px;
        left: 10px;
        padding: 6px 10px;
        font-size: 0.75rem;
    }
    
    /* Scale down reaction bar */
    .reaction-wrapper {
        right: 5px;
        transform: translateY(-50%) scale(0.8);
        transform-origin: right center;
    }

    /* Timer Display on Mobile (Overlay) */
    .timer-display {
        right: auto;
        left: 0;
        top: 0;
        transform: none;
        width: 100%;
        height: 100%;
        border-radius: 4px;
        background: rgba(220, 20, 60, 0.2);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 4rem;
        font-weight: 900;
        color: rgba(255, 255, 255, 0.3);
        text-shadow: none;
        pointer-events: none; /* Allow typing */
        box-shadow: inset 0 0 15px rgba(220, 20, 60, 0.2);
        animation: pulseMobile 2s infinite alternate ease-in-out;
        z-index: 20;
        /* backdrop-filter removed */
    }

    @keyframes pulseMobile {
        0% { 
            background: rgba(220, 20, 60, 0.2); 
            color: rgba(255, 255, 255, 0.3);
            box-shadow: inset 0 0 10px rgba(220, 20, 60, 0.2);
        }
        100% { 
            background: rgba(220, 20, 60, 0.25); 
            color: rgba(255, 255, 255, 0.35);
            box-shadow: inset 0 0 20px rgba(220, 20, 60, 0.3);
        }
    }
}
