/* 全局样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* 根变量定义 */
:root {
    --primary-color: #ff6b6b;
    --secondary-color: #4ecdc4;
    --accent-color: #45b7d1;
    --dark-color: #2c3e50;
    --light-color: #ecf0f1;
    --success-color: #2ecc71;
    --warning-color: #f39c12;
    --danger-color: #e74c3c;
    
    --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-secondary: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --gradient-accent: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    
    --shadow-light: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-medium: 0 8px 25px rgba(0, 0, 0, 0.15);
    --shadow-heavy: 0 20px 40px rgba(0, 0, 0, 0.2);
    
    --border-radius: 16px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 基础样式 */
body {
    font-family: 'Orbitron', 'Arial', sans-serif;
    background: var(--gradient-primary);
    min-height: 100vh;
    color: var(--dark-color);
    overflow-x: hidden;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 游戏头部 */
.game-header {
    text-align: center;
    margin-bottom: 30px;
    animation: slideDown 0.8s ease-out;
}

.game-title {
    font-size: clamp(3rem, 8vw, 6rem);
    font-weight: 900;
    background: var(--gradient-secondary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 20px;
    text-shadow: 0 0 30px rgba(255, 107, 107, 0.5);
    letter-spacing: 4px;
}

.score-container {
    display: flex;
    justify-content: center;
    gap: 30px;
    flex-wrap: wrap;
}

.score-box {
    background: rgba(255, 255, 255, 0.95);
    padding: 20px 30px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-medium);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    transition: var(--transition);
    min-width: 120px;
}

.score-box:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-heavy);
}

.score-label {
    display: block;
    font-size: 0.9rem;
    color: var(--dark-color);
    margin-bottom: 8px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.score-value {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* 游戏控制按钮 */
.game-controls {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.control-btn {
    background: var(--gradient-accent);
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: var(--border-radius);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow-light);
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
}

.control-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.5s;
}

.control-btn:hover::before {
    left: 100%;
}

.control-btn:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-medium);
}

.control-btn:active {
    transform: translateY(0);
}

/* 游戏板容器 */
.game-board-container {
    position: relative;
    display: flex;
    justify-content: center;
    margin-bottom: 40px;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 12px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius);
    backdrop-filter: blur(20px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: var(--shadow-heavy);
    max-width: 400px;
    width: 100%;
    aspect-ratio: 1;
}

/* 游戏格子 */
.tile {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    font-weight: 700;
    color: var(--dark-color);
    transition: var(--transition);
    box-shadow: var(--shadow-light);
    position: relative;
    overflow: hidden;
}

.tile::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--gradient-secondary);
    opacity: 0;
    transition: opacity 0.3s;
}

.tile.merged::before {
    opacity: 0.3;
}

.tile.new {
    animation: tileAppear 0.3s ease-out;
}

.tile.merged {
    animation: tileMerge 0.3s ease-out;
}

/* 数字颜色 */
.tile[data-value="2"] { background: #ffeb3b; color: #333; }
.tile[data-value="4"] { background: #ff9800; color: white; }
.tile[data-value="8"] { background: #f44336; color: white; }
.tile[data-value="16"] { background: #e91e63; color: white; }
.tile[data-value="32"] { background: #9c27b0; color: white; }
.tile[data-value="64"] { background: #673ab7; color: white; }
.tile[data-value="128"] { background: #3f51b5; color: white; }
.tile[data-value="256"] { background: #2196f3; color: white; }
.tile[data-value="512"] { background: #00bcd4; color: white; }
.tile[data-value="1024"] { background: #009688; color: white; }
.tile[data-value="2048"] { background: var(--gradient-secondary); color: white; }

/* 游戏结束遮罩 */
.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    display: none;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius);
    z-index: 10;
}

.game-overlay.show {
    display: flex;
    animation: fadeIn 0.3s ease-out;
}

.overlay-content {
    background: rgba(255, 255, 255, 0.95);
    padding: 40px;
    border-radius: var(--border-radius);
    text-align: center;
    box-shadow: var(--shadow-heavy);
    backdrop-filter: blur(20px);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.overlay-content h2 {
    font-size: 2.5rem;
    margin-bottom: 20px;
    color: var(--primary-color);
}

.overlay-content p {
    font-size: 1.2rem;
    margin-bottom: 30px;
    color: var(--dark-color);
}

.overlay-btn {
    background: var(--gradient-accent);
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: var(--border-radius);
    font-family: inherit;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.overlay-btn:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-medium);
}

/* 游戏信息卡片 */
.game-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 30px;
    margin-bottom: 40px;
}

.info-card {
    background: rgba(255, 255, 255, 0.95);
    padding: 30px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-medium);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    transition: var(--transition);
}

.info-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-heavy);
}

.info-card h3 {
    font-size: 1.5rem;
    margin-bottom: 15px;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.info-card p {
    line-height: 1.6;
    color: var(--dark-color);
}

/* 页脚 */
.game-footer {
    text-align: center;
    padding: 20px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
    margin-top: auto;
}

/* 动画定义 */
@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes tileAppear {
    from {
        opacity: 0;
        transform: scale(0.5);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* 响应式设计 */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    .game-board {
        gap: 8px;
        padding: 15px;
    }
    
    .score-container {
        gap: 20px;
    }
    
    .score-box {
        padding: 15px 20px;
        min-width: 100px;
    }
    
    .game-controls {
        gap: 15px;
    }
    
    .control-btn {
        padding: 12px 20px;
        font-size: 0.9rem;
    }
    
    .game-info {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .info-card {
        padding: 20px;
    }
}

@media (max-width: 480px) {
    .game-title {
        font-size: 3rem;
    }
    
    .score-container {
        flex-direction: column;
        align-items: center;
    }
    
    .game-controls {
        flex-direction: column;
        align-items: center;
    }
    
    .control-btn {
        width: 200px;
    }
    
    .game-board {
        max-width: 300px;
    }
}

/* 触摸设备优化 */
@media (hover: none) {
    .control-btn:hover,
    .score-box:hover,
    .info-card:hover {
        transform: none;
    }
    
    .control-btn:active {
        transform: scale(0.95);
    }
}

/* 高对比度模式支持 */
@media (prefers-contrast: high) {
    :root {
        --primary-color: #000;
        --secondary-color: #333;
        --accent-color: #666;
        --dark-color: #000;
        --light-color: #fff;
    }
}

/* 减少动画模式支持 */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
