/* 2048 Game Custom Styling */
:root {
    --bg-color: #faf8ef;
    --text-color: #776e65;
    --board-bg: #bbada0;
    --cell-bg: rgba(238, 228, 218, 0.4);
    --tile-text-dark: #776e65;
    --tile-text-light: #f9f6f2;
    --primary-btn: #8f7a66;
    --primary-btn-hover: #7f6a56;
    --score-bg: #bbada0;
    --header-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --board-max-width: 480px;
    --grid-gap: 12px;
    --grid-size: 4;
}

[data-theme="dark"] {
    --bg-color: #181a20;
    --text-color: #e2e8f0;
    --board-bg: #2b313e;
    --cell-bg: #1e232d;
    --tile-text-dark: #2d3748;
    --tile-text-light: #ffffff;
    --primary-btn: #6366f1;
    --primary-btn-hover: #4f46e5;
    --score-bg: #2b313e;
}

[data-theme="neon"] {
    --bg-color: #0b0f19;
    --text-color: #38bdf8;
    --board-bg: #1e293b;
    --cell-bg: #0f172a;
    --tile-text-dark: #0f172a;
    --tile-text-light: #ffffff;
    --primary-btn: #0ea5e9;
    --primary-btn-hover: #0284c7;
    --score-bg: #1e293b;
}

[data-theme="pastel"] {
    --bg-color: #fcf8f2;
    --text-color: #5c5470;
    --board-bg: #d7c4b7;
    --cell-bg: rgba(255, 255, 255, 0.6);
    --tile-text-dark: #5c5470;
    --tile-text-light: #ffffff;
    --primary-btn: #b08968;
    --primary-btn-hover: #9c6644;
    --score-bg: #d7c4b7;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: "DM Sans", var(--header-font);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.game-page-wrapper {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px;
}

/* Header & Controls */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    flex-wrap: wrap;
    gap: 10px;
}

.game-title-group {
    display: flex;
    flex-direction: column;
}

.game-title {
    font-size: 3.2rem;
    font-weight: 800;
    line-height: 1;
    margin: 0;
    color: var(--text-color);
    letter-spacing: -1.5px;
}

.game-subtitle {
    font-size: 0.9rem;
    color: #8c827a;
    margin: 4px 0 0 0;
}

.scores-wrapper {
    display: flex;
    gap: 8px;
}

.score-box {
    background: var(--score-bg);
    padding: 6px 14px;
    border-radius: 6px;
    color: #fff;
    min-width: 72px;
    text-align: center;
    position: relative;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.score-box .score-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #eee4da;
    letter-spacing: 0.5px;
}

.score-box .score-val {
    font-size: 1.25rem;
    font-weight: 800;
    line-height: 1.2;
}

.score-addition {
    position: absolute;
    right: 20px;
    bottom: -5px;
    color: #f59e0b;
    font-size: 1.1rem;
    font-weight: bold;
    z-index: 100;
    animation: scoreFloatUp 0.8s ease-in-out forwards;
    pointer-events: none;
}

@keyframes scoreFloatUp {
    0% {
        opacity: 1;
        transform: translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateY(-35px);
    }
}

/* Control Toolbar */
.controls-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    flex-wrap: wrap;
    gap: 8px;
}

