/* =========================================
   1. 全局基础重置
   ========================================= */
html,
body {
    width: 100%;
    height: 100%;
    /* 禁止浏览器处理触摸手势，完全交给 JS */
    touch-action: none;
    /* iOS 禁止长按弹出菜单 */
    -webkit-touch-callout: none;
    /* 禁止因内容溢出而产生的弹性滑动 */
    overscroll-behavior: none;
    overflow: hidden;
    /* 这一行对 iOS Safari 尤其重要，防止橡皮筋回弹效果 */
    position: fixed;
}

/* --- 修复：禁止双击选中变蓝 --- */
body,
#game-container,
#mapCanvas,
.ref-building,
.dynamic-npc,
.building-img,
img {
    /* <--- 确保 img 标签也被包含 */
    /* 禁止文本选择 */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;

    /* ★★★ 新增：禁止原生拖拽 (Webkit内核) ★★★ */
    -webkit-user-drag: none;

    /* 移除移动端点击高亮 */
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

/* 确保输入框依然可以输入文字 */
input,
textarea,
select {
    -webkit-user-select: auto !important;
    user-select: auto !important;
}

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

body {
    background-color: #1a1a1a;
    /* 更深色的背景增强沉浸感 */
    height: 100vh;
    width: 100vw;
    /* 禁止滑动条，完全由缩放控制 */
    display: block;
    justify-content: center;
    align-items: center;
    margin: 0;
}

#game-container {
    position: relative;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.9);
    transform-origin: center center;
    transition: none !important;
}

/* =========================================
   2. 地图画布（作为背景容器）
   ========================================= */
#mapCanvas {
    background-color: #fafaf9;
    position: relative;
    /* 彻底放弃 Grid 布局，改为高性能的绝对定位地基 */
    display: block !important;

    /* 背景图由 JS 的 Canvas 拼图生成后注入 */
    background-repeat: no-repeat;
    background-position: top left;

    image-rendering: auto;

    overflow: hidden !important;
    /* 初始透明度，配合场景载入时的淡入淡出逻辑 */
    opacity: 0;

}

/* 室内模式特殊背景 */
#mapCanvas.room-mode {
    background-color: #fafaf9 !important;
    /* <-- 改成和外面一致 */
}


/* =========================================
   3. 动态实体（角色、通用 NPC、建筑实体）
   ========================================= */

/* 统一所有实体的基础行为：绝对定位、硬件加速、像素清晰 */
#character,
.building-img,
.collision-block,
.dynamic-npc {
    position: absolute;
    will-change: left, top;
    /* 强制像素艺术清晰度 */
    image-rendering: auto;
}

/* 玩家特有样式 */
#character {
    z-index: 1000;
    pointer-events: none;
    /* 玩家自身不响应鼠标，防止挡住后面的建筑点击 */
    transform-origin: bottom center;
}

/* 通用动态 NPC 样式 (由编辑器数据生成的) */
.dynamic-npc {
    background-repeat: no-repeat;
    pointer-events: auto;
    /* 允许点击，用于触发 NPC 对话或视频 */
    overflow: hidden;
    /* 必须隐藏，用于切片显示 Spritesheet 的单帧 */
}

/* 建筑图片样式 */
.building-img {
    transition: opacity 0.5s ease;
    /* 配合隐形门显形的淡入效果 */
}

/* 逻辑阻挡块 */
.collision-block {
    background-color: transparent;
    /* 游戏内不可见 */
    z-index: 99999;
}

/* =========================================
   4. 交互 UI（标签、气泡、弹窗）
   ========================================= */

.map-label {
    /* --- 定位核心 (保持不变) --- */
    position: absolute;
    transform: translateX(-50%);
    /* 水平居中 */
    white-space: nowrap;
    /* 禁止换行 */
    pointer-events: none;
    /* 鼠标穿透，不影响点击建筑 */

    /* --- 这里的 z-index 要比游戏里的角色(约几百)大 --- */
    z-index: 10000;

    /* --- 视觉样式 (从编辑器代码复制过来) --- */
    font-size: 12px;
    font-weight: normal;
    /* 编辑器看起来没加粗，如果你想加粗就把这行删了 */

    background: rgba(255, 187, 0, 0.7);
    /* 半透明黄底 */
    color: #0004ff;
    /* 亮蓝色文字 */

    padding: 1px 4px;
    /* 内边距 */
    border-radius: 3px;
    /* 小圆角 */

    /* --- 清除旧的阴影样式 (防止之前的特效干扰) --- */
    text-shadow: none;
    border: none;
    box-shadow: none;
}

