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

body {
    font-family: 'Poppins', "Clear Sans", "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background-attachment: fixed;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    position: relative;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 1px, transparent 1px);
    background-size: 50px 50px;
    animation: backgroundMove 20s linear infinite;
    pointer-events: none;
}

@keyframes backgroundMove {
    0% {
        transform: translate(0, 0);
    }
    100% {
        transform: translate(50px, 50px);
    }
}

.container {
    max-width: 500px;
    width: 100%;
    position: relative;
    z-index: 1;
    animation: slideIn 0.6s ease-out;
}

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

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

.title {
    font-size: 80px;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 3px 6px rgba(0, 0, 0, 0.3), 0 0 40px rgba(255, 255, 255, 0.3);
    margin: 0;
    letter-spacing: -2px;
    animation: titleGlow 3s ease-in-out infinite;
}

@keyframes titleGlow {
    0%, 100% {
        text-shadow: 0 3px 6px rgba(0, 0, 0, 0.3), 0 0 40px rgba(255, 255, 255, 0.3);
    }
    50% {
        text-shadow: 0 3px 6px rgba(0, 0, 0, 0.3), 0 0 60px rgba(255, 255, 255, 0.5);
    }
}

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

.score-container {
    background: rgba(238, 228, 218, 0.35);
    padding: 10px 20px;
    border-radius: 12px;
    text-align: center;
    min-width: 80px;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    transition: all 0.3s ease;
}

.score-container:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.score-label {
    color: #eee4da;
    font-size: 13px;
    font-weight: bold;
    text-transform: uppercase;
    margin-bottom: 3px;
}

.score {
    color: white;
    font-size: 25px;
    font-weight: bold;
}

.game-intro {
    background: rgba(255, 255, 255, 0.95);
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(10px);
}

.game-intro p {
    color: #776e65;
    font-size: 14px;
    margin: 0;
    flex: 1;
}

.button-group {
    display: flex;
    gap: 10px;
    margin-left: 15px;
}

.new-game-btn,
.auto-play-btn {
    background: linear-gradient(135deg, #8f7a66 0%, #7a6656 100%);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2), inset 0 -2px 5px rgba(0, 0, 0, 0.2);
    position: relative;
    overflow: hidden;
}

.new-game-btn::before,
.auto-play-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.new-game-btn:hover::before,
.auto-play-btn:hover::before {
    width: 300px;
    height: 300px;
}

.auto-play-btn {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    position: relative;
}

.auto-play-btn.active {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
}

.auto-play-btn.active::after {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #fff;
    border-radius: 50%;
    margin-right: 8px;
    animation: pulse 1.5s ease-in-out infinite;
    position: relative;
    z-index: 1;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.3;
    }
}

.new-game-btn:hover,
.auto-play-btn:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3), inset 0 -2px 5px rgba(0, 0, 0, 0.2);
}

.new-game-btn:hover {
    background: linear-gradient(135deg, #9f8a76 0%, #8a7066 100%);
}

.auto-play-btn:hover {
    background: linear-gradient(135deg, #2980b9 0%, #21618c 100%);
}

.auto-play-btn.active:hover {
    background: linear-gradient(135deg, #c0392b 0%, #a93226 100%);
}

.new-game-btn:active,
.auto-play-btn:active {
    transform: translateY(-1px) scale(0.98);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2), inset 0 -1px 3px rgba(0, 0, 0, 0.2);
}

/* 速度控制器样式 */
.speed-control {
    background: rgba(255, 255, 255, 0.95);
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(10px);
}

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

.speed-header label {
    color: #776e65;
    font-size: 14px;
    font-weight: bold;
}

.speed-value {
    color: #3498db;
    font-size: 14px;
    font-weight: bold;
}

.speed-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
    margin-bottom: 5px;
}

.speed-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #3498db;
    cursor: pointer;
    transition: all 0.3s ease;
}

