* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: radial-gradient(150% 150% at 50% 0%, #fdfcfb 0%, #e2d1c3 50%, #fdfcfb 100%);
    background-size: 200% 200%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    position: relative;
    overflow: hidden;
    animation: breatheGradient 12s ease-in-out infinite;
}

/* 动态背景装饰 */
.bg-blob {
    position: fixed;
    border-radius: 50%;
    filter: blur(40px);
    z-index: 0;
    opacity: 0.4;
    pointer-events: none;
    animation: floatBlob 20s infinite alternate ease-in-out;
}

.blob-1 {
    width: 400px;
    height: 400px;
    background: #ede0c8;
    top: -100px;
    left: -100px;
}

.blob-2 {
    width: 350px;
    height: 350px;
    background: #f2b179;
    bottom: -50px;
    right: -50px;
    animation-delay: -5s;
}

.blob-3 {
    width: 250px;
    height: 250px;
    background: #bbada0;
    top: 40%;
    right: 15%;
    animation-delay: -10s;
}

@keyframes floatBlob {
    0% { transform: translate(0, 0) scale(1) rotate(0deg); }
    33% { transform: translate(50px, 30px) scale(1.1) rotate(10deg); }
    66% { transform: translate(-20px, 60px) scale(0.9) rotate(-10deg); }
    100% { transform: translate(0, 0) scale(1) rotate(0deg); }
}

body::before,
body::after {
    content: "";
    position: fixed;
    inset: -20% -20%;
    background:
        linear-gradient(45deg, rgba(187, 173, 160, 0.15) 0 0) 10% 10%/80px 80px,
        linear-gradient(135deg, rgba(238, 228, 218, 0.4) 0 0) 80% 80%/100px 100px,
        linear-gradient(0deg, rgba(242, 177, 121, 0.1) 0 0) 30% 70%/60px 60px,
        linear-gradient(90deg, rgba(187, 173, 160, 0.12) 0 0) 70% 20%/120px 120px;
    background-repeat: no-repeat;
    pointer-events: none;
    z-index: 0;
    animation: floatSquares 25s linear infinite;
}

body::after {
    opacity: 0.5;
    animation: floatSquares 35s linear infinite reverse;
    filter: blur(2px);
}

@keyframes floatSquares {
    0% { transform: rotate(0deg) translate(0, 0); }
    100% { transform: rotate(360deg) translate(20px, 20px); }
}

