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

body {
    font-family: 'Arial', 'Microsoft YaHei', sans-serif;
    background-color: var(--bg-color, #faf8ef);
    color: var(--text-color, #776e65);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    max-width: 500px;
    width: 100%;
    margin: 0 auto;
}

/* 头部样式 */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.title h1 {
    font-size: 3rem;
    font-weight: bold;
    color: var(--title-color, #776e65);
    line-height: 1;
}

.subtitle {
    font-size: 0.9rem;
    color: var(--subtitle-color, #776e65);
    opacity: 0.8;
}

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

.score-box {
    background: var(--score-bg, #bbada0);
    color: var(--score-color, #eee4da);
    padding: 8px 15px;
    border-radius: 6px;
    text-align: center;
    min-width: 80px;
}

.score-box .label {
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.score-box .value {
    display: block;
    font-size: 1.5rem;
    font-weight: bold;
}

/* 游戏容器 */
.game-container {
    background: var(--game-bg, #bbada0);
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 20px;
}

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

.game-info {
    display: flex;
    gap: 15px;
    font-size: 0.9rem;
    color: var(--info-color, #eee4da);
}

.game-controls {
    display: flex;
    gap: 8px;
}

/* 按钮样式 */
.btn {
    background: var(--btn-bg, #8f7a66);
    color: var(--btn-color, #f9f6f2);
    border: none;
    border-radius: 6px;
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

.btn:hover {
    background: var(--btn-hover-bg, #9f8b77);
}

.btn:active {
    transform: scale(0.95);
}

.btn:disabled {
    background: var(--btn-disabled-bg, #ccc);
    cursor: not-allowed;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.8rem;
}

/* 棋盘容器 */
.board-container {
    position: relative;
    margin-bottom: 15px;
}

.board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 10px;
    background: var(--board-bg, #bbada0);
    border-radius: 8px;
    padding: 10px;
    width: 100%;
    aspect-ratio: 1;
}

/* 单元格样式 */
.cell {
    background: var(--cell-bg, rgba(238, 228, 218, 0.35));
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: bold;
    color: var(--cell-color, #776e65);
    position: relative;
    overflow: hidden;
}

/* 方块样式 */
.tile {
    width: 100%;
    height: 100%;
    background: var(--tile-2-bg, #eee4da);
    color: var(--tile-2-color, #776e65);
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: bold;
    transition: transform 0.15s ease;
    position: absolute;
    top: 0;
    left: 0;
}

.tile.tile-2 { background: var(--tile-2-bg, #eee4da); color: var(--tile-2-color, #776e65); }
.tile.tile-4 { background: var(--tile-4-bg, #ede0c8); color: var(--tile-4-color, #776e65); }
.tile.tile-8 { background: var(--tile-8-bg, #f2b179); color: var(--tile-8-color, #f9f6f2); }
.tile.tile-16 { background: var(--tile-16-bg, #f59563); color: var(--tile-16-color, #f9f6f2); }
.tile.tile-32 { background: var(--tile-32-bg, #f67c5f); color: var(--tile-32-color, #f9f6f2); }
.tile.tile-64 { background: var(--tile-64-bg, #f65e3b); color: var(--tile-64-color, #f9f6f2); }
.tile.tile-128 { background: var(--tile-128-bg, #edcf72); color: var(--tile-128-color, #f9f6f2); }
.tile.tile-256 { background: var(--tile-256-bg, #edcc61); color: var(--tile-256-color, #f9f6f2); }
.tile.tile-512 { background: var(--tile-512-bg, #edc850); color: var(--tile-512-color, #f9f6f2); }
.tile.tile-1024 { background: var(--tile-1024-bg, #edc53f); color: var(--tile-1024-color, #f9f6f2); }
.tile.tile-2048 { background: var(--tile-2048-bg, #edc22e); color: var(--tile-2048-color, #f9f6f2); }
.tile.tile-super { background: var(--tile-super-bg, #3c3a32); color: var(--tile-super-color, #f9f6f2); }

/* 方块动画 */
.tile-new {
    animation: tileAppear 0.2s ease;
}

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

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

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

/* 游戏消息 */
.game-message {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--message-bg, rgba(238, 228, 218, 0.73));
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 8px;
    z-index: 100;
    animation: fadeIn 0.8s ease;
}

.game-message.active {
    display: flex;
}

.game-message p {
    font-size: 3rem;
    font-weight: bold;
    color: var(--message-color, #776e65);
    margin-bottom: 20px;
}

.message-buttons {
    display: flex;
    gap: 10px;
}

/* 游戏底部 */
.game-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.theme-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--info-color, #eee4da);
}

.theme-btn {
    width: 24px;
    height: 24px;
    border: 2px solid var(--theme-border, #eee4da);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s;
}

.theme-btn:hover {
    transform: scale(1.1);
}

.theme-btn.active {
    border-color: var(--theme-active-border, #f9f6f2);
    transform: scale(1.2);
}

.theme-btn[data-theme="default"] { background: #faf8ef; }
.theme-btn[data-theme="dark"] { background: #1a1a2e; }

.action-buttons {
    display: flex;
    gap: 8px;
}

/* 游戏说明 */
.instructions {
    background: var(--instructions-bg, #f9f6f2);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
}

.instructions h3 {
    margin-bottom: 10px;
    color: var(--instructions-title, #776e65);
}

.instructions ul {
    list-style: none;
    padding-left: 0;
}

.instructions li {
    margin-bottom: 5px;
    padding-left: 20px;
    position: relative;
}

.instructions li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: var(--instructions-bullet, #776e65);
}

/* 页脚 */
footer {
    text-align: center;
    font-size: 0.8rem;
    color: var(--footer-color, #776e65);
    opacity: 0.7;
}

/* 模态框 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--modal-bg, #f9f6f2);
    border-radius: 10px;
    padding: 30px;
    max-width: 400px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--modal-close-color, #776e65);
}

.modal-body h2 {
    margin-bottom: 20px;
    color: var(--modal-title-color, #776e65);
}

/* 表单样式 */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: var(--form-label-color, #776e65);
}

.form-group input {
    width: 100%;
    padding: 10px;
    border: 2px solid var(--form-border, #bbada0);
    border-radius: 6px;
    font-size: 1rem;
    background: var(--form-input-bg, #fff);
    color: var(--form-input-color, #776e65);
}

.form-group input:focus {
    outline: none;
    border-color: var(--form-focus-border, #8f7a66);
}

.form-submit {
    width: 100%;
    padding: 12px;
    background: var(--btn-bg, #8f7a66);
    color: var(--btn-color, #f9f6f2);
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
}

.form-submit:hover {
    background: var(--btn-hover-bg, #9f8b77);
}

/* 验证码输入框样式 */
.code-input-group {
    display: flex;
    gap: 10px;
}

.code-input-group input {
    flex: 1;
}

.btn-send-code {
    background: var(--btn-bg, #8f7a66);
    color: var(--btn-color, #f9f6f2);
    border: none;
    border-radius: 6px;
    padding: 10px 15px;
    font-size: 0.85rem;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
    white-space: nowrap;
}

.btn-send-code:hover {
    background: var(--btn-hover-bg, #9f8b77);
}

.btn-send-code:disabled {
    background: var(--btn-disabled-bg, #ccc);
    cursor: not-allowed;
}

/* 排行榜样式 */
.leaderboard-list {
    list-style: none;
    padding: 0;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid var(--leaderboard-border, #eee4da);
}

.leaderboard-item:last-child {
    border-bottom: none;
}

.leaderboard-rank {
    font-weight: bold;
    color: var(--leaderboard-rank-color, #776e65);
    width: 30px;
}

.leaderboard-user {
    flex: 1;
    margin-left: 10px;
}

.leaderboard-score {
    font-weight: bold;
    color: var(--leaderboard-score-color, #776e65);
}

/* 动画 */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

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

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

/* 响应式设计 */
@media (max-width: 500px) {
    body {
        padding: 10px;
    }
    
    .title h1 {
        font-size: 2.5rem;
    }
    
    .score-box {
        padding: 6px 10px;
        min-width: 70px;
    }
    
    .score-box .value {
        font-size: 1.2rem;
    }
    
    .game-container {
        padding: 10px;
    }
    
    .board {
        gap: 8px;
        padding: 8px;
    }
    
    .cell, .tile {
        font-size: 1.5rem;
    }
    
    .game-message p {
        font-size: 2rem;
    }
    
    .btn {
        padding: 8px 15px;
        font-size: 0.9rem;
    }
}

@media (max-width: 360px) {
    .title h1 {
        font-size: 2rem;
    }
    
    .scores {
        flex-direction: column;
        gap: 5px;
    }
    
    .game-header {
        flex-direction: column;
        gap: 10px;
    }
    
    .game-footer {
        flex-direction: column;
        gap: 10px;
    }
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
    .btn {
        padding: 12px 20px;
    }
    
    .theme-btn {
        width: 32px;
        height: 32px;
    }
}