/* ===== 移动端游戏控制器样式 - 优化版 ===== */

/* 基础控制器容器 - 完全独立的覆盖层 */
.mobile-game-controls {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 999999 !important;
    pointer-events: none !important; /* 让点击穿透到游戏 */
    background: transparent !important;
    display: none;
    transition: opacity 0.3s ease;
}

/* 只有控制按钮可以点击 */
.mobile-game-controls .control-button,
.mobile-game-controls .dpad-btn,
.mobile-game-controls .action-btn,
.mobile-game-controls .wasd-btn,
.mobile-game-controls .controls-help-panel {
    pointer-events: auto !important;
}

/* 移动设备检测时显示 */
@media screen and (max-width: 768px) {
    .mobile-game-controls.visible {
        display: block !important;
        opacity: 1 !important;
    }
}

/* 强制在触摸设备上显示 */
@media (hover: none) and (pointer: coarse) {
    .mobile-game-controls {
        display: block !important;
        opacity: 1 !important;
    }
}

/* 控制按钮基础样式 */
.control-button {
    position: absolute;
    width: 48px;
    height: 48px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
    cursor: pointer;
    pointer-events: all;
    transition: all 0.2s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.control-button:active {
    background: rgba(0, 113, 227, 0.8);
    transform: scale(0.95);
}

/* 全屏按钮 */
.fullscreen-btn {
    top: 20px;
    right: 20px;
    background: rgba(0, 113, 227, 0.9);
}

.fullscreen-btn:active {
    background: rgba(0, 143, 255, 1);
}

/* 控制器开关按钮 */
.toggle-btn {
    top: 80px;
    right: 20px;
}

/* 帮助按钮 */
.help-btn {
    top: 140px;
    right: 20px;
    background: rgba(34, 197, 94, 0.9);
}

.help-btn:active {
    background: rgba(74, 222, 128, 1);
}

/* 控制说明面板 */
.controls-help-panel {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 24px;
    color: white;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
    max-width: 320px;
    width: 90vw;
    z-index: 10001 !important;
    pointer-events: all;
    animation: helpPanelSlideIn 0.3s ease-out;
}

.help-content {
    text-align: center;
}

.help-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 20px;
    color: #ffffff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.help-section {
    margin-bottom: 18px;
}

.help-subtitle {
    font-size: 14px;
    font-weight: 600;
    color: #FFD60A;
    margin-bottom: 10px;
    text-align: left;
}

.help-buttons,
.help-directions {
    margin-bottom: 12px;
}

.help-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 14px;
    text-align: left;
}

.help-key {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 6px 12px;
    font-weight: 600;
    font-size: 12px;
    min-width: 60px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.3);
    margin-right: 12px;
}

/* ABXY按钮颜色区分 */
.help-key-a {
    background: rgba(52, 199, 89, 0.8);
    border-color: rgba(52, 199, 89, 1);
    color: white;
}

.help-key-b {
    background: rgba(255, 59, 48, 0.8);
    border-color: rgba(255, 59, 48, 1);
    color: white;
}

.help-key-x {
    background: rgba(0, 122, 255, 0.8);
    border-color: rgba(0, 122, 255, 1);
    color: white;
}

.help-key-y {
    background: rgba(255, 149, 0, 0.8);
    border-color: rgba(255, 149, 0, 1);
    color: white;
}

.help-tip {
    font-size: 12px;
    color: #FFD60A;
    background: rgba(255, 214, 10, 0.1);
    padding: 8px 12px;
    border-radius: 10px;
    margin-top: 12px;
    text-align: center;
    border: 1px solid rgba(255, 214, 10, 0.3);
}

/* 全屏模式优化 */
.mobile-game-controls.fullscreen-active {
    background: rgba(0, 0, 0, 0.5) !important;
    z-index: 9999 !important;
}

/* 确保全屏模式下按钮可见 */
.mobile-game-controls.fullscreen-active .fullscreen-btn,
.mobile-game-controls.fullscreen-active .toggle-btn,
.mobile-game-controls.fullscreen-active .help-btn {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    z-index: 10000 !important;
}

