/* ===== 2048 Game Styles ===== */

/* Fix for overlapping seasonal effects (Snow, Stars) */
.snow-wrapper,
.snow-cap,
.snow-drip,
#star-canvas,
#snowflake-container {
    pointer-events: none !important;
}

/* ===================== BASE STYLES ===================== */
body {
    margin: 0 !important;
    padding: 0 !important;
    background-color: var(--body-bg-color, #0B1020) !important;
    background-image: var(--body-bg-image) !important;
    color: var(--text-color, #ffffff) !important;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
    overflow: hidden !important;
    user-select: none !important;
    height: 100dvh !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
}

/* Reset global main styles from _layout.css */
main {
    margin: 0 !important;
    margin-top: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    height: 100% !important;
    flex: none !important;
}

/* Default: Column layout for mobile */
.app-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 10px;
    box-sizing: border-box;
    gap: 8px;
}

/* ===================== HEADER ===================== */
.game-header {
    flex-shrink: 0;
    /* Reset global header styles from _header.css */
    position: static !important;
    transform: none !important;
    left: auto !important;
    margin-top: 0 !important;
    width: auto !important;
    background: transparent !important;
    box-shadow: none !important;
    border: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    padding: 5px 0 !important;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.back-btn {
    color: var(--text-color);
    text-decoration: none;
    font-size: 0.85rem;
    opacity: 0.7;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: opacity 0.2s;
}

.back-btn:hover {
    opacity: 1;
}

.game-title {
    margin: 0 !important;
    font-size: 1.6rem !important;
    font-weight: 800 !important;
    letter-spacing: 3px !important;
    background: linear-gradient(135deg, #edc850, #f2b179, #f67c5f) !important;
    -webkit-background-clip: text !important;
    background-clip: text !important;
    -webkit-text-fill-color: transparent !important;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.05);
    border: none;
    color: var(--text-color);
    font-size: 1.1rem;
    cursor: pointer;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    min-height: 34px !important;
    min-width: 34px !important;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: rotate(90deg);
}

/* --- Score Panel --- */
.score-panel {
    display: flex;
    gap: 8px;
}

.score-box {
    flex: 1;
    background: rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    padding: 6px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    position: relative;
}

.score-label {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--text-grey, #a0a0a0);
}

.score-value {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text-color, white);
    font-variant-numeric: tabular-nums;
}

/* --- Score add animation --- */
.score-add {
    position: absolute;
    top: -0.3rem;
    right: 0.5rem;
    font-size: 0.85rem;
    font-weight: 700;
    color: #edc850;
    animation: scoreFloat 0.7s ease-out forwards;
    pointer-events: none;
}

@keyframes scoreFloat {
    0% {
        opacity: 1;
        transform: translateY(0);
    }

    100% {
        opacity: 0;
        transform: translateY(-24px);
    }
}

/* ===================== GAME BOARD ===================== */
.board-wrapper {
    flex: 1 1 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 0;
    margin: 0 !important;
    padding: 0 !important;
    width: auto !important;
    max-width: none;
}

.game-board {
    width: 100%;
    aspect-ratio: 1 / 1;
    max-width: 100%;
    max-height: 100%;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 10px;
    padding: 10px;
    position: relative;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.5);
}

/* Background cells */
.cell {
    background: rgba(255, 255, 255, 0.04);
    border-radius: 10px;
}

/* --- Tiles --- */
.tile {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    border-radius: 10px;
    user-select: none;
    transition: top 0.12s ease, left 0.12s ease;
    z-index: 10;
}

/* Tile value themes */
.tile[data-value="2"] {
    background: rgba(238, 228, 218, 0.95);
    color: #776e65;
}

.tile[data-value="4"] {
    background: rgba(237, 224, 200, 0.95);
    color: #776e65;
}

.tile[data-value="8"] {
    background: rgba(242, 177, 121, 0.95);
    color: #fff;
}

.tile[data-value="16"] {
    background: rgba(245, 149, 99, 0.95);
    color: #fff;
}

.tile[data-value="32"] {
    background: rgba(246, 124, 95, 0.95);
    color: #fff;
}

.tile[data-value="64"] {
    background: rgba(246, 94, 59, 0.95);
    color: #fff;
}

.tile[data-value="128"] {
    background: rgba(237, 207, 114, 0.95);
    color: #fff;
    box-shadow: 0 0 20px rgba(237, 207, 114, 0.35);
}

.tile[data-value="256"] {
    background: rgba(237, 204, 97, 0.95);
    color: #fff;
    box-shadow: 0 0 25px rgba(237, 204, 97, 0.4);
}

.tile[data-value="512"] {
    background: rgba(237, 200, 80, 0.95);
    color: #fff;
    box-shadow: 0 0 30px rgba(237, 200, 80, 0.45);
}

.tile[data-value="1024"] {
    background: rgba(237, 197, 63, 0.95);
    color: #fff;
    box-shadow: 0 0 35px rgba(237, 197, 63, 0.5);
}

