* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Microsoft YaHei', sans-serif;
}

/* 优化网页中像素与切图的缩放渲染，防止 WebView 拉伸导致的模糊 */ 
html, body, canvas, img, 
.equip-slot, 
.inv-grid-item, 
.inv-qty-badge, 
.minimap-bg-asset, 
.hud-avatar-frame, 
.hud-minimap-frame-v2, 
.hud-menu-btn img, 
.hud-chat-btn img,
.selected::after {
    image-rendering: -moz-crisp-edges;         /* Firefox */
    image-rendering: -webkit-optimize-contrast; /* Safari / iOS WebView */
    image-rendering: crisp-edges;              /* CSS3 标准 */
    image-rendering: pixelated;                /* Chrome / Android WebView */
}


:root {
    --app-vh: 1vh;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
}

body {
    background-color: #2c3e50;
    display: flex;
    justify-content: center;
    align-items: center;
    height: calc(var(--app-vh) * 100);
    overflow: hidden;
    padding-top: var(--safe-top);
    padding-right: var(--safe-right);
    padding-bottom: var(--safe-bottom);
    padding-left: var(--safe-left);
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    background-color: #000;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* 让点击穿透UI层到Canvas，子元素需要恢复pointer-events */
}

.ui-panel {
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.3);
    /* 更透明 */
    border: none;
    /* 去掉粗边框 */
    color: #fff;
    padding: 10px;
}

/* ===================================================
   全新 HUD 系统 (根据参考图复刻)
   =================================================== */

.hud-container {
    position: absolute;
    pointer-events: auto;
    display: flex;
    z-index: 100;
}

/* --- 左上角：角色状态栏 --- */
#player-hud-top-left {
    top: calc(10px + var(--safe-top));
    left: calc(10px + var(--safe-left));
    align-items: flex-start;
    gap: 10px;
}

.hud-avatar-frame {
    position: relative;
    width: 84px;
    height: 84px;
    background: rgba(0, 0, 0, 0.6);
    border: 3px solid #5d4037;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
}

.hud-avatar-frame img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#hud-player-level {
    position: absolute;
    bottom: -5px;
    right: -5px;
    background: #fff;
    color: #333;
    border: 2px solid #5d4037;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 16px;
    font-weight: bold;
    font-style: italic;
    box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5);
    z-index: 10;
}

.hud-status-bars {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 5px;
}

.hud-bar-container {
    position: relative;
    width: 180px;
    height: 24px;
    background: #333;
    border: 2px solid #5d4037;
    border-radius: 4px;
    overflow: hidden;
}

.hud-bar-fill {
    height: 100%;
    width: 100%;
    transition: width 0.3s ease;
}

.hp .hud-bar-fill {
    background: linear-gradient(to right, #e74c3c, #c0392b);
}

.mp .hud-bar-fill {
    background: linear-gradient(to right, #3498db, #2980b9);
}

.hud-bar-text {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
    font-size: 14px;
    font-weight: bold;
    text-shadow: 1px 1px 2px #000;
}

/* --- 左侧：队伍状态栏 --- */
#team-hud {
    position: absolute;
    top: calc(110px + var(--safe-top));
    left: calc(10px + var(--safe-left));
    z-index: 90;
    background: rgba(30, 20, 10, 0.7);
    border: 1px solid #5d4037;
    border-radius: 4px;
    padding: 4px;
    width: 120px;
    pointer-events: auto;
}

.team-hud-title {
    color: #f1c40f;
    font-size: 11px;
    font-weight: bold;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    padding-bottom: 2px;
    margin-bottom: 2px;
}

.team-member {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid #3d2b27;
    border-radius: 4px;
    padding: 4px;
    margin-bottom: 4px;
}

.team-member .tm-name {
    color: #ecf0f1;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    margin-bottom: 3px;
}

.team-member .tm-leader-icon {
    color: #f1c40f;
    font-size: 12px;
}

.tm-bar-bg {
    width: 100%;
    height: 4px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 2px;
    margin-bottom: 1px;
    overflow: hidden;
}

.tm-hp-fill {
    height: 100%;
    background: linear-gradient(to right, #e74c3c, #c0392b);
    transition: width 0.3s;
}

.tm-mp-fill {
    height: 100%;
    background: linear-gradient(to right, #3498db, #2980b9);
    transition: width 0.3s;
}


/* --- 右上角：地图与任务 --- */
#map-hud-top-right {
    top: calc(10px + var(--safe-top));
    right: calc(10px + var(--safe-right));
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

.hud-minimap-frame-v2 {
    position: relative;
    width: 154px;
    /* 根据资源比例微调 */
}

.minimap-bg-asset {
    width: 100%;
    display: block;
}

#hud-map-name {
    position: absolute;
    top: 6px;
    left: 0;
    width: 100%;
    text-align: center;
    color: #ffd700;
    font-weight: bold;
    font-size: 14px;
    text-shadow: 1px 1px 2px #000;
    pointer-events: none;
}

#hud-minimap-render {
    position: absolute;
    top: 32px;
    left: 14px;
    right: 14px;
    bottom: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    background: transparent;
}

#minimap-canvas {
    width: 120px;
    height: 120px;
    background: transparent;
}

