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

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #3b82f6;
    --accent: #0ea5e9;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.07);
}

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

.game-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.game-container {
    background: white;
    border-radius: 20px;
    padding: 2rem;
    max-width: 500px;
    width: 100%;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border);
}

.game-header h1 {
    font-size: 1.8rem;
    color: var(--primary);
    font-weight: 700;
}

.back-btn {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 600;
    transition: color 0.3s ease;
    padding: 0.5rem 1rem;
    border-radius: 8px;
}

.back-btn:hover {
    color: var(--primary);
    background: var(--bg-secondary);
}

.game-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.game-info {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.score-container {
    display: flex;
    gap: 1rem;
    width: 100%;
    justify-content: center;
}

.score-box {
    background: var(--bg-tertiary);
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    text-align: center;
    flex: 1;
    max-width: 150px;
}

.score-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.score-value {
    display: block;
    font-size: 1.5rem;
    color: var(--primary);
    font-weight: 700;
}

.game-controls {
    display: flex;
    justify-content: center;
}

.game-btn {
    padding: 0.75rem 2rem;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.game-btn-primary {
    background: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(37, 99, 235, 0.3);
}

.game-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4);
}

.game-btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(37, 99, 235, 0.3);
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    background: var(--bg-tertiary);
    padding: 10px;
    border-radius: 10px;
    width: 100%;
    aspect-ratio: 1;
    position: relative;
}

.grid-cell {
    background: var(--bg-secondary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
    transition: all 0.15s ease;
    position: relative;
}

.grid-cell[data-value="2"] { background: #eee4da; color: #776e65; }
.grid-cell[data-value="4"] { background: #ede0c8; color: #776e65; }
.grid-cell[data-value="8"] { background: #f2b179; color: #f9f6f2; }
.grid-cell[data-value="16"] { background: #f59563; color: #f9f6f2; }
.grid-cell[data-value="32"] { background: #f67c5f; color: #f9f6f2; }
.grid-cell[data-value="64"] { background: #f65e3b; color: #f9f6f2; }
.grid-cell[data-value="128"] { background: #edcf72; color: #f9f6f2; font-size: 1.75rem; }
.grid-cell[data-value="256"] { background: #edcc61; color: #f9f6f2; font-size: 1.75rem; }
.grid-cell[data-value="512"] { background: #edc850; color: #f9f6f2; font-size: 1.75rem; }
.grid-cell[data-value="1024"] { background: #edc53f; color: #f9f6f2; font-size: 1.5rem; }
.grid-cell[data-value="2048"] { background: #edc22e; color: #f9f6f2; font-size: 1.5rem; }
.grid-cell[data-value="4096"] { background: #3c3a32; color: #f9f6f2; font-size: 1.5rem; }
.grid-cell[data-value="8192"] { background: #3c3a32; color: #f9f6f2; font-size: 1.5rem; }

.grid-cell.new {
    animation: appear 0.2s ease;
}

.grid-cell.merged {
    animation: pop 0.2s ease;
}

@keyframes appear {
    0% {
        opacity: 0;
        transform: scale(0);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

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

.game-message {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 2rem;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    z-index: 10;
}

.game-message.show {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.game-message p {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.mobile-controls {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
}

.mobile-row {
    display: flex;
    gap: 0.5rem;
}

.mobile-btn {
    width: 60px;
    height: 60px;
    border: 2px solid var(--primary);
    background: white;
    border-radius: 10px;
    font-size: 1.5rem;
    color: var(--primary);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

.mobile-btn:active {
    background: var(--primary);
    color: white;
    transform: scale(0.9);
}

.game-instructions {
    width: 100%;
    text-align: center;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 10px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

@media (max-width: 768px) {
    body {
        padding: 5px;
    }

    .game-container {
        padding: 1rem;
        max-width: 100%;
    }

    .game-header {
        margin-bottom: 1rem;
    }

    .game-header h1 {
        font-size: 1.3rem;
    }

    .back-btn {
        font-size: 0.85rem;
        padding: 0.4rem 0.8rem;
    }

    .score-container {
        gap: 0.5rem;
    }

    .score-box {
        padding: 0.5rem 1rem;
    }

    .score-value {
        font-size: 1.2rem;
    }

    .grid-container {
        gap: 8px;
        padding: 8px;
    }

    .grid-cell {
        font-size: 1.5rem;
        border-radius: 6px;
    }

    .mobile-controls {
        display: flex;
    }

    .mobile-btn {
        width: 55px;
        height: 55px;
        font-size: 1.3rem;
    }

    .game-instructions {
        font-size: 0.8rem;
        padding: 0.75rem;
    }
}

@media (max-width: 480px) {
    .game-header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .back-btn {
        width: 100%;
        text-align: center;
    }

    .mobile-btn {
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }
}
