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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.game-container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 24px;
    padding: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 450px;
    width: 90vw;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.game-title {
    font-size: 2.5em;
    font-weight: 800;
    background: linear-gradient(135deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -1px;
}

.score-container {
    background: #fafafa;
    border-radius: 12px;
    padding: 8px 16px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    text-align: center;
    min-width: 80px;
}

.score-label {
    font-size: 0.75em;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.score-value {
    font-size: 1.5em;
    font-weight: 700;
    color: #333;
}

.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.new-game-btn {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.new-game-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

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

.best-score-container {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #666;
    font-size: 0.85em;
}

.best-score-label {
    font-size: 0.75em;
}

.best-score-value {
    font-weight: 700;
    color: #333;
}

.game-board {
    background: #bbada0;
    border-radius: 12px;
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 8px;
    position: relative;
}

.tile {
    background: #eee4da;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2em;
    font-weight: 700;
    transition: all 0.15s ease;
    position: relative;
    overflow: hidden;
    /* Enable smooth transforms */
    will-change: transform;
}

/* Smooth movement transition */
.tile.moving {
    transition: transform 0.12s cubic-bezier(0.4, 0, 0.2, 1);
}

.tile::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.1), transparent);
    border-radius: 8px;
}

.tile-2 { background: #eee4da; }
.tile-4 { background: #ede0c8; }
.tile-8 { background: #f2b179; color: white; }
.tile-16 { background: #f59563; color: white; }
.tile-32 { background: #f67c5f; color: white; }
.tile-64 { background: #f65e3b; color: white; }
.tile-128 { background: #edcf72; color: white; }
.tile-256 { background: #edcc61; color: white; }
.tile-512 { background: #edc850; color: white; }
.tile-1024 { background: #edc53f; color: white; }
.tile-2048 { background: #edc22e; color: white; }

.tile-value {
    position: relative;
    z-index: 1;
}

.tile-new {
    animation: tileAppear 0.2s ease-out;
}

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

.tile-moving {
    animation: tileMove 0.12s cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

@keyframes tileMove {
    from {
        transform: translate(0, 0);
    }
    to {
        transform: translate(var(--tx, 0), var(--ty, 0));
    }
}

@keyframes tileSlideIn {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 12px;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.overlay.active {
    display: flex;
}

.overlay-content {
    text-align: center;
    color: white;
}

.overlay-content h2 {
    font-size: 2em;
    margin-bottom: 10px;
}

.overlay-content p {
    font-size: 1.2em;
    margin-bottom: 20px;
    opacity: 0.9;
}

.retry-btn {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 10px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

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

.instructions {
    text-align: center;
    margin-top: 15px;
    color: #666;
    font-size: 0.85em;
}

.instructions strong {
    background: #f5f5f5;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
}

/* Mobile optimizations */
@media (max-width: 480px) {
    .game-container {
        padding: 16px;
        border-radius: 20px;
    }

    .game-title {
        font-size: 2em;
    }

    .tile {
        font-size: 1.5em;
    }

    .instructions {
        font-size: 0.75em;
    }
}

/* iOS-style scrollbar */
.game-board::-webkit-scrollbar {
    display: none;
}