* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #2c1810, #1a0f08);
    color: #fff;
    overflow: hidden;
    cursor: default; /* 默认显示鼠标指针 */
}

#gameContainer {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

#gameCanvas {
    border: 2px solid #8B4513;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(139, 69, 19, 0.5);
    background: linear-gradient(45deg, #2F4F2F, #1C3F1C);
    cursor: none; /* 只在游戏画布上隐藏鼠标指针，显示自定义准星 */
}

#ui {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* 默认不接收鼠标事件 */
    z-index: 10;
}

/* 让需要交互的元素可以接收鼠标事件 */
#stats,
#upgradePanel,
.upgrade-panel,
.upgrade-item,
.close-upgrade-btn,
#closeUpgrade,
#closeUpgradeBottom {
    pointer-events: auto;
}

#stats {
    position: absolute;
    top: 20px;
    left: 20px;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.9), rgba(20, 20, 20, 0.9));
    padding: 20px;
    border-radius: 15px;
    border: 2px solid #8B4513;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    min-width: 200px;
}

.stat-group {
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(139, 69, 19, 0.3);
}

.stat-group:last-child {
    margin-bottom: 0;
    border-bottom: none;
}

.stat-item {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: bold;
    transition: all 0.3s ease;
}

.stat-item:hover {
    transform: translateX(3px);
    color: #FFD700;
}

.stat-item:last-child {
    margin-bottom: 0;
}

.stat-label {
    min-width: 90px;
    color: #FFA500;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    font-size: 13px;
}

.health-bar {
    width: 100px;
    height: 15px;
    background: rgba(255, 0, 0, 0.3);
    border: 1px solid #8B0000;
    border-radius: 8px;
    margin: 0 10px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.health-fill {
    height: 100%;
    background: linear-gradient(90deg, #FF0000, #FF4500, #32CD32);
    width: 100%;
    transition: width 0.3s ease;
    box-shadow: 0 0 10px rgba(255, 69, 0, 0.5);
}

/* 升级面板样式 */
.upgrade-panel {
    position: fixed; /* 改为fixed定位，确保在视口中 */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.95), rgba(30, 30, 30, 0.95));
    padding: 25px;
    border-radius: 20px;
    border: 3px solid #8B4513;
    backdrop-filter: blur(15px);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
    z-index: 9999; /* 提高z-index */
    min-width: 650px;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
    pointer-events: auto; /* 明确设置可以接收鼠标事件 */
    cursor: default; /* 确保显示默认鼠标指针 */
}

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

.upgrade-header h3 {
    color: #FFD700;
    font-size: 2em;
    margin: 0;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.8);
}

.close-upgrade-btn {
    background: linear-gradient(45deg, #8B0000, #DC143C);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.2em;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    pointer-events: auto; /* 确保可以点击 */
    z-index: 10000; /* 确保在最顶层 */
}

.close-upgrade-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(220, 20, 60, 0.4);
}

.upgrade-instructions {
    background: rgba(255, 215, 0, 0.1);
    padding: 15px;
    border-radius: 10px;
    border: 1px solid #FFD700;
    margin-bottom: 20px;
    text-align: center;
}

.upgrade-instructions p {
    margin: 5px 0;
    color: #FFD700;
    font-weight: bold;
}

.upgrade-footer {
    margin-top: 20px;
    text-align: center;
}

.upgrade-message {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 10px 15px;
    border-radius: 8px;
    font-weight: bold;
    z-index: 1001;
    display: none;
    max-width: 250px;
    text-align: center;
}

.upgrade-message.success {
    background: linear-gradient(135deg, rgba(0, 255, 0, 0.9), rgba(50, 205, 50, 0.9));
    color: white;
    border: 2px solid #32CD32;
}

.upgrade-message.error {
    background: linear-gradient(135deg, rgba(255, 0, 0, 0.9), rgba(220, 20, 60, 0.9));
    color: white;
    border: 2px solid #FF0000;
}

.upgrade-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
    margin-bottom: 25px;
}

.upgrade-item {
    display: flex;
    align-items: center;
    background: linear-gradient(135deg, rgba(139, 69, 19, 0.2), rgba(160, 82, 45, 0.2));
    border: 2px solid #8B4513;
    border-radius: 12px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    pointer-events: auto; /* 确保可以点击 */
    z-index: 10001; /* 确保在面板之上 */
}

