/* ===== 基础设置 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Courier New', 'Microsoft YaHei', monospace;
    background: linear-gradient(135deg, #0a0a0a 0%, #1a1a2e 50%, #0f0f23 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
    overflow: hidden;
}

/* ===== 游戏容器 ===== */
.game-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 20px;
}

/* ===== 信息面板 ===== */
.info-panel {
    display: flex;
    gap: 24px;
    background: rgba(20, 20, 40, 0.9);
    border: 2px solid #4a9eff;
    border-radius: 8px;
    padding: 12px 28px;
    box-shadow: 0 0 20px rgba(74, 158, 255, 0.3),
                inset 0 0 10px rgba(74, 158, 255, 0.1);
}

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

.info-item .label {
    font-size: 12px;
    color: #7ab8ff;
    letter-spacing: 2px;
}

.info-item span:last-child {
    font-size: 24px;
    font-weight: bold;
    color: #ffd700;
    text-shadow: 0 0 8px rgba(255, 215, 0, 0.6);
}

/* ===== 游戏画布 ===== */
#gameCanvas {
    border: 3px solid #4a9eff;
    border-radius: 4px;
    background: #000;
    box-shadow: 0 0 30px rgba(74, 158, 255, 0.4),
                0 0 60px rgba(74, 158, 255, 0.2);
    image-rendering: pixelated;
}

/* ===== 遮罩层（开始/暂停/结束界面） ===== */
.overlay {
    position: absolute;
    top: 72px;
    left: 20px;
    width: 624px;
    height: 624px;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 4px;
    z-index: 10;
    backdrop-filter: blur(4px);
    overflow-y: auto;
    padding: 20px 0;
}

.overlay.hidden {
    display: none;
}

/* 可滚动 overlay 内部内容 */
.scroll-inner {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.overlay h1 {
    font-size: 56px;
    color: #ffd700;
    letter-spacing: 12px;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.8),
                 0 0 20px rgba(255, 100, 0, 0.6);
    margin-bottom: 8px;
}

.overlay .subtitle {
    font-size: 20px;
    color: #ff6b35;
    letter-spacing: 8px;
    margin-bottom: 36px;
}

.overlay h2 {
    font-size: 40px;
    color: #ff6b35;
    margin-bottom: 20px;
    text-shadow: 0 0 10px rgba(255, 107, 53, 0.6);
}

.overlay p {
    font-size: 16px;
    color: #b8d4ff;
    margin: 6px 0;
}

.controls-info {
    background: rgba(74, 158, 255, 0.1);
    border: 1px solid #4a9eff;
    border-radius: 8px;
    padding: 20px 40px;
    margin-bottom: 32px;
    text-align: center;
}

.controls-info p:first-child {
    font-size: 18px;
    color: #ffd700;
    margin-bottom: 12px;
    font-weight: bold;
}

/* ===== 按钮 ===== */
.game-btn {
    font-family: inherit;
    font-size: 22px;
    font-weight: bold;
    color: #000;
    background: linear-gradient(180deg, #ffd700 0%, #ff9500 100%);
    border: 2px solid #fff;
    border-radius: 6px;
    padding: 14px 48px;
    cursor: pointer;
    letter-spacing: 6px;
    transition: all 0.2s;
    box-shadow: 0 4px 15px rgba(255, 150, 0, 0.5);
}

.game-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 150, 0, 0.8);
}

.game-btn:active {
    transform: translateY(1px);
    box-shadow: 0 2px 8px rgba(255, 150, 0, 0.5);
}

#finalScore, #victoryScore {
    color: #ffd700;
    font-size: 28px;
    font-weight: bold;
}