/* 通用提示弹窗 */
#info-popup {
    position: absolute;
    background-color: rgba(255, 255, 255, 0.95);
    color: #333;
    border: 2px solid #222;
    padding: 12px 18px;
    font-size: 14px;
    font-weight: bold;
    border-radius: 8px;
    display: none;
    z-index: 20000;
    text-align: center;
    pointer-events: none;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
    max-width: 250px;
    white-space: pre-wrap;
    /* 允许 CSV 换行符生效 */
}

/* NPC 对话气泡 */
.npc-speech-bubble {
    position: absolute;
    background-image: url('images/ltalk.png');
    background-size: 100% 100%;
    background-repeat: no-repeat;
    padding: 15px 15px 25px 15px;
    /* 根据图片边框微调 */
    color: #000;
    font-size: 12px;
    font-weight: bold;
    text-align: center;
    width: auto;
    min-width: 90px;
    max-width: 200px;
    white-space: pre-wrap;
    word-break: break-word;
    /* 允许在长单词内换行 */
    line-height: 1.4;
    /* 增加行高，让多行看起来更舒服 */
    z-index: 20000;
    pointer-events: none;
}

/* =========================================
   5. 多媒体弹窗 (新闻/视频)
   ========================================= */

/* 新闻弹窗 */
/* 新闻弹窗容器 - 现在的逻辑是透明且穿透 */
#news-modal {
    display: none;
    position: absolute;
    /* 必须高于广告(2000000)和控制层(999999) */
    z-index: 5000000 !important;
    left: 0;
    top: 0;
    width: 100%;
    /* 手机模式下撑满背景，方便定位 */
    height: 100%;

    /* ▼▼▼▼▼▼▼▼ 修改这两行 ▼▼▼▼▼▼▼▼ */
    background-color: transparent;
    pointer-events: none;
    /* ▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲ */

    justify-content: center;
    align-items: center;
}

/* 弹窗内容主体 */
.news-content {
    position: absolute;
    /* 改为绝对定位，由 JS 控制 left/top */
    background-color: #fff;

    /* 默认尺寸，JS 会覆盖 */
    width: 800px;
    height: 600px;

    border-radius: 8px;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.3);
    /* 阴影稍微淡一点 */
    overflow: hidden;
    border: 3px solid #007bff;
    /* 蓝色边框，更有科技感 */

    /* 关键：内容区域必须恢复鼠标响应 */
    pointer-events: auto;
}

/* 调整关闭按钮，让它显眼一点 */
.news-content .close-btn {
    position: absolute;
    top: 5px;
    right: 10px;
    color: #333;
    /* 深色叉叉 */
    z-index: 50001;
    font-size: 28px;
    text-shadow: none;
    background: rgba(255, 255, 255, 0.8);
    width: 30px;
    height: 30px;
    line-height: 26px;
    text-align: center;
    border-radius: 4px;
}

.news-content .close-btn:hover {
    background: #f00;
    color: #fff;
}


/* 视频播放器弹窗 */
#video-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: transparent;

    /* ★★★ 修改这里：由 40000 改为 200000，解决被空气墙遮挡导致无法点击的问题 ★★★ */
    z-index: 200000 !important;

    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
    /* 允许点击周围穿透 */
}



.video-wrapper {
    position: relative;
    background: #000;
    border: 3px solid #666;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    /* 恢复视频区域交互 */
    overflow: hidden;
    transform: none;
}

#video-placeholder {
    width: 100%;
    height: 100%;
    min-width: 0;
}

#video-placeholder video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* 保持比例 */
    display: block;
}