.mobile-game-controls.fullscreen-active .virtual-dpad,
.mobile-game-controls.fullscreen-active .action-buttons,
.mobile-game-controls.fullscreen-active .wasd-controls {
    opacity: 0.9 !important;
    display: block !important;
    visibility: visible !important;
}

/* 全屏时游戏容器优化 */
:-webkit-full-screen #game-box,
:-moz-full-screen #game-box,
:-ms-fullscreen #game-box,
:fullscreen #game-box {
    width: 100% !important;
    height: 100% !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    z-index: 9998 !important;
}

:-webkit-full-screen #game-box iframe,
:-moz-full-screen #game-box iframe,
:-ms-fullscreen #game-box iframe,
:fullscreen #game-box iframe {
    width: 100% !important;
    height: 100% !important;
}

/* 全屏时游戏容器父级优化 */
:-webkit-full-screen #ava-game_container,
:-moz-full-screen #ava-game_container,
:-ms-fullscreen #ava-game_container,
:fullscreen #ava-game_container {
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #000 !important;
}

/* 横屏模式优化 */
@media screen and (orientation: landscape) and (max-height: 500px) {
    .mobile-game-controls {
        background: rgba(0, 0, 0, 0.3);
    }

    /* 调整控制器位置，避免遮挡游戏 */
    .virtual-dpad {
        bottom: 10px;
        left: 10px;
        transform: scale(0.9);
    }

    .action-buttons {
        bottom: 10px;
        right: 10px;
        transform: scale(0.9);
    }

    .wasd-controls {
        bottom: 10px;
        left: 50%;
        transform: translateX(-50%) scale(0.8);
    }

    .fullscreen-btn {
        top: 10px;
        right: 10px;
        transform: scale(0.8);
    }

    .toggle-btn {
        top: 60px;
        right: 10px;
        transform: scale(0.8);
    }

    .help-btn {
        top: 110px;
        right: 10px;
        transform: scale(0.8);
    }
}

/* 超小屏幕横屏模式 */
@media screen and (orientation: landscape) and (max-height: 400px) {
    .virtual-dpad,
    .action-buttons,
    .wasd-controls {
        transform: scale(0.7);
    }

    .fullscreen-btn,
    .toggle-btn,
    .help-btn {
        transform: scale(0.7);
    }
}

