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

body {
    font-family: 'Poppins', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow-x: hidden;
}

.particles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
}

.particle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    animation: float 6s infinite linear;
}

@keyframes float {
    0% {
        transform: translateY(100vh) rotate(0deg);
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    90% {
        opacity: 1;
    }
    100% {
        transform: translateY(-100px) rotate(360deg);
        opacity: 0;
    }
}

.container {
    max-width: 500px;
    margin: 0 auto;
    padding: 20px;
    text-align: center;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

.header {
    margin-bottom: 30px;
}

.title {
    font-size: 4rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    margin-bottom: 20px;
    background: linear-gradient(45deg, #ff6b6b, #feca57, #48dbfb, #ff9ff3);
    background-size: 400% 400%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradientShift 3s ease-in-out infinite;
}

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

.score-container {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
}

.score-box {
    background: linear-gradient(135deg, #ff6b6b, #ee5a24);
    padding: 15px 25px;
    border-radius: 15px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
    transform: perspective(1000px) rotateX(10deg);
    transition: all 0.3s ease;
}

.score-box:hover {
    transform: perspective(1000px) rotateX(0deg) scale(1.05);
}

.score-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.score {
    font-size: 1.8rem;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.game-intro {
    margin-bottom: 30px;
}

.game-explanation {
    font-size: 1.1rem;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 20px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.restart-button {
    background: linear-gradient(135deg, #48dbfb, #0abde3);
    color: #fff;
    border: none;
    padding: 15px 30px;
    border-radius: 25px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.restart-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.3);
}

.restart-button:active {
    transform: translateY(-1px);
}

.how-to-play {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.8);
    font-weight: 400;
}

.game-container {
    position: relative;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 30px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.grid-container {
    position: relative;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 15px;
    padding: 10px;
    box-shadow: inset 0 4px 8px rgba(0, 0, 0, 0.3);
}

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

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

.grid-cell {
    width: 90px;
    height: 90px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    margin-right: 10px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
}

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

.tile-container {
    position: absolute;
    top: 30px;
    left: 30px;
    z-index: 2;
}

.tile {
    position: absolute;
    width: 90px;
    height: 90px;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 700;
    font-size: 2rem;
    transition: all 0.15s ease-in-out;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.3);
}

/* 基于CSS的网格定位系统 */
.tile[data-x='0'] { top: 0px !important; }
.tile[data-x='1'] { top: 100px !important; }
.tile[data-x='2'] { top: 200px !important; }
.tile[data-x='3'] { top: 300px !important; }

.tile[data-y='0'] { left: 0px !important; }
.tile[data-y='1'] { left: 100px !important; }
.tile[data-y='2'] { left: 200px !important; }
.tile[data-y='3'] { left: 300px !important; }

.tile-2 { background: linear-gradient(135deg, #ff9a9e, #fecfef); color: #776e65; }
.tile-4 { background: linear-gradient(135deg, #a8edea, #fed6e3); color: #776e65; }
.tile-8 { background: linear-gradient(135deg, #ffecd2, #fcb69f); color: #f9f6f2; }
.tile-16 { background: linear-gradient(135deg, #ff8a80, #ff5722); color: #f9f6f2; }
.tile-32 { background: linear-gradient(135deg, #ff6b6b, #ee5a24); color: #f9f6f2; }
.tile-64 { background: linear-gradient(135deg, #feca57, #ff9ff3); color: #f9f6f2; }
.tile-128 { background: linear-gradient(135deg, #48dbfb, #0abde3); color: #f9f6f2; font-size: 1.8rem; }
.tile-256 { background: linear-gradient(135deg, #1dd1a1, #10ac84); color: #f9f6f2; font-size: 1.8rem; }
.tile-512 { background: linear-gradient(135deg, #a55eea, #8854d0); color: #f9f6f2; font-size: 1.8rem; }
.tile-1024 { background: linear-gradient(135deg, #fd79a8, #e84393); color: #f9f6f2; font-size: 1.5rem; }
.tile-2048 { background: linear-gradient(135deg, #fdcb6e, #e17055); color: #f9f6f2; font-size: 1.5rem; animation: pulse 1s infinite; }

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

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

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

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

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

.game-message {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    color: #fff;
    text-align: center;
}

.game-message p {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 30px;
    text-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
}

.game-message .lower {
    display: flex;
    gap: 20px;
}

.keep-playing-button,
.retry-button {
    background: linear-gradient(135deg, #48dbfb, #0abde3);
    color: #fff;
    border: none;
    padding: 15px 25px;
    border-radius: 25px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

.retry-button {
    background: linear-gradient(135deg, #ff6b6b, #ee5a24);
}

.keep-playing-button:hover,
.retry-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.3);
}

.footer {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
}

.footer p {
    margin-bottom: 10px;
}

.social-links {
    font-size: 1.2rem;
}

/* 响应式设计 */
@media (max-width: 768px) and (min-width: 601px) {
    .container {
        max-width: 90vw;
        padding: 15px;
    }
    
    .title {
        font-size: 3rem;
    }
    
    .grid-cell,
    .tile {
        width: 75px;
        height: 75px;
    }
    
    .tile {
        font-size: 1.6rem;
    }
    
    .tile-128,
    .tile-256,
    .tile-512 {
        font-size: 1.4rem;
    }
    
    .tile-1024,
    .tile-2048 {
        font-size: 1.2rem;
    }
}

@media (max-width: 600px) {
    body {
        padding: 10px 0;
    }
    
    .container {
        max-width: 95vw;
        padding: 10px;
        margin: 0 auto;
    }
    
    .header {
        margin-bottom: 15px;
    }
    
    .title {
        font-size: 2.5rem;
        margin-bottom: 10px;
    }
    
    .score-container {
        flex-direction: row;
        gap: 10px;
        margin-bottom: 10px;
    }
    
    .score-box {
        padding: 10px 15px;
        flex: 1;
    }
    
    .game-intro {
        margin-bottom: 15px;
    }
    
    .game-explanation {
        font-size: 1rem;
        margin-bottom: 10px;
    }
    
    .game-container {
        padding: 15px;
        margin-bottom: 15px;
    }
    
    .grid-container {
        padding: 8px;
    }
    
    .grid-cell,
    .tile {
        width: 65px;
        height: 65px;
    }
    
    .grid-cell {
        margin-right: 8px;
    }
    
    .grid-row {
        margin-bottom: 8px;
    }
    
    .tile-container {
        top: 23px;
        left: 23px;
    }
    
    .tile {
        font-size: 1.4rem;
        line-height: 65px;
    }
    
    /* 中等屏幕的网格定位 */
    .tile[data-x='0'] { top: 0px !important; }
    .tile[data-x='1'] { top: 73px !important; }
    .tile[data-x='2'] { top: 146px !important; }
    .tile[data-x='3'] { top: 219px !important; }
    
    .tile[data-y='0'] { left: 0px !important; }
    .tile[data-y='1'] { left: 73px !important; }
    .tile[data-y='2'] { left: 146px !important; }
    .tile[data-y='3'] { left: 219px !important; }
    
    .tile-128,
    .tile-256,
    .tile-512 {
        font-size: 1.2rem;
    }
    
    .tile-1024,
    .tile-2048 {
        font-size: 1rem;
    }
    
    .game-message p {
        font-size: 1.5rem;
    }
    
    .game-message .lower {
        flex-direction: column;
        gap: 15px;
    }
    
    .footer {
        font-size: 0.8rem;
    }
}

@media (max-width: 400px) {
    .container {
        max-width: 98vw;
        padding: 8px;
    }
    
    .title {
        font-size: 2rem;
        margin-bottom: 8px;
    }
    
    .score-box {
        padding: 8px 12px;
    }
    
    .score {
        font-size: 1.5rem;
    }
    
    .score-label {
        font-size: 0.8rem;
    }
    
    .game-container {
        padding: 12px;
    }
    
    .grid-container {
        padding: 6px;
    }
    
    .grid-cell,
    .tile {
        width: 55px;
        height: 55px;
    }
    
    .grid-cell {
        margin-right: 6px;
    }
    
    .grid-row {
        margin-bottom: 6px;
    }
    
    .tile-container {
        top: 18px;
        left: 18px;
    }
    
    .tile {
        font-size: 1.1rem;
        line-height: 55px;
    }
    
    /* 小屏幕的网格定位 */
    .tile[data-x='0'] { top: 0px !important; }
    .tile[data-x='1'] { top: 61px !important; }
    .tile[data-x='2'] { top: 122px !important; }
    .tile[data-x='3'] { top: 183px !important; }
    
    .tile[data-y='0'] { left: 0px !important; }
    .tile[data-y='1'] { left: 61px !important; }
    .tile[data-y='2'] { left: 122px !important; }
    .tile[data-y='3'] { left: 183px !important; }
    
    .tile-128,
    .tile-256,
    .tile-512 {
        font-size: 0.9rem;
    }
    
    .tile-1024,
    .tile-2048 {
        font-size: 0.8rem;
    }
    
    .restart-button {
        padding: 12px 20px;
        font-size: 0.9rem;
    }
    
    .game-explanation {
        font-size: 0.9rem;
    }
}