/* =============================================
   2048 游戏 - 专属样式
   ============================================= */

.g2048-layout {
    display: flex;
    gap: 32px;
    padding: 40px 0;
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
}

/* ---- 游戏主区域 ---- */
.g2048-main {
    flex: 1;
    max-width: 460px;
}

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

.g2048-header h1 {
    font-size: 3rem;
    font-weight: 800;
    color: var(--primary);
    margin: 0;
}

.g2048-scores {
    display: flex;
    gap: 12px;
}

.g2048-score-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 16px;
    text-align: center;
    min-width: 80px;
}

.g2048-score-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.g2048-score-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text);
}

/* ---- 棋盘 ---- */
.g2048-board {
    background: #1a1a2e;
    border-radius: 12px;
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    aspect-ratio: 1 / 1;
    border: 2px solid var(--border);
}

.g2048-cell {
    background: #16213e;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 2rem;
    color: white;
    transition: all 0.12s ease;
    user-select: none;
    aspect-ratio: 1 / 1;
}

/* 方块颜色 */
.g2048-cell[data-val="2"]    { background: #264653; color: #e9f5db; }
.g2048-cell[data-val="4"]    { background: #2a9d8f; color: #fff; }
.g2048-cell[data-val="8"]    { background: #e9c46a; color: #1a1a2e; }
.g2048-cell[data-val="16"]   { background: #f4a261; color: #1a1a2e; }
.g2048-cell[data-val="32"]   { background: #e76f51; color: #fff; }
.g2048-cell[data-val="64"]   { background: #e63946; color: #fff; }
.g2048-cell[data-val="128"]  { background: #a8dadc; color: #1a1a2e; font-size: 1.7rem; }
.g2048-cell[data-val="256"]  { background: #457b9d; color: #fff; font-size: 1.7rem; }
.g2048-cell[data-val="512"]  { background: #1d3557; color: #f1faee; font-size: 1.7rem; }
.g2048-cell[data-val="1024"] { background: #6d28d9; color: #fff; font-size: 1.4rem; }
.g2048-cell[data-val="2048"] { background: linear-gradient(135deg, #f59e0b, #ef4444); color: #fff; font-size: 1.4rem; box-shadow: 0 0 20px rgba(245,158,11,0.5); }
.g2048-cell[data-val="super"]{ background: linear-gradient(135deg, #ec4899, #8b5cf6); color: #fff; font-size: 1.2rem; }

/* 新方块出现动画 */
.g2048-cell.g2048-pop {
    animation: pop 0.2s ease;
}

@keyframes pop {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

/* 合并动画 */
.g2048-cell.g2048-merge {
    animation: merge 0.25s ease;
}

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

/* ---- 操作按钮 ---- */
.g2048-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.g2048-actions .btn {
    flex: 1;
    justify-content: center;
}

.g2048-hint {
    margin-top: 16px;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
}

/* ---- 排行榜 ---- */
.g2048-rankings {
    flex: 1;
    max-width: 360px;
    min-width: 280px;
}

.g2048-rank-header h2 {
    font-size: 1.5rem;
    margin-bottom: 12px;
}

.g2048-rank-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.g2048-rank-tab {
    padding: 6px 16px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s;
}

.g2048-rank-tab:hover {
    border-color: var(--primary);
    color: var(--text);
}

.g2048-rank-tab.active {
    background: var(--primary);
    color: #000;
    border-color: var(--primary);
}

.g2048-rank-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 500px;
    overflow-y: auto;
}

.g2048-rank-item {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: all 0.2s;
}

.g2048-rank-item:hover {
    border-color: var(--primary);
}

.g2048-rank-item.g2048-rank-me {
    border-color: var(--primary);
    background: rgba(245, 158, 11, 0.08);
}

.g2048-rank-pos {
    font-size: 1.2rem;
    font-weight: 800;
    min-width: 36px;
    text-align: center;
}

.g2048-rank-pos.pos-1 { color: #f59e0b; }
.g2048-rank-pos.pos-2 { color: #94a3b8; }
.g2048-rank-pos.pos-3 { color: #cd7f32; }

.g2048-rank-info {
    flex: 1;
    margin-left: 12px;
}

.g2048-rank-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.g2048-rank-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.g2048-rank-score {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--primary);
}

.g2048-rank-loading {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 0;
}

.g2048-rank-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 0;
    font-size: 0.9rem;
}

.g2048-my-rank {
    margin-top: 16px;
    padding: 12px 16px;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid var(--primary);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.9rem;
}

.g2048-my-rank strong {
    color: var(--primary);
}

/* ---- 游戏结束弹窗 ---- */
.g2048-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(4px);
}

.g2048-overlay-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px;
    text-align: center;
    min-width: 300px;
}

.g2048-overlay-card h2 {
    font-size: 2rem;
    margin-bottom: 12px;
}

.g2048-overlay-card p {
    font-size: 1.1rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.g2048-overlay-card #overlayBestRecord {
    color: var(--primary);
    font-weight: 700;
    font-size: 1.3rem;
}

.g2048-overlay-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    justify-content: center;
}

/* ---- 响应式 ---- */
@media (max-width: 860px) {
    .g2048-layout {
        flex-direction: column;
        align-items: center;
    }

    .g2048-main {
        max-width: 100%;
        width: 100%;
    }

    .g2048-board {
        max-width: 420px;
        margin: 0 auto;
    }

    .g2048-rankings {
        max-width: 100%;
        width: 100%;
    }
}

@media (max-width: 480px) {
    .g2048-header h1 {
        font-size: 2rem;
    }

    .g2048-cell {
        font-size: 1.5rem;
    }

    .g2048-cell[data-val="128"],
    .g2048-cell[data-val="256"],
    .g2048-cell[data-val="512"] { font-size: 1.3rem; }

    .g2048-cell[data-val="1024"],
    .g2048-cell[data-val="2048"],
    .g2048-cell[data-val="super"] { font-size: 1.1rem; }

    .g2048-board {
        gap: 6px;
        padding: 6px;
    }
}

/* ---- 虚拟方向键 ---- */
.g2048-dpad {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
    user-select: none;
}

.g2048-dpad-mid {
    display: flex;
    align-items: center;
    gap: 8px;
}

.g2048-dpad-btn {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    border: 2px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.g2048-dpad-btn:hover {
    background: var(--primary);
    color: #000;
    border-color: var(--primary);
    transform: scale(1.08);
}

.g2048-dpad-btn:active {
    transform: scale(0.95);
    background: var(--primary-dark);
}

.g2048-dpad-center {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #fb923c);
    opacity: 0.3;
}

@media (max-width: 480px) {
    .g2048-dpad-btn {
        width: 48px;
        height: 48px;
        font-size: 1.2rem;
    }
    .g2048-dpad-center {
        width: 48px;
        height: 48px;
    }
}