.upgrade-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 215, 0, 0.2), transparent);
    transition: left 0.5s ease;
}

.upgrade-item:hover::before {
    left: 100%;
}

.upgrade-item:hover {
    transform: translateY(-3px);
    border-color: #FFD700;
    box-shadow: 0 10px 25px rgba(255, 215, 0, 0.3);
}

.upgrade-item.affordable {
    border-color: #32CD32;
}

.upgrade-item.unaffordable {
    opacity: 0.5;
    cursor: not-allowed;
}

.upgrade-icon {
    font-size: 2.5em;
    margin-right: 15px;
    filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.5));
}

.upgrade-info {
    flex: 1;
}

.upgrade-name {
    font-size: 1.2em;
    font-weight: bold;
    color: #FFD700;
    margin-bottom: 5px;
}

.upgrade-desc {
    color: #DDDDDD;
    font-size: 0.9em;
    margin-bottom: 8px;
}

.upgrade-cost {
    color: #32CD32;
    font-weight: bold;
    font-size: 1.1em;
}

.close-btn {
    width: 100%;
    background: linear-gradient(45deg, #8B0000, #DC143C);
    margin-top: 10px;
}

/* 暂停界面样式 */
.pause-menu {
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-width: 300px;
    margin: 0 auto;
}

.pause-menu button {
    padding: 12px 24px;
    font-size: 1.1em;
}

#pauseScreen h2 {
    margin-bottom: 30px;
}

#crosshair {
    position: absolute;
    width: 30px;
    height: 30px;
    border: 2px solid #FF0000;
    border-radius: 50%;
    pointer-events: none;
    z-index: 20;
    box-shadow: 0 0 10px rgba(255, 0, 0, 0.8);
    display: none; /* 默认隐藏，只在游戏画布上显示 */
}

#crosshair::before,
#crosshair::after {
    content: '';
    position: absolute;
    background: #FF0000;
    box-shadow: 0 0 5px rgba(255, 0, 0, 0.8);
}

#crosshair::before {
    width: 2px;
    height: 10px;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
}

#crosshair::after {
    width: 10px;
    height: 2px;
    left: -6px;
    top: 50%;
    transform: translateY(-50%);
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.screen.hidden {
    display: none;
}

.upgrade-panel.hidden {
    display: none;
}

.screen h1 {
    font-size: 4em;
    color: #FF4500;
    text-shadow: 4px 4px 8px rgba(0, 0, 0, 0.8);
    margin-bottom: 30px;
    text-align: center;
}

.screen h2 {
    font-size: 3em;
    color: #FF0000;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.8);
    margin-bottom: 20px;
}

.instructions {
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.9), rgba(30, 30, 30, 0.9));
    padding: 25px;
    border-radius: 20px;
    border: 2px solid #8B4513;
    margin-bottom: 30px;
    text-align: center;
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.instructions h3 {
    color: #FFA500;
    margin-bottom: 20px;
    font-size: 1.8em;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

.control-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    max-width: 600px;
    margin: 0 auto;
}

.control-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    background: rgba(139, 69, 19, 0.2);
    border-radius: 10px;
    border: 1px solid #8B4513;
    transition: all 0.3s ease;
}

.control-item:hover {
    transform: translateY(-2px);
    background: rgba(139, 69, 19, 0.3);
    box-shadow: 0 5px 15px rgba(139, 69, 19, 0.3);
}

kbd {
    background: linear-gradient(135deg, #2C2C2C, #4A4A4A);
    color: #FFD700;
    padding: 8px 12px;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    font-size: 0.9em;
    border: 2px solid #666;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
    margin-bottom: 8px;
    min-width: 40px;
    text-align: center;
}

.control-item span {
    color: #DDDDDD;
    font-size: 0.9em;
    font-weight: bold;
}

.game-controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}

