/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    color: #333;
}

/* Header Styles */
.header {
    text-align: center;
    margin-bottom: 30px;
}

.title {
    font-size: 3.5rem;
    font-weight: bold;
    color: white;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    margin-bottom: 10px;
}

.subtitle {
    color: rgba(255,255,255,0.9);
    font-size: 1.1rem;
    margin-bottom: 20px;
}

/* Score Container */
.score-container {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.score-box {
    background: rgba(255,255,255,0.9);
    padding: 15px 25px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

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

.score-value {
    font-size: 1.8rem;
    font-weight: bold;
    color: #333;
}

/* Control Buttons */
.controls {
    display: flex;
    gap: 15px;
    margin-bottom: 30px;
    flex-wrap: wrap;
    justify-content: center;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.btn-primary {
    background: #4CAF50;
    color: white;
}

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

.btn-warning {
    background: #FF9800;
    color: white;
}

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

.btn:active {
    transform: translateY(0);
}

/* Game Container and Grid */
.game-container {
    background: rgba(255,255,255,0.95);
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.grid-container {
    background: #bbada0;
    border-radius: 10px;
    padding: 10px;
    position: relative;
    width: 320px;
    height: 320px;
}

.grid-row {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.grid-row:last-child {
    margin-bottom: 0;
}

.grid-cell {
    width: 70px;
    height: 70px;
    background: rgba(238, 228, 218, 0.35);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: bold;
    position: relative;
    transition: all 0.15s ease-in-out;
}

/* Tile Styles */
.tile {
    position: absolute;
    width: 70px;
    height: 70px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: bold;
    transition: all 0.15s ease-in-out;
    animation: tileAppear 0.2s ease-in-out;
}

/* Animations */
@keyframes tileAppear {
    0% {
        transform: scale(0);
    }
    100% {
        transform: scale(1);
    }
}

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

.tile-merged {
    animation: tileMerge 0.3s ease-in-out;
}

/* Tile Colors */
.tile-2 { 
    background: #eee4da; 
    color: #776e65; 
}

.tile-4 { 
    background: #ede0c8; 
    color: #776e65; 
}

.tile-8 { 
    background: #f2b179; 
    color: #f9f6f2; 
}

.tile-16 { 
    background: #f59563; 
    color: #f9f6f2; 
}

.tile-32 { 
    background: #f67c5f; 
    color: #f9f6f2; 
}

.tile-64 { 
    background: #f65e3b; 
    color: #f9f6f2; 
}

.tile-128 { 
    background: #edcf72; 
    color: #f9f6f2; 
    font-size: 1.8rem; 
}

.tile-256 { 
    background: #edcc61; 
    color: #f9f6f2; 
    font-size: 1.8rem; 
}

.tile-512 { 
    background: #edc850; 
    color: #f9f6f2; 
    font-size: 1.8rem; 
}

.tile-1024 { 
    background: #edc53f; 
    color: #f9f6f2; 
    font-size: 1.5rem; 
}

.tile-2048 { 
    background: #edc22e; 
    color: #f9f6f2; 
    font-size: 1.5rem; 
    box-shadow: 0 0 30px #edc22e; 
}

/* Instructions */
.instructions {
    margin-top: 30px;
    text-align: center;
    color: rgba(255,255,255,0.9);
    max-width: 400px;
}

.instructions h3 {
    margin-bottom: 10px;
    font-size: 1.3rem;
}

.instructions p {
    line-height: 1.6;
    margin-bottom: 10px;
}

/* Overlay Styles */
.game-over-overlay, 
.win-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.overlay-content {
    background: white;
    padding: 40px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0,0,0,0.3);
}

.overlay-content h2 {
    font-size: 2.5rem;
    margin-bottom: 20px;
    color: #333;
}

.overlay-content p {
    font-size: 1.2rem;
    margin-bottom: 30px;
    color: #666;
}

/* Responsive Design */
@media (max-width: 480px) {
    .title {
        font-size: 2.5rem;
    }
    
    .grid-container {
        width: 280px;
        height: 280px;
    }
    
    .grid-cell, .tile {
        width: 60px;
        height: 60px;
        font-size: 1.5rem;
    }
    
    .tile-128, .tile-256, .tile-512 {
        font-size: 1.3rem;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 1.1rem;
    }
    
    .score-container {
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }
    
    .controls {
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }
    
    .btn {
        width: 200px;
    }
}