@keyframes helpPanelSlideIn {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

/* 虚拟方向键 */
.virtual-dpad {
    position: absolute;
    bottom: 80px;
    left: 40px;
    pointer-events: all;
}

.dpad-center {
    position: relative;
    width: 140px;
    height: 140px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
}

.dpad-horizontal {
    display: flex;
    justify-content: space-between;
    width: 140px;
}

.dpad-btn {
    width: 50px;
    height: 50px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.1s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3),
                inset 0 2px 4px rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.dpad-btn:active {
    background: rgba(0, 113, 227, 0.9);
    transform: scale(0.9);
    box-shadow: 0 2px 8px rgba(0, 113, 227, 0.5),
                inset 0 2px 4px rgba(255, 255, 255, 0.2);
}

/* 动作按钮 */
.action-buttons {
    position: absolute;
    bottom: 80px;
    right: 40px;
    width: 140px;
    height: 140px;
    pointer-events: all;
}

.action-btn {
    position: absolute;
    width: 55px;
    height: 55px;
    background: rgba(220, 38, 38, 0.8);
    backdrop-filter: blur(10px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.1s ease;
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.4),
                inset 0 2px 4px rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.action-btn:active {
    background: rgba(255, 68, 68, 1);
    transform: scale(0.9);
    box-shadow: 0 2px 8px rgba(255, 68, 68, 0.6),
                inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

/* A按钮位置 (右下) - 绿色跳跃 */
.action-a {
    bottom: 10px;
    right: 10px;
    background: rgba(52, 199, 89, 0.9);
    box-shadow: 0 4px 12px rgba(52, 199, 89, 0.4),
                inset 0 2px 4px rgba(255, 255, 255, 0.2);
}

.action-a:active {
    background: rgba(52, 199, 89, 1);
    box-shadow: 0 2px 8px rgba(52, 199, 89, 0.6),
                inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

/* B按钮位置 (右中) - 红色确认 */
.action-b {
    bottom: 50px;
    right: 50px;
    background: rgba(255, 59, 48, 0.9);
    box-shadow: 0 4px 12px rgba(255, 59, 48, 0.4),
                inset 0 2px 4px rgba(255, 255, 255, 0.2);
}

.action-b:active {
    background: rgba(255, 59, 48, 1);
    box-shadow: 0 2px 8px rgba(255, 59, 48, 0.6),
                inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

/* X按钮位置 (左中) - 蓝色攻击 */
.action-x {
    bottom: 50px;
    left: 10px;
    background: rgba(0, 122, 255, 0.9);
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.4),
                inset 0 2px 4px rgba(255, 255, 255, 0.2);
}

.action-x:active {
    background: rgba(0, 122, 255, 1);
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.6),
                inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

/* Y按钮位置 (左上) - 橙色特殊 */
.action-y {
    top: 10px;
    left: 50px;
    background: rgba(255, 149, 0, 0.9);
    box-shadow: 0 4px 12px rgba(255, 149, 0, 0.4),
                inset 0 2px 4px rgba(255, 255, 255, 0.2);
}

.action-y:active {
    background: rgba(255, 149, 0, 1);
    box-shadow: 0 2px 8px rgba(255, 149, 0, 0.6),
                inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

/* B按钮位置 (右上) */
.action-b {
    top: 10px;
    right: 10px;
    background: rgba(239, 68, 68, 0.8);
}

.action-b:active {
    background: rgba(248, 113, 113, 1);
}

/* X按钮位置 (左中) */
.action-x {
    top: 50%;
    left: 10px;
    transform: translateY(-50%);
    background: rgba(59, 130, 246, 0.8);
}

.action-x:active {
    background: rgba(96, 165, 250, 1);
    transform: translateY(-50%) scale(0.9);
}

/* Y按钮位置 (上中) */
.action-y {
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(251, 146, 60, 0.8);
}

.action-y:active {
    background: rgba(251, 191, 36, 1);
    transform: translateX(-50%) scale(0.9);
}

/* WASD控制 */
.wasd-controls {
    position: absolute;
    top: 100px;
    left: 40px;
    pointer-events: all;
    display: none; /* 默认隐藏,可以通过选项启用 */
}

.wasd-controls.active {
    display: block;
}

.wasd-horizontal {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.wasd-btn {
    width: 45px;
    height: 45px;
    background: rgba(147, 51, 234, 0.8);
    backdrop-filter: blur(10px);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.1s ease;
    box-shadow: 0 4px 12px rgba(147, 51, 234, 0.3),
                inset 0 2px 4px rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.wasd-btn:active {
    background: rgba(168, 85, 247, 1);
    transform: scale(0.9);
    box-shadow: 0 2px 8px rgba(168, 85, 247, 0.5),
                inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

/* 横屏模式优化 */
@media screen and (orientation: landscape) and (max-height: 500px) {
    .virtual-dpad {
        bottom: 40px;
        left: 30px;
    }

    .dpad-center {
        width: 120px;
        height: 120px;
    }

    .dpad-btn {
        width: 42px;
        height: 42px;
        font-size: 16px;
    }

    .action-buttons {
        bottom: 40px;
        right: 30px;
        width: 120px;
        height: 120px;
    }

    .action-btn {
        width: 48px;
        height: 48px;
        font-size: 16px;
    }

    .control-button {
        width: 42px;
        height: 42px;
        font-size: 18px;
    }

    .fullscreen-btn {
        top: 15px;
        right: 15px;
    }

    .toggle-btn {
        top: 65px;
        right: 15px;
    }
}

/* 触摸反馈动画 */
@keyframes ripple {
    0% {
        transform: scale(0);
        opacity: 1;
    }
    100% {
        transform: scale(2);
        opacity: 0;
    }
}

.button-ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    animation: ripple 0.6s ease-out;
    pointer-events: none;
}

/* 按键激活状态指示器 */
.dpad-btn.pressed,
.action-btn.pressed,
.wasd-btn.pressed {
    background: rgba(0, 143, 255, 1) !important;
    box-shadow: 0 0 20px rgba(0, 143, 255, 0.8),
                inset 0 2px 8px rgba(255, 255, 255, 0.4) !important;
}