/* ===== 主菜单 ===== */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
    margin-bottom: 24px;
}
.menu-btn {
    width: 280px;
    padding: 14px 24px;
}
.unlock-btn {
    background: linear-gradient(180deg, #6a8aff 0%, #3a4af0 100%);
    color: #fff;
    border-color: #aab8ff;
    box-shadow: 0 4px 14px rgba(60, 80, 220, 0.5);
    font-size: 18px;
    padding: 10px 24px;
}
.unlock-btn:active {
    transform: translateY(1px);
    box-shadow: 0 2px 8px rgba(60, 80, 220, 0.5);
}
.survival-highscore {
    font-size: 14px;
    color: #7ab8ff;
    margin-bottom: 28px;
    letter-spacing: 1px;
}
.survival-highscore span {
    color: #ffd700;
    font-weight: bold;
}
.footer-text {
    font-size: 12px;
    color: #6a7a9a;
    letter-spacing: 2px;
    margin-top: auto;
    padding-top: 8px;
}

/* ===== 关卡选择 ===== */
.select-hint {
    font-size: 13px;
    color: #7ab8ff;
    margin-bottom: 18px;
}
.level-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    width: 460px;
    max-width: 90%;
    margin-bottom: 24px;
}
.level-cell {
    aspect-ratio: 1 / 1;
    border: 2px solid #4a9eff;
    border-radius: 8px;
    background: linear-gradient(145deg, rgba(74, 158, 255, 0.18), rgba(74, 158, 255, 0.04));
    color: #fff;
    font-size: 22px;
    font-weight: bold;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s, box-shadow 0.1s, background 0.1s;
    position: relative;
}
.level-cell:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(74, 158, 255, 0.5);
}
.level-cell .lvl-num { font-size: 24px; color: #ffd700; }
.level-cell .lvl-name {
    font-size: 10px;
    color: #b8d4ff;
    margin-top: 4px;
    letter-spacing: 1px;
    text-align: center;
    padding: 0 2px;
    line-height: 1.2;
}
.level-cell.locked {
    opacity: 0.45;
    cursor: not-allowed;
    border-color: #555;
    background: linear-gradient(145deg, rgba(80, 80, 100, 0.2), rgba(40, 40, 60, 0.1));
}
.level-cell.locked .lvl-num::after { content: " 🔒"; }
.level-cell.cleared {
    border-color: #ffd700;
    background: linear-gradient(145deg, rgba(255, 215, 0, 0.18), rgba(255, 150, 0, 0.05));
}
.level-cell.cleared .lvl-num { color: #ffd700; }

/* ===== 关卡简介 ===== */
.intro-name {
    font-size: 26px;
    color: #ffd700;
    margin: 8px 0 14px;
    letter-spacing: 4px;
}
.intro-desc {
    font-size: 14px;
    color: #c8d8ff;
    max-width: 460px;
    text-align: center;
    line-height: 1.7;
    margin-bottom: 28px;
    padding: 0 20px;
}
.intro-buttons {
    display: flex;
    gap: 16px;
    align-items: center;
}
.small-btn {
    font-size: 16px;
    padding: 10px 24px;
    letter-spacing: 3px;
    background: linear-gradient(180deg, #6a7a9a 0%, #3a4a6a 100%);
    color: #fff;
    border-color: #aab8d8;
    box-shadow: 0 4px 12px rgba(60, 80, 120, 0.5);
}

/* ===== 玩法说明 ===== */
.how-to-content {
    width: 480px;
    max-width: 90%;
    max-height: 420px;
    overflow-y: auto;
    padding: 6px 12px;
    margin-bottom: 20px;
}
.how-section {
    background: rgba(74, 158, 255, 0.08);
    border: 1px solid rgba(74, 158, 255, 0.35);
    border-radius: 8px;
    padding: 12px 18px;
    margin-bottom: 12px;
}
.how-title {
    font-size: 15px;
    color: #ffd700;
    font-weight: bold;
    margin-bottom: 8px;
}
.how-section p {
    font-size: 13px;
    color: #c8d8ff;
    line-height: 1.7;
    margin: 2px 0;
}

/* ============================================================
 *  移动端适配（触屏控件 + 响应式布局 + 竖屏提示）
 * ============================================================ */

/* 默认在桌面端隐藏触摸控件 */
.touch-dpad,
.touch-actions,
.portrait-mask {
    display: none;
}

/* --- 竖屏提示 --- */
.portrait-mask {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.96);
    z-index: 9999;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    gap: 14px;
}
.portrait-mask .rotate-icon {
    font-size: 90px;
    animation: rotatePhone 2.2s ease-in-out infinite;
}
.portrait-mask p {
    font-size: 22px;
    color: #ffd700;
    letter-spacing: 2px;
}
.portrait-mask p.small {
    font-size: 14px;
    color: #b8d4ff;
}
@keyframes rotatePhone {
    0%, 20%   { transform: rotate(0deg); }
    60%, 100% { transform: rotate(-90deg); }
}

/* --- 触摸方向键 (左下) --- */
.touch-dpad {
    position: fixed;
    left: calc(env(safe-area-inset-left, 0px) + 16px);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
    width: 160px;
    height: 160px;
    z-index: 9000;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
}
.dpad-middle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.dpad-center {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(74, 158, 255, 0.25) 0%, rgba(74, 158, 255, 0.05) 70%);
}
.dpad-btn {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: linear-gradient(145deg, rgba(74, 158, 255, 0.45), rgba(74, 158, 255, 0.15));
    border: 2px solid rgba(120, 184, 255, 0.6);
    color: #fff;
    font-size: 22px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5), inset 0 0 8px rgba(120, 184, 255, 0.3);
    transition: transform 0.06s, background 0.1s;
    font-family: inherit;
    padding: 0;
    margin: 0;
}
.dpad-btn:active,
.dpad-btn.active {
    transform: scale(0.9);
    background: linear-gradient(145deg, rgba(255, 215, 0, 0.55), rgba(255, 150, 0, 0.35));
    border-color: rgba(255, 215, 0, 0.8);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5), 0 0 16px rgba(255, 215, 0, 0.4);
}