.speed-slider::-webkit-slider-thumb:hover {
    background: #2980b9;
    transform: scale(1.2);
}

.speed-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #3498db;
    cursor: pointer;
    border: none;
    transition: all 0.3s ease;
}

.speed-slider::-moz-range-thumb:hover {
    background: #2980b9;
    transform: scale(1.2);
}

.speed-labels {
    display: flex;
    justify-content: space-between;
    color: #776e65;
    font-size: 12px;
    padding: 0 5px;
}

.game-container {
    position: relative;
    background: linear-gradient(135deg, #bbada0 0%, #a99890 100%);
    border-radius: 16px;
    padding: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(0, 0, 0, 0.1);
}

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

.grid-row {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
}

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

.grid-cell {
    width: 106.25px;
    height: 106.25px;
    background: rgba(238, 228, 218, 0.35);
    border-radius: 8px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.tile-container {
    position: absolute;
    top: 15px;
    left: 15px;
    z-index: 2;
    width: calc(100% - 30px);
    height: calc(100% - 30px);
}

.tile {
    position: absolute;
    top: 0;
    left: 0;
    width: 106.25px;
    height: 106.25px;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 55px;
    font-weight: bold;
    transition: transform 0.15s ease-in-out, opacity 0.15s ease;
    will-change: transform;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* 瓦片出现动画 */
@keyframes appear {
    0% {
        opacity: 0;
        transform: translate(var(--tile-x), var(--tile-y)) scale(0);
    }
    100% {
        opacity: 1;
        transform: translate(var(--tile-x), var(--tile-y)) scale(1);
    }
}

.tile-new {
    animation: appear 0.2s ease-out;
}

/* 瓦片合并动画 */
@keyframes merge {
    0% {
        transform: translate(var(--tile-x), var(--tile-y)) scale(1);
    }
    50% {
        transform: translate(var(--tile-x), var(--tile-y)) scale(1.15);
    }
    100% {
        transform: translate(var(--tile-x), var(--tile-y)) scale(1);
    }
}

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

/* 瓦片移除动画 */
.tile-removed {
    opacity: 0;
    transform: scale(0.8);
}

/* 不同数字的颜色 */
.tile-2 {
    background: linear-gradient(135deg, #eee4da 0%, #e5dbc8 100%);
    color: #776e65;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.tile-4 {
    background: linear-gradient(135deg, #ede0c8 0%, #e4d7b6 100%);
    color: #776e65;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.tile-8 {
    background: linear-gradient(135deg, #f2b179 0%, #eda967 100%);
    color: #f9f6f2;
    box-shadow: 0 3px 8px rgba(242, 177, 121, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.tile-16 {
    background: linear-gradient(135deg, #f59563 0%, #f08d51 100%);
    color: #f9f6f2;
    box-shadow: 0 3px 8px rgba(245, 149, 99, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.tile-32 {
    background: linear-gradient(135deg, #f67c5f 0%, #f1744d 100%);
    color: #f9f6f2;
    box-shadow: 0 3px 8px rgba(246, 124, 95, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.tile-64 {
    background: linear-gradient(135deg, #f65e3b 0%, #f15629 100%);
    color: #f9f6f2;
    box-shadow: 0 3px 8px rgba(246, 94, 59, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.tile-128 {
    background: linear-gradient(135deg, #edcf72 0%, #e8ca60 100%);
    color: #f9f6f2;
    font-size: 45px;
    box-shadow: 0 4px 12px rgba(237, 207, 114, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.tile-256 {
    background: linear-gradient(135deg, #edcc61 0%, #e8c74f 100%);
    color: #f9f6f2;
    font-size: 45px;
    box-shadow: 0 4px 12px rgba(237, 204, 97, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.tile-512 {
    background: linear-gradient(135deg, #edc850 0%, #e8c33e 100%);
    color: #f9f6f2;
    font-size: 45px;
    box-shadow: 0 4px 12px rgba(237, 200, 80, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.tile-1024 {
    background: linear-gradient(135deg, #edc53f 0%, #e8c02d 100%);
    color: #f9f6f2;
    font-size: 35px;
    box-shadow: 0 5px 15px rgba(237, 197, 63, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.tile-2048 {
    background: linear-gradient(135deg, #edc22e 0%, #e8bd1c 100%);
    color: #f9f6f2;
    font-size: 35px;
    box-shadow: 0 6px 20px rgba(237, 194, 46, 0.7), 0 0 40px rgba(237, 194, 46, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.4);
    animation: glow2048 2s ease-in-out infinite;
}

@keyframes glow2048 {
    0%, 100% {
        box-shadow: 0 6px 20px rgba(237, 194, 46, 0.7), 0 0 40px rgba(237, 194, 46, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.4);
    }
    50% {
        box-shadow: 0 6px 20px rgba(237, 194, 46, 0.9), 0 0 60px rgba(237, 194, 46, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.4);
    }
}

.tile-super {
    background: linear-gradient(135deg, #3c3a32 0%, #2d2b25 100%);
    color: #f9f6f2;
    font-size: 30px;
    box-shadow: 0 5px 15px rgba(60, 58, 50, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* 游戏结束消息 */
.game-message {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(238, 228, 218, 0.97);
    border-radius: 16px;
    z-index: 100;
    text-align: center;
    animation: fadeIn 0.5s ease-in-out;
    backdrop-filter: blur(5px);
}

.game-message.show {
    display: flex;
    justify-content: center;
    align-items: center;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.message-content {
    color: #776e65;
    animation: messageSlideIn 0.6s ease-out 0.2s both;
}

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

.message-content p {
    font-size: 60px;
    font-weight: bold;
    margin-bottom: 30px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.retry-btn {
    background: linear-gradient(135deg, #8f7a66 0%, #7a6656 100%);
    color: white;
    border: none;
    padding: 15px 40px;
    border-radius: 10px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2), inset 0 -2px 5px rgba(0, 0, 0, 0.2);
    position: relative;
    overflow: hidden;
}

.retry-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.retry-btn:hover::before {
    width: 300px;
    height: 300px;
}

.retry-btn:hover {
    background: linear-gradient(135deg, #9f8a76 0%, #8a7066 100%);
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3), inset 0 -2px 5px rgba(0, 0, 0, 0.2);
}

.retry-btn:active {
    transform: translateY(-1px) scale(1.02);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2), inset 0 -1px 3px rgba(0, 0, 0, 0.2);
}

/* 响应式设计 */
@media screen and (max-width: 520px) {
    body::before {
        background-size: 30px 30px;
    }

    .container {
        animation: slideIn 0.4s ease-out;
    }

    .title {
        font-size: 50px;
    }

    .score-container {
        min-width: 60px;
        padding: 8px 15px;
    }

    .score {
        font-size: 20px;
    }

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

    .game-intro {
        flex-direction: column;
        gap: 15px;
    }

    .game-intro p {
        text-align: center;
    }

    .button-group {
        margin-left: 0;
        width: 100%;
    }

    .new-game-btn,
    .auto-play-btn {
        flex: 1;
        padding: 12px 15px;
        font-size: 14px;
    }

    .game-container {
        padding: 10px;
    }

    .grid-row {
        gap: 10px;
        margin-bottom: 10px;
    }

    .grid-cell,
    .tile {
        width: 70px;
        height: 70px;
    }

    .tile {
        font-size: 35px;
    }

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

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

    .tile-super {
        font-size: 20px;
    }

    .tile-container {
        top: 10px;
        left: 10px;
        width: calc(100% - 20px);
        height: calc(100% - 20px);
    }

    .message-content p {
        font-size: 40px;
    }

    .retry-btn {
        padding: 12px 30px;
        font-size: 16px;
    }
}