@keyframes breatheGradient {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

header,
#grid-container,
.button-group,
.instructions {
    position: relative;
    z-index: 1;
}

.github-corner:hover .octo-arm {
    animation: octocat-wave 560ms ease-in-out;
}

@keyframes octocat-wave {
    0%, 100% {
        transform: rotate(0);
    }
    20%, 60% {
        transform: rotate(-25deg);
    }
    40%, 80% {
        transform: rotate(10deg);
    }
}

@media (max-width: 500px) {
    .github-corner:hover .octo-arm {
        animation: none;
    }
    .github-corner .octo-arm {
        animation: octocat-wave 560ms ease-in-out;
    }
}

.fade {
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

header {
    text-align: center;
    margin-bottom: 30px;
}

.scoreboard {
    display: inline-flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.score-row {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

#title {
    font-size: 80px;
    font-weight: bold;
    color: #776e65;
    margin-bottom: 10px;
}

.lang {
    color: #776e65;
    font-size: 18px;
}

.counter {
    display: inline-block;
    background: #bbada0;
    color: #fff;
    padding: 5px 15px;
    border-radius: 5px;
    font-size: 18px;
    min-width: 100px;
    text-align: center;
}

#grid-container {
    position: relative;
    background: #bbada0;
    padding: 15px;
    border-radius: 10px;
    width: 500px;
    height: 500px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 15px;
}

.grid-cell {
    background: rgba(238, 228, 218, 0.35);
    border-radius: 5px;
    position: relative;
}

.tile {
    position: absolute;
    width: 100px;
    height: 100px;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 45px;
    transition:
        transform 0.18s cubic-bezier(0.22, 0.61, 0.36, 1),
        top 0.18s cubic-bezier(0.22, 0.61, 0.36, 1),
        left 0.18s cubic-bezier(0.22, 0.61, 0.36, 1),
        opacity 0.18s ease;
    animation: pop 0.18s ease-out;
    will-change: transform;
    z-index: 1;
}

.tile.merged {
    animation: merge 0.2s ease-in;
}

@keyframes merge {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes pop {
    0% {
        transform: scale(0.85);
        opacity: 0;
    }
    50% {
        transform: scale(1.05);
        opacity: 1;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.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;
    font-size: 40px;
}

.tile-256 {
    background: #edcc61;
    color: #f9f6f2;
    font-size: 40px;
}

.tile-512 {
    background: #edc850;
    color: #f9f6f2;
    font-size: 40px;
}

.tile-1024 {
    background: #edc53f;
    color: #f9f6f2;
    font-size: 35px;
}

.tile-2048 {
    background: #edc22e;
    color: #f9f6f2;
    font-size: 35px;
}

.tile-super {
    background: #3c3a32;
    color: #f9f6f2;
    font-size: 30px;
}

.button {
    padding: 15px 40px;
    font-size: 18px;
    cursor: pointer;
    border: none;
    outline: none;
    transition: all 0.3s ease;
}

.button-3d {
    box-shadow: 0 5px 0 #8f7a66, 0 10px 10px rgba(0, 0, 0, 0.1);
}

.button-primary {
    background: #8f7a66;
    color: #fff;
}

.button-rounded {
    border-radius: 5px;
}

.button:hover {
    transform: translateY(-2px);
    box-shadow: 0 7px 0 #8f7a66, 0 12px 12px rgba(0, 0, 0, 0.1);
}

.button:active {
    transform: translateY(2px);
    box-shadow: 0 3px 0 #8f7a66, 0 6px 6px rgba(0, 0, 0, 0.1);
}

.button-group {
    display: flex;
    gap: 15px;
    margin-top: 30px;
}

.button-secondary {
    background: #bbada0;
}

.button-secondary:hover {
    box-shadow: 0 7px 0 #8f7a66, 0 12px 12px rgba(0, 0, 0, 0.1);
}

.button-secondary:active {
    box-shadow: 0 3px 0 #8f7a66, 0 6px 6px rgba(0, 0, 0, 0.1);
}

.game-over-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(238, 228, 218, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    animation: fadeIn 0.3s ease;
    z-index: 10;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.game-over-overlay.visible {
    display: flex;
}

.game-over-content {
    text-align: center;
    background: #fff;
    padding: 30px 50px;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.game-over-content h2 {
    font-size: 36px;
    color: #776e65;
    margin-bottom: 15px;
}

.game-over-content p {
    font-size: 20px;
    color: #776e65;
    margin-bottom: 20px;
}

.game-over-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.instructions {
    margin-top: 20px;
    color: #776e65;
    font-size: 14px;
    text-align: center;
}

@media (max-width: 600px) {
    #title {
        font-size: 50px;
    }
    
    #grid-container {
        width: 340px;
        height: 340px;
        padding: 10px;
        gap: 10px;
    }
    
    .tile {
        width: 70px;
        height: 70px;
        font-size: 35px;
    }
    
    .tile-128,
    .tile-256,
    .tile-512 {
        font-size: 28px;
    }
    
    .tile-1024,
    .tile-2048 {
        font-size: 24px;
    }
    
    .tile-super {
        font-size: 20px;
    }
    
    .lang {
        font-size: 14px;
    }

    .scoreboard {
        gap: 8px;
    }

    .score-row {
        gap: 8px;
    }
    
    .counter {
        padding: 3px 10px;
        font-size: 14px;
        min-width: 70px;
    }
    
    .button {
        padding: 12px 30px;
        font-size: 16px;
    }
    
    .button-group {
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }
    
    .game-over-content {
        padding: 20px 30px;
    }
    
    .game-over-content h2 {
        font-size: 28px;
    }
    
    .game-over-content p {
        font-size: 16px;
    }
}
