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

:root {
    --primary: #6366f1;
    --secondary: #8b5cf6;
    --bg: #faf8ef;
    --grid-bg: #bbada0;
    --empty-cell: #cdc1b4;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    min-height: 100vh;
    padding: 1rem;
}

.container {
    max-width: 500px;
    margin: 0 auto;
}

.header {
    text-align: center;
    margin-bottom: 2rem;
    position: relative;
}

.back-btn {
    position: absolute;
    left: 0;
    top: 0;
    background: white;
    color: var(--primary);
    padding: 0.75rem 1.5rem;
    border-radius: 12px;
    border: 2px solid var(--primary);
    text-decoration: none;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 48px;
}

.back-btn:hover {
    transform: translateX(-5px);
    background: var(--primary);
    color: white;
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.back-btn:active {
    transform: translateX(-3px) scale(0.98);
}

.brand h1 {
    color: white;
    font-size: 3rem;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.brand-text {
    color: rgba(255,255,255,0.9);
    font-size: 0.9rem;
}

.game-container {
    background: white;
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.score-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1rem;
}

.action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.action-btn {
    padding: 0.75rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.action-btn:hover {
    background: var(--secondary);
    transform: translateY(-2px);
}

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

.hint-btn {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
}

.hint-btn:hover {
    background: linear-gradient(135deg, #f59e0b, #d97706);
}

.score-box {
    flex: 1;
    background: var(--grid-bg);
    padding: 1rem;
    border-radius: 10px;
    text-align: center;
}

.score-label {
    color: #eee4da;
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
}

.score-value {
    color: white;
    font-size: 2rem;
    font-weight: 700;
}

.new-game-btn {
    width: 100%;
    padding: 1rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 1rem;
    transition: all 0.3s;
}

.new-game-btn:hover {
    transform: scale(1.02);
    box-shadow: 0 5px 20px rgba(99, 102, 241, 0.4);
}

.grid-container {
    background: var(--grid-bg);
    border-radius: 10px;
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 1rem;
    position: relative;
}

.cell {
    aspect-ratio: 1;
    background: var(--empty-cell);
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
    transition: all 0.15s ease;
}

.tile {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
    border-radius: 5px;
    transition: all 0.15s ease;
    animation: appear 0.2s;
}

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

.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; }
.tile-super { background: #3c3a32; color: #f9f6f2; font-size: 1.2rem; }

.instructions {
    text-align: center;
    color: #776e65;
    font-size: 0.9rem;
    line-height: 1.6;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: white;
    padding: 3rem;
    border-radius: 20px;
    text-align: center;
    animation: scaleIn 0.3s;
}

.modal-content h2 {
    font-size: 2rem;
    margin-bottom: 1rem;
    color: var(--primary);
}

.final-score {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 1rem 0;
}

.modal-btn {
    padding: 1rem 2rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin: 0.5rem;
}

@keyframes scaleIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@media (max-width: 500px) {
    .header {
        margin-bottom: 1.5rem;
    }
    
    .back-btn {
        position: relative;
        left: auto;
        top: auto;
        margin-bottom: 1rem;
        width: 100%;
        justify-content: center;
        padding: 1rem;
        font-size: 1.1rem;
    }
    
    .brand {
        text-align: center;
    }
    
    .brand h1 {
        font-size: 2.5rem;
    }
    
    .tile, .cell {
        font-size: 1.5rem;
    }
    
    .tile-128, .tile-256, .tile-512 {
        font-size: 1.3rem;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 1.1rem;
    }
}
