:root {
    --primary-color: #776e65;
    --secondary-color: #bbada0;
    --background-color: #faf8ef;
    --grid-color: #bbada0;
    --text-light: #f9f6f2;
    --button-color: #8f7a66;
}

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

body {
    font-family: 'Arial', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    background-color: var(--background-color);
    color: var(--primary-color);
}

.container {
    max-width: 600px;
    width: 100%;
    padding: 15px;
    margin: auto;
}

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

.brand h1 {
    font-size: 48px;
    font-weight: bold;
    margin: 0;
}

.stats {
    display: flex;
    gap: 10px;
}

.score-container, .best-container {
    background-color: var(--secondary-color);
    color: var(--text-light);
    padding: 10px 15px;
    border-radius: 5px;
    text-align: center;
    min-width: 100px;
}

.button {
    background-color: var(--button-color);
    color: var(--text-light);
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.button:hover {
    filter: brightness(1.1);
}

.ad-container {
    width: 100%;
    max-width: 728px;
    margin: 20px auto;
    min-height: 90px;
    background: #f8f8f8;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 8px;
    overflow: hidden;
}

#top-ad {
    margin-bottom: 30px;
}

#bottom-ad {
    margin-top: 30px;
}

.game-container {
    background-color: var(--grid-color);
    border-radius: 5px;
    padding: 15px;
    position: relative;
}

#grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    width: 100%;
    aspect-ratio: 1;
    background-color: var(--grid-color);
}

.tile {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    font-weight: bold;
    border-radius: 5px;
    transition: all 0.15s ease-in-out;
    position: relative;
    transform-origin: center;
}

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

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

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

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

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

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(238, 228, 218, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    text-align: center;
    padding: 20px;
}

.share-buttons {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    justify-content: center;
}

.share-button {
    padding: 8px 15px;
    border: none;
    border-radius: 5px;
    color: white;
    cursor: pointer;
}

.share-button.twitter {
    background-color: #1DA1F2;
}

.share-button.facebook {
    background-color: #4267B2;
}

.footer {
    margin-top: 30px;
    text-align: center;
    font-size: 14px;
}

.footer-links {
    margin-top: 10px;
}

.footer-links a {
    color: var(--primary-color);
    text-decoration: none;
    margin: 0 10px;
}

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

.modal.hidden {
    display: none;
}

.modal-content {
    background-color: white;
    padding: 20px;
    border-radius: 5px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.close {
    position: absolute;
    right: 15px;
    top: 10px;
    font-size: 24px;
    cursor: pointer;
}

.mobile-show {
    display: none;
}

@media (max-width: 600px) {
    .container {
        padding: 10px;
    }

    .header {
        flex-direction: column;
        align-items: stretch;
    }

    .brand h1 {
        font-size: 36px;
        text-align: center;
    }

    .controls {
        display: flex;
        justify-content: center;
        gap: 10px;
    }

    .mobile-show {
        display: block;
    }

    .tile {
        font-size: 20px;
    }

    .tile-128, .tile-256, .tile-512 {
        font-size: 18px;
    }

    .tile-1024, .tile-2048 {
        font-size: 16px;
    }
}
