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

body {
    font-family: 'Segoe UI', -apple-system, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.back-home {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1000;
}

.back-home a {
    color: white;
    text-decoration: none;
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 25px;
    backdrop-filter: blur(10px);
    transition: all 0.3s;
}

.back-home a:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateX(-5px);
}

.game-container {
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 100%;
}

.game-header h1 {
    text-align: center;
    color: #667eea;
    margin-bottom: 20px;
    font-size: 2.5rem;
}

.score-board {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 20px;
}

.score-item {
    text-align: center;
}

.score-item .label {
    display: block;
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 5px;
}

.score-item .value {
    display: block;
    color: #667eea;
    font-size: 2rem;
    font-weight: bold;
}

.game-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.btn {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
    transform: translateY(-2px);
}

.btn-secondary {
    background: #f093fb;
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #e080e8;
}

.btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#gameContainer {
    position: relative;
    user-select: none;
}

#gridContainer {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    background-color: #bbada0;
    padding: 10px;
    border-radius: 8px;
}

.grid-cell {
    background-color: rgba(238, 228, 218, 0.35);
    border-radius: 6px;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.tile {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: bold;
    border-radius: 6px;
    animation: appear 0.2s;
}

@keyframes appear {
    from { transform: scale(0); }
    to { transform: scale(1); }
}

.tile-2 { background-color: #eee4da; color: #776e65; }
.tile-4 { background-color: #ede0c8; color: #776e65; }
.tile-8 { background-color: #f2b179; color: #f9f6f2; }
.tile-16 { background-color: #f59563; color: #f9f6f2; }
.tile-32 { background-color: #f67c5f; color: #f9f6f2; }
.tile-64 { background-color: #f65e3b; color: #f9f6f2; }
.tile-128 { background-color: #edcf72; color: #f9f6f2; font-size: 28px; }
.tile-256 { background-color: #edcc61; color: #f9f6f2; font-size: 28px; }
.tile-512 { background-color: #edc850; color: #f9f6f2; font-size: 28px; }
.tile-1024 { background-color: #edc53f; color: #f9f6f2; font-size: 24px; }
.tile-2048 { background-color: #edc22e; color: #f9f6f2; font-size: 24px; }

.game-message {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(238, 228, 218, 0.95);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
    color: #776e65;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 10;
}

.game-message.show {
    opacity: 1;
    pointer-events: auto;
}

.game-message.win-message {
    background-color: rgba(237, 194, 46, 0.95);
    color: white;
}

.game-message.lose-message {
    background-color: rgba(143, 122, 102, 0.95);
    color: white;
}

.instructions {
    margin-top: 20px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
}

.instructions h3 {
    color: #333;
    margin-bottom: 10px;
}

.instructions p {
    color: #666;
    line-height: 1.6;
}

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

.key-hints div {
    display: flex;
    align-items: center;
    gap: 8px;
}

kbd {
    padding: 4px 8px;
    background: #667eea;
    color: white;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9rem;
}

@media (max-width: 500px) {
    .game-container {
        padding: 15px;
    }

    #gridContainer {
        gap: 8px;
        padding: 8px;
    }

    .tile {
        font-size: 24px;
    }

    .tile-128, .tile-256, .tile-512 {
        font-size: 20px;
    }

    .tile-1024, .tile-2048 {
        font-size: 18px;
    }
}
