* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    background: var(--bg-main);
    min-height: 100vh;
    color: var(--text-1);
    overflow-x: hidden;
    line-height: 1.6;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
}


.header {
    text-align: center;
    margin-bottom: 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface-1);
    backdrop-filter: blur(var(--glass-blur));
    padding: 24px 32px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-1);
    box-shadow: var(--shadow-md);
}

.header h1 {
    font-size: 3rem;
    font-family: var(--font-display);
    font-weight: 800;
    color: var(--text-0);
    margin: 0;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.home-btn {
    background: var(--surface-2);
    color: var(--text-0);
    border: 1px solid var(--border-1);
    padding: 12px 24px;
    border-radius: var(--radius-full);
    cursor: pointer;
    font-family: var(--font-main);
    font-weight: 600;
    transition: var(--transition-base);
}

.home-btn:hover {
    background: var(--surface-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow-sm);
}


.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    gap: 20px;
    flex-wrap: wrap;
}

.score-panel {
    display: flex;
    gap: 20px;
    background: var(--surface-1);
    backdrop-filter: blur(var(--glass-blur));
    padding: 24px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-1);
    box-shadow: var(--shadow-md);
}

.score-item {
    text-align: center;
    min-width: 90px;
}

.score-item .label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-2);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.score-item .value {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-0);
    font-family: var(--font-display);
}

.controls {
    display: flex;
    gap: 12px;
}

.control-btn {
    padding: 14px 24px;
    border: 1px solid var(--border-1);
    border-radius: var(--radius-full);
    font-family: var(--font-main);
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition-base);
    font-size: 0.95rem;
    color: var(--text-0);
}

.control-btn.primary {
    background: var(--accent-gradient);
    border: none;
    box-shadow: var(--shadow-glow-sm);
}

.control-btn.secondary {
    background: var(--surface-2);
}

.control-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    filter: brightness(1.1);
    box-shadow: var(--shadow-glow-md);
}


.game-container {
    position: relative;
    display: flex;
    justify-content: center;
    margin-bottom: 30px;
}

.game-board {
    background: var(--surface-1);
    backdrop-filter: blur(var(--glass-blur));
    border-radius: var(--radius-lg);
    padding: 16px;
    position: relative;
    width: 400px;
    height: 400px;
    border: 1px solid var(--border-1);
    box-shadow: var(--shadow-xl);
}

.grid-container {
    position: absolute;
    z-index: 1;
}

.grid-row {
    display: flex;
    margin-bottom: 10px;
}

.grid-row:last-child {
    margin-bottom: 0;
}

.grid-cell {
    width: 87.5px;
    height: 87.5px;
    background: var(--surface-2);
    border-radius: var(--radius-md);
    margin-right: 10px;
}

.grid-cell:last-child {
    margin-right: 0;
}

.tile-container {
    position: absolute;
    z-index: 2;
}

.tile {
    position: absolute;
    width: 87.5px;
    height: 87.5px;
    background: #eee4da;
    border-radius: var(--radius-md);
    font-weight: 800;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2.2rem;
    font-family: var(--font-display);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
}

.tile.moving {
    transition: all 0.2s ease-in-out;
    z-index: 10;
}


.tile-2 {
    background: #E0E7FF;
    color: #1E1B4B;
}

.tile-4 {
    background: #C7D2FE;
    color: #1E1B4B;
}

.tile-8 {
    background: rgba(249, 115, 22, 0.2);
    color: #FFF;
    border: 1px solid rgba(249, 115, 22, 0.5);
    box-shadow: 0 0 15px rgba(249, 115, 22, 0.3);
}

.tile-16 {
    background: rgba(234, 88, 12, 0.4);
    color: #FFF;
    border: 1px solid rgba(234, 88, 12, 0.6);
    box-shadow: 0 0 20px rgba(234, 88, 12, 0.4);
}

.tile-32 {
    background: rgba(220, 38, 38, 0.5);
    color: #FFF;
    border: 1px solid rgba(220, 38, 38, 0.7);
    box-shadow: 0 0 25px rgba(220, 38, 38, 0.5);
}

.tile-64 {
    background: rgba(185, 28, 28, 0.7);
    color: #FFF;
    border: 1px solid rgba(185, 28, 28, 0.9);
    box-shadow: 0 0 30px rgba(185, 28, 28, 0.6);
}

.tile-128 {
    background: var(--accent-gradient);
    color: #FFF;
    font-size: 1.8rem;
    box-shadow: var(--shadow-glow-sm);
}

.tile-256 {
    background: var(--accent-gradient);
    color: #FFF;
    font-size: 1.8rem;
    box-shadow: var(--shadow-glow-md);
    transform: scale(1.02);
}

.tile-512 {
    background: var(--accent-gradient);
    color: #FFF;
    font-size: 1.8rem;
    box-shadow: var(--shadow-glow-lg);
    transform: scale(1.05);
}

.tile-1024 {
    background: var(--accent-gradient);
    color: #FFF;
    font-size: 1.5rem;
    box-shadow: 0 0 40px var(--accent-primary);
    transform: scale(1.08);
}

.tile-2048 {
    background: var(--accent-gradient);
    color: #FFF;
    font-size: 1.5rem;
    box-shadow: 0 0 50px var(--accent-primary);
    transform: scale(1.1);
    outline: 2px solid rgba(255, 255, 255, 0.5);
}

