/**
 * 2048 Game Styles
 */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #faf8ef;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    touch-action: none;
}

.game-container {
    width: 100%;
    max-width: 400px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.title {
    font-size: 2.5rem;
    font-weight: 700;
    color: #776e65;
}

.scores {
    display: flex;
    gap: 0.5rem;
}

.score-box {
    background: #bbada0;
    border-radius: 6px;
    padding: 0.5rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 70px;
}

.score-box .label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #eee4da;
    text-transform: uppercase;
}

.score-box .value {
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
}

.instruction {
    color: #776e65;
    font-size: 1rem;
}

/* Grid container */
.grid {
    position: relative;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    background: #bbada0;
    border-radius: 8px;
    padding: 10px;
    width: 100%;
    aspect-ratio: 1;
}

/* Background cells */
.cell-bg {
    background: rgba(238, 228, 218, 0.35);
    border-radius: 6px;
    aspect-ratio: 1;
}

/* Animated tiles */
.tile {
    position: absolute;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: 700;
    color: #776e65;
    background: #eee4da;
    z-index: 10;
}

/* Slide animation with subtle bounce */
.tile-moving {
    transition: top 150ms ease-out, left 150ms ease-out;
}

/* New tile pop-in */
.tile-new {
    animation: tile-appear 200ms ease-out;
}

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

/* Merged tile bounce */
.tile-merged {
    animation: tile-bounce 200ms ease-out;
}

@keyframes tile-bounce {
    0% {
        transform: scale(1);
    }
    30% {
        transform: scale(1.15);
    }
    60% {
        transform: scale(0.95);
    }
    100% {
        transform: scale(1);
    }
}

/* Tile colors by value */
.tile[data-value="2"] { background: #eee4da; color: #776e65; }
.tile[data-value="4"] { background: #ede0c8; color: #776e65; }
.tile[data-value="8"] { background: #f2b179; color: #f9f6f2; }
.tile[data-value="16"] { background: #f59563; color: #f9f6f2; }
.tile[data-value="32"] { background: #f67c5f; color: #f9f6f2; }
.tile[data-value="64"] { background: #f65e3b; color: #f9f6f2; }
.tile[data-value="128"] { background: #edcf72; color: #f9f6f2; font-size: 1.75rem; }
.tile[data-value="256"] { background: #edcc61; color: #f9f6f2; font-size: 1.75rem; }
.tile[data-value="512"] { background: #edc850; color: #f9f6f2; font-size: 1.75rem; box-shadow: 0 0 20px 5px rgba(237, 194, 46, 0.4); }
.tile[data-value="1024"] { background: #edc53f; color: #f9f6f2; font-size: 1.5rem; box-shadow: 0 0 20px 5px rgba(237, 194, 46, 0.4); }
.tile[data-value="2048"] { background: #edc22e; color: #f9f6f2; font-size: 1.5rem; box-shadow: 0 0 25px 8px rgba(237, 194, 46, 0.6); }

/* Higher values */
.tile[data-value="4096"],
.tile[data-value="8192"],
.tile[data-value="16384"],
.tile[data-value="32768"],
.tile[data-value="65536"] {
    background: #3c3a32;
    color: #f9f6f2;
    font-size: 1.25rem;
    box-shadow: 0 0 25px 8px rgba(60, 58, 50, 0.5);
}

/* Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(238, 228, 218, 0.73);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    background: #fff;
    padding: 2rem;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.overlay-content h2 {
    font-size: 2rem;
    color: #776e65;
    margin-bottom: 0.5rem;
}

.overlay-content p {
    font-size: 1.25rem;
    color: #776e65;
    margin-bottom: 1.5rem;
}

.restart-btn {
    background: #8f7a66;
    color: #f9f6f2;
    border: none;
    border-radius: 6px;
    padding: 1rem 2rem;
    font-size: 1.125rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.restart-btn:hover {
    background: #9f8b77;
}

.restart-btn:focus-visible {
    outline: 3px solid #776e65;
    outline-offset: 2px;
}

/* Home link */
.home-link {
    margin-top: 1rem;
    color: #776e65;
    text-decoration: none;
    font-size: 0.875rem;
    transition: color 0.2s;
}

.home-link:hover {
    color: #8f7a66;
    text-decoration: underline;
}

.home-link:focus-visible {
    outline: 2px solid #776e65;
    outline-offset: 2px;
}

/* Responsive */
@media (max-width: 420px) {
    .game-container {
        padding: 0.75rem;
    }

    .title {
        font-size: 2rem;
    }

    .tile {
        font-size: 1.5rem;
    }

    .tile[data-value="128"],
    .tile[data-value="256"],
    .tile[data-value="512"] {
        font-size: 1.25rem;
    }

    .tile[data-value="1024"],
    .tile[data-value="2048"] {
        font-size: 1rem;
    }

    .tile[data-value="4096"],
    .tile[data-value="8192"],
    .tile[data-value="16384"],
    .tile[data-value="32768"],
    .tile[data-value="65536"] {
        font-size: 0.875rem;
    }
}
