:root {
    --bg-color: #0f172a;
    --board-bg: rgba(255, 255, 255, 0.05);
    --cell-bg: rgba(255, 255, 255, 0.05);
    --text-color: #f8fafc;
    --text-muted: #94a3b8;
    --accent-color: #38bdf8;
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.1);
    --tile-radius: 8px;
    --transition-time: 150ms;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-color);
    background-image:
        radial-gradient(circle at 20% 20%, rgba(56, 189, 248, 0.15) 0%, transparent 40%),
        radial-gradient(circle at 80% 80%, rgba(139, 92, 246, 0.15) 0%, transparent 40%);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
}

#game-container {
    width: 100%;
    max-width: 500px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#title-container {
    text-align: center;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
}

#game-title {
    font-size: 3rem;
    font-weight: 800;
    background: linear-gradient(135deg, #38bdf8, #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

#game-subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
}

#scores-container {
    display: flex;
    gap: 10px;
}

.score-box {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    padding: 10px 20px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 80px;
}

.score-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}

#score,
#high-score {
    font-size: 1.25rem;
    font-weight: 700;
}

#game-board-container {
    position: relative;
    aspect-ratio: 1 / 1;
    width: 100%;
    background: var(--board-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 12px;
}

#game-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 12px;
    width: 100%;
    height: 100%;
    position: relative;
}

.grid-cell {
    background: var(--cell-bg);
    border-radius: var(--tile-radius);
    width: 100%;
    height: 100%;
}

#tile-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
}

.tile {
    position: absolute;
    width: calc(25% - 9px);
    /* Approximate size based on 12px gap */
    height: calc(25% - 9px);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 700;
    font-size: 1.5rem;
    border-radius: var(--tile-radius);
    transition: top var(--transition-time) ease-in-out, left var(--transition-time) ease-in-out;
    z-index: 11;
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Position helpers for tiles (row-col) */
.tile-pos-0-0 {
    transform: translate(calc(0 * 100% + 0px), calc(0 * 100% + 0px));
}

/* These will be set dynamic via JS styles for better accuracy with gaps */

.tile-new {
    animation: appear 200ms ease-out;
}

.tile-merged {
    animation: pop 200ms ease-in-out;
    z-index: 12;
}

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

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

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

    50% {
        transform: scale(1.15);
    }

    100% {
        transform: scale(1);
    }
}

/* Tile colors based on value */
.tile-2 {
    background: rgba(248, 250, 252, 0.1);
    color: #f8fafc;
}

.tile-4 {
    background: rgba(241, 245, 249, 0.15);
    color: #f8fafc;
}

.tile-8 {
    background: rgba(56, 189, 248, 0.3);
    color: #fff;
    box-shadow: 0 0 15px rgba(56, 189, 248, 0.2);
}

.tile-16 {
    background: rgba(14, 165, 233, 0.4);
    color: #fff;
    box-shadow: 0 0 15px rgba(14, 165, 233, 0.3);
}

.tile-32 {
    background: rgba(2, 132, 199, 0.5);
    color: #fff;
}

.tile-64 {
    background: rgba(139, 92, 246, 0.5);
    color: #fff;
}

.tile-128 {
    background: rgba(124, 58, 237, 0.6);
    color: #fff;
    font-size: 1.25rem;
}

.tile-256 {
    background: rgba(109, 40, 217, 0.7);
    color: #fff;
    font-size: 1.25rem;
}

.tile-512 {
    background: rgba(236, 72, 153, 0.7);
    color: #fff;
    font-size: 1.25rem;
}

.tile-1024 {
    background: rgba(219, 39, 119, 0.8);
    color: #fff;
    font-size: 1rem;
}

.tile-2048 {
    background: rgba(244, 63, 94, 0.9);
    color: #fff;
    font-size: 1rem;
    box-shadow: 0 0 25px rgba(244, 63, 94, 0.5);
}

#overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    border-radius: 16px;
    opacity: 1;
    transition: opacity 300ms;
}

#overlay.hidden {
    display: none;
    opacity: 0;
}

#overlay-content {
    text-align: center;
}

#overlay-title {
    font-size: 3rem;
    margin-bottom: 20px;
    background: linear-gradient(135deg, #fff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

footer {
    display: flex;
    justify-content: center;
    align-items: center;
}

button {
    background: var(--accent-color);
    color: #fff;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 150ms, filter 150ms;
}

button:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

button:active {
    transform: translateY(0);
}

#new-game-button {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--glass-border);
    padding: 14px 28px;
    font-size: 1rem;
}

#instructions {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-align: center;
}

@media (max-width: 400px) {
    #game-title {
        font-size: 2rem;
    }

    .score-box {
        padding: 8px 12px;
        min-width: 60px;
    }

    #score,
    #high-score {
        font-size: 1rem;
    }

    #game-board {
        gap: 8px;
    }

    #game-board-container {
        padding: 8px;
    }
}


/* Header Buttons */
.header-buttons {
    display: flex;
    gap: 10px;
}

.secondary-btn {
    background: #8f7a66;
    color: #f9f6f2;
    border: none;
    border-radius: 3px;
    padding: 0 20px;
    font-size: 18px;
    height: 100%;
    /* Match parent height or specific px if needed */
    line-height: inherit;
    /* Align text */
    display: block;
    text-align: center;
    cursor: pointer;
    font-weight: bold;
    text-decoration: none;
}

/* Specific Override for the inline style issue */
#instructions-overlay.hidden {
    display: none !important;
}