/* --- 触摸操作按钮 (右下: 射击 + 暂停) --- */
.touch-actions {
    position: fixed;
    right: calc(env(safe-area-inset-right, 0px) + 16px);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
    z-index: 9000;
    display: none;
    flex-direction: column;
    align-items: flex-end;
    gap: 14px;
}
.action-btn {
    border: none;
    color: #fff;
    font-family: inherit;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
    transition: transform 0.06s, box-shadow 0.1s;
    padding: 0;
    margin: 0;
}
.action-fire {
    width: 92px;
    height: 92px;
    border-radius: 50%;
    font-size: 32px;
    background: radial-gradient(circle at 35% 30%, #ff8050, #c02020 70%);
    border: 3px solid rgba(255, 220, 180, 0.7);
    box-shadow: 0 6px 20px rgba(190, 30, 0, 0.6), inset 0 -6px 12px rgba(0, 0, 0, 0.3);
}
.action-fire:active,
.action-fire.active {
    transform: scale(0.92);
    box-shadow: 0 2px 8px rgba(190, 30, 0, 0.7), 0 0 24px rgba(255, 150, 0, 0.7);
    background: radial-gradient(circle at 35% 30%, #ffa070, #e03010 70%);
}
.action-pause {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    font-size: 22px;
    background: linear-gradient(145deg, rgba(90, 90, 120, 0.9), rgba(40, 40, 60, 0.9));
    border: 2px solid rgba(180, 180, 220, 0.5);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    margin-right: 18px;
}
.action-pause:active {
    transform: scale(0.9);
}

/* --- 埋雷按钮 --- */
.action-row {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 10px;
}
.action-mine {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    font-size: 26px;
    background: radial-gradient(circle at 35% 30%, #6a6a8a, #2a2a3e 70%);
    border: 2px solid rgba(160, 160, 200, 0.6);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    display: none;
}
.action-mine.has-mines {
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 35% 30%, #ff6080, #801030 70%);
    border: 2px solid rgba(255, 200, 200, 0.7);
    box-shadow: 0 4px 14px rgba(190, 30, 60, 0.6);
}
.action-mine.has-mines:active {
    transform: scale(0.9);
    box-shadow: 0 0 20px rgba(255, 100, 100, 0.7);
}

/* ============================================================
 *  响应式布局：当屏幕宽度 <= 980px 时
 *  - 启用触摸控件
 *  - Canvas 按窗口尺寸等比缩放
 *  - 竖屏提示根据方向显示
 * ============================================================ */
@media screen and (max-width: 980px), (pointer: coarse) {
    body {
        overflow: hidden;
        /* 横屏下容器高度可能超过 viewport,改成 flex-start 避免上下裁切 */
        align-items: flex-start;
    }
    .game-container {
        padding: 6px;
        gap: 8px;
        /* 水平方向 auto 居中,垂直方向由 body 的 flex-start 控制 */
        margin: 0 auto;
    }
    .info-panel {
        gap: 12px;
        padding: 8px 18px;
    }
    .info-item .label {
        font-size: 10px;
    }
    .info-item span:last-child {
        font-size: 18px;
    }

    /* 触摸控件显示 */
    .touch-dpad    { display: flex; }
    .touch-actions { display: flex; }

    /* overlay 改成 fixed 定位,直接基于 viewport 居中
       不再依赖 .game-container(横屏下容器高度可能超出 viewport,会导致 absolute 定位的 overlay 跑出屏幕) */
    .overlay {
        position: fixed !important;
        inset: auto;
        left: 50% !important;
        top: 50% !important;
        transform: translate(-50%, -50%);
        width: min(624px, 92vw) !important;
        height: min(624px, 80vh) !important;
    }
    .overlay h1 {
        font-size: 36px;
        letter-spacing: 6px;
    }
    .overlay .subtitle {
        font-size: 14px;
        letter-spacing: 4px;
        margin-bottom: 20px;
    }
    .overlay h2 {
        font-size: 28px;
    }
    .overlay p {
        font-size: 14px;
    }
    .controls-info {
        padding: 14px 20px;
        margin-bottom: 22px;
    }
    .controls-info p:first-child {
        font-size: 15px;
    }
    .game-btn {
        font-size: 18px;
        padding: 12px 32px;
        letter-spacing: 4px;
    }
    .menu-btn { width: 240px; padding: 12px 20px; }
    .small-btn { font-size: 14px; padding: 9px 18px; }
    .level-grid {
        grid-template-columns: repeat(3, 1fr);
        width: 320px;
        gap: 10px;
    }
    .level-cell .lvl-num { font-size: 20px; }
    .level-cell .lvl-name { font-size: 9px; }
    .intro-name { font-size: 20px; letter-spacing: 2px; }
    .intro-desc { font-size: 12px; max-width: 90%; }
    .how-to-content { width: 90%; max-height: 56vh; padding: 4px 8px; }
    .how-title { font-size: 13px; }
    .how-section p { font-size: 11px; }
    .how-section { padding: 10px 12px; }
    .footer-text { font-size: 11px; }
    .survival-highscore { font-size: 12px; margin-bottom: 14px; }

    /* 竖屏时显示旋转提示 */
    @media (orientation: portrait) and (max-height: 980px) {
        .portrait-mask { display: flex; }
    }
    @media (orientation: landscape) {
        .portrait-mask { display: none !important; }
    }
}

/* 横屏下小屏继续缩小按钮 */
@media screen and (max-width: 900px) and (orientation: landscape) {
    .touch-dpad  { width: 132px; height: 132px; bottom: 12px; left: 12px; }
    .dpad-btn    { width: 44px; height: 44px; font-size: 18px; }
    .dpad-center { width: 44px; height: 44px; }
    .action-fire { width: 76px; height: 76px; font-size: 26px; bottom: 12px; right: 12px; }
    .action-pause { width: 46px; height: 46px; font-size: 18px; }
    .action-mine { width: 52px; height: 52px; font-size: 22px; }
    .touch-actions { bottom: 12px; right: 12px; gap: 10px; }
}

/* 极小屏 */
@media screen and (max-width: 640px) {
    .touch-dpad  { width: 116px; height: 116px; }
    .dpad-btn    { width: 38px; height: 38px; font-size: 16px; }
    .dpad-center { width: 38px; height: 38px; }
    .action-fire { width: 66px; height: 66px; font-size: 22px; }
    .action-pause { width: 40px; height: 40px; font-size: 16px; }
    .action-mine { width: 46px; height: 46px; font-size: 18px; }
}
