/* ===== 基础重置与布局 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: #1a1a1a;
    font-family: 'Arial', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    color: white;
}

.game-wrapper {
    text-align: center;
}

/* ===== 标题 ===== */
.game-title {
    font-size: 48px;
    margin-bottom: 20px;
    color: #FFD700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

/* ===== 菜单界面 ===== */
.menu-screen {
    background: rgba(0, 0, 0, 0.8);
    padding: 40px;
    border-radius: 10px;
    display: inline-block;
}

.mode-selection {
    margin: 30px 0;
}

.mode-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    padding: 15px 40px;
    margin: 10px;
    font-size: 18px;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.mode-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

/* ===== 游戏容器 ===== */
.game-container {
    display: none;
    position: relative;
}

#gameCanvas {
    border: 3px solid #FFD700;
    background: #000;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
}

/* ===== 分数板 ===== */
.score-board {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    font-size: 20px;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
    padding: 0 10px;
}

.game-buttons {
    display: flex;
    gap: 10px;
    align-items: center;
}

.player-score {
    padding: 10px 20px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.6);
}

.player1 {
    color: #FFD700;
    border: 2px solid #FFD700;
}

.player2 {
    color: #00FF00;
    border: 2px solid #00FF00;
}

/* ===== 控制说明 ===== */
.controls-info {
    margin-top: 20px;
    font-size: 14px;
    color: #aaa;
}

/* ===== 按钮通用 ===== */
.back-btn {
    background: #ff4444;
    border: none;
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
}

.back-btn:hover {
    background: #ff6666;
    transform: translateY(-2px);
}

/* ===== 游戏结束界面 ===== */
.game-over {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    padding: 40px;
    border-radius: 10px;
    border: 3px solid #FFD700;
}

.game-over h2 {
    font-size: 36px;
    margin-bottom: 20px;
    color: #FFD700;
}

.restart-btn {
    background: #4CAF50;
    border: none;
    color: white;
    padding: 15px 30px;
    font-size: 18px;
    border-radius: 25px;
    cursor: pointer;
    margin-top: 20px;
}

.restart-btn:hover {
    background: #45a049;
}

/* ===== 昵称输入 ===== */
#playerNickname {
    padding: 12px 20px;
    font-size: 16px;
    border: 2px solid #FFD700;
    border-radius: 25px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    text-align: center;
    width: 250px;
    outline: none;
}

#playerNickname::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

/* ===== 排行榜按钮 ===== */
.leaderboard-btn {
    background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
    border: none;
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    box-shadow: 0 2px 8px rgba(255, 215, 0, 0.3);
    transition: all 0.3s;
}

.leaderboard-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 215, 0, 0.5);
}

/* ===== 排行榜模态框 ===== */
.leaderboard-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    justify-content: center;
    align-items: center;
}

.leaderboard-content {
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
    padding: 30px;
    border-radius: 15px;
    border: 3px solid #FFD700;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.3);
}

.leaderboard-header {
    text-align: center;
    margin-bottom: 20px;
}

.leaderboard-header h2 {
    color: #FFD700;
    font-size: 28px;
    margin-bottom: 10px;
}

.mode-tabs {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 20px;
}

.mode-tab {
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid transparent;
    border-radius: 20px;
    color: white;
    cursor: pointer;
    transition: all 0.3s;
}

.mode-tab.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: #FFD700;
}