#hud-quest-tracker {
    width: 140px;
    background: rgba(60, 40, 20, 0.7);
    border: 1px solid #5d4037;
    padding: 8px;
    color: #eee;
}

.quest-header {
    color: #f1c40f;
    font-weight: bold;
    font-size: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    padding-bottom: 4px;
    margin-bottom: 5px;
}

.quest-title {
    font-size: 13px;
    color: #fff;
    margin-bottom: 2px;
}

.quest-desc {
    font-size: 11px;
    color: #ccc;
}

/* --- 顶部中右：功能按键 --- */
#function-menu-top {
    top: calc(10px + var(--safe-top));
    right: calc(170px + var(--safe-right));
    gap: 15px;
}

.hud-menu-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: transform 0.1s;
}

.hud-menu-btn:hover {
    transform: scale(1.1);
}

.hud-menu-btn img {
    width: 64px;
    height: 64px;
}

/* --- 左下角：聊天系统 --- */
#chat-hud-bottom-left {
    bottom: calc(15px + var(--safe-bottom));
    left: calc(15px + var(--safe-left));
    flex-direction: column;
    gap: 8px;
    max-width: 320px;
    width: 40%;
}

#hud-chat-logs {
    background: rgba(0, 0, 0, 0.3);
    padding: 10px;
    border-radius: 8px;
    max-height: 150px;
    overflow-y: hidden;
    pointer-events: none;
}

.chat-line {
    color: #fff;
    font-size: 13px;
    margin-bottom: 4px;
    text-shadow: 1px 1px 1px #000;
}

.chat-line .name {
    color: #f1c40f;
    margin-right: 5px;
}

#hud-chat-btn-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.hud-chat-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
}

.hud-chat-btn img {
    width: 52px;
    height: 52px;
}

#hud-currency-quick {
    color: #f1c40f;
    font-weight: bold;
    font-size: 14px;
    text-shadow: 1px 1px 2px #000;
}

/* --- 右下角：主菜单 --- */
#main-menu-bottom-right {
    bottom: calc(15px + var(--safe-bottom));
    right: calc(15px + var(--safe-right));
    gap: 12px;
}

/* 覆盖旧 UIPanel 的透明度 */
.ui-panel {
    background: rgba(30, 20, 10, 0.9) !important;
    border: 2px solid #5d4037 !important;
}

#chat-input-wrap {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: rgba(0, 0, 0, 0.4);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

#chat-input {
    flex: 1;
    background: rgba(30, 20, 10, 0.8);
    border: 1px solid #5d4037;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 13px;
    outline: none;
}

#chat-input:focus {
    border-color: #f1c40f;
}

#chat-send-btn {
    background: linear-gradient(135deg, #e67e22, #d35400);
    border: 1px solid #5d4037;
    color: white;
    padding: 0 10px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}

#battle-log {
    list-style: none;
}

#battle-log li {
    margin-bottom: 2px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    line-height: 1.4;
}

/* 任务追踪面板 */
#quest-tracker {
    position: absolute;
    top: 80px;
    left: 10px;
    width: 160px;
    /* 缩小面板宽度 */
    background: rgba(0, 0, 0, 0.5);
    pointer-events: none;
    z-index: 40;
}

#quest-tracker h3 {
    color: #f1c40f;
    font-size: 14px;
    border-bottom: 1px solid #555;
    padding-bottom: 5px;
    margin-bottom: 5px;
}

/* 角色面板宽度优化 */
#hero-inventory-panel {
    width: 640px;
    /* 从 700 缩小 */
    height: 480px;
    display: flex;
    padding: 0;
    flex-direction: column;
    background: rgba(20, 10, 5, 0.95);
}