.tile[data-value="2048"] {
    background: linear-gradient(135deg, #edc22e, #f2b179);
    color: #fff;
    box-shadow: 0 0 50px rgba(237, 194, 46, 0.6);
}

/* Super tiles (beyond 2048) */
.tile-super {
    background: linear-gradient(135deg, #a24cff, #f67c5f) !important;
    color: #fff !important;
    box-shadow: 0 0 60px rgba(162, 76, 255, 0.5) !important;
}

/* --- Tile Animations --- */
.tile-new {
    animation: tileAppear 0.2s ease-out;
}

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

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

.tile-merged {
    animation: tilePop 0.2s ease-out;
    z-index: 20;
}

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

    50% {
        transform: scale(1.2);
    }

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

/* --- Controls Hint --- */
.controls-hint {
    flex-shrink: 0;
    color: var(--text-grey, #a0a0a0);
    text-align: center;
    opacity: 0.7;
    font-size: 0.75rem;
    padding: 2px 0;
}

/* ===================== MODALS ===================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999 !important;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(10px);
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto !important;
}

.modal-content {
    background: rgba(30, 30, 38, 0.6);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 30px;
    border-radius: 24px;
    text-align: center;
    width: 90%;
    max-width: 380px;
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
    pointer-events: auto !important;
    position: relative;
    z-index: 10000 !important;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

.modal-content h2 {
    margin-top: 0;
    color: #edc850;
    font-weight: 800;
    font-size: 1.4rem;
}

.modal-content p {
    color: var(--text-grey, #a0a0a0);
    margin-bottom: 1rem;
    font-size: 1rem;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.diff-btn {
    padding: 12px 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    pointer-events: auto !important;
    position: relative;
    z-index: 10002 !important;
}

.diff-btn:hover {
    background: rgba(237, 200, 80, 0.15);
    border-color: #edc850;
    color: #edc850;
    transform: translateY(-2px);
}

.diff-btn.secondary {
    background: rgba(255, 255, 255, 0.03);
}

.diff-btn.secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
    color: #fff;
}

/* =====================================================================
   RESPONSIVE LAYOUTS
   ===================================================================== */

/* ===================== MOBILE (Portrait, default) ===================== */
@media (max-width: 599px) {
    body {
        overflow: auto !important;
    }

    .app-container {
        padding: 8px;
        gap: 6px;
        height: auto;
        min-height: 100dvh;
    }

    .game-title {
        font-size: 1.4rem !important;
    }

    .board-wrapper {
        flex: 0 0 auto;
        width: 100%;
        max-width: calc(100vw - 16px);
        max-height: calc(100vw - 16px);
    }

    .game-board {
        gap: 7px;
        padding: 7px;
    }

    .score-value {
        font-size: 1.1rem;
    }
}

/* ===================== TABLET / SMALL DESKTOP (600-799px) ===================== */
@media (min-width: 600px) and (max-width: 799px) {
    .app-container {
        padding: 12px;
        gap: 10px;
        max-width: 600px;
        margin: 0 auto;
    }

    .board-wrapper {
        flex: 0 0 auto;
        width: 100%;
        max-width: min(calc(100vw - 24px), calc(100dvh - 180px));
        max-height: min(calc(100vw - 24px), calc(100dvh - 180px));
    }
}

/* ===================== DESKTOP (≥800px) — Header LEFT, Board CENTER ===================== */
@media (min-width: 800px) {
    .app-container {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        justify-content: center !important;
        align-items: center !important;
        padding: 15px;
        gap: 30px;
        max-width: 1200px;
        margin: 0 auto;
    }

    .game-header {
        flex: 0 0 auto !important;
        width: clamp(180px, 18vw, 260px) !important;
        order: 1 !important;
    }

    .header-top {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px;
        margin-bottom: 15px;
    }

    .game-title {
        font-size: clamp(2rem, 3vw, 3rem) !important;
    }

    .score-panel {
        flex-direction: column;
    }

    .board-wrapper {
        order: 2 !important;
        flex: 1 1 auto !important;
        max-width: min(calc(100dvh - 30px), 75vw);
        max-height: calc(100dvh - 30px);
    }

    .game-board {
        gap: 12px;
        padding: 12px;
        border-radius: 16px;
        border-width: 2px;
    }

    .cell {
        border-radius: 12px;
    }

    .tile {
        border-radius: 12px;
    }

    .controls-hint {
        order: 3 !important;
        flex: 0 0 auto !important;
        width: clamp(100px, 10vw, 180px) !important;
        text-align: left;
    }
}

/* ===================== LARGER DESKTOP (≥1200px) ===================== */
@media (min-width: 1200px) {
    .app-container {
        gap: 40px;
        padding: 20px;
    }

    .game-board {
        gap: 14px;
        padding: 14px;
    }
}

/* ===================== ULTRA-WIDE / 4K (≥1600px) ===================== */
@media (min-width: 1600px) {
    .app-container {
        gap: 50px;
        padding: 30px;
        max-width: 1600px;
    }

    .modal-content {
        max-width: 500px;
        padding: 40px;
    }
}