* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Microsoft YaHei', sans-serif;
}

body {
    background-color: #2c3e50;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
}

#game-container {
    position: relative;
    width: 1024px;
    height: 768px;
    background-color: #000;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
    transform-origin: center 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: 10px;
    left: 10px;
    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;
}

/* --- 右上角：地图与任务 --- */
#map-hud-top-right {
    top: 10px;
    right: 10px;
    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: rgba(0, 0, 0, 0.4);
}

#minimap-canvas {
    width: 120px;
    height: 120px;
    background: #000;
}

#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: 10px;
    right: 170px;
    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: 10px;
    left: 10px;
    flex-direction: column;
    gap: 10px;
    max-width: 300px;
}

#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: 15px;
    right: 15px;
    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;
    z-index: 3000;
    /* 调得更高，确保绝对盖过所有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;
}

.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 .filter-btn {
    background: #4e342e;
    color: #bdc3c7;
    border: 1px solid #5d4037;
    padding: 2px 10px;
    border-radius: 4px;
    cursor: pointer;
}

.shop-filter-bar .filter-btn.active {
    background: #f39c12;
    color: #fff;
    border-color: #f1c40f;
}

/* 综合面板左侧装备孔位 */
.equip-slot {
    width: 48px;
    height: 48px;
    background: rgba(30, 20, 15, 0.8);
    border: 2px solid #8b5a2b;
    border-radius: 8px;
    box-shadow: inset 0 0 10px #000, 0 2px 4px rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
}

.equip-slot:hover {
    border-color: #f1c40f;
    box-shadow: inset 0 0 15px rgba(241, 196, 15, 0.3), 0 0 8px #f1c40f;
    transform: scale(1.05);
}

.equip-slot .slot-bg {
    font-size: 20px;
    color: #555;
    font-weight: bold;
    user-select: none;
}

/* 综合面板右侧包裹网格里的独立物品格子 */
.inv-grid-item {
    background: rgba(40, 30, 20, 0.9);
    border: 1px solid #5d4037;
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    cursor: pointer;
    box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.6);
}

.inv-grid-item:hover {
    border-color: #e74c3c;
    background: rgba(60, 40, 20, 0.9);
}

.inv-grid-item-inner {
    width: 80%;
    height: 80%;
    background: linear-gradient(135deg, #8e44ad, #2980b9);
    border-radius: 4px;
    border: 1px solid #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 10px;
    font-weight: bold;
    text-align: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.8);
    overflow: hidden;
}

/* 物品数量角标 */
.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;
}

/* 玩家交互菜单 */
#player-interaction-menu {
    pointer-events: auto;
}

#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 #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 {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        background: #000;
        height: 100dvh;
        margin: 0;
        overflow: hidden;
    }

    #game-container {
        /*
         * 宽度铺满屏幕。JS 端已经处理可视内容放大（zoom）
         */
        width: min(100vw, calc(100dvh * 4 / 3)) !important;
        height: min(100vw, 100dvh) !important;
        transform: none !important;
        box-shadow: none;
        margin: auto;
        position: relative;
        /* 保持 relative，作为 ui-layer 的定位层 */
    }

    /* ---- 左上角状态栏 ---- */
    #player-status {
        top: 6px;
        left: 6px;
        width: clamp(120px, 42vw, 180px);
    }

    .avatar-box {
        width: clamp(32px, 9vw, 44px);
        height: clamp(32px, 9vw, 44px);
        font-size: clamp(14px, 4vw, 20px);
        margin-right: 5px;
    }

    #player-name {
        font-size: clamp(9px, 2.5vw, 12px);
        margin-bottom: 1px;
    }

    .hp-bar-bg,
    .mp-bar-bg,
    .exp-bar-bg {
        height: 7px;
        margin-top: 1px;
    }

    .status-text {
        font-size: clamp(7px, 2vw, 9px);
        margin-top: -9px;
    }

    /* ---- 右上方功能菜单 (榜/福/商) ---- */
    #top-right-menu {
        top: 6px;
        right: clamp(90px, 25vw, 130px);
        gap: 6px;
    }

    /* ---- 右下方主控菜单 (技/角/包/设) ---- */
    #bottom-right-menu {
        bottom: 10px;
        right: 6px;
        gap: 6px;
    }

    /* ---- 左侧中部互动菜单 (武/友/聊) ---- */
    #left-middle-menu {
        left: 6px;
        gap: 8px;
    }

    /* ---- 所有图标按钮统一缩小 ---- */
    .menu-icon-btn {
        font-size: clamp(8px, 2.2vw, 10px);
    }

    .menu-icon-btn .icon-bg {
        width: clamp(28px, 8vw, 36px);
        height: clamp(28px, 8vw, 36px);
        line-height: clamp(22px, 6vw, 30px);
        font-size: clamp(13px, 3.5vw, 17px);
        border-width: 2px;
        border-radius: 7px;
        margin-bottom: 1px;
    }

    /* ---- 底部聊天框 ---- */
    #chat-panel {
        bottom: 6px;
        left: clamp(40px, 12vw, 55px);
        width: clamp(160px, 52vw, 240px);
        height: clamp(90px, 22vw, 130px);
    }

    #chat-log-container {
        font-size: clamp(9px, 2.2vw, 11px);
    }

    #chat-input {
        font-size: clamp(10px, 2.5vw, 12px);
        padding: 3px 6px;
    }

    #chat-send-btn {
        font-size: clamp(10px, 2.5vw, 12px);
        padding: 0 6px;
    }

    /* ---- 任务追踪 ---- */
    #quest-tracker {
        top: clamp(50px, 14vw, 70px);
        left: 6px;
        width: clamp(90px, 28vw, 130px);
        padding: 5px;
    }

    #quest-tracker h3 {
        font-size: clamp(9px, 2.5vw, 12px);
    }

    #quest-list-content {
        font-size: clamp(8px, 2.2vw, 11px);
    }

    /* ---- 地图名称显示 ---- */
    #map-name-display {
        font-size: clamp(10px, 2.8vw, 14px);
        top: 8px;
        right: 10px;
    }

    /* ---- 弹窗面板适配 ---- */
    .modal-panel {
        max-width: 96vw;
        max-height: 88dvh;
        overflow-y: auto;
    }

    #hero-inventory-panel {
        width: min(640px, 96vw);
        height: min(480px, 84dvh);
    }
}

/* 超小屏兜底 (宽度 < 380px, 如 SE) */
@media screen and (max-width: 380px) {
    .menu-icon-btn .icon-bg {
        width: 24px;
        height: 24px;
        line-height: 18px;
        font-size: 11px;
    }

    .menu-icon-btn {
        font-size: 7px;
    }

    #chat-panel {
        width: 142px;
        height: 78px;
    }

    #quest-tracker {
        width: 76px;
    }
}

/* 横屏模式（高度 < 600px，适用于手机横放）*/
@media screen and (orientation: landscape) and (max-height: 600px) {
    body {
        background: #000;
    }

    /* 横屏时 #game-container 的 min() 公式已自动处理，无需额外规则 */
}

/* --- 最底部：经验条 (全屏) --- */
#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/login_bg.png') no-repeat center center;
    background-size: cover;
    z-index: 2000; /* between game-container and modal-panels */
}