.modal-panel {
    pointer-events: auto;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #3e2723;
    border: 4px solid #8d6e63;
    border-radius: 10px;
    color: white;
    padding: 20px;
    display: flex;
    flex-direction: column;
    z-index: 5000;
    /* 调高，确保盖过所有HUD和提示层 */
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.9);
}

.hidden {
    display: none !important;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #5d4037;
    padding-bottom: 10px;
    margin-bottom: 10px;
    flex-shrink: 0;
}

.close-btn {
    background: #c0392b;
    color: white;
    border: none;
    width: 24px;
    height: 24px;
    border-radius: 12px;
    cursor: pointer;
    font-weight: bold;
}

#create-role-panel {
    text-align: center;
}

.role-select {
    margin: 20px 0;
    display: flex;
    justify-content: space-around;
}

#role-name-input {
    width: 80%;
    padding: 8px;
    margin-bottom: 20px;
    background: #1a1a1a;
    border: 1px solid #8d6e63;
    color: #fff;
}

#create-role-panel button {
    padding: 10px 30px;
    background: #27ae60;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
}

/* 商城列表样式 */
.shop-item {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid #795548;
    padding: 10px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.shop-item-info h4 {
    color: #ffeb3b;
    margin-bottom: 5px;
}

.shop-item-info p {
    font-size: 12px;
    color: #ccc;
}

.buy-btn {
    background: #e67e22;
    color: white;
    border: none;
    padding: 5px 15px;
    border-radius: 3px;
    cursor: pointer;
}

.shop-filter-bar {
    padding: 10px;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    flex-shrink: 0;
    scrollbar-width: none; /* Firefox */
}

.shop-filter-bar::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

.shop-filter-bar .filter-btn {
    background: #4e342e;
    color: #bdc3c7;
    border: 1px solid #5d4037;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    flex-shrink: 0;
}

.shop-filter-bar .filter-btn.active {
    background: #f39c12;
    color: #fff;
    border-color: #f1c40f;
}

/* 综合面板左侧装备孔位 */
.equip-slot {
    width: 52px;
    height: 52px;
    background-size: 100% 100% !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background-color: transparent !important;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
}

/* Empty slot backgrounds */
#eq-head { background-image: url('../img/ui/bbtk.png') !important; }
#eq-armor { background-image: url('../img/ui/bbyf.png') !important; }
#eq-belt { background-image: url('../img/ui/bbys.png') !important; }
#eq-shoes { background-image: url('../img/ui/bbxz.png') !important; }
#eq-weapon { background-image: url('../img/ui/bbwq.png') !important; }
#eq-necklace { background-image: url('../img/ui/bbxl.png') !important; }
#eq-ring { background-image: url('../img/ui/bbjz.png') !important; }
#eq-accessory { background-image: url('../img/ui/bbtx.png') !important; }

/* Equipped slot quality backgrounds */
.equip-slot.q-normal { background-image: url('../img/ui/bbzbwpz.png') !important; }
.equip-slot.q-good { background-image: url('../img/ui/bbzbls.png') !important; }
.equip-slot.q-rare { background-image: url('../img/ui/bbzbzs.png') !important; }
.equip-slot.q-epic { background-image: url('../img/ui/bbzbhs.png') !important; }

.equip-slot:hover {
    filter: brightness(1.2);
    transform: scale(1.05);
}

.equip-slot .slot-bg {
    display: none !important;
}

/* 综合面板右侧包裹网格里的独立物品格子 */
.inv-grid-item {
    background: url('../img/ui/bbpt.png') no-repeat center center;
    background-size: 100% 100% !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background-color: transparent !important;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    cursor: pointer;
}

.inv-grid-item:hover {
    filter: brightness(1.2);
    transform: scale(1.02);
}

/* Item grid item quality backgrounds */
.inv-grid-item.q-normal { background-image: url('../img/ui/bbbs.png') !important; }
.inv-grid-item.q-good { background-image: url('../img/ui/bbls.png') !important; }
.inv-grid-item.q-rare { background-image: url('../img/ui/bbzs.png') !important; }
.inv-grid-item.q-epic { background-image: url('../img/ui/bbhs.png') !important; }

.inv-grid-item-inner {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 11px;
    font-weight: bold;
    text-align: center;
    text-shadow: 1px 1px 2px #000;
    pointer-events: none;
    border: none !important;
}

/* 物品选中高亮边框 */
.inv-grid-item.selected::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('../img/ui/bbwp.png') no-repeat center center;
    background-size: 100% 100% !important;
    pointer-events: none;
    z-index: 10;
}

