/* Apple-inspired color palette and modern design */
:root {
    --primary-blue: #007AFF;
    --secondary-blue: #5AC8FA;
    --green: #34C759;
    --yellow: #FFCC00;
    --orange: #FF9500;
    --red: #FF3B30;
    --pink: #FF2D92;
    --purple: #AF52DE;
    --teal: #5AC8FA;
    --indigo: #5856D6;
    --gray-1: #8E8E93;
    --gray-2: #AEAEB2;
    --gray-3: #C7C7CC;
    --gray-4: #D1D1D6;
    --gray-5: #E5E5EA;
    --gray-6: #F2F2F7;
    --background: #FAFAFA;
    --text-dark: #1D1D1F;
    --text-light: #86868B;
    --grid-bg: #BBADA0;
    --cell-bg: rgba(238, 228, 218, 0.35);
}



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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, var(--background) 0%, var(--gray-6) 100%);
    color: var(--text-dark);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    max-width: 500px;
    width: 100%;
    text-align: center;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
    position: relative;
}



.title {
    font-size: 3.5rem;
    font-weight: 700;
    background: linear-gradient(45deg, var(--primary-blue), var(--secondary-blue), var(--green), var(--yellow));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    margin: 0;
}

.score-container {
    display: flex;
    gap: 10px;
}

.score-box {
    background: var(--green);
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    min-width: 80px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease;
}

.score-box:hover {
    transform: translateY(-2px);
}

.score-box.best {
    background: var(--yellow);
    color: var(--text-dark);
}

.score-label {
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 2px;
}

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

.game-intro {
    margin-bottom: 20px;
}

.game-intro p {
    font-size: 1.1rem;
    color: var(--text-light);
    margin-bottom: 10px;
}

.game-controls {
    margin: 20px 0;
}

.instructions {
    background: var(--gray-6);
    padding: 12px 15px;
    border-radius: 12px;
    margin: 15px 0 20px 0;
    text-align: left;
}

.instructions p {
    font-size: 0.9rem;
    line-height: 1.3;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 4px;
    margin: 0;
}

.arrow-key {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--background);
    border: 2px solid var(--gray-3);
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dark);
    margin: 0 2px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.swipe-emoji {
    font-size: 1.2em;
    margin: 0 4px;
}

.new-game-btn {
    background: var(--primary-blue);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}

.new-game-btn:hover {
    background: #0056CC;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.4);
}

.game-container {
    position: relative;
    background: var(--grid-bg);
    border-radius: 12px;
    padding: 10px;
    margin: 0 auto 20px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-gap: 10px;
    position: relative;
    z-index: 1;
}

.grid-cell {
    background: var(--cell-bg);
    border-radius: 6px;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tile-container {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    bottom: 10px;
    z-index: 2;
}

.tile {
    position: absolute;
    border-radius: 6px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.4s ease-in-out;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    font-size: 2rem;
}

/* Tile colors inspired by Apple's design system */
.tile-2 { background: var(--secondary-blue); color: white; }
.tile-4 { background: var(--red); color: white; }
.tile-8 { background: var(--yellow); color: var(--text-dark); }
.tile-16 { background: var(--green); color: white; }
.tile-32 { background: var(--pink); color: white; }
.tile-64 { background: var(--teal); color: white; }
.tile-128 { background: var(--orange); color: white; font-size: 1.8rem; }
.tile-256 { background: var(--purple); color: white; font-size: 1.8rem; }
.tile-512 { background: var(--indigo); color: white; font-size: 1.8rem; }
.tile-1024 { background: var(--primary-blue); color: white; font-size: 1.5rem; }
.tile-2048 { background: linear-gradient(45deg, var(--yellow), var(--orange)); color: white; font-size: 1.5rem; }

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

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

@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 {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(5px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.game-message.show {
    display: flex;
}

.message-content {
    background: white;
    padding: 40px;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    text-align: center;
    max-width: 300px;
}

.message-content h2 {
    color: var(--text-dark);
    margin-bottom: 15px;
    font-size: 1.8rem;
}

.message-content p {
    color: var(--text-light);
    margin-bottom: 25px;
}

.try-again-btn {
    background: var(--primary-blue);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.try-again-btn:hover {
    background: #0056CC;
}

.mobile-controls {
    margin-top: 20px;
}

.swipe-hint {
    color: var(--text-light);
    font-size: 0.9rem;
    display: none;
}

/* Responsive design */
@media (max-width: 600px) {
    .container {
        padding: 10px;
    }
    
    .title {
        font-size: 2.5rem;
    }
    
    header {
        justify-content: center;
        text-align: center;
    }
    
    .score-container {
        justify-content: center;
    }
    
    .tile {
        font-size: 1.5rem;
    }
    
    .tile-128, .tile-256, .tile-512 {
        font-size: 1.3rem;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 1.1rem;
    }
    
    .swipe-hint {
        display: block;
    }
    
    .instructions {
        font-size: 0.85rem;
    }
}

@media (max-width: 400px) {
    .title {
        font-size: 2rem;
    }
    
    .tile {
        font-size: 1.2rem;
    }
    
    .tile-128, .tile-256, .tile-512 {
        font-size: 1rem;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 0.9rem;
    }
}