/* 2048 Game Styles */

:root {
    --grid-size: 4;
    --cell-size: 100px;
    --cell-gap: 15px;
    --board-bg: #bbada0;
    --cell-bg: rgba(238, 228, 218, 0.35);
    --tile-2: #eee4da;
    --tile-4: #ede0c8;
    --tile-8: #f2b179;
    --tile-16: #f59563;
    --tile-32: #f67c5f;
    --tile-64: #f65e3b;
    --tile-128: #edcf72;
    --tile-256: #edcc61;
    --tile-512: #edc850;
    --tile-1024: #edc53f;
    --tile-2048: #edc22e;
    --tile-4096: #3c3a32;
    --tile-8192: #3c3a32;
}

/* Score Boxes */
.score-box {
    background: var(--board-bg);
    border-radius: 8px;
    padding: 15px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

[data-bs-theme="dark"] .score-box {
    background: #6e6456;
}

.score-box.score-best {
    background: linear-gradient(135deg, #f59563 0%, #f67c5f 100%);
    color: #fff;
}

.score-box.score-moves {
    background: linear-gradient(135deg, #edcf72 0%, #edc22e 100%);
    color: #fff;
}

.score-box.score-time {
    background: linear-gradient(135deg, #3c3a32 0%, #6e6456 100%);
    color: #fff;
}

.score-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
    opacity: 0.9;
}

.score-value {
    font-size: 28px;
    font-weight: 900;
    font-family: 'Courier New', monospace;
}

.score-add {
    position: absolute;
    right: 15px;
    top: 15px;
    color: #f67c5f;
    font-size: 18px;
    font-weight: 700;
    display: none;
    animation: scoreAdd 1s ease-out;
}

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

/* Game Container */
.game-container {
    --grid-size: 4;
    max-width: 550px;
    margin: 0 auto;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
}

.game-container:fullscreen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #faf8ef;
}

[data-bs-theme="dark"] .game-container:fullscreen {
    background: #1a1a1a;
}

.game-board-wrapper {
    position: relative;
    background: var(--board-bg);
    border-radius: 12px;
    padding: var(--cell-gap);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

[data-bs-theme="dark"] .game-board-wrapper {
    background: #6e6456;
}

/* Grid Container */
.grid-container {
    display: grid;
    grid-template-columns: repeat(var(--grid-size), var(--cell-size));
    grid-template-rows: repeat(var(--grid-size), var(--cell-size));
    gap: var(--cell-gap);
    position: relative;
}

.grid-cell {
    background: var(--cell-bg);
    border-radius: 6px;
}

[data-bs-theme="dark"] .grid-cell {
    background: rgba(136, 126, 118, 0.35);
}

/* Tiles Container */
.tiles-container {
    position: absolute;
    top: var(--cell-gap);
    left: var(--cell-gap);
    width: calc(var(--grid-size) * var(--cell-size) + (var(--grid-size) - 1) * var(--cell-gap));
    height: calc(var(--grid-size) * var(--cell-size) + (var(--grid-size) - 1) * var(--cell-gap));
    pointer-events: none;
}

/* Tile */
.tile {
    position: absolute;
    width: var(--cell-size);
    height: var(--cell-size);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: 900;
    color: #776e65;
    transition: all 0.15s ease-in-out;
    animation: tileAppear 0.2s ease-in-out;
    transform: translate(
        calc(var(--col) * (var(--cell-size) + var(--cell-gap))),
        calc(var(--row) * (var(--cell-size) + var(--cell-gap)))
    );
}

@keyframes tileAppear {
    0% {
        opacity: 0;
        transform: translate(
            calc(var(--col) * (var(--cell-size) + var(--cell-gap))),
            calc(var(--row) * (var(--cell-size) + var(--cell-gap)))
        ) scale(0);
    }
    100% {
        opacity: 1;
        transform: translate(
            calc(var(--col) * (var(--cell-size) + var(--cell-gap))),
            calc(var(--row) * (var(--cell-size) + var(--cell-gap)))
        ) scale(1);
    }
}

/* Tile Colors */
.tile-2 {
    background: var(--tile-2);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.tile-4 {
    background: var(--tile-4);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.tile-8 {
    background: var(--tile-8);
    color: #f9f6f2;
    box-shadow: 0 2px 8px rgba(242, 177, 121, 0.4);
}

.tile-16 {
    background: var(--tile-16);
    color: #f9f6f2;
    box-shadow: 0 2px 8px rgba(245, 149, 99, 0.4);
}

.tile-32 {
    background: var(--tile-32);
    color: #f9f6f2;
    box-shadow: 0 2px 8px rgba(246, 124, 95, 0.4);
}

.tile-64 {
    background: var(--tile-64);
    color: #f9f6f2;
    box-shadow: 0 2px 8px rgba(246, 94, 59, 0.4);
}

.tile-128 {
    background: var(--tile-128);
    color: #f9f6f2;
    font-size: 28px;
    box-shadow: 0 4px 12px rgba(237, 207, 114, 0.5);
}

.tile-256 {
    background: var(--tile-256);
    color: #f9f6f2;
    font-size: 28px;
    box-shadow: 0 4px 12px rgba(237, 204, 97, 0.5);
}

.tile-512 {
    background: var(--tile-512);
    color: #f9f6f2;
    font-size: 28px;
    box-shadow: 0 4px 12px rgba(237, 200, 80, 0.5);
}

.tile-1024 {
    background: var(--tile-1024);
    color: #f9f6f2;
    font-size: 24px;
    box-shadow: 0 6px 16px rgba(237, 197, 63, 0.6);
}

.tile-2048 {
    background: var(--tile-2048);
    color: #f9f6f2;
    font-size: 24px;
    box-shadow: 0 6px 16px rgba(237, 194, 46, 0.6);
    animation: tile2048Pulse 1s ease-in-out infinite;
}

.tile-4096 {
    background: var(--tile-4096);
    color: #f9f6f2;
    font-size: 22px;
    box-shadow: 0 8px 20px rgba(60, 58, 50, 0.7);
}

.tile-8192 {
    background: var(--tile-8192);
    color: #f9f6f2;
    font-size: 22px;
    box-shadow: 0 8px 20px rgba(60, 58, 50, 0.7);
}

@keyframes tile2048Pulse {
    0%, 100% {
        box-shadow: 0 6px 16px rgba(237, 194, 46, 0.6);
    }
    50% {
        box-shadow: 0 8px 24px rgba(237, 194, 46, 0.9);
    }
}

/* Game Overlay */
.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(238, 228, 218, 0.95);
    border-radius: 12px;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: overlayAppear 0.3s ease-in-out;
}

[data-bs-theme="dark"] .game-overlay {
    background: rgba(60, 58, 50, 0.95);
}

@keyframes overlayAppear {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.overlay-content {
    text-align: center;
    padding: 40px;
}

.overlay-icon {
    font-size: 80px;
    margin-bottom: 20px;
    animation: iconBounce 0.5s ease-in-out;
}

@keyframes iconBounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-20px);
    }
}

.overlay-title {
    font-size: 36px;
    font-weight: 900;
    color: #776e65;
    margin-bottom: 15px;
}

[data-bs-theme="dark"] .overlay-title {
    color: #f9f6f2;
}

.overlay-message {
    font-size: 18px;
    color: #776e65;
    margin-bottom: 25px;
}

[data-bs-theme="dark"] .overlay-message {
    color: #e8e4dc;
}

.overlay-score {
    background: rgba(187, 173, 160, 0.3);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 25px;
    font-size: 16px;
    color: #776e65;
}

[data-bs-theme="dark"] .overlay-score {
    background: rgba(110, 100, 86, 0.5);
    color: #f9f6f2;
}

.overlay-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Instructions */
.instruction-item {
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #f59563;
}

[data-bs-theme="dark"] .instruction-item {
    background: #2d3239;
    border-left-color: #f67c5f;
}

.kbd-group {
    display: inline-flex;
    gap: 8px;
    margin: 8px 0;
}

kbd {
    display: inline-block;
    padding: 6px 12px;
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
    color: #24292e;
    vertical-align: middle;
    background-color: #fafbfc;
    border: 1px solid #d1d5da;
    border-radius: 6px;
    box-shadow: inset 0 -1px 0 #d1d5da;
    font-family: 'Courier New', monospace;
}

[data-bs-theme="dark"] kbd {
    color: #f9f6f2;
    background-color: #2d3239;
    border-color: #495057;
    box-shadow: inset 0 -1px 0 #495057;
}

/* Statistics */
.stat-card {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 20px 15px;
    text-align: center;
    border: 1px solid #e9ecef;
    transition: all 0.3s ease;
    height: 100%;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

[data-bs-theme="dark"] .stat-card {
    background: #2d3239;
    border-color: #495057;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 8px;
    font-family: 'Courier New', monospace;
    line-height: 1;
}

.stat-label {
    font-size: 12px;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

[data-bs-theme="dark"] .stat-label {
    color: #adb5bd;
}

/* Responsive Design */
@media (max-width: 768px) {
    :root {
        --cell-size: 70px;
        --cell-gap: 10px;
    }

    .tile {
        font-size: 24px;
    }

    .tile-128,
    .tile-256,
    .tile-512 {
        font-size: 20px;
    }

    .tile-1024,
    .tile-2048 {
        font-size: 18px;
    }

    .tile-4096,
    .tile-8192 {
        font-size: 16px;
    }

    .score-value {
        font-size: 24px;
    }

    .overlay-title {
        font-size: 28px;
    }

    .overlay-message {
        font-size: 16px;
    }

    .overlay-icon {
        font-size: 60px;
    }
}

@media (max-width: 480px) {
    :root {
        --cell-size: 60px;
        --cell-gap: 8px;
    }

    .tile {
        font-size: 20px;
    }

    .tile-128,
    .tile-256,
    .tile-512 {
        font-size: 16px;
    }

    .tile-1024,
    .tile-2048,
    .tile-4096,
    .tile-8192 {
        font-size: 14px;
    }

    .score-box {
        padding: 10px;
    }

    .score-label {
        font-size: 9px;
    }

    .score-value {
        font-size: 20px;
    }

    .stat-value {
        font-size: 24px;
    }

    .overlay-content {
        padding: 20px;
    }

    .overlay-title {
        font-size: 24px;
    }

    .overlay-message {
        font-size: 14px;
    }

    .overlay-icon {
        font-size: 50px;
    }
}

/* Grid size adjustments */
@media (min-width: 769px) {
    .game-container[style*="--grid-size: 3"] {
        --cell-size: 120px;
    }

    .game-container[style*="--grid-size: 5"] {
        --cell-size: 85px;
    }

    .game-container[style*="--grid-size: 6"] {
        --cell-size: 70px;
    }
}

/* Animation for tile merges */
@keyframes tileMerge {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

/* Touch feedback */
.game-container:active {
    cursor: grabbing;
}

/* Prevent text selection during game */
.game-board-wrapper,
.tile {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}