/* 物品堆叠数量标记 */
.inv-qty-badge {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    background: url('../img/ui/bbwpdds.png') no-repeat center center;
    background-size: 100% 100% !important;
    color: #ffffff !important;
    font-size: 10px;
    font-family: "Courier New", Courier, monospace, sans-serif;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    text-shadow: 1px 1px 1px #000;
    pointer-events: none;
    z-index: 5;
    padding-top: 1px;
    box-sizing: border-box;
}

/* 背包物品网格容器 */
#inventory-grid {
    flex: 1;
    padding: 10px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    grid-auto-rows: 64px;
}

#hero-avatar-wrap {
    position: absolute !important;
    left: 50% !important;
    top: 43% !important; /* pulled up from 50% */
    transform: translate(-50%, -50%) !important;
    width: 120px !important;
    height: 200px !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
}

.equip-slots-col {
    position: absolute !important;
    top: 68px !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
}
.equip-slots-col.left-col {
    left: 12px !important;
}
.equip-slots-col.right-col {
    right: 12px !important;
}

/* 物品数量角标 */
.inv-item-count {
    position: absolute;
    bottom: 2px;
    right: 4px;
    color: #fff;
    text-shadow: 1px 1px 2px #000;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.8);
    transition: background 0.2s;
}

/* 物品操作悬浮菜单 */
#item-action-menu {
    pointer-events: auto;
    z-index: 6000;
    /* 高于 modal-panel 的 5000 */
}

/* 玩家交互菜单 */
#player-interaction-menu {
    pointer-events: auto;
    z-index: 6000;
    /* 高于 modal-panel 的 5000 */
}

#item-action-menu .action-btn,
#item-action-menu button {
    pointer-events: auto;
    cursor: pointer;
    width: 100%;
    border: 1px solid #555;
    border-radius: 3px;
    padding: 6px 5px;
    font-size: 13px;
    font-weight: bold;
    color: #fff;
    background: rgba(0, 0, 0, 0.5);
    margin-bottom: 4px;
}

#item-action-menu .action-btn:hover,
#item-action-menu button:hover {
    filter: brightness(1.3);
}


/* 战斗十字菜单 */
#combat-action-panel {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: auto;
    z-index: 1000;
}

.combat-cross-menu {
    display: grid;
    grid-template-areas:
        ". top ."
        "left center right"
        ". bottom .";
    gap: 4px;
}

.cross-slot {
    width: 66px;
    height: 66px;
    background: #3e1a0d;
    border: 2px solid #5d2510;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    color: #f1c40f;
    font-weight: bold;
    font-size: 16px;
    text-shadow: 1px 1px 2px #000;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.8);
    transition: background 0.2s;
}

/* 战斗状态下的 UI 隐藏与简化 */
#ui-layer.battling #player-status,
#ui-layer.battling #function-menu-top,
#ui-layer.battling #main-menu-bottom-right,
#ui-layer.battling #map-hud-top-right,
#ui-layer.battling #hud-quest-tracker {
    display: none !important;
}

#ui-layer.battling #map-name-display {
    display: block !important;
}

#map-name-display {
    position: absolute;
    top: 15px;
    right: 20px;
    color: #2ecc71;
    font-size: 16px;
    font-weight: bold;
    text-shadow: 1px 1px 2px #000;
    pointer-events: none;
}

.cross-slot:hover {
    background: #5d2510;
}

.cross-slot.top {
    grid-area: top;
}

.cross-slot.left {
    grid-area: left;
}

.cross-slot.center {
    grid-area: center;
}

.cross-slot.right {
    grid-area: right;
}

.cross-slot.bottom {
    grid-area: bottom;
}

.cross-slot button {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    color: inherit;
    font: inherit;
    cursor: pointer;
}

/* ===================================================
   响应式适配：移动端竖屏优先布局
   针对屏幕宽度小于 1024px 的设备
   =================================================== */