button {
    background: linear-gradient(45deg, #8B4513, #A0522D);
    color: white;
    border: none;
    padding: 15px 30px;
    font-size: 1.3em;
    font-weight: bold;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid #654321;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

button:hover {
    background: linear-gradient(45deg, #A0522D, #CD853F);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

button:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

/* 确保所有互动元素都显示正确的鼠标指针 */
button, 
.upgrade-item, 
.close-upgrade-btn,
.screen,
.instructions {
    cursor: pointer !important;
}

/* 文本和标签显示默认指针 */
.stat-label,
.upgrade-name,
.upgrade-desc,
.upgrade-cost,
p, h1, h2, h3 {
    cursor: default !important;
}

/* 输入区域显示文本指针 */
input, textarea {
    cursor: text !important;
}

/* 响应式设计 */
@media (max-width: 1300px) {
    #gameCanvas {
        width: 95vw;
        height: calc(95vw * 0.67);
        max-height: 90vh;
    }
}

@media (max-width: 768px) {
    #stats {
        top: 10px;
        left: 10px;
        padding: 10px;
        font-size: 14px;
    }
    
    .stat-item {
        font-size: 14px;
    }
    
    .screen h1 {
        font-size: 2.5em;
    }
    
    .instructions {
        padding: 15px;
        margin: 0 20px 20px;
    }
}

/* 加载动画 */
@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

.loading {
    animation: pulse 1s infinite;
}

/* 移动端支持 */
@media (max-width: 768px) {
    body {
        overflow: hidden;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
    }
    
    #gameContainer {
        width: 100vw;
        height: 100vh;
        padding: 0;
    }
    
    #gameCanvas {
        border: none;
        border-radius: 0;
        width: 100vw !important;
        height: 100vh !important;
    }
    
    /* 调整UI为移动端布局 */
    #stats {
        position: absolute;
        top: 10px;
        left: 10px;
        right: 10px;
        font-size: 12px;
        z-index: 20;
    }
    
    .stat-group {
        flex-wrap: wrap;
        gap: 5px;
    }
    
    .stat-item {
        min-width: auto;
        font-size: 11px;
    }
    
    /* 升级面板移动端适配 */
    .upgrade-panel {
        width: 95vw !important;
        height: 80vh !important;
        max-width: none !important;
        max-height: none !important;
        padding: 15px;
        font-size: 14px;
    }
    
    .upgrade-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    
    .upgrade-item {
        padding: 10px;
        font-size: 12px;
    }
    
    /* 游戏控制按钮 */
    .game-controls {
        position: fixed;
        bottom: 10px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 30;
    }
    
    .game-controls button {
        font-size: 14px;
        padding: 8px 16px;
    }
}

/* 移动端触摸控制 */
.mobile-controls {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 15;
}

@media (max-width: 768px) {
    .mobile-controls {
        display: block;
    }
}

/* 虚拟摇杆 */
.joystick {
    position: absolute;
    bottom: 60px;
    left: 60px;
    width: 120px;
    height: 120px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    pointer-events: auto;
    touch-action: none;
}

.joystick-knob {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: all 0.1s;
    border: 2px solid #333;
}

/* 移动端按钮样式 */
.mobile-btn {
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    border: 2px solid rgba(255, 255, 255, 0.3);
    transition: all 0.2s;
}

.mobile-btn:active {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0.95);
}

/* 右侧按钮组 */
.mobile-buttons-right {
    position: absolute;
    bottom: 40px;
    right: 40px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
}

/* 左上角按钮组 */
.mobile-buttons-top {
    position: absolute;
    top: 100px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* 特殊按钮样式 */
.shoot-btn {
    background: rgba(255, 0, 0, 0.7) !important;
    width: 80px;
    height: 80px;
    font-size: 30px;
}

.grenade-btn {
    background: rgba(255, 165, 0, 0.7) !important;
}

.reload-btn {
    background: rgba(0, 255, 0, 0.7) !important;
}

.weapon-btn {
    background: rgba(138, 43, 226, 0.7) !important;
}

.pause-btn {
    background: rgba(128, 128, 128, 0.7) !important;
}

/* 横屏提示 */
@media (max-width: 768px) and (orientation: portrait) {
    #gameContainer::before {
        content: "🔄 请将设备旋转至横屏以获得最佳游戏体验";
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        background: rgba(0, 0, 0, 0.9);
        color: white;
        padding: 20px;
        border-radius: 10px;
        z-index: 1000;
        text-align: center;
        font-size: 16px;
        max-width: 80%;
        line-height: 1.5;
    }
}

/* 触摸反馈动画 */
@keyframes touchFeedback {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.mobile-btn.touching {
    animation: touchFeedback 0.15s ease-out;
}
