@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;600;700;800&display=swap');

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

#g2048 {
    font-family: 'Space Grotesk', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.5rem 1rem 2rem;
    min-height: 560px;
    user-select: none;
}

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 420px;
    margin-bottom: 1.2rem;
}

.logo {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--color-text-primary);
    letter-spacing: -1px;
}

.logo span {
    background: linear-gradient(135deg, #e67e22, #e74c3c);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.score-group {
    display: flex;
    gap: 10px;
}

.score-box {
    background: var(--color-background-secondary);
    border: 0.5px solid var(--color-border-tertiary);
    border-radius: 10px;
    padding: 6px 14px;
    text-align: center;
    min-width: 72px;
}

.score-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--color-text-secondary);
    text-transform: uppercase;
}

.score-val {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--color-text-primary);
    line-height: 1.2;
}

.btn-row {
    display: flex;
    gap: 8px;
    margin-bottom: 1.2rem;
    width: 100%;
    max-width: 420px;
}

.btn {
    flex: 1;
    padding: 9px 14px;
    border-radius: 10px;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.1s;
    border: none;
    letter-spacing: 0.02em;
}

.btn:active {
    transform: scale(0.97);
}

.btn-new {
    background: linear-gradient(135deg, #e67e22, #e74c3c);
    color: white;
}

.btn-undo {
    background: var(--color-background-secondary);
    border: 0.5px solid var(--color-border-secondary);
    color: var(--color-text-primary);
}

.board-wrap {
    position: relative;
    width: 100%;
    max-width: 420px;
}

#board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    padding: 10px;
    background: #bbada0;
    border-radius: 16px;
    width: 100%;
    aspect-ratio: 1;
}

.cell-bg {
    background: rgba(238, 228, 218, 0.35);
    border-radius: 8px;
    aspect-ratio: 1;
}

.tile-container {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    bottom: 10px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    pointer-events: none;
}

.tile-slot {
    position: relative;
}

.tile {
    position: absolute;
    inset: 0;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: clamp(1rem, 3.5vw, 1.6rem);
    letter-spacing: -0.5px;
    transition: all 0.12s ease-out;
    animation: pop 0.18s ease-out;
}

@keyframes pop {
    0% {
        transform: scale(0.6);
        opacity: 0.5;
    }

    70% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.tile.merge-pop {
    animation: mergePop 0.22s ease-out;
}

@keyframes mergePop {
    0% {
        transform: scale(1);
    }

    40% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

.overlay {
    position: absolute;
    inset: 0;
    background: rgba(238, 228, 218, 0.85);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    z-index: 10;
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.overlay.show {
    opacity: 1;
    pointer-events: all;
}

.overlay-title {
    font-size: 2rem;
    font-weight: 800;
    color: #776e65;
}

.overlay-title.win {
    color: #e67e22;
}

.overlay-sub {
    font-size: 1rem;
    color: #776e65;
}

.overlay-btn {
    padding: 10px 28px;
    background: linear-gradient(135deg, #e67e22, #e74c3c);
    color: white;
    border: none;
    border-radius: 10px;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.1s;
}

.overlay-btn:active {
    transform: scale(0.97);
}

.overlay-btn-secondary {
    padding: 8px 20px;
    background: transparent;
    color: #776e65;
    border: 1.5px solid #bbada0;
    border-radius: 10px;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}
.hint { 
    font-size: 0.78rem; 
    color: var(--color-text-secondary); 
    margin-top: 0.5rem; 
    text-align: center; 
}