@media screen and (max-width: 1024px) {
    body {
        background: #000;
        height: 100vh;
        margin: 0;
        overflow: hidden;
    }

    #game-container {
        width: 100vw !important;
        height: 100vh !important;
        transform: none !important;
        box-shadow: none;
        margin: 0;
    }

    /* ---- 左上角状态栏 (头像与血蓝条) ---- */
    #player-hud-top-left {
        top: calc(10px + var(--safe-top));
        left: calc(15px + var(--safe-left));
        gap: 8px;
    }

    .hud-avatar-frame {
        width: 40px;
        /* 缩小头像框 */
        height: 40px;
        border-width: 2px;
    }

    #hud-player-level {
        font-size: 10px;
        /* 缩小等级文字 */
        padding: 1px 3px;
        bottom: -2px;
        right: -2px;
    }

    .hud-status-bars {
        gap: 6px;
        padding-top: 2px;
    }

    .hud-bar-container {
        width: 110px;
        /* 缩小条宽 */
        height: 14px;
        /* 缩小条高 */
        border-width: 1px;
    }

    .hud-bar-text {
        font-size: 9px;
        /* 缩小数值文字 */
        line-height: 14px;
    }

    /* ---- 顶部中右：功能按键 (排行、社交、商城) ---- */
    #function-menu-top {
        top: calc(10px + var(--safe-top));
        right: calc(180px + var(--safe-right));
        gap: 12px;
    }

    .hud-menu-btn img {
        width: 58px;
        height: 58px;
    }

    /* ---- 右上角：小地图与任务 ---- */
    #map-hud-top-right {
        top: calc(10px + var(--safe-top));
        right: calc(15px + var(--safe-right));
    }

    .hud-minimap-frame-v2 {
        width: 100px;
    }

    #hud-map-name {
        font-size: 10px;
        top: 3px;
    }

    #hud-minimap-render {
        top: 18px;
        left: 8px;
        right: 8px;
        bottom: 7px;
    }

    #minimap-canvas {
        width: 64px;
        height: 64px;
    }

    #hud-quest-tracker {
        width: 90px;
        padding: 4px;
    }

    .quest-header {
        font-size: 13px;
    }

    .quest-title {
        font-size: 12px;
    }

    .quest-desc {
        font-size: 11px;
    }

    /* ---- 左下角：聊天系统 ---- */
    #chat-hud-bottom-left {
        bottom: calc(15px + var(--safe-bottom));
        left: calc(15px + var(--safe-left));
        gap: 4px;
        max-width: 200px;
        /* 极小化宽度 */
    }

    #hud-chat-logs {
        padding: 4px;
        max-height: 75px;
        /* 极小化高度 */
    }

    .chat-line {
        font-size: 10px;
        /* 字体极小化 */
    }

    .hud-chat-btn img {
        width: 42px;
        height: 42px;
    }

    #hud-currency-quick {
        font-size: 13px;
    }

    /* ---- 右下角：主菜单 ---- */
    #main-menu-bottom-right {
        bottom: calc(15px + var(--safe-bottom));
        right: calc(15px + var(--safe-right));
        gap: 12px;
    }

    #main-menu-bottom-right .hud-menu-btn img {
        width: 58px;
        height: 58px;
    }

    /* ---- 弹窗面板适配 ---- */
    .modal-panel {
        max-width: 96vw;
        max-height: 82dvh;
        /* 减小，防止被浏览器刘海/工具栏遮挡 */
        padding: 5px;
        border-width: 2px;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .modal-panel h2 {
        font-size: 16px !important;
        padding: 6px !important;
    }

    .hero-tab {
        padding: 6px 4px !important;
        font-size: 12px !important;
    }

    #chat-input-wrap,
    .chat-input-row {
        display: flex;
        gap: 8px;
        padding: 4px;
        flex-shrink: 0;
    }

    /* --- 登录/注册面板 --- */
    #login-panel {
        width: min(300px, 88vw) !important;
        max-height: 80dvh !important;
        overflow-y: auto !important;
        padding: 12px !important;
    }

    #login-panel h2 {
        font-size: 15px !important;
        margin-bottom: 6px !important;
    }

    /* --- 创建角色面板（单独缩小）--- */
    #create-role-panel {
        width: min(280px, 86vw) !important;
        max-height: 75dvh !important;
        overflow-y: auto !important;
        padding: 10px 12px !important;
    }

    #create-role-panel h2 {
        font-size: 14px !important;
        margin-bottom: 6px !important;
        padding-bottom: 4px !important;
        border-bottom: 1px solid #5d4037;
    }

    /* 族名标签缩小 */
    #create-role-panel .role-select>div[style*="color:#f1c40f"],
    #create-role-panel .role-select>div[style*="color:#3498db"],
    #create-role-panel .role-select>div[style*="color:#e74c3c"] {
        font-size: 12px !important;
    }

    /* 选项行间距压缩 */
    #create-role-panel .role-select {
        gap: 2px !important;
    }

    #create-role-panel .role-select label {
        font-size: 12px !important;
    }

    /* 名称输入框 */
    #role-name-input {
        margin-top: 6px !important;
        padding: 5px !important;
        font-size: 13px !important;
    }

    /* 进入游戏按钮 */
    #create-role-panel button {
        padding: 7px 20px !important;
        font-size: 13px !important;
        margin-top: 6px !important;
    }

    /* --- 设置面板 --- */
    #settings-panel {
        width: min(280px, 90vw) !important;
        max-height: 80dvh !important;
    }

    #settings-panel>div {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* --- 聊天弹窗 --- */
    #chat-modal-panel {
        width: min(360px, 92vw) !important;
        max-height: 75dvh !important;
    }

    #chat-modal-panel #chat-modal-log-container {
        max-height: 35dvh !important;
    }

    /* --- 角色面板（背包）--- */
    #hero-inventory-panel {
        width: min(600px, 96vw) !important;
        height: min(460px, 90dvh) !important;
        /* 稍微增加高度确保时装栏显示 */
    }

    /* 标题栏压缩：减小 padding 和字体 */
    #hero-inventory-panel .panel-header {
        padding: 5px 8px !important;
        padding-bottom: 5px !important;
        margin-bottom: 0 !important;
        min-height: 0 !important;
    }

    #hero-inventory-panel .panel-header h2 {
        font-size: 13px !important;
        margin: 0 !important;
    }

    #hero-inventory-panel .close-btn {
        width: 18px !important;
        height: 18px !important;
        border-radius: 9px !important;
        font-size: 10px !important;
        line-height: 18px !important;
        padding: 0 !important;
        flex-shrink: 0 !important;
    }

    /* 左侧角色区域收窄，并允许纵向滚动以显示全部装备槽 */
    #hero-inventory-panel .hero-panel-left {
        flex: 0 0 200px !important;
        position: relative !important;
        height: 100% !important;
        overflow: hidden !important;
        /* 关闭不稳定的滚动，改用固定布局 */
        background: #dfd8c8 !important;
    }

    #hero-inventory-panel #fashion-selector-wrap {
        position: absolute !important;
        bottom: 8px !important; /* 更靠近底部 */
        left: 0 !important;
        width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        z-index: 100 !important;
        background: rgba(0, 0, 0, 0.5) !important;
        padding: 2px 0 !important; /* 极窄内边距 */
        gap: 3px !important; /* 压缩元素间距 */
    }
    #fashion-selector-wrap button {
        padding: 2px 8px !important; /* 按钮瘦身 */
        font-size: 10px !important; /* 字体缩小 */
    }
    #fashion-name-preview {
        font-size: 11px !important;
        min-width: 60px !important;
    }

    #hero-name-txt {
        font-size: 13px !important;
        margin-bottom: 0 !important;
        padding-top: 5px !important;
    }

    #hero-class-txt {
        font-size: 11px !important;
        margin-bottom: 5px !important;
    }

    /* 头像容器调整位置，避免太挤 */
    #hero-avatar-wrap {
        width: 120px !important;
        height: 140px !important;
        top: 44% !important; /* 下移一点，避免顶部拥挤 */
    }

    /* 装备槽也整体下移 */
    #hero-inventory-panel .equip-slots-col {
        top: 72px !important; /* 下移一点，避免顶部拥挤 */
        gap: 8px !important;
    }
    
    #hero-inventory-panel .equip-slot {
        width: 46px !important;
        height: 46px !important;
        margin-bottom: 0px !important;
    }

    #hero-inventory-panel .equip-slot .slot-bg {
        display: none !important;
    }

    #inventory-grid {
        grid-auto-rows: 58px !important;
        gap: 6px !important;
    }

    /* --- 帮派面板 --- */
    #guild-panel {
        width: min(560px, 96vw) !important;
        max-height: 82dvh !important;
    }

    #guild-tabs-content {
        height: auto !important;
        max-height: calc(82dvh - 120px) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* --- 好友/社交面板 --- */
    #social-panel {
        width: min(560px, 96vw) !important;
        max-height: 82dvh !important;
    }

    #social-panel>div:last-child {
        height: auto !important;
        max-height: calc(82dvh - 120px) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* --- 排行榜面板 --- */
    #leaderboard-panel {
        width: min(360px, 92vw) !important;
        max-height: 82dvh !important;
    }

    #leaderboard-list {
        height: auto !important;
        max-height: calc(82dvh - 160px) !important;
        overflow-y: auto !important;
    }

    /* --- 商城面板 --- */
    #shop-panel {
        width: min(360px, 94vw) !important;
        max-height: 82dvh !important;
    }

    #shop-list {
        max-height: calc(82dvh - 140px) !important;
    }

    /* --- 技能/竞技场面板 --- */
    #skills-panel,
    #arena-panel {
        width: min(360px, 92vw) !important;
        max-height: 80dvh !important;
    }

    #skills-list-container {
        max-height: calc(80dvh - 100px) !important;
    }

    /* --- 交易面板 --- */
    #trade-modal {
        width: min(700px, 96vw) !important;
        height: min(400px, 78dvh) !important;
    }

    #trade-content {
        height: auto !important;
        flex: 1;
        min-height: 0;
    }

    #hero-tab-stats,
    #hero-tab-inventory {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .equip-slot {
        width: 40px;
        height: 40px;
    }

    .equip-slot .slot-bg {
        font-size: 16px;
    }

    /* ---- 战斗十字菜单进一步缩小 ---- */
    .cross-slot {
        width: 44px;
        height: 44px;
        font-size: 12px;
    }

    .combat-cross-menu {
        gap: 2px;
    }
}