/* 关闭按钮通用样式 */
.close-btn {
    position: absolute;
    top: 10px;
    right: 20px;
    color: #fff;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    z-index: 50001;
    text-shadow: 0 0 10px #000;
    transition: transform 0.2s;
}

.close-btn:hover {
    transform: scale(1.2);
}


/* 让新闻 iframe 填满弹窗 */
#news-frame {
    width: 100%;
    height: 100%;
    display: block;
    /* 防止底部出现微小缝隙 */
}




/* 调试模式下的碰撞框样式 */
.debug-collision-rect {
    position: absolute;
    pointer-events: none;
    /* 必须穿透，不影响交互 */
    z-index: 999999;
    border: 1px solid;
    box-sizing: border-box;
}

/* 玩家脚部碰撞盒 - 绿色 */
.debug-player-feet {
    background-color: rgba(0, 255, 0, 0.4);
    border-color: #00ff00;
}

/* 建筑/NPC 的 bodyRect - 蓝色 */
.debug-body-rect {
    background-color: rgba(0, 0, 255, 0.2);
    border-color: #0000ff;
}

/* 传送门的 doorRect - 紫色 */
.debug-door-rect {
    background-color: rgba(255, 0, 255, 0.3);
    border-color: #ff00ff;
}

/* =========================================
   移动端虚拟控制器 (Virtual Controls)
   ========================================= */
#mobile-controls {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* 让中间区域穿透，不挡视野 */
    z-index: 999999;
    display: none;
    /* 默认隐藏，JS检测到手机开启 */
}

/* 左侧摇杆区域 */
#joystick-zone {
    position: absolute;
    bottom: 40px;
    left: 40px;
    width: 140px;
    height: 140px;
    background: rgba(255, 255, 255, 0.15);
    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: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}

/* 右侧按钮区域 */
.action-btn {
    position: absolute;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.4);
    border: 3px solid rgba(255, 255, 255, 0.6);
    pointer-events: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    color: white;
    user-select: none;
    touch-action: none;
}

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

/* 攻击键 (J) - 剑图标 */
#btn-melee {
    bottom: 50px;
    right: 130px;
    background-color: rgba(255, 87, 34, 0.6);
    /* 橙红色 */
}

/* 射击键 (K) - 枪图标 */
#btn-shoot {
    bottom: 140px;
    right: 40px;
    background-color: rgba(33, 150, 243, 0.6);
    /* 蓝色 */
}

/* =========================================
   网盟广告条 (Ad Banner)
   ========================================= */
#game-ad-banner {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 600px;
    /* 限制最大宽度，以免电脑上太丑 */
    height: auto;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 2000000;
    /* 确保在最上层 */
    display: none;
    /* 默认隐藏，JS控制显示 */
    cursor: pointer;
    text-align: center;
    border-top: 2px solid #ffcc00;
}

#game-ad-banner img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 100px;
    /* 防止图片过高挡住游戏 */
    object-fit: contain;
}

/* 关闭广告的小按钮 */
#ad-close-btn {
    position: absolute;
    top: -10px;
    right: 5px;
    background: #333;
    color: #fff;
    border: 1px solid #fff;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    line-height: 18px;
    text-align: center;
    font-size: 12px;
    cursor: pointer;
}

/* ====== 搜索栏组件样式 ====== */
/* 搜索栏容器 */
#game-search-bar {
    position: absolute;
    display: none;
    width: 320px;
    /* 默认值，JS会覆盖 */
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.5);
    border: 3px solid #007bff;
    /* padding: 10px;  <-- 删除固定的 padding，改用 flex 控制 */
    padding: 6px;
    z-index: 9999999 !important;
    animation: popIn 0.2s ease-out;

    /* ★ 新增：盒模型控制，确保宽高包含 padding */
    box-sizing: border-box;
    display: flex;
    /* 让容器本身变成 flex */
    flex-direction: column;
    /* 内部内容垂直排列 (虽然目前只有 inner) */
    justify-content: center;
}

