:root {
    /* 2048 Specific Variables */
    --tile-text-dark: #1f2428;
    --tile-text-light: #f8f9fa;
    --tile-text-shadow: rgba(0, 0, 0, 0.35);
    --tile-empty: #dee2e6;
    --tile-2: #f1f3f5;
    --tile-4: #e9ecef;
    --tile-8: #ced4da;
    --tile-16: #adb5bd;
    --tile-32: #868e96;
    --tile-64: #495057;
    --tile-128: #343a40;
    --tile-256: #212529;
    --tile-512: #212529;
    --tile-1024: #212529;
    --tile-2048: #212529;
    --tile-super: #212529;
    --border-radius: 4px;
}

.stats-bar > button.stat-card {
    border: 0;
    color: inherit;
    font: inherit;
}

#rankedRetryBtn {
    margin-top: 6px;
}

[data-theme="dark"] {
    --tile-text-shadow: rgba(0, 0, 0, 0.15);
    --tile-empty: #3d3d3d;
    --tile-2: #4a4a4a;
    --tile-4: #5a5a5a;
    --tile-8: #6a6a6a;
    --tile-16: #8a8a8a;
    --tile-32: #949494;
    --tile-64: #9a9a9a;
    --tile-128: #aaaaaa;
    --tile-256: #bababa;
    --tile-512: #cacaca;
    --tile-1024: #dadada;
    --tile-2048: #eaeaea;
    --tile-super: #fafafa;
}

/* Ensure Board fits */
.board {
    display: grid;
    width: 100%;
    max-width: 400px; /* Limit max width */
    aspect-ratio: 1;
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 8px;
    gap: 6px;
    margin: 0 auto;
}

/* Limit Grid height on mobile like other games */
@media (max-width: 360px) and (max-height: 780px) {
    .board {
        max-width: 340px;
    }
}

.tile {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 600;
    border-radius: var(--border-radius);
    background: var(--tile-empty);
    color: var(--text-primary);
}

.tile-new {
    animation: appear 0.3s ease-out forwards;
}

.tile-merged {
    animation: pop 0.3s ease-out forwards;
}

/* Tile Colors */
.tile-2 { background: var(--tile-2); color: var(--tile-text-dark); }
.tile-4 { background: var(--tile-4); color: var(--tile-text-dark); }
.tile-8 { background: var(--tile-8); color: var(--tile-text-dark); }
.tile-16 { background: var(--tile-16); color: var(--tile-text-dark); }
.tile-32 { background: var(--tile-32); color: var(--tile-text-light); text-shadow: 0 1px 1px var(--tile-text-shadow); }
.tile-64 { background: var(--tile-64); color: var(--tile-text-light); text-shadow: 0 1px 1px var(--tile-text-shadow); }
.tile-128 { background: var(--tile-128); color: var(--tile-text-light); font-size: 20px; text-shadow: 0 1px 1px var(--tile-text-shadow); }
.tile-256 { background: var(--tile-256); color: var(--tile-text-light); font-size: 20px; text-shadow: 0 1px 1px var(--tile-text-shadow); }
.tile-512 { background: var(--tile-512); color: var(--tile-text-light); font-size: 20px; text-shadow: 0 1px 1px var(--tile-text-shadow); }
.tile-1024 { background: var(--tile-1024); color: var(--tile-text-light); font-size: 16px; text-shadow: 0 1px 1px var(--tile-text-shadow); }
.tile-2048 { background: var(--tile-2048); color: var(--tile-text-light); font-size: 16px; text-shadow: 0 1px 1px var(--tile-text-shadow); }
.tile-super { background: var(--tile-super); color: var(--tile-text-light); font-size: 14px; text-shadow: 0 1px 1px var(--tile-text-shadow); }

[data-theme="dark"] .tile-2,
[data-theme="dark"] .tile-4,
[data-theme="dark"] .tile-8 {
    color: var(--tile-text-light);
}

[data-theme="dark"] .tile-32,
[data-theme="dark"] .tile-64,
[data-theme="dark"] .tile-128,
[data-theme="dark"] .tile-256,
[data-theme="dark"] .tile-512,
[data-theme="dark"] .tile-1024,
[data-theme="dark"] .tile-2048,
[data-theme="dark"] .tile-super {
    color: var(--tile-text-dark);
    text-shadow: none;
}

@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); }
}

/* Overlays inside game-surface */
.game-overlay, .pause-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(248, 249, 250, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius);
    z-index: 10;
    text-align: center;
}

[data-theme="dark"] .game-overlay,
[data-theme="dark"] .pause-overlay {
    background: rgba(26, 26, 26, 0.9);
}

.game-overlay h2, .pause-overlay h2 {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.game-overlay p, .pause-overlay p {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

/* Score Overlay */
.score-overlay {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    opacity: 0;
    padding: 6px 12px;
    border-radius: 10px;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 5;
}

.score-overlay.changed {
    opacity: 1;
    color: var(--tile-32);
    transform: translateY(-20px);
}

/* Mode Selector in Stats Bar */
.mode-selector {
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    border: none;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    text-align: center;
    width: 100%;
    cursor: pointer;
    font-family: inherit;
    padding: 0;
}

/* Responsive Tile Text */
@media (max-width: 480px) {
    .tile {
        font-size: 18px;
    }
    .tile-128, .tile-256, .tile-512 {
        font-size: 16px;
    }
    .tile-1024, .tile-2048, .tile-super {
        font-size: 12px;
    }
}

/* Z-Index Fixes */
.game-header {
    z-index: 1002;
}
.menu-backdrop {
    z-index: 1000;
}
.menu-dropdown {
    z-index: 1001;
}
