/* Variables */
:root {
    --primary-color: #776e65;
    --secondary-color: #bbada0;
    --background-color: #faf8ef;
    --grid-color: #bbada0;
    --tile-color: #eee4da;
    --text-light: #f9f6f2;
    --text-dark: #776e65;
    --glass-background: rgba(255, 255, 255, 0.25);
    --glass-border: rgba(255, 255, 255, 0.3);
    --glass-shadow: rgba(0, 0, 0, 0.1);
    --grid-size: min(80vw, 400px);
    --cell-size: calc(var(--grid-size) / 4 - 12px);
}

/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Arial', sans-serif;
}

body {
    background: linear-gradient(135deg, #faf8ef 0%, #eee4da 100%);
    color: var(--text-dark);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* Glass Panel Effect */
.glass-panel {
    background: var(--glass-background);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 15px;
    box-shadow: 0 8px 32px var(--glass-shadow);
    padding: 20px;
}

/* Game Container */
.game-container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.game-header {
    display: flex;
    justify-content: space-between;
    padding: 1rem;
    margin-bottom: 1rem;
    width: 100%;
}

.scores-container {
    display: flex;
    justify-content: space-between;
    padding: 1rem;
    margin-bottom: 1rem;
    width: 100%;
    max-width: 800px;
}

.player-info, .opponent-info {
    flex: 1;
    text-align: center;
}

.name {
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
    color: #776e65;
}

.score {
    font-size: 1.5rem;
    font-weight: bold;
    color: #776e65;
}

#player-name, #opponent-name {
    font-weight: bold;
    color: #f67c5f;
}

.score-container {
    font-size: 1.2rem;
    color: #776e65;
}

.score-container span {
    margin: 0 0.5rem;
}

#player-score, #opponent-score {
    font-weight: bold;
    color: #f67c5f;
}

.game-grids {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 2rem;
}

.grid-container {
    text-align: center;
}

.grid-container h3 {
    margin-bottom: 1rem;
    color: #776e65;
}

.game-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    background: var(--grid-color);
    border-radius: 8px;
    padding: 12px;
    aspect-ratio: 1;
}

.grid-cell {
    background: rgba(238, 228, 218, 0.35);
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2em;
    font-weight: bold;
    aspect-ratio: 1;
    transition: all 0.15s ease;
}

/* Grille de l'adversaire */
#opponent-grid {
    transform: scale(0.8);
    margin: -30px auto; /* Compenser l'espace créé par scale */
}

#opponent-grid .grid-cell {
    font-size: 0.9em;
}

.instructions {
    text-align: center;
    padding: 1rem;
    margin: 1rem auto;
    max-width: 600px;
    color: #776e65;
    font-size: 1.1rem;
    line-height: 1.5;
}

.scores-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    width: 100%;
    background: rgba(255, 255, 255, 0.9);
    position: sticky;
    top: 0;
    z-index: 10;
}

.score-box {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    color: #776e65;
    font-size: 0.9rem;
}

.score-box .player {
    font-weight: bold;
}

.score-box .score {
    background: #bbada0;
    color: white;
    padding: 0.2rem 0.5rem;
    border-radius: 1rem;
    font-weight: bold;
    min-width: 2.5rem;
    text-align: center;
}

.help-btn {
    background: #8f7a66;
    color: white;
    border: none;
    padding: 0.3rem 0.8rem;
    border-radius: 1rem;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background-color 0.2s;
}

@media (max-width: 768px) {
    .scores-header {
        flex-direction: row;
        padding: 0.3rem;
        gap: 0.3rem;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
    }

    .score-box {
        font-size: 0.8rem;
        flex: 1;
        justify-content: center;
        white-space: nowrap;
        overflow: hidden;
    }

    .score-box .player {
        max-width: 60px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .help-btn {
        padding: 0.2rem 0.5rem;
        font-size: 0.7rem;
    }

    .game-container {
        margin-top: 40px;
    }

    #game-grid {
        width: 100%;
        max-width: 350px;
        margin: 0 auto;
        margin-top: 150px;
    }

    #opponent-grid {
        width: 100%;
        max-width: 280px;
        transform: scale(0.7);
        margin: -45px auto;
    }
}

@media (max-width: 768px) {
    :root {
        --grid-size: min(90vw, 350px);
    }

    .game-container {
        padding: 10px;
    }

    .game-header {
        flex-direction: column;
        align-items: center;
        gap: 0.5rem;
    }

    .game-grids {
        flex-direction: column;
        gap: 1rem;
    }

    .grid-container {
        width: 100%;
    }

    .game-grid {
        width: 100%;
        max-width: 350px;
        margin: 0 auto;
    }

    .game-container {
        padding-bottom: 180px;
    }
}

