body {
    font-family: "Helvetica Neue", Arial, sans-serif;
    background: #faf8ef;
    color: #776e65;
    margin: 0;
    padding: 0;
}

.game-container {
    width: 500px;
    margin: 40px auto;
    position: relative;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.title {
    font-size: 80px;
    font-weight: bold;
    margin: 0;
    display: block;
    float: left;
    color: #776e65;
}

.scores-container {
    float: right;
    text-align: center;
}

.score-container, .best-container {
    display: inline-block;
    background: #bbada0;
    padding: 15px 25px;
    font-size: 25px;
    height: 25px;
    line-height: 47px;
    font-weight: bold;
    border-radius: 3px;
    color: white;
    margin-left: 10px;
    text-align: center;
}

.score-title, .best-title {
    text-transform: uppercase;
    font-size: 13px;
    margin-bottom: 5px;
    line-height: 13px;
}

.score-value, .best-value {
    font-size: 25px;
    line-height: 30px;
}

.game-intro {
    margin-bottom: 20px;
    font-size: 16px;
    color: #776e65;
}

.game-intro strong {
    font-weight: bold;
}

.game-area {
    position: relative;
    padding: 15px;
    cursor: default;
    background: #bbada0;
    border-radius: 6px;
    width: 500px;
    height: 500px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

.grid-container {
    position: absolute;
    z-index: 1;
}

.grid-row {
    margin-bottom: 15px;
}

.grid-row:last-child {
    margin-bottom: 0;
}

.grid-cell {
    width: 106.25px;
    height: 106.25px;
    margin-right: 15px;
    float: left;
    border-radius: 3px;
    background: rgba(238, 228, 218, 0.35);
}

.grid-cell:last-child {
    margin-right: 0;
}

.tile-container {
    position: absolute;
    z-index: 2;
}

.tile, .tile .tile-inner {
    width: 107px;
    height: 107px;
    line-height: 116.25px;
}

.tile {
    position: absolute;
    -webkit-transition: 100ms ease-in-out;
    -moz-transition: 100ms ease-in-out;
    transition: 100ms ease-in-out;
    -webkit-transition-property: -webkit-transform;
    -moz-transition-property: -moz-transform;
    transition-property: transform;
}

.tile .tile-inner {
    border-radius: 3px;
    background: #eee4da;
    text-align: center;
    font-weight: bold;
    z-index: 10;
    font-size: 55px;
    color: #776e65;
}

.tile.tile-2 .tile-inner {
    background: #eee4da;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0), inset 0 0 0 1px rgba(255, 255, 255, 0);
}

.tile.tile-4 .tile-inner {
    background: #ede0c8;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0), inset 0 0 0 1px rgba(255, 255, 255, 0);
}

.tile.tile-8 .tile-inner {
    color: #f9f6f2;
    background: #f2b179;
}

.tile.tile-16 .tile-inner {
    color: #f9f6f2;
    background: #f59563;
}

.tile.tile-32 .tile-inner {
    color: #f9f6f2;
    background: #f67c5f;
}

.tile.tile-64 .tile-inner {
    color: #f9f6f2;
    background: #f65e3b;
}

.tile.tile-128 .tile-inner {
    color: #f9f6f2;
    background: #edcf72;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.2381), inset 0 0 0 1px rgba(255, 255, 255, 0.14286);
    font-size: 45px;
}

.tile.tile-256 .tile-inner {
    color: #f9f6f2;
    background: #edcc61;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.31746), inset 0 0 0 1px rgba(255, 255, 255, 0.19048);
    font-size: 45px;
}

.tile.tile-512 .tile-inner {
    color: #f9f6f2;
    background: #edc850;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.39683), inset 0 0 0 1px rgba(255, 255, 255, 0.2381);
    font-size: 45px;
}

.tile.tile-1024 .tile-inner {
    color: #f9f6f2;
    background: #edc53f;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.47619), inset 0 0 0 1px rgba(255, 255, 255, 0.28571);
    font-size: 35px;
}

.tile.tile-2048 .tile-inner {
    color: #f9f6f2;
    background: #edc22e;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.55556), inset 0 0 0 1px rgba(255, 255, 255, 0.33333);
    font-size: 35px;
}

.tile.tile-super .tile-inner {
    color: #f9f6f2;
    background: #3c3a32;
    font-size: 30px;
}

.game-message {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(238, 228, 218, 0.73);
    z-index: 100;
    text-align: center;
    -webkit-animation: fade-in 800ms ease 1200ms;
    -moz-animation: fade-in 800ms ease 1200ms;
    animation: fade-in 800ms ease 1200ms;
    -webkit-animation-fill-mode: both;
    -moz-animation-fill-mode: both;
    animation-fill-mode: both;
}

.game-message p {
    font-size: 60px;
    font-weight: bold;
    height: 60px;
    line-height: 60px;
    margin-top: 222px;
}

.game-message .lower {
    display: block;
    margin-top: 59px;
}

.game-message a {
    display: inline-block;
    background: #8f7a66;
    border-radius: 3px;
    padding: 0 20px;
    text-decoration: none;
    color: #f9f6f2;
    height: 40px;
    line-height: 42px;
    margin-left: 9px;
}

.controls {
    margin-top: 20px;
    text-align: center;
}

.restart-button {
    display: inline-block;
    background: #8f7a66;
    border-radius: 3px;
    padding: 0 20px;
    text-decoration: none;
    color: #f9f6f2;
    height: 40px;
    line-height: 42px;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    border: none;
}

.restart-button:hover {
    background: #9f8a76;
}

/* 移动端优化 */
@media screen and (max-width: 520px) {
    .game-container {
        width: 280px;
        margin: 20px auto;
    }

    .game-area {
        width: 280px;
        height: 280px;
        padding: 10px;
    }

    .grid-cell {
        width: 57.5px;
        height: 57.5px;
        margin-right: 10px;
    }

    .grid-cell:last-child {
        margin-right: 0;
    }

    .grid-row {
        margin-bottom: 10px;
    }

    .grid-row:last-child {
        margin-bottom: 0;
    }

    .tile, .tile .tile-inner {
        width: 58px;
        height: 58px;
        line-height: 67.5px;
    }

    .tile.tile-128 .tile-inner,
    .tile.tile-256 .tile-inner,
    .tile.tile-512 .tile-inner {
        font-size: 25px;
    }

    .tile.tile-1024 .tile-inner,
    .tile.tile-2048 .tile-inner {
        font-size: 20px;
    }

    .tile.tile-super .tile-inner {
        font-size: 16px;
    }

    .title {
        font-size: 40px;
    }

    .score-container, .best-container {
        padding: 10px 15px;
        font-size: 18px;
        margin-left: 5px;
    }

    .score-title, .best-title {
        font-size: 12px;
    }

    .score-value, .best-value {
        font-size: 20px;
    }
    
    .game-intro {
        font-size: 14px;
        margin-bottom: 15px;
    }
    
    .controls {
        margin-top: 15px;
    }
    
    .restart-button {
        padding: 0 15px;
        height: 35px;
        line-height: 37px;
        font-size: 16px;
    }
}

/* 超小屏幕设备优化 */
@media screen and (max-width: 320px) {
    .game-container {
        width: 240px;
        margin: 10px auto;
    }

    .game-area {
        width: 240px;
        height: 240px;
        padding: 8px;
    }

    .grid-cell {
        width: 47px;
        height: 47px;
        margin-right: 8px;
    }

    .tile, .tile .tile-inner {
        width: 47px;
        height: 47px;
        line-height: 55px;
    }

    .tile.tile-128 .tile-inner,
    .tile.tile-256 .tile-inner,
    .tile.tile-512 .tile-inner {
        font-size: 20px;
    }

    .tile.tile-1024 .tile-inner,
    .tile.tile-2048 .tile-inner {
        font-size: 16px;
    }

    .tile.tile-super .tile-inner {
        font-size: 12px;
    }

    .title {
        font-size: 32px;
    }

    .score-container, .best-container {
        padding: 8px 12px;
        font-size: 16px;
        margin-left: 4px;
    }

    .score-title, .best-title {
        font-size: 10px;
    }

    .score-value, .best-value {
        font-size: 18px;
    }
    
    .game-intro {
        font-size: 12px;
        margin-bottom: 10px;
    }
    
    .restart-button {
        padding: 0 12px;
        height: 30px;
        line-height: 32px;
        font-size: 14px;
    }
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
    .tile {
        -webkit-transition: none;
        -moz-transition: none;
        transition: none;
    }
    
    .tile .tile-inner {
        -webkit-tap-highlight-color: transparent;
    }
}