:root {
    --bg-color: #1a1a2e;
    --grid-bg: rgba(255, 255, 255, 0.1);
    --cell-bg: rgba(255, 255, 255, 0.05);
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);

    --tile-2: rgba(238, 228, 218, 0.8);
    --tile-4: rgba(237, 224, 200, 0.8);
    --tile-8: rgba(242, 177, 121, 0.8);
    --tile-16: rgba(245, 149, 99, 0.8);
    --tile-32: rgba(246, 124, 95, 0.8);
    --tile-64: rgba(246, 94, 59, 0.8);
    --tile-128: rgba(237, 207, 114, 0.8);
    --tile-256: rgba(237, 204, 97, 0.8);
    --tile-512: rgba(237, 200, 80, 0.8);
    --tile-1024: rgba(237, 197, 63, 0.8);
    --tile-2048: rgba(237, 194, 46, 0.8);

    --glass-border: 1px solid rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);

    --field-width: 500px;
    --grid-spacing: 15px;
    --grid-row-cells: 4;
    --tile-size: calc((var(--field-width) - var(--grid-spacing) * (var(--grid-row-cells) + 1)) / var(--grid-row-cells));
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow: hidden;
}

#particles-js {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background: radial-gradient(circle at 50% 50%, #16213e 0%, #1a1a2e 100%);
}

.container {
    width: var(--field-width);
    margin: 0 auto;
    position: relative;
    z-index: 10;
}

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

.title-container h1 {
    font-size: 80px;
    font-weight: 800;
    line-height: 1;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
}

.subtitle {
    font-size: 18px;
    color: var(--text-secondary);
}

.scores-container {
    display: flex;
    gap: 10px;
}

.score-box {
    position: relative;
    background: var(--grid-bg);
    padding: 10px 20px;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    backdrop-filter: blur(10px);
    border: var(--glass-border);
    box-shadow: var(--glass-shadow);
    min-width: 70px;
}

.score-label {
    font-size: 13px;
    text-transform: uppercase;
    color: var(--text-secondary);
    font-weight: 600;
}

#score,
#best-score {
    font-size: 25px;
    font-weight: bold;
}

.score-addition {
    position: absolute;
    right: 30px;
    top: 10px;
    font-size: 25px;
    line-height: 25px;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.9);
    z-index: 100;
    animation: move-up-fade 600ms ease-in;
    animation-fill-mode: both;
    display: none;
}

.score-addition.active {
    display: block;
}

@keyframes move-up-fade {
    0% {
        top: 25px;
        opacity: 1;
    }

    100% {
        top: -20px;
        opacity: 0;
    }
}

.controls-container {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
}

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 12px 24px;
    border-radius: 12px;
    font-weight: 700;
    cursor: pointer;
    font-size: 16px;
    font-family: inherit;
    border: none;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    backdrop-filter: blur(10px);
    position: relative;
    overflow: hidden;
}


.btn:active {
    transform: scale(0.95);
}


.primary-btn {
    background: #e94560;
    color: white;
    box-shadow: 0 4px 15px rgba(233, 69, 96, 0.4);
}

.primary-btn:hover {
    background: #ff5e78;
    transform: translateY(-2px);
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.game-container {
    position: relative;
    padding: var(--grid-spacing);
    cursor: default;
    background: var(--grid-bg);
    border-radius: 10px;
    width: var(--field-width);
    height: var(--field-width);
    box-sizing: border-box;
    backdrop-filter: blur(10px);
    border: var(--glass-border);
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.2), var(--glass-shadow);
    touch-action: none;
}

.grid-container {
    position: absolute;
    z-index: 1;
}

.grid-row {
    margin-bottom: var(--grid-spacing);
}

.grid-row:last-child {
    margin-bottom: 0;
}

.grid-row:after {
    content: "";
    display: block;
    clear: both;
}

.grid-cell {
    width: var(--tile-size);
    height: var(--tile-size);
    margin-right: var(--grid-spacing);
    float: left;
    border-radius: 6px;
    background: var(--cell-bg);
    border: 1px solid rgba(255, 255, 255, 0.02);
}

.grid-cell:last-child {
    margin-right: 0;
}

.tile-container {
    position: absolute;
    z-index: 2;
}

