/* 2048 极速挑战 - 样式 */

/* ========== 基础样式 ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* 通用隐藏类 */
.hidden {
    display: none !important;
}

body {
    font-family: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    min-height: 100vh;
    color: #fff;
    overflow-x: hidden;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* 允许输入框文本选择 */
input, textarea {
    user-select: text;
    -webkit-user-select: text;
}

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

/* ========== 顶部固定栏 ========== */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    margin-bottom: 10px;
    gap: 10px;
}

/* 标题 */
.header {
    text-align: left;
    flex-shrink: 0;
}

.header h1 {
    font-size: 1.5rem;
    background: linear-gradient(90deg, #feca57, #ff6b6b, #a55eea, #48dbfb);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.2;
}

.subtitle {
    color: #888;
    font-size: 0.75rem;
    margin-top: 2px;
}

/* 用户栏 */
.user-bar {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-name {
    color: #48dbfb;
    font-weight: bold;
    font-size: 0.9rem;
}

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

/* 顶部操作按钮 */
.top-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.btn-rank {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    background: linear-gradient(135deg, #feca57, #ff9f43);
    border: none;
    border-radius: 8px;
    color: #1a1a2e;
    font-weight: bold;
    font-size: 0.85rem;
    cursor: pointer;
    transition: transform 0.2s;
}

.btn-rank:hover {
    transform: scale(1.05);
}

.btn-rank .icon {
    font-size: 1rem;
}

.btn-help {
    width: 36px;
    height: 36px;
    padding: 0;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-help:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ========== 月度信息 ========== */
.monthly-info {
    text-align: center;
    padding: 8px;
    background: rgba(255, 215, 0, 0.1);
    border-radius: 8px;
    margin-bottom: 10px;
    font-size: 0.8rem;
    color: #ffd700;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

.monthly-info .divider {
    color: rgba(255, 215, 0, 0.4);
}

.monthly-info strong {
    color: #fff;
}

/* ========== 状态栏 ========== */
.status-bar {
    display: flex;
    justify-content: space-around;
    padding: 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    margin-bottom: 15px;
}

.stat-item {
    text-align: center;
    flex: 1;
}

.stat-item .label {
    display: block;
    font-size: 0.75rem;
    color: #888;
    margin-bottom: 4px;
}

.stat-item .value {
    display: block;
    font-size: 1.4rem;
    font-weight: bold;
    color: #fff;
}

.stat-item.highlight .value {
    color: #ffd700;
}

/* ========== 游戏区域 - 居中 ========== */
.game-area {
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    min-height: 320px;
    position: relative;
}

/* 游戏画布 */
.game-board {
    width: 320px;
    height: 320px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 8px;
    position: relative;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.cell {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: bold;
    transition: all 0.15s ease;
}

/* 数字方块颜色 */
.cell[data-value="2"] { background: #eee4da; color: #776e65; }
.cell[data-value="4"] { background: #ede0c8; color: #776e65; }
.cell[data-value="8"] { background: #f2b179; color: #f9f6f2; }
.cell[data-value="16"] { background: #f59563; color: #f9f6f2; }
.cell[data-value="32"] { background: #f67c5f; color: #f9f6f2; }
.cell[data-value="64"] { background: #f65e3b; color: #f9f6f2; }
.cell[data-value="128"] { background: #edcf72; color: #f9f6f2; font-size: 1.3rem; }
.cell[data-value="256"] { background: #edcc61; color: #f9f6f2; font-size: 1.3rem; }
.cell[data-value="512"] { background: #edc850; color: #f9f6f2; font-size: 1.3rem; }
.cell[data-value="1024"] { background: #edc53f; color: #f9f6f2; font-size: 1.1rem; }
.cell[data-value="2048"] { background: #edc22e; color: #f9f6f2; font-size: 1.1rem; }
.cell[data-value="4096"] { background: #3c3a32; color: #f9f6f2; font-size: 1.1rem; }
.cell[data-value="8192"] { background: #3c3a32; color: #f9f6f2; font-size: 1.1rem; }
.cell[data-value="16384"] { background: #3c3a32; color: #f9f6f2; font-size: 0.95rem; }
.cell[data-value="32768"] { background: #3c3a32; color: #f9f6f2; font-size: 0.95rem; }
.cell[data-value="65536"] { background: #3c3a32; color: #f9f6f2; font-size: 0.95rem; }
.cell[data-value="131072"] { background: #3c3a32; color: #f9f6f2; font-size: 0.8rem; }

/* 遮罩层 */
.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.game-overlay.hidden {
    display: none;
}

.overlay-content {
    text-align: center;
    padding: 20px;
}

.overlay-content h2 {
    font-size: 1.5rem;
    margin-bottom: 10px;
    background: linear-gradient(90deg, #feca57, #ff6b6b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.overlay-content p {
    color: #888;
    margin-bottom: 20px;
}

.overlay-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* ========== 底部区域 ========== */
.bottom-area {
    margin-top: auto;
    padding-top: 10px;
}

/* 奖励区域 */
.reward-section {
    text-align: center;
    padding: 10px;
}

.btn-large {
    padding: 15px 30px;
    font-size: 1.1rem;
    background: linear-gradient(135deg, #feca57, #ff9f43);
    border: none;
    border-radius: 12px;
    color: #1a1a2e;
    font-weight: bold;
    cursor: pointer;
    animation: pulse 2s infinite;
}

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

/* ========== 按钮基础样式 ========== */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-small {
    padding: 4px 10px;
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn:hover {
    transform: translateY(-1px);
    opacity: 0.9;
}

/* ========== 弹窗样式 ========== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 16px;
    padding: 24px;
    max-width: 400px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    font-size: 1.5rem;
    cursor: pointer;
    color: #888;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* 登录/注册弹窗 */
.auth-modal h2 {
    text-align: center;
    margin-bottom: 20px;
    font-size: 1.3rem;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.auth-form input {
    width: 100%;
    padding: 15px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
    font-size: 16px;
    user-select: text;
    -webkit-user-select: text;
    -webkit-appearance: none;
    appearance: none;
}

.auth-form input:focus {
    outline: none;
    border-color: #667eea;
}

.auth-form input::placeholder {
    color: #666;
}

.auth-form button {
    padding: 15px;
    font-size: 1rem;
}

.auth-switch {
    text-align: center;
    font-size: 0.85rem;
    color: #888;
    margin-top: 10px;
}

.auth-switch a {
    color: #48dbfb;
    text-decoration: none;
}

.error-msg {
    color: #ff6b6b;
    font-size: 0.85rem;
    text-align: center;
    margin-top: 10px;
    min-height: 20px;
}

/* 排行榜弹窗 */
.leaderboard-modal-content {
    max-width: 450px;
}

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

.leaderboard-header h2 {
    margin: 0;
    font-size: 1.3rem;
}

.month-selector select {
    padding: 8px 12px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    font-size: 0.9rem;
    min-width: 120px;
}

/* 表头 */
.leaderboard-table-header {
    display: grid;
    grid-template-columns: 50px 1fr 70px 80px;
    gap: 10px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px 8px 0 0;
    font-size: 0.8rem;
    color: #888;
    font-weight: 500;
}

.leaderboard-table-header .col-score {
    text-align: right;
}

/* 列表 */
.leaderboard-list {
    max-height: 350px;
    overflow-y: auto;
    border-radius: 0 0 8px 8px;
}

.leaderboard-item {
    display: grid;
    grid-template-columns: 50px 1fr 70px 80px;
    gap: 10px;
    align-items: center;
    padding: 12px;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: background 0.2s;
}

.leaderboard-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.leaderboard-item:last-child {
    border-bottom: none;
    border-radius: 0 0 8px 8px;
}

/* 排名样式 */
.leaderboard-item .rank {
    font-weight: bold;
    font-size: 1rem;
    text-align: center;
}

.leaderboard-item.rank-1 {
    background: linear-gradient(90deg, rgba(255, 215, 0, 0.15), rgba(255, 215, 0, 0.05));
}

.leaderboard-item.rank-1 .rank {
    color: #ffd700;
    font-size: 1.2rem;
}

.leaderboard-item.rank-2 {
    background: linear-gradient(90deg, rgba(192, 192, 192, 0.15), rgba(192, 192, 192, 0.05));
}

.leaderboard-item.rank-2 .rank {
    color: #c0c0c0;
    font-size: 1.2rem;
}

.leaderboard-item.rank-3 {
    background: linear-gradient(90deg, rgba(205, 127, 50, 0.15), rgba(205, 127, 50, 0.05));
}

.leaderboard-item.rank-3 .rank {
    color: #cd7f32;
    font-size: 1.2rem;
}

/* 玩家信息 */
.leaderboard-item .player-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.leaderboard-item .player-name {
    font-weight: 500;
    font-size: 0.95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-item.champion .player-name::before {
    content: '👑 ';
}

/* 最高数字 */
.leaderboard-item .max-tile {
    font-size: 0.85rem;
    color: #feca57;
    text-align: center;
}

/* 分数 */
.leaderboard-item .score {
    font-weight: bold;
    color: #48dbfb;
    text-align: right;
    font-size: 0.95rem;
}

.my-rank {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
}

/* 游戏结束弹窗 */
.gameover-stats {
    text-align: center;
    margin: 20px 0;
}

.gameover-stats p {
    margin: 10px 0;
    font-size: 1.1rem;
}

.gameover-stats strong {
    color: #48dbfb;
    font-size: 1.3rem;
}

.gameover-form {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.9rem;
    z-index: 200;
    transition: all 0.3s;
}

.toast.hidden {
    display: none !important;
}

/* 加载指示器 */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
    z-index: 300;
    transition: all 0.3s;
}

.loading-overlay.hidden {
    display: none !important;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: #48dbfb;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========== 响应式适配 ========== */
@media (max-width: 400px) {
    .game-container {
        padding: 8px;
    }
    
    .game-board {
        width: 280px;
        height: 280px;
    }
    
    .cell {
        font-size: 1.3rem;
    }
    
    .cell[data-value="128"],
    .cell[data-value="256"],
    .cell[data-value="512"] {
        font-size: 1.1rem;
    }
    
    .cell[data-value="1024"],
    .cell[data-value="2048"],
    .cell[data-value="4096"] {
        font-size: 0.9rem;
    }
    
    .header h1 {
        font-size: 1.2rem;
    }
    
    .dir-btn {
        width: 55px;
        height: 55px;
    }
}

@media (max-height: 700px) {
    .game-area {
        min-height: 280px;
    }
    
    .game-board {
        width: 280px;
        height: 280px;
    }
    
    .dir-btn {
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }
}