.tile-super {
    background: #000;
    color: #FFF;
    font-size: 1.2rem;
    box-shadow: 0 0 60px #FFF;
}


.tile-new {
    animation: appear 0.2s ease-in-out;
}

.tile-merged {
    animation: pop 0.2s ease-in-out;
}

@keyframes appear {
    0% {
        opacity: 0;
        transform: scale(0);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes pop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}


.game-overlay,
.game-over {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(5, 8, 20, 0.85);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: var(--radius-lg);
    z-index: 1000;
}

.game-over.hidden,
.game-overlay.hidden {
    display: none;
}

.game-over-content,
.game-start-content {
    background: var(--surface-1);
    backdrop-filter: blur(var(--glass-blur));
    padding: 48px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-1);
    text-align: center;
    box-shadow: var(--shadow-xl);
    transform: scale(0.8);
    animation: modalAppear 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    min-width: 340px;
}

@keyframes modalAppear {
    to {
        transform: scale(1);
    }
}

.game-over-content h2,
.game-start-content h2 {
    font-size: 2.5rem;
    font-family: var(--font-display);
    margin-bottom: 24px;
    color: var(--text-0);
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.game-over-content p,
.game-start-content p {
    font-size: 1.1rem;
    margin-bottom: 24px;
    color: var(--text-2);
}

#high-score-msg {
    color: #f67c5f;
    font-weight: bold;
    animation: glow 1s ease-in-out infinite alternate;
}

@keyframes glow {
    from {
        text-shadow: 0 0 5px #f67c5f;
    }

    to {
        text-shadow: 0 0 20px #f67c5f, 0 0 30px #f67c5f;
    }
}

.modal-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
    flex-wrap: wrap;
}


.instructions {
    background: var(--surface-1);
    backdrop-filter: blur(var(--glass-blur));
    padding: 32px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-1);
    box-shadow: var(--shadow-md);
}

.instructions h3 {
    text-align: center;
    margin-bottom: 24px;
    font-size: 1.8rem;
    font-family: var(--font-display);
    color: var(--text-0);
}

.instruction-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 25px;
}

.instruction-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 16px;
    background: var(--surface-2);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-2);
    transition: var(--transition-base);
}

.instruction-item:hover {
    border-color: var(--accent-primary);
    transform: translateX(5px);
}

.instruction-item .key {
    background: var(--accent-gradient);
    color: #FFF;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-weight: 800;
    min-width: 60px;
    text-align: center;
    box-shadow: var(--shadow-glow-sm);
}

.instruction-item .desc {
    font-size: 0.95rem;
    color: var(--text-1);
}

.game-rules {
    background: var(--surface-2);
    padding: 24px;
    border-radius: var(--radius-md);
    border-left: 4px solid var(--accent-primary);
    margin-top: 32px;
}

.game-rules h4 {
    margin-bottom: 20px;
    color: var(--text-0);
    font-size: 1.3rem;
    font-family: var(--font-display);
}

.game-rules ul {
    list-style: none;
    padding: 0;
}

.game-rules li {
    padding: 8px 0;
    padding-left: 28px;
    position: relative;
    color: var(--text-1);
    font-size: 1.05rem;
}

.game-rules li:before {
    content: "✦";
    position: absolute;
    left: 0;
    color: var(--accent-primary);
}


@media (max-width: 768px) {
    .container {
        padding: 15px;
    }

    .header {
        flex-direction: column;
        gap: 15px;
    }

    .header h1 {
        font-size: 2.5rem;
    }

    .game-info {
        flex-direction: column;
        align-items: stretch;
    }

    .score-panel {
        justify-content: center;
    }

    .controls {
        justify-content: center;
    }

    .game-board {
        width: min(90vw, 350px);
        height: min(90vw, 350px);
        padding: 10px;
        margin: 0 auto;
    }

    .grid-cell,
    .tile {
        width: calc((min(90vw, 350px) - 50px) / 4);
        height: calc((min(90vw, 350px) - 50px) / 4);
    }

    .tile {
        font-size: 1.6rem;
        font-weight: bold;
    }

    .tile-128,
    .tile-256,
    .tile-512 {
        font-size: 1.3rem;
    }

    .tile-1024,
    .tile-2048 {
        font-size: 1.1rem;
    }

    .tile-super {
        font-size: 0.9rem;
    }

    .instruction-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .score-panel {
        gap: 10px;
    }

    .score-item .value {
        font-size: 1.5rem;
    }

    .controls {
        flex-direction: column;
    }

    .control-btn {
        width: 100%;
    }

    .modal-buttons {
        flex-direction: column;
    }

    .game-board {
        width: min(85vw, 320px);
        height: min(85vw, 320px);
        padding: 8px;
    }

    .grid-cell,
    .tile {
        width: calc((min(85vw, 320px) - 40px) / 4);
        height: calc((min(85vw, 320px) - 40px) / 4);
    }

    .tile {
        font-size: 1.4rem;
        font-weight: bold;
    }

    .tile-128,
    .tile-256,
    .tile-512 {
        font-size: 1rem;
    }

    .tile-1024,
    .tile-2048 {
        font-size: 0.9rem;
    }

    .tile-super {
        font-size: 0.7rem;
    }
}