.tile {
    position: absolute;
    width: var(--tile-size);
    height: var(--tile-size);
    border-radius: 6px;
    transition: transform 100ms ease-in-out;
    will-change: transform;
    z-index: 10;
}

.tile-inner {
    border-radius: 6px;
    background: var(--tile-2);
    text-align: center;
    font-weight: bold;
    z-index: 10;
    font-size: 55px;
    line-height: var(--tile-size);
    width: 100%;
    height: 100%;
    color: #1a1a2e;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-top: 1px solid rgba(255, 255, 255, 0.4);
    background-clip: padding-box;
}

.tile-2 .tile-inner {
    background: var(--tile-2);
    box-shadow: 0 0 10px var(--tile-2);
}

.tile-4 .tile-inner {
    background: var(--tile-4);
    box-shadow: 0 0 10px var(--tile-4);
}

.tile-8 .tile-inner {
    background: var(--tile-8);
    color: white;
    box-shadow: 0 0 15px var(--tile-8);
}

.tile-16 .tile-inner {
    background: var(--tile-16);
    color: white;
    box-shadow: 0 0 15px var(--tile-16);
}

.tile-32 .tile-inner {
    background: var(--tile-32);
    color: white;
    box-shadow: 0 0 20px var(--tile-32);
}

.tile-64 .tile-inner {
    background: var(--tile-64);
    color: white;
    box-shadow: 0 0 20px var(--tile-64);
}

.tile-128 .tile-inner {
    background: var(--tile-128);
    color: white;
    box-shadow: 0 0 25px var(--tile-128);
    font-size: 45px;
}

.tile-256 .tile-inner {
    background: var(--tile-256);
    color: white;
    box-shadow: 0 0 25px var(--tile-256);
    font-size: 45px;
}

.tile-512 .tile-inner {
    background: var(--tile-512);
    color: white;
    box-shadow: 0 0 30px var(--tile-512);
    font-size: 45px;
}

.tile-1024 .tile-inner {
    background: var(--tile-1024);
    color: white;
    box-shadow: 0 0 30px var(--tile-1024);
    font-size: 35px;
}

.tile-2048 .tile-inner {
    background: var(--tile-2048);
    color: white;
    box-shadow: 0 0 40px var(--tile-2048);
    font-size: 35px;
}

.tile-super .tile-inner {
    background: #3c3553;
    color: white;
    font-size: 30px;
    box-shadow: 0 0 50px rgba(255, 255, 255, 0.5);
    border: 2px solid #fff;
}

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

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

.tile-new {
    z-index: 15;
}

.tile-new .tile-inner {
    animation: appear 200ms ease;
}

.tile-merged {
    z-index: 20;
}

.tile-merged .tile-inner {
    animation: pop 200ms ease 100ms;
    animation-fill-mode: backwards;
}

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

    50% {
        transform: scale(1.2);
    }

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

/* ROLLBACK: Reference Style UI */
.game-message {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(13, 13, 23, 0.9);
    z-index: 1000;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    border-radius: 10px;
    animation: fadeIn 0.3s ease;
}

.game-message.game-over,
.game-message.game-won {
    display: flex !important;
}

.game-message-content {
    background: rgba(25, 32, 46, 0.95);
    padding: 35px 25px;
    border-radius: 24px;
    border: 1px solid rgba(44, 252, 254, 0.3);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5), inset 0 0 20px rgba(44, 252, 254, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 340px;
    text-align: center;
}

.message-header {
    margin-bottom: 5px;
}

.game-status-text {
    font-size: 38px !important;
    font-weight: 900 !important;
    color: #ffffff !important;
    text-shadow: 0 0 15px rgba(255, 255, 255, 0.3) !important;
}

.game-motivational-text {
    font-size: 16px;
    color: #2cfcfe;
    font-weight: 600;
    margin-top: 5px;
    opacity: 0.8;
}