/* 超小屏兜底 (宽度 < 380px, 如 SE) */
@media screen and (max-width: 380px) {
    .hud-bar-container {
        width: 80px;
    }

    .hud-menu-btn img {
        width: 32px;
        height: 32px;
    }

    #chat-hud-bottom-left {
        max-width: 160px;
    }

    #map-hud-top-right,
    #hud-quest-tracker {
        width: 70px;
    }
}

/* 横屏模式（高度 < 600px，适用于手机横放，如 vivo Y85 2280×1080 横屏）*/
@media screen and (orientation: landscape) and (max-height: 600px) {
    body {
        background: #000;
    }

    /* 头像框和血条极度压缩 */
    .hud-avatar-frame {
        width: 32px !important;
        height: 32px !important;
    }

    #hud-player-level {
        font-size: 8px !important;
        padding: 1px 2px !important;
    }

    .hud-bar-container {
        width: 90px !important;
        height: 12px !important;
    }

    .hud-bar-text {
        font-size: 8px !important;
    }

    .hud-status-bars {
        gap: 4px !important;
    }

    /* 右上角小地图收窄 */
    .hud-minimap-frame-v2 {
        width: 72px !important;
    }

    #hud-minimap-render {
        top: 14px !important;
        left: 6px !important;
        right: 6px !important;
        bottom: 5px !important;
    }

    #minimap-canvas {
        width: 48px !important;
        height: 48px !important;
    }

    #hud-map-name {
        font-size: 8px !important;
        top: 2px !important;
    }

    /* 任务追踪隐藏（横屏空间不足）*/
    #hud-quest-tracker {
        display: none !important;
    }

    /* 顶部功能键右移避开小地图 */
    #function-menu-top {
        right: calc(85px + var(--safe-right)) !important;
        gap: 8px !important;
        top: calc(6px + var(--safe-top)) !important;
    }

    #function-menu-top .hud-menu-btn img {
        width: 34px !important;
        height: 34px !important;
    }

    /* 右下角主菜单按键缩小 */
    #main-menu-bottom-right {
        gap: 6px !important;
        bottom: calc(6px + var(--safe-bottom)) !important;
    }

    #main-menu-bottom-right .hud-menu-btn img {
        width: 36px !important;
        height: 36px !important;
    }

    /* 左下角聊天区域压缩 */
    #chat-hud-bottom-left {
        bottom: calc(6px + var(--safe-bottom)) !important;
        max-width: 160px !important;
        gap: 3px !important;
    }

    #hud-chat-logs {
        max-height: 50px !important;
        padding: 3px !important;
    }

    .hud-chat-btn img {
        width: 34px !important;
        height: 34px !important;
    }

    .chat-line {
        font-size: 9px !important;
    }

    /* 战斗菜单缩小 */
    .cross-slot {
        width: 38px !important;
        height: 38px !important;
        font-size: 10px !important;
    }

    .combat-cross-menu {
        gap: 2px !important;
    }

    /* 横屏下角色面板：极度压缩，装备槽更小，时装切换器隐藏 */
    #hero-inventory-panel {
        width: min(560px, 96vw) !important;
        height: min(320px, 90dvh) !important;
    }

    #hero-inventory-panel .equip-slot {
        width: 38px !important;
        height: 38px !important;
    }

    #hero-inventory-panel .equip-slot .slot-bg {
        display: none !important;
    }

    #inventory-grid {
        grid-auto-rows: 44px !important;
        gap: 4px !important;
    }

    #hero-inventory-panel .equip-slots-col {
        top: 56px !important; /* 下移一点，避免顶部拥挤 */
        gap: 4px !important;
    }

    #hero-inventory-panel #hero-avatar-wrap {
        width: 100px !important;
        height: 120px !important;
        top: 44% !important; /* 下移一点，避免顶部拥挤 */
    }

    /* 横屏时时装切换器隐藏，节省左侧空间 */
    #fashion-selector-wrap {
        display: none !important;
    }

    /* 弹窗面板在横屏下的定位与高度限制，确保不超出屏幕顶底 */
    .modal-panel {
        top: 8px !important;
        transform: translate(-50%, 0) !important;
        max-height: calc(100dvh - 16px) !important;
        padding: 8px !important;
    }

    /* 横屏下神秘商城适配 */
    #shop-panel {
        width: min(460px, 95vw) !important;
        max-height: calc(100dvh - 16px) !important;
    }

    #shop-list {
        max-height: calc(100dvh - 130px) !important;
    }

    /* 横屏下技能、竞技场、排行榜适配 */
    #skills-panel,
    #arena-panel,
    #leaderboard-panel {
        width: min(400px, 92vw) !important;
        max-height: calc(100dvh - 16px) !important;
    }
    
    #skills-list-container,
    #leaderboard-list {
        max-height: calc(100dvh - 110px) !important;
    }
}

