:root {
    --bg-color: #faf8ef;
    --text-color: #776e65;
    --grid-bg: #bbada0;
    --cell-bg: rgba(238, 228, 218, 0.35);
    --tile-bg: #eee4da;
}

body {
    font-family: "Clear Sans", "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    padding: 20px;
    background: var(--bg-color);
    color: var(--text-color);
    transition: all 0.3s ease;
    touch-action: manipulation;
}

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

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

.title {
    font-size: 80px;
    font-weight: bold;
    margin: 0;
    color: #776e65;
}

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

.sound-container {
    display: flex;
    justify-content: flex-start;
    margin-top: 10px;
    margin-left: calc(50% - 250px + 50px);
}

.sound-toggle {
    background: #8f7a66;
    color: #f9f6f2;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sound-toggle:hover {
    background: #9f8a76;
    transform: scale(1.1);
}

.sound-toggle.muted {
    opacity: 0.5;
}

.score-box {
    background: #bbada0;
    padding: 10px 14px;
    border-radius: 3px;
    color: white;
    text-align: center;
    min-width: 50px;
}

.score-label {
    font-size: 13px;
    font-weight: bold;
}

#score {
    font-size: 25px;
    font-weight: bold;
}

.game-container {
    position: relative;
    background: var(--grid-bg);
    border-radius: 6px;
    width: 500px;
    height: 500px;
    box-sizing: border-box;
    padding: 10px;
    transition: transform 0.1s ease-in-out;
}

.grid-container {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 1;
}

.grid-row {
    display: flex;
    margin-bottom: 10px;
}

.grid-row:last-child {
    margin-bottom: 0;
}

.grid-cell {
    width: 107px;
    height: 107px;
    background: var(--cell-bg);
    border-radius: 3px;
    margin-right: 10px;
}

.grid-cell:last-child {
    margin-right: 0;
}

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

.tile {
    position: absolute;
    width: 107px;
    height: 107px;
    background: var(--tile-bg);
    border-radius: 3px;
    font-weight: bold;
    text-align: center;
    line-height: 107px;
    font-size: 55px;
    transition: all 0.15s ease-in-out;
}

.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: 45px; }
.tile-256 { background: #edcc61; color: #f9f6f2; font-size: 45px; }
.tile-512 { background: #edc850; color: #f9f6f2; font-size: 45px; }
.tile-1024 { background: #edc53f; color: #f9f6f2; font-size: 35px; }
.tile-2048 { background: #edc22e; color: #f9f6f2; font-size: 35px; }

.game-explanation {
    margin-top: 30px;
    line-height: 1.65;
}



.button-container {
    display: flex;
    gap: 5px;
    margin-top: 20px;
    justify-content: center;
}

.restart-button, .share-button, .theme-button, .leaderboard-button {
    background: #8f7a66;
    color: #f9f6f2;
    border: none;
    border-radius: 3px;
    padding: 8px 18px;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.2s;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.restart-button:hover, .share-button:hover, .theme-button:hover, .leaderboard-button:hover {
    background: #9f8a76;
}

.leaderboard {
    margin-top: 30px;
    background: var(--tile-bg);
    border-radius: 6px;
    padding: 20px;
    max-width: 500px;
    transition: all 0.3s ease;
}

.leaderboard.hidden {
    display: none;
}

.leaderboard h3 {
    margin-top: 0;
    text-align: center;
    color: var(--text-color);
}

.leaderboard-entry {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    margin: 5px 0;
    background: var(--cell-bg);
    border-radius: 3px;
}

.submit-score {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.submit-score > div {
    display: flex;
    gap: 10px;
}

.submit-score input {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--grid-bg);
    border-radius: 3px;
    background: var(--bg-color);
    color: var(--text-color);
}

.submit-score button {
    background: #8f7a66;
    color: #f9f6f2;
    border: none;
    border-radius: 3px;
    padding: 10px 20px;
    cursor: pointer;
}

.submit-score button:hover {
    background: #9f8a76;
}

.submit-info {
    font-size: 12px;
    color: var(--text-color);
    opacity: 0.7;
    margin: 0;
    text-align: center;
}

/* Dark Theme */
body.theme-dark {
    --bg-color: #1a1a1a;
    --text-color: #ffffff;
    --grid-bg: #2d2d2d;
    --cell-bg: rgba(255, 255, 255, 0.1);
    --tile-bg: #3d3d3d;
}

/* Neon Theme */
body.theme-neon {
    --bg-color: #000011;
    --text-color: #00ffff;
    --grid-bg: #001122;
    --cell-bg: rgba(0, 255, 255, 0.1);
    --tile-bg: #002244;
}

body.theme-neon .tile {
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.3);
    color: #00ffff;
}

.restart-button:hover {
    background: #9f8a76;
}

.ripple {
    position: absolute;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    animation: ripple-animation 0.6s ease-out;
    pointer-events: none;
    z-index: 10;
}

@keyframes ripple-animation {
    0% {
        transform: scale(0);
        opacity: 1;
    }
    100% {
        transform: scale(3);
        opacity: 0;
    }
}

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

.milestone-popup.hidden {
    display: none;
}

.milestone-content {
    background: var(--bg-color);
    padding: 40px;
    border-radius: 10px;
    text-align: center;
    max-width: 300px;
    animation: milestone-bounce 0.5s ease-out;
}

.milestone-content h2 {
    margin-top: 0;
    color: var(--text-color);
    font-size: 24px;
}

#milestone-tile {
    width: 80px;
    height: 80px;
    background: #f67c5f;
    color: #f9f6f2;
    border-radius: 6px;
    font-size: 32px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 20px auto;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.milestone-content p {
    color: var(--text-color);
    font-size: 18px;
    margin: 20px 0;
}

.milestone-content button {
    background: #8f7a66;
    color: #f9f6f2;
    border: none;
    border-radius: 3px;
    padding: 12px 24px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.2s;
}

.milestone-content button:hover {
    background: #9f8a76;
}

@keyframes milestone-bounce {
    0% {
        transform: scale(0.3);
        opacity: 0;
    }
    50% {
        transform: scale(1.05);
    }
    70% {
        transform: scale(0.9);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