.mode-tab:hover {
    background: rgba(255, 255, 255, 0.2);
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.leaderboard-table th,
.leaderboard-table td {
    padding: 12px 10px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-table th {
    color: #FFD700;
    font-size: 16px;
    background: rgba(255, 215, 0, 0.1);
}

.leaderboard-table td {
    color: white;
    font-size: 14px;
}

.leaderboard-table tr:hover {
    background: rgba(255, 255, 255, 0.05);
}

.rank-1 { color: #FFD700 !important; font-weight: bold; }
.rank-2 { color: #C0C0C0 !important; font-weight: bold; }
.rank-3 { color: #CD7F32 !important; font-weight: bold; }

.close-leaderboard {
    display: block;
    margin: 20px auto 0;
    padding: 12px 30px;
    background: #ff4444;
    border: none;
    color: white;
    border-radius: 20px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s;
}

.close-leaderboard:hover {
    background: #ff6666;
    transform: translateY(-2px);
}

.loading-text,
.empty-leaderboard {
    text-align: center;
    color: #aaa;
    padding: 30px;
    font-size: 16px;
}

/* ===== 虚拟按钮 ===== */
.mobile-controls {
    display: none;
    position: fixed;
    bottom: 155px;
    left: 0;
    right: 0;
    padding: 0 15px;
    z-index: 1000;
    pointer-events: none;
}

.mobile-controls.active {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.direction-pad {
    position: relative;
    width: 140px;
    height: 140px;
    pointer-events: auto;
}

.dir-btn {
    position: absolute;
    width: 46px;
    height: 46px;
    background: rgba(255, 215, 0, 0.25);
    border: 2px solid rgba(255, 215, 0, 0.5);
    border-radius: 8px;
    color: white;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    transition: all 0.1s;
}

.dir-btn:active, .dir-btn.pressed {
    background: rgba(255, 215, 0, 0.5);
    transform: scale(0.92);
}

.dir-up { top: 0; left: 47px; }
.dir-down { bottom: 0; left: 47px; }
.dir-left { top: 47px; left: 0; }
.dir-right { top: 47px; right: 0; }

/* 射击按钮 */
.fire-btn {
    position: fixed;
    bottom: 220px;
    right: 30px;
    width: 140px;
    height: 140px;
    background: rgba(255, 68, 68, 0.35);
    border: 3px solid rgba(255, 68, 68, 0.6);
    border-radius: 50%;
    color: white;
    font-size: 20px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    pointer-events: auto;
    transition: all 0.1s;
    box-shadow: 0 4px 12px rgba(255, 68, 68, 0.3);
    z-index: 1001;
}

.fire-btn:active, .fire-btn.pressed {
    background: rgba(255, 68, 68, 0.6);
    transform: scale(0.88);
}

/* ===== 移动端适配 ===== */
@media (max-width: 768px) {
    body {
        align-items: flex-start;
        padding-top: 10px;
        overflow: hidden;
        touch-action: none;
    }

    .game-title {
        display: none;
    }

    #gameCanvas {
        max-width: 100vw;
        max-height: 45vh;
        margin-top: 5px;
        margin-bottom: 2px;
    }

    .game-container {
        padding-top: 0;
        padding-bottom: 0;
    }

    .score-board {
        font-size: 16px;
        margin-bottom: 2px;
        margin-top: 0;
        flex-wrap: wrap;
        gap: 5px;
    }

    .game-buttons {
        width: 100%;
        justify-content: center;
        order: -1;
    }

    .leaderboard-btn,
    .back-btn {
        padding: 6px 12px;
        font-size: 12px;
    }

    .controls-info {
        display: none;
    }

    /* 增大虚拟按钮 */
    .direction-pad {
        width: 200px;
        height: 200px;
    }

    .dir-btn {
        width: 70px;
        height: 70px;
        font-size: 30px;
        border-radius: 12px;
    }

    .dir-up { top: 0; left: 65px; }
    .dir-down { bottom: 0; left: 65px; }
    .dir-left { top: 65px; left: 0; }
    .dir-right { top: 65px; right: 0; }

    /* 排行榜模态框移动端适配 */
    .leaderboard-content {
        padding: 20px;
        width: 95%;
        max-height: 85vh;
    }

    .leaderboard-header h2 {
        font-size: 22px;
    }

    .mode-tab {
        padding: 8px 15px;
        font-size: 14px;
    }

    .leaderboard-table th,
    .leaderboard-table td {
        padding: 8px 5px;
        font-size: 12px;
    }

    .leaderboard-table th:nth-child(2),
    .leaderboard-table td:nth-child(2) {
        width: 90px;
        max-width: 90px;
    }

    /* 昵称输入框移动端适配 */
    #playerNickname {
        width: 200px;
        padding: 10px 15px;
        font-size: 16px;
    }
}