/* --- 最底部：经验条 (全屏) --- */
#hud-exp-bar-container {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: rgba(0, 0, 0, 0.6);
    z-index: 9999;
}

#hud-exp-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(to right, #2ecc71, #27ae60);
    box-shadow: 0 0 8px rgba(46, 204, 113, 0.5);
    transition: width 0.4s ease-out;
}

/* Login Background Overlay */
.login-bg-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: url('../img/ui/001.png') no-repeat center center;
    background-size: cover;
    z-index: 2000;
    /* between game-container and modal-panels */
}

/* 跑马灯公告横幅 */
.announcement-banner {
    position: absolute;
    top: 70px; /* 避开左上角头像和右上角菜单 */
    left: 0;
    width: 100%;
    height: 36px;
    background-color: rgba(0, 0, 0, 0.65);
    z-index: 99; /* 渲染在地图和玩家之上，但在弹窗之下 */
    overflow: hidden;
    display: flex;
    align-items: center;
    border-top: 1px solid rgba(243, 156, 18, 0.25);
    border-bottom: 1px solid rgba(243, 156, 18, 0.25);
    pointer-events: none; /* 鼠标点击穿透 */
}

.announcement-banner.hidden {
    display: none !important;
}

.announcement-text {
    position: absolute;
    white-space: nowrap;
    font-size: 14px;
    font-weight: bold;
    color: #f1c40f;
    text-shadow: 1px 1px 2px #000;
    left: 100%;
}

.announcement-text.scrolling {
    animation: marquee-scroll 15s linear forwards; /* 滚动一次并保持在结束状态 */
}

@keyframes marquee-scroll {
    0% {
        left: 100%;
        transform: translate3d(0, 0, 0);
    }
    100% {
        left: 0;
        transform: translate3d(-100%, 0, 0);
    }
}

/* 自动识别屏幕高度：当可视高度 <= 600px 时，强制调整所有弹窗面板的位置与最大高度，防止关闭按钮和头部被挤出屏幕 */
@media screen and (max-height: 600px) {
    .modal-panel {
        top: 8px !important;
        transform: translate(-50%, 0) !important;
        max-height: calc(100dvh - 16px) !important;
        padding: 8px !important;
    }
}