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

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

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: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
}

/* ========== 标题 ========== */
.header {
    text-align: center;
    margin-bottom: 10px;
}

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

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

/* ========== 用户栏 ========== */
.user-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 10px 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

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

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

.user-info .btn-small {
    padding: 5px 15px;
    font-size: 0.8rem;
}

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

.auth-buttons .btn {
    padding: 8px 20px;
    font-size: 0.9rem;
}

/* ========== 状态栏 ========== */
.status-bar {
    display: flex;
    gap: 10px;
    width: 100%;
    margin-bottom: 15px;
}

.stat-item {
    flex: 1;
    background: rgba(255, 255, 255, 0.1);
    padding: 12px;
    border-radius: 10px;
    text-align: center;
    backdrop-filter: blur(10px);
}

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

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

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

/* ========== 游戏区域 ========== */
.game-area {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    max-width: 400px;
    margin-bottom: 15px;
}

.game-board {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 15px;
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 10px;
    box-shadow: 0 0 30px rgba(72, 219, 251, 0.2);
}

.cell {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 1.5rem;
    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; box-shadow: 0 0 30px #edc22e; }
.cell[data-value="4096"] { background: #3c3a32; color: #f9f6f2; font-size: 1.1rem; box-shadow: 0 0 30px #a55eea; }
.cell[data-value="8192"] { background: #3c3a32; color: #f9f6f2; font-size: 1.1rem; box-shadow: 0 0 30px #ff6b6b; }
.cell[data-value="16384"] { background: linear-gradient(135deg, #feca57, #ff6b6b); color: #fff; font-size: 0.9rem; box-shadow: 0 0 40px #feca57; }
.cell[data-value="32768"] { background: linear-gradient(135deg, #48dbfb, #a55eea); color: #fff; font-size: 0.9rem; box-shadow: 0 0 50px #48dbfb; }
.cell[data-value="65536"] { background: linear-gradient(135deg, #1dd1a1, #10ac84); color: #fff; font-size: 0.85rem; box-shadow: 0 0 60px #1dd1a1; }
.cell[data-value="131072"] { background: linear-gradient(135deg, #ff9f43, #ee5a24); color: #fff; font-size: 0.75rem; box-shadow: 0 0 70px #ff9f43; animation: rainbow 2s linear infinite; }

@keyframes rainbow {
    0% { box-shadow: 0 0 70px #ff6b6b; }
    25% { box-shadow: 0 0 70px #feca57; }
    50% { box-shadow: 0 0 70px #48dbfb; }
    75% { box-shadow: 0 0 70px #a55eea; }
    100% { box-shadow: 0 0 70px #ff6b6b; }
}

/* 方块动画 */
.cell.new {
    animation: popIn 0.2s ease;
}

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

.cell.merge {
    animation: merge 0.2s ease;
}

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

/* ========== 游戏遮罩 ========== */
.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    border-radius: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

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

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

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

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

.overlay-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ========== 按钮 ========== */
.btn {
    padding: 12px 30px;
    border: none;
    border-radius: 25px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
}

.btn-small {
    padding: 8px 20px;
    font-size: 0.85rem;
}

.btn-large {
    padding: 15px 40px;
    font-size: 1.1rem;
}

.btn-primary {
    background: linear-gradient(90deg, #feca57, #ff9f43);
    color: #1a1a2e;
}

.btn-primary:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 20px rgba(254, 202, 87, 0.5);
}

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

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

.btn-danger {
    background: #ff6b6b;
    color: #fff;
}

/* ========== 方向按钮控制 ========== */
.direction-controls {
    margin-bottom: 15px;
    width: 100%;
    display: flex;
    justify-content: center;
}

.d-pad {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.dir-middle {
    display: flex;
    gap: 5px;
    align-items: center;
}

.dir-btn {
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(145deg, #2a2a4a, #1a1a2e);
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.1s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.dir-btn:active {
    transform: scale(0.95);
    background: linear-gradient(145deg, #3a3a5a, #2a2a4a);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.dir-center {
    background: linear-gradient(145deg, #feca57, #ff9f43);
    color: #1a1a2e;
    font-size: 1.2rem;
    cursor: default;
}

.dir-center:active {
    transform: none;
    background: linear-gradient(145deg, #feca57, #ff9f43);
}

/* ========== 道具栏 ========== */
.power-ups {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    width: 100%;
    max-width: 400px;
}

.power-up {
    flex: 1;
    background: rgba(255, 255, 255, 0.1);
    padding: 10px;
    border-radius: 10px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.power-up:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

.power-up.disabled {
    opacity: 0.5;
    pointer-events: none;
}

.power-up .icon {
    font-size: 1.5rem;
    display: block;
}

.power-up .name {
    font-size: 0.8rem;
    color: #aaa;
}

.power-up .count {
    display: inline-block;
    background: #feca57;
    color: #1a1a2e;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: bold;
    margin-top: 5px;
}

/* ========== 月度信息 ========== */
.monthly-info {
    background: rgba(254, 202, 87, 0.2);
    border: 1px solid #feca57;
    padding: 10px 20px;
    border-radius: 10px;
    margin-bottom: 15px;
    font-size: 0.9rem;
}

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

/* ========== 操作按钮 ========== */
.action-buttons {
    display: flex;
    gap: 10px;
    width: 100%;
    max-width: 400px;
    margin-bottom: 15px;
}

.action-buttons .btn {
    flex: 1;
}

/* ========== 奖励区域 ========== */
.reward-section {
    width: 100%;
    max-width: 400px;
    margin-top: 10px;
}

.reward-section .btn {
    width: 100%;
}

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

.modal.hidden {
    display: none;
}

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

.modal-content h2 {
    text-align: center;
    margin-bottom: 20px;
    color: #feca57;
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 1.5rem;
    cursor: pointer;
    color: #888;
}

.close-btn:hover {
    color: #ff6b6b;
}

/* ========== 认证表单 ========== */
.auth-modal {
    max-width: 380px;
}

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

.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; /* Safari 需要至少16px避免缩放 */
    user-select: text;
    -webkit-user-select: text;
    -webkit-appearance: none; /* 移除 Safari 默认样式 */
    appearance: none;
}

.auth-form input:focus {
    outline: none;
    border-color: #48dbfb;
}

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

.auth-form .btn {
    margin-top: 5px;
}

.auth-switch {
    text-align: center;
    color: #888;
    font-size: 0.9rem;
}

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

.auth-switch a:hover {
    text-decoration: underline;
}

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

/* ========== 排行榜 ========== */
.month-selector {
    margin-bottom: 20px;
}

.month-selector select {
    width: 100%;
    padding: 10px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    font-size: 1rem;
}

.leaderboard-list {
    max-height: 400px;
    overflow-y: auto;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    margin-bottom: 10px;
}

.leaderboard-item .rank {
    width: 40px;
    font-size: 1.2rem;
    font-weight: bold;
}

.leaderboard-item.rank-1 .rank { color: #feca57; }
.leaderboard-item.rank-2 .rank { color: #c0c0c0; }
.leaderboard-item.rank-3 .rank { color: #cd7f32; }

.leaderboard-item .info {
    flex: 1;
}

.leaderboard-item .name {
    font-weight: bold;
    margin-bottom: 3px;
}

.leaderboard-item .meta {
    font-size: 0.8rem;
    color: #888;
}

.leaderboard-item .score {
    font-size: 1.2rem;
    font-weight: bold;
    color: #48dbfb;
}

.leaderboard-item.champion {
    background: linear-gradient(135deg, rgba(254, 202, 87, 0.3), rgba(255, 159, 67, 0.3));
    border: 1px solid #feca57;
}

.my-rank {
    margin-top: 20px;
    padding: 15px;
    background: rgba(72, 219, 251, 0.2);
    border-radius: 10px;
    text-align: center;
}

.my-rank strong {
    color: #48dbfb;
    font-size: 1.2rem;
}

/* ========== 领奖 ========== */
.claim-content {
    text-align: center;
}

.claim-content p {
    margin-bottom: 15px;
    color: #aaa;
}

.claim-content .prize-code {
    font-size: 1.5rem;
    font-family: monospace;
    letter-spacing: 3px;
    background: rgba(72, 219, 251, 0.2);
    padding: 20px;
    border-radius: 10px;
    margin: 15px 0;
    color: #48dbfb;
    border: 2px dashed #48dbfb;
}

.claim-content .copy-btn {
    margin-top: 10px;
}

.claim-success {
    color: #1dd1a1;
    font-size: 1.1rem;
}

.claim-empty {
    color: #888;
}

.claim-already {
    color: #feca57;
}

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

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

.gameover-stats strong {
    color: #feca57;
    font-size: 1.5rem;
}

#new-record, #personal-best {
    color: #1dd1a1;
    font-size: 1.2rem;
}

.gameover-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ========== Toast ========== */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    padding: 15px 30px;
    border-radius: 10px;
    font-size: 1rem;
    z-index: 200;
    animation: toastIn 0.3s ease;
}

.toast.hidden {
    display: none;
}

.toast.error {
    background: rgba(255, 107, 107, 0.9);
}

.toast.success {
    background: rgba(29, 209, 161, 0.9);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ========== 响应式 ========== */
@media (max-width: 480px) {
    .header h1 {
        font-size: 1.5rem;
    }
    
    .stat-item .value {
        font-size: 1.2rem;
    }
    
    .cell {
        font-size: 1.2rem;
    }
    
    .cell[data-value="128"],
    .cell[data-value="256"],
    .cell[data-value="512"] {
        font-size: 1rem;
    }
    
    .cell[data-value="1024"],
    .cell[data-value="2048"],
    .cell[data-value="4096"],
    .cell[data-value="8192"],
    .cell[data-value="16384"] {
        font-size: 0.85rem;
    }
    
    .cell[data-value="32768"],
    .cell[data-value="65536"] {
        font-size: 0.75rem;
    }
    
    .cell[data-value="131072"] {
        font-size: 0.65rem;
    }
    
    .power-up .icon {
        font-size: 1.2rem;
    }
    
    .power-up .name {
        font-size: 0.7rem;
    }
}