.btn-game-action {
    background-color: var(--primary-btn);
    color: #fff;
    font-weight: 700;
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 0.92rem;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-game-action:hover {
    background-color: var(--primary-btn-hover);
    color: #fff;
    transform: translateY(-1px);
}

.btn-game-action:active {
    transform: scale(0.98);
}

.btn-game-action:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.btn-game-outline {
    background-color: transparent;
    color: var(--text-color);
    border: 2px solid var(--board-bg);
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 6px;
    transition: all 0.15s ease;
    cursor: pointer;
    font-size: 0.88rem;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.btn-game-outline:hover {
    background-color: var(--board-bg);
    color: #fff;
}

.btn-game-outline:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Board Container */
.game-board-container {
    position: relative;
    max-width: var(--board-max-width);
    width: 100%;
    margin: 0 auto;
    aspect-ratio: 1 / 1;
    background-color: var(--board-bg);
    border-radius: 12px;
    padding: var(--grid-gap);
    box-sizing: border-box;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    cursor: grab;
}

.game-board-container:active {
    cursor: grabbing;
}

.grid-background {
    display: grid;
    width: 100%;
    height: 100%;
    gap: var(--grid-gap);
}

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

.tile-container {
    position: absolute;
    top: var(--grid-gap);
    left: var(--grid-gap);
    right: var(--grid-gap);
    bottom: var(--grid-gap);
    display: grid;
    gap: var(--grid-gap);
    pointer-events: none;
}

.tile {
    width: 100%;
    height: 100%;
    border-radius: 6px;
    font-weight: 800;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    -webkit-user-select: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
    transition: transform 100ms ease-out;
}

.tile-new {
    animation: tileAppear 160ms ease-out forwards;
}

.tile-merged {
    animation: tilePop 180ms ease-in-out forwards;
}

@keyframes tileAppear {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes tilePop {
    0% {
        transform: scale(0.9);
    }
    50% {
        transform: scale(1.12);
    }
    100% {
        transform: scale(1);
    }
}

/* Classic Tile Colors */
.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; box-shadow: 0 0 10px rgba(237, 207, 114, 0.45); }
.tile-256 { background: #edcc61; color: #f9f6f2; box-shadow: 0 0 14px rgba(237, 204, 97, 0.55); }
.tile-512 { background: #edc850; color: #f9f6f2; box-shadow: 0 0 18px rgba(237, 200, 80, 0.65); }
.tile-1024 { background: #edc53f; color: #f9f6f2; box-shadow: 0 0 22px rgba(237, 197, 63, 0.75); }
.tile-2048 { background: #edc22e; color: #ffffff; box-shadow: 0 0 28px rgba(237, 194, 46, 0.95); }
.tile-4096 { background: #3c3a32; color: #ffffff; box-shadow: 0 0 22px rgba(60, 58, 50, 0.8); }
.tile-8192 { background: #7c3aed; color: #ffffff; box-shadow: 0 0 25px rgba(124, 58, 237, 0.8); }
.tile-16384 { background: #ec4899; color: #ffffff; box-shadow: 0 0 25px rgba(236, 72, 153, 0.8); }
.tile-32768 { background: #06b6d4; color: #ffffff; box-shadow: 0 0 25px rgba(6, 182, 212, 0.8); }
.tile-65536 { background: #10b981; color: #ffffff; box-shadow: 0 0 25px rgba(16, 185, 129, 0.8); }
.tile-super { background: #111827; color: #f59e0b; box-shadow: 0 0 30px rgba(245, 158, 11, 0.9); }

/* Overlays (Win / Game Over) */
.game-overlay {
    position: absolute;
    inset: 0;
    background: rgba(238, 228, 218, 0.92);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    animation: overlayFadeIn 250ms ease-out forwards;
    padding: 24px;
    text-align: center;
}

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

@keyframes overlayFadeIn {
    0% { opacity: 0; transform: scale(0.96); }
    100% { opacity: 1; transform: scale(1); }
}

.overlay-title {
    font-size: 2.6rem;
    font-weight: 800;
    margin-bottom: 8px;
    color: var(--text-color);
}

.overlay-subtitle {
    font-size: 1.05rem;
    margin-bottom: 20px;
    color: var(--text-color);
    opacity: 0.9;
}

.overlay-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

/* Mobile D-Pad Control Buttons */
.mobile-controls {
    display: block;
    margin-top: 14px;
    text-align: center;
}

.d-pad {
    display: inline-grid;
    grid-template-columns: repeat(3, 62px);
    grid-template-rows: repeat(3, 50px);
    gap: 6px;
    margin: 0 auto;
}

.d-pad-btn {
    background: var(--board-bg);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1.35rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    touch-action: manipulation;
    transition: transform 0.1s, background-color 0.15s;
}

.d-pad-btn:active {
    background: var(--primary-btn);
    transform: scale(0.94);
}

.d-pad-up { grid-column: 2; grid-row: 1; }
.d-pad-left { grid-column: 1; grid-row: 2; }
.d-pad-right { grid-column: 3; grid-row: 2; }
.d-pad-down { grid-column: 2; grid-row: 3; }

/* Settings / Options bar */
.settings-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 14px;
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 8px;
}

.settings-group {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
}

.settings-select {
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid #ccc;
    font-size: 0.85rem;
    background: #fff;
    color: #333;
}

/* Content & Guide sections */
.content-section {
    margin-top: 36px;
    background: #ffffff;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .content-section {
    background: #232a3b;
    color: #e2e8f0;
}

.section-title {
    font-weight: 700;
    margin-bottom: 14px;
    color: var(--text-color);
}

.feature-card {
    padding: 14px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid rgba(0, 0, 0, 0.06);
    height: 100%;
}

@media (max-width: 576px) {
    .game-title {
        font-size: 2.4rem;
    }
    .score-box {
        min-width: 60px;
        padding: 4px 8px;
    }
    .score-box .score-val {
        font-size: 1.1rem;
    }
    .content-section {
        padding: 16px;
    }
}
