/* ===== 基础重置和全局样式 ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #1a1a1a;
    font-family: 'Microsoft YaHei', 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
    color: #fff;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

/* ===== 游戏包装器 ===== */
#game-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

/* ===== 游戏容器 ===== */
#game-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #000;
    border: 4px solid #4a4a4a;
    border-radius: 4px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
}

#gameCanvas {
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* ===== HUD 信息栏 ===== */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 8px 16px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent);
    z-index: 10;
    font-size: 14px;
    pointer-events: none;
}

.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.hud-label {
    font-size: 11px;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#score, #lives, #level, #enemies-left {
    font-size: 18px;
    font-weight: bold;
    color: #f1c40f;
    text-shadow: 0 0 4px rgba(241, 196, 15, 0.5);
}

/* ===== 移动端控制 ===== */
#mobile-controls {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 20px;
    z-index: 20;
    pointer-events: none;
}

#mobile-controls > * {
    pointer-events: auto;
}

#joystick-zone {
    position: relative;
    width: 120px;
    height: 120px;
}

#joystick-base {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.3);
}

#joystick-knob {
    position: absolute;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(241, 196, 15, 0.6);
    border: 2px solid rgba(241, 196, 15, 0.9);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: transform 0.05s;
    box-shadow: 0 0 10px rgba(241, 196, 15, 0.4);
}

#action-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.action-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.1s;
    touch-action: manipulation;
}

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

#btn-fire {
    background: rgba(231, 76, 60, 0.3);
    border-color: rgba(231, 76, 60, 0.6);
}

#btn-fire:active {
    background: rgba(231, 76, 60, 0.5);
}

/* ===== 覆盖层和菜单 ===== */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.85);
    z-index: 100;
    transition: opacity 0.3s;
}

.overlay.hidden {
    display: none;
    opacity: 0;
    pointer-events: none;
}

.menu-panel {
    background: linear-gradient(135deg, #2c3e50, #1a252f);
    border: 2px solid #f1c40f;
    border-radius: 12px;
    padding: 32px 40px;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    text-align: center;
    box-shadow: 0 0 30px rgba(241, 196, 15, 0.2);
    animation: panelIn 0.3s ease-out;
}

@keyframes panelIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.menu-panel h1 {
    font-size: 32px;
    color: #f1c40f;
    margin-bottom: 4px;
    text-shadow: 0 0 10px rgba(241, 196, 15, 0.4);
}

.menu-panel h2 {
    font-size: 20px;
    color: #ecf0f1;
    margin-bottom: 24px;
    letter-spacing: 3px;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
}

.menu-btn {
    padding: 12px 32px;
    font-size: 16px;
    border: 2px solid #7f8c8d;
    border-radius: 8px;
    background: transparent;
    color: #ecf0f1;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    min-width: 180px;
    touch-action: manipulation;
}

.menu-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: #95a5a6;
}

.menu-btn.primary {
    background: #f1c40f;
    border-color: #f1c40f;
    color: #2c3e50;
    font-weight: bold;
}

.menu-btn.primary:hover {
    background: #f39c12;
    border-color: #f39c12;
}

.back-btn {
    margin-top: 16px;
}

.version {
    margin-top: 20px;
    font-size: 12px;
    color: #7f8c8d;
}

/* ===== 游戏说明 ===== */
.instructions-content {
    text-align: left;
    max-height: 50vh;
    overflow-y: auto;
    padding: 0 8px;
}

.inst-section {
    margin-bottom: 16px;
}

.inst-section h3 {
    font-size: 14px;
    color: #f1c40f;
    margin-bottom: 6px;
}

.inst-section p {
    font-size: 13px;
    color: #bdc3c7;
    line-height: 1.6;
    margin-bottom: 4px;
}

/* ===== 设置 ===== */
.settings-content {
    text-align: left;
    margin: 16px 0;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.setting-row label {
    font-size: 14px;
    color: #ecf0f1;
}

.setting-row input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: #f1c40f;
    cursor: pointer;
}

.setting-row select {
    padding: 4px 12px;
    border-radius: 4px;
    border: 1px solid #7f8c8d;
    background: #1a252f;
    color: #ecf0f1;
    font-family: inherit;
    cursor: pointer;
}

/* ===== 游戏结束 ===== */
.final-score {
    font-size: 24px;
    margin: 16px 0;
}

.final-score span:first-child {
    color: #bdc3c7;
}

.final-score span:last-child {
    color: #f1c40f;
    font-weight: bold;
    margin-left: 8px;
}

/* ===== 关卡完成 ===== */
#level-complete .menu-panel {
    animation: levelComplete 0.5s ease-out;
}

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

/* ===== 响应式适配 ===== */

/* PC端隐藏移动端控件 */
@media (hover: hover) and (pointer: fine) {
    .hidden-on-pc {
        display: none !important;
    }
}

/* 小屏手机 */
@media (max-width: 480px) {
    .menu-panel {
        padding: 20px 24px;
    }

    .menu-panel h1 {
        font-size: 24px;
    }

    .menu-panel h2 {
        font-size: 16px;
    }

    .menu-btn {
        padding: 10px 24px;
        font-size: 14px;
        min-width: 140px;
    }

    #hud {
        padding: 4px 8px;
        font-size: 12px;
    }

    .hud-label {
        font-size: 9px;
    }

    #score, #lives, #level, #enemies-left {
        font-size: 14px;
    }

    #joystick-zone {
        width: 100px;
        height: 100px;
    }

    #joystick-knob {
        width: 40px;
        height: 40px;
    }

    .action-btn {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
}

/* 平板 */
@media (min-width: 768px) and (max-width: 1024px) {
    #joystick-zone {
        width: 140px;
        height: 140px;
    }

    .action-btn {
        width: 70px;
        height: 70px;
        font-size: 28px;
    }
}

/* 横屏手机 */
@media (max-height: 480px) and (orientation: landscape) {
    #mobile-controls {
        bottom: 10px;
        padding: 0 10px;
    }

    #joystick-zone {
        width: 80px;
        height: 80px;
    }

    #joystick-knob {
        width: 32px;
        height: 32px;
    }

    .action-btn {
        width: 44px;
        height: 44px;
        font-size: 18px;
    }

    #hud {
        padding: 2px 8px;
    }
}

/* 自定义滚动条 */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}

::-webkit-scrollbar-thumb {
    background: rgba(241, 196, 15, 0.4);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(241, 196, 15, 0.6);
}