/* 引擎切换器 */
#game-search-switcher {
    width: auto;
    /* 自动适应内容 */
    max-width: 60px;
    /* 但最大不超过 60px */
    min-width: 45px;
    /* 最小不低于 45px */
    flex-shrink: 1;

    border: 1px solid #ccc;
    border-radius: 4px;
    background-color: #f8f9fa;
    font-size: 12px;
    color: #333;
    outline: none;
    cursor: pointer;

    /* ★ 改动2：减少左侧内边距，防止文字被截断 */
    padding-left: 0;
    text-align: center;
    /* 让文字居中一点 */

    height: 100%;
    min-height: 28px;
}

#game-search-switcher:hover {
    background-color: #e9ecef;
}

/* 简单的弹出动画 */
@keyframes popIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* 1. 内部布局容器 */
.search-bar-inner {
    display: flex;
    gap: 4px;
    /* ★ 修改：间距改小一点，适应小宽度 */
    position: relative;
    align-items: center;
    width: 100%;
    height: 100%;
}

/* 2. 输入框 (核心修改) */
#game-search-input {
    flex: 1;
    /* 占据剩余空间 */

    /* ★★★ 关键修复：允许输入框宽度无限缩小，不被默认文字撑大 ★★★ */
    min-width: 0;

    padding: 0 6px;
    /* 内边距稍微改小 */
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    outline: none;
    color: #333 !important;
    background: #fff !important;

    height: 100%;
    min-height: 28px;
    /* 最小高度微调 */
}

/* 3. 搜索按钮 */
#game-search-btn {
    background: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    font-size: 13px;
    white-space: nowrap;

    /* ★★★ 关键修复：防止按钮被挤扁 ★★★ */
    flex-shrink: 0;

    height: 100%;
    min-height: 28px;
    padding: 0 10px;
    /* ★ 修改：内边距改小，更紧凑 */
}


#game-search-btn:hover {
    background: #0056b3;
}

/* 关闭按钮 (红叉) */
#game-search-close {
    position: absolute;
    top: -18px;
    right: -18px;
    width: 26px;
    height: 26px;
    background: #ff4d4d;
    color: white;
    border-radius: 50%;
    text-align: center;
    line-height: 24px;
    cursor: pointer;
    font-weight: bold;
    border: 2px solid #fff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    font-size: 16px;
    user-select: none;
}

#game-search-close:hover {
    background: #cc0000;
    transform: scale(1.1);
}

/* 加载界面全屏遮罩 */
#game-loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 9999999;
    display: none;
    /* 初始隐藏 */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s;
}

/* 加载展示图 */
#loader-display-img {
    max-width: 80%;
    max-height: 60%;
    margin-bottom: 30px;
    object-fit: contain;
}

/* 进度条容器 */
#loader-bar-container {
    width: 5%;
    height: 8px;
    background: #333;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid #444;
}

/* 进度条本体 */
#loader-bar-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #007bff, #00d2ff);
    transition: width 0.1s;
    box-shadow: 0 0 10px rgba(0, 123, 255, 0.5);
}

#loader-text {
    color: #888;
    font-size: 12px;
    margin-top: 10px;
    font-family: monospace;
}

/* ====== 移动端竖屏适配 (防止摇杆和按钮重合) ====== */
@media (orientation: portrait) {

    /* 1. 左侧摇杆：稍微往左下角缩一点 */
    #joystick-zone {
        bottom: 30px !important;
        left: 20px !important;
        /* 原来是 40px，往边上靠一点 */
        width: 120px !important;
        /* 稍微调小一点点 */
        height: 120px !important;
    }

    /* 2. 摇杆头：配合缩小 */
    #joystick-knob {
        width: 50px !important;
        height: 50px !important;
    }

    /* 3. 攻击键 (J)：往右下角缩，并且稍微变小 */
    #btn-melee {
        right: 90px !important;
        /* 原来是 130px，这会让它离摇杆更远 */
        bottom: 40px !important;
        width: 60px !important;
        /* 缩小按钮 */
        height: 60px !important;
        font-size: 20px !important;
    }

    /* 4. 射击键 (K)：往右边靠 */
    #btn-shoot {
        right: 20px !important;
        /* 原来是 40px */
        bottom: 110px !important;
        /* 稍微往下压一点 */
        width: 60px !important;
        height: 60px !important;
        font-size: 20px !important;
    }
}