.best-tile-container {
    background: rgba(255, 255, 255, 0.05);
    padding: 15px;
    border-radius: 16px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.best-tile-label {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.6);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.tile-preview {
    width: 70px;
    height: 70px;
    background: #eee4da;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 20px rgba(238, 228, 218, 0.4);
    transition: all 0.3s ease;
}

.tile-preview span {
    font-size: 28px;
    font-weight: 800;
    color: #1a1a2e;
}

.game-message .lower {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.revive-btn {
    background: linear-gradient(135deg, #7b4dff 0%, #5a2ae0 100%) !important;
    height: 75px !important;
    padding: 0 25px !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    box-shadow: 0 10px 30px rgba(123, 77, 255, 0.5), inset 0 0 15px rgba(255, 255, 255, 0.1) !important;
    animation: pulseGlow 2s infinite !important;
    color: white !important;
    border-radius: 16px !important;
}

.revive-btn:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 15px 40px rgba(123, 77, 255, 0.7), inset 0 0 20px rgba(255, 255, 255, 0.2) !important;
}

.revive-btn::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transform: rotate(45deg);
    animation: shine 3s infinite;
}

.btn-icon {
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    filter: drop-shadow(0 0 5px rgba(0, 0, 0, 0.2));
    flex-shrink: 0;
}

.btn-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    line-height: 1.2;
}

.btn-text-main {
    font-size: 20px;
    font-weight: 800;
    display: block;
    letter-spacing: 0.5px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.btn-text-sub {
    font-size: 12px;
    font-weight: 400;
    opacity: 0.9;
    margin-top: 2px;
}

.retry-btn {
    background: rgba(255, 255, 255, 0.1) !important;
    color: white !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    height: 60px !important;
    border-radius: 16px !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2) !important;
    transition: all 0.3s ease !important;
    margin-top: 5px;
}

.retry-btn:hover {
    background: rgba(255, 255, 255, 0.2) !important;
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3) !important;
    border-color: rgba(255, 255, 255, 0.4) !important;
}

.keep-playing-btn {
    background: rgba(44, 252, 254, 0.1) !important;
    color: #2cfcfe !important;
    border: 1px solid rgba(44, 252, 254, 0.3) !important;
    height: 60px !important;
    border-radius: 16px !important;
    font-weight: 800 !important;
    font-size: 18px !important;
    transition: all 0.3s ease !important;
}

.keep-playing-btn:hover {
    background: rgba(44, 252, 254, 0.2) !important;
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(44, 252, 254, 0.2) !important;
}


@keyframes pulseGlow {
    0% {
        box-shadow: 0 0 10px rgba(123, 77, 255, 0.4);
    }

    50% {
        box-shadow: 0 0 25px rgba(123, 77, 255, 0.8);
    }

    100% {
        box-shadow: 0 0 10px rgba(123, 77, 255, 0.4);
    }
}

@keyframes shine {
    0% {
        transform: translateX(-150%) rotate(45deg);
    }

    100% {
        transform: translateX(150%) rotate(45deg);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}



.game-footer {
    margin-top: 20px;
    color: var(--text-secondary);
    text-align: center;
}

@media screen and (max-width: 520px) {
    :root {
        --field-width: 280px;
        --grid-spacing: 10px;
    }

    .container {
        width: var(--field-width);
        margin-top: 20px;
    }

    .title-container h1 {
        font-size: 42px;
        margin-bottom: 0;
    }

    .subtitle {
        font-size: 14px;
        margin-top: 0;
    }

    .controls-container {
        margin-top: 15px;
        margin-bottom: 15px;
    }

    .btn {
        padding: 10px 15px;
        font-size: 14px;
        gap: 8px;
    }

    .btn svg {
        width: 18px;
        height: 18px;
    }

    /* Adjust game message for smaller screens */
    .game-message-content {
        width: 260px;
        padding: 20px;
    }

    .game-status-text {
        font-size: 30px !important;
    }

    .revive-btn {
        height: 60px !important;
    }

    .btn-text-main {
        font-size: 16px;
    }

    .btn-text-sub {
        font-size: 10px;
    }

    .best-tile-container {
        padding: 10px;
    }

    .tile-preview {
        width: 50px;
        height: 50px;
    }

    .tile-preview span {
        font-size: 20px;
    }

    /* Mobile Tile Font Sizes */
    .tile-inner {
        font-size: 32px !important;
        line-height: var(--tile-size) !important;
    }

    .tile-128 .tile-inner,
    .tile-256 .tile-inner,
    .tile-512 .tile-inner {
        font-size: 24px !important;
    }

    .tile-1024 .tile-inner,
    .tile-2048 .tile-inner,
    .tile-super .tile-inner {
        font-size: 18px !important;
    }
}