/* Styles pour mobile */
@media (max-width: 768px) {
    html, body {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
        -webkit-overflow-scrolling: touch;
    }

    .grid {
        touch-action: none;
        -webkit-touch-callout: none;
        -ms-touch-callout: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: rgba(0,0,0,0);
        -webkit-text-size-adjust: none;
        -ms-text-size-adjust: none;
    }

    .game-container {
        touch-action: none;
        -webkit-touch-callout: none;
        -ms-touch-callout: none;
    }
}

/* Tile Styles */
.tile-2 { background: #eee4da; }
.tile-4 { background: #ede0c8; }
.tile-8 { background: #f2b179; color: var(--text-light); }
.tile-16 { background: #f59563; color: var(--text-light); }
.tile-32 { background: #f67c5f; color: var(--text-light); }
.tile-64 { background: #f65e3b; color: var(--text-light); }
.tile-128 { 
    background: #edcf72; 
    color: var(--text-light);
    font-size: 1.8em;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.2381), inset 0 0 0 1px rgba(255, 255, 255, 0.14286);
}
.tile-256 { 
    background: #edcc61; 
    color: var(--text-light);
    font-size: 1.8em;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.31746), inset 0 0 0 1px rgba(255, 255, 255, 0.19048);
}
.tile-512 { 
    background: #edc850; 
    color: var(--text-light);
    font-size: 1.8em;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.39683), inset 0 0 0 1px rgba(255, 255, 255, 0.2381);
}
.tile-1024 { 
    background: #edc53f; 
    color: var(--text-light);
    font-size: 1.5em;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.47619), inset 0 0 0 1px rgba(255, 255, 255, 0.28571);
}
.tile-2048 { 
    background: #edc22e; 
    color: var(--text-light);
    font-size: 1.5em;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.55556), inset 0 0 0 1px rgba(255, 255, 255, 0.33333);
}

/* Overlay et popup d'aide */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.overlay.show {
    display: flex;
}

.help-content {
    background: rgba(255, 255, 255, 0.95);
    padding: 2rem;
    border-radius: 1rem;
    text-align: center;
    max-width: 90%;
    width: 400px;
}

.help-content h3 {
    color: #776e65;
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

.help-content p {
    color: #776e65;
    line-height: 1.5;
    margin-bottom: 1.5rem;
}

.close-btn {
    background: #8f7a66;
    color: white;
    border: none;
    padding: 0.8rem 2rem;
    border-radius: 1rem;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s;
}

.close-btn:hover {
    background: #7f6a56;
}

/* Message Overlay */
.message-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.message-box {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
    text-align: center;
    max-width: 80%;
    width: 400px;
}

.message-box h3 {
    margin-bottom: 15px;
    color: var(--text-dark);
}

.message-box p {
    margin-bottom: 20px;
    color: var(--text-dark);
}

.message-box .btn {
    min-width: 100px;
}

/* Error Messages */
.error-message {
    color: #e74c3c;
    margin-top: 5px;
    font-size: 0.9em;
    text-align: center;
}

/* Success Messages */
.success-message {
    color: #27ae60;
    margin-top: 5px;
    font-size: 0.9em;
    text-align: center;
}

/* Info Messages */
.info-message {
    color: var(--text-dark);
    margin-top: 5px;
    font-size: 0.9em;
    text-align: center;
    padding: 10px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 5px;
}

/* Animations */
@keyframes slide-in {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.grid-cell {
    animation: slide-in 0.2s ease-out;
}

/* Responsive Design */
@media (max-width: 768px) {
    :root {
        --grid-size: min(90vw, 350px);
    }

    .game-container {
        padding: 10px;
    }

    .game-header {
        flex-direction: column;
        align-items: center;
        gap: 0.5rem;
    }

    .game-grids {
        flex-direction: column;
        gap: 1rem;
    }

    .grid-container {
        width: 100%;
    }

    .game-grid {
        width: 100%;
        max-width: 350px;
        margin: 0 auto;
    }

    .game-container {
        padding-bottom: 180px;
    }
}

/* Contrôles mobiles */
.mobile-controls {
    display: none;
    flex-direction: column;
    align-items: center;
    margin-top: 20px;
    gap: 10px;
}

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

.control-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

/* Afficher les contrôles uniquement sur mobile */
@media (max-width: 768px) {
    .mobile-controls {
        display: flex;
    }
}

/* Screens */
.screen {
    display: none;
    width: 100%;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    padding: 20px;
}

.screen.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.container {
    max-width: 500px;
    width: 100%;
    text-align: center;
}

/* Headers */
h1 {
    font-size: 48px;
    margin-bottom: 30px;
    color: var(--text-dark);
}

h2 {
    font-size: 36px;
    margin-bottom: 20px;
}

h3 {
    font-size: 24px;
    margin-bottom: 10px;
}

/* Input Fields */
input[type="text"] {
    width: 100%;
    padding: 15px;
    margin: 10px 0;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.8);
    font-size: 16px;
    text-align: center;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 5px;
    min-width: 120px;
}

.btn.primary {
    background: #8f7a66;
    color: var(--text-light);
}

.btn.secondary {
    background: var(--secondary-color);
    color: var(--text-light);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

/* Loader */
.loader {
    width: 48px;
    height: 48px;
    border: 5px solid var(--secondary-color);
    border-bottom-color: transparent;
    border-radius: 50%;
    display: inline-block;
    animation: rotation 1s linear infinite;
    margin: 20px auto;
}

@keyframes rotation {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Toast Container */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
}

.toast {
    background: var(--glass-background);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 12px 24px;
    margin-top: 10px;
    color: var(--text-dark);
    animation: slideIn 0.3s ease forwards;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Responsive Design */
@media (max-width: 500px) {
    .container {
        padding: 10px;
    }

    h1 {
        font-size: 36px;
    }

    .game-grid {
        gap: 5px;
        padding: 5px;
    }

    .grid-cell {
        font-size: 20px;
    }
}

/* Touch Feedback */
@media (hover: hover) {
    .control-btn:hover {
        transform: scale(1.1);
        background: var(--primary-color);
    }
}

/* Animations */
.new-tile {
    animation: pop 0.2s ease-in-out;
}

@keyframes pop {
    0% { transform: scale(0); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* Résultats de jeu */
.result-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.result-container {
    background: white;
    padding: 2rem;
    border-radius: 1rem;
    text-align: center;
    max-width: 90%;
    width: 400px;
}

.result-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.result-message {
    font-size: 1.5rem;
    margin: 1rem 0;
    color: #333;
}

.winner {
    color: #f1c40f;
}

.loser {
    color: #e74c3c;
}

.controls-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
}

#play-again {
    margin-top: 1rem;
    padding: 0.75rem 1.5rem;
    font-size: 1.1rem;
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

#play-again:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

#play-again:active {
    transform: translateY(0);
}

/* Room styles */
.room-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin: 1rem 0;
}

.room-info .code {
    font-size: 1.5rem;
    font-weight: bold;
    color: #776e65;
    background: rgba(238, 228, 218, 0.35);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    letter-spacing: 2px;
}

.players-info {
    margin: 1.5rem 0;
}

.player {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.player .label {
    font-weight: bold;
    color: #776e65;
}

.btn.small {
    padding: 0.3rem 0.8rem;
    font-size: 0.9rem;
}

.error-message {
    color: #e74c3c;
    font-size: 0.9rem;
    margin-top: 0.5rem;
    min-height: 1.2em;
}

#room-id-input {
    text-align: center;
    font-size: 1.2rem;
    letter-spacing: 2px;
    text-transform: uppercase;
}

/* Loader animation */
.loader {
    width: 48px;
    height: 48px;
    border: 5px solid #eee4da;
    border-bottom-color: #776e65;
    border-radius: 50%;
    display: inline-block;
    box-sizing: border-box;
    animation: rotation 1s linear infinite;
    margin: 1rem 0;
}

@keyframes rotation {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Room key styles */
.room-key {
    text-align: center;
    margin: 1.5rem 0;
}

.key-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin: 1rem 0;
    background: rgba(238, 228, 218, 0.35);
    padding: 1rem;
    border-radius: 0.5rem;
}

.key-text {
    font-family: monospace;
    font-size: 2rem;
    font-weight: bold;
    color: #776e65;
    letter-spacing: 4px;
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 0.5rem;
    min-width: 12ch;
    text-align: center;
    display: inline-block;
}

#room-key:empty::before {
    content: "------";
    color: #ccc;
}

#copy-key {
    min-width: 80px;
    background-color: #8f7a66;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 0.3rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

#copy-key:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#copy-key:not(:disabled):hover {
    background-color: #776e65;
}

.copy-text {
    display: inline-block;
    min-width: 3rem;
}

.player.waiting {
    opacity: 0.7;
}

.waiting-text {
    text-align: center;
    color: #776e65;
    margin: 1rem 0;
    font-style: italic;
}

/* Join room screen */
#room-key-input {
    font-family: monospace;
    font-size: 1.5rem;
    text-align: center;
    letter-spacing: 3px;
    padding: 0.8rem;
    width: 100%;
    max-width: 200px;
    margin: 0 auto;
    display: block;
    text-transform: uppercase;
}

.form-group label {
    display: block;
    text-align: center;
    margin-bottom: 0.5rem;
    color: #776e65;
    font-weight: bold;
}

.error-message {
    color: #e74c3c;
    text-align: center;
    margin-top: 0.5rem;
    min-height: 1.2em;
    font-size: 0.9rem;
}
