body {
    margin: 0;
    overflow: hidden;
    background-color: #87CEEB; /* 天空蓝 */
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#ui-layer {
    position: absolute;
    top: 10px;
    left: 10px;
    padding: 10px;
    pointer-events: none;
    user-select: none;
    z-index: 10;
}

/* 左上角头像 */
#avatar-container {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 1000;
    pointer-events: auto;
}

#avatar-wrapper {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid rgba(139, 110, 99, 0.8);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

#avatar-wrapper:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

#avatar-canvas {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

#avatar-menu {
    position: absolute;
    top: 60px;
    left: 0;
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid rgba(139, 110, 99, 0.8);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    min-width: 150px;
    padding: 8px 0;
    z-index: 1001;
}

#avatar-username {
    padding: 8px 16px;
    font-weight: bold;
    color: #5d4037;
    font-size: 14px;
    text-align: center;
    border-bottom: 1px solid rgba(139, 110, 99, 0.3);
}

.avatar-menu-divider {
    height: 1px;
    background: rgba(139, 110, 99, 0.3);
    margin: 4px 0;
}

.avatar-menu-item {
    padding: 10px 16px;
    cursor: pointer;
    color: #5d4037;
    font-size: 14px;
    transition: background 0.2s;
}

.avatar-menu-item:hover {
    background: rgba(139, 110, 99, 0.1);
}

#logout-btn {
    color: #d32f2f;
}

#logout-btn:hover {
    background: rgba(211, 47, 47, 0.1);
}

canvas {
    display: block;
    position: relative;
    z-index: 1;
}

/* 登录/注册浮层 */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center; /* 水平居中 */
    align-items: center;     /* 垂直居中 */
    z-index: 100;
}

.auth-box {
    background: #fff8e1; /* 米色纸张感 */
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    text-align: center;
    border: 4px solid #8d6e63; /* 木质边框 */
    width: 300px;
}

.auth-box h2 {
    color: #5d4037;
    margin-top: 0;
    margin-bottom: 20px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group input[type="text"],
.form-group input[type="password"] {
    width: 100%;
    padding: 10px;
    border: 2px solid #d7ccc8;
    border-radius: 5px;
    box-sizing: border-box; /* 确保 padding 不增加宽度 */
    font-size: 16px;
}

.btn-group {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-top: 20px;
}

.btn-group button, .start-btn {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    transition: transform 0.1s;
}

.btn-group button:first-child, .start-btn {
    background-color: #8bc34a; /* 绿色 */
    color: white;
    box-shadow: 0 4px #689f38;
}

.btn-group button:last-child {
    background-color: #ffa726; /* 橙色 */
    color: white;
    box-shadow: 0 4px #ef6c00;
}

.btn-group button:active, .start-btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 #689f38;
}

#auth-msg {
    color: #d32f2f;
    margin-top: 10px;
    font-size: 14px;
    min-height: 20px;
}

/* 角色定制界面 */
.creator-box {
    background: #fff8e1;
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    text-align: center;
    border: 4px solid #8d6e63;
    width: 350px;
}

.preview-area {
    background: #87CEEB;
    width: 100px;
    height: 100px;
    margin: 0 auto 20px;
    border: 4px solid white;
    border-radius: 10px;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
}

.options-grid {
    text-align: left;
    margin-bottom: 20px;
}

.option-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    color: #5d4037;
    font-weight: bold;
}

.start-btn {
    width: 100%;
    margin-top: 10px;
}

/* 背包 */
#inventory-ui {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 248, 225, 0.95);
    border: 4px solid #8d6e63;
    border-radius: 10px;
    padding: 15px;
    width: 320px;
    display: none; /* 默认隐藏 */
    z-index: 50;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

#inventory-ui h3 {
    margin: 0;
    color: #5d4037;
}

#inventory-close-btn {
    background: #f44336;
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

#inventory-close-btn:hover {
    background: #d32f2f;
}

#inventory-close-btn:active {
    background: #b71c1c;
    text-align: center;
}

#inventory-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.inv-slot {
    width: 50px;
    height: 50px;
    background: #d7ccc8;
    border: 2px solid #a1887f;
    border-radius: 4px;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.inv-item {
    width: 32px;
    height: 32px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.inv-count {
    position: absolute;
    bottom: 2px;
    right: 2px;
    font-size: 10px;
    color: white;
    text-shadow: 1px 1px 0 #000;
    font-weight: bold;
}

#inventory-hint {
    text-align: center;
    margin-top: 10px;
    color: #8d6e63;
    font-size: 12px;
}

#inventory-info {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, calc(-50% - 250px));
    width: 320px;
    padding: 10px;
    background: rgba(255, 248, 225, 0.95);
    border: 3px solid #8d6e63;
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
    z-index: 51;
    display: none;
    margin-bottom: 20px;
}

#inventory-info-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.info-item-icon {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    border-radius: 4px;
    background-color: transparent;
}

.info-item-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.info-item-name {
    font-size: 16px;
    font-weight: 500;
    color: #5d4037;
}

.info-item-count {
    font-size: 13px;
    color: #8d6e63;
}

.info-item-desc {
    font-size: 12px;
    color: #6d4c41;
    line-height: 1.4;
    margin-top: 4px;
}

.inv-slot.selected {
    border: 3px solid #ff9800;
    box-shadow: 0 0 8px rgba(255, 152, 0, 0.5);
}

/* 底部快捷栏 Hotbar */
/* 物品栏容器 */
#hotbar-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    align-items: center;
    gap: 10px;
    z-index: 20;
}

/* 背包按钮独立定位到右上角 */
#inventory-btn {
    position: fixed;
    /* 放到底部工具栏上方中间位置 */
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 60px;
    background: transparent !important;
    border: none;
    cursor: pointer;
    font-size: 40px;
    color: white;
    transition: all 0.2s;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    filter: drop-shadow(2px 2px 3px rgba(0, 0, 0, 0.5));
    z-index: 100;
}

/* 右上角小地图按钮（看起来像一张小图片，而不是按钮） */
#minimap-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    padding: 0;
    margin: 0;
    border: none;
    background: none;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    z-index: 150;
    /* 隐藏按钮文字，只显示伪元素的小图标 */
    font-size: 0;
}

#minimap-btn::before {
    content: "";
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 4px;
    box-sizing: border-box;
    /* 使用项目内生成的地图图标素材，带版本号避免缓存 */
    background-image: url("icons/minimap.svg?v=2");
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
}

#minimap-btn:hover {
    filter: brightness(1.08);
}

#hotbar {
    /* 工具栏本身不再是整块底色，方便“挖空”露出下方画面 */
    background: transparent;
    padding: 0;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    border: none;
    box-shadow: none;
}

.hotbar-row {
    display: flex;
    align-items: center;
    justify-content: center;
}

.hotbar-row-top {
    /* 让背包按钮更紧贴下面的木板，看上去是一整块 */
    margin-bottom: -8px;
}

.hotbar-row-bottom {
    gap: 6px;
    /* 底部整条工具栏：木制样式 */
    padding: 8px 12px; /* 略微增大上下间距，让物品离木板边缘更远一点 */
    background: #8b6f47;
    border-radius: 12px;
    border: 3px solid #5d4a37;
    border-top: none; /* 去掉木板上边线，让它和上面的背包贴成一体 */
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3), 0 4px 8px rgba(0, 0, 0, 0.4);
}

.hotbar-slot {
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 6px;
    position: relative;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.1s, border-color 0.1s;
}

.hotbar-slot.selected {
    border-color: #ffd700; /* 金色选中框 */
    background: rgba(255, 255, 255, 0.4);
    transform: scale(1.1);
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
    z-index: 1;
}

.hotbar-slot:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* 中间的背包格子样式 */
.hotbar-slot-bag {
    /* 与下方工具栏完全一体的木纹背景，没有白色边框/透明效果 */
    width: 50px;
    height: 50px;
    /* 上圆角、下直角，和下面木板无缝对齐 */
    border-radius: 8px 8px 0 0;
    background: #8b6f47;               /* 和工具栏木板同色 */
    border: 3px solid #5d4a37;         /* 和工具栏边框一致 */
    border-bottom: none;               /* 去掉背包格子底部边线，让缝隙消失 */
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.25);
}

.hotbar-bag-icon {
    font-size: 44px;  /* 背包图标再大一些 */
    line-height: 1;
}

.hotbar-slot-bag:hover {
    /* 背包按钮悬停时保持完全静止，不高亮不放大 */
    background: #8b6f47;
    transform: none;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.25);
}

/* 移动端控制 */
.mobile-only {
    display: none;
}

/* 媒体查询：仅在小屏幕显示移动控件 */
@media (max-width: 768px) {
    .mobile-only {
        display: block;
    }

    #mobile-controls {
        position: absolute;
        width: 100%;
        height: 100%;
        pointer-events: none; /* 让点击穿透，只响应按钮 */
        z-index: 90;
    }

    /* 虚拟摇杆 */
    #joystick-zone {
        position: absolute;
        bottom: 160px; /* 向上移动：从120px改为160px */
        left: 30px;
        width: 120px;
        height: 120px;
        background: rgba(255, 255, 255, 0.2);
        border: 2px solid rgba(255, 255, 255, 0.4);
        border-radius: 50%;
        pointer-events: auto;
        touch-action: none; /* 防止触摸滚动 */
    }

    #joystick-nipple {
        position: absolute;
        top: 50%;
        left: 50%;
        width: 50px;
        height: 50px;
        margin-top: -25px;
        margin-left: -25px;
        background: rgba(255, 255, 255, 0.8);
        border-radius: 50%;
        box-shadow: 0 2px 5px rgba(0,0,0,0.2);
        transition: transform 0.1s; /* 回弹动画，拖动时会被JS覆盖 */
    }

    /* 动作键区域 (右下角) */
    #action-btns {
        position: absolute;
        bottom: 150px; /* 再向上移动一点：从120px改为150px */
        right: 80px;
        pointer-events: auto;
        display: flex;
        flex-direction: column;
        gap: 20px;
    }

    .action-btn {
        width: 70px;
        height: 70px;
        border-radius: 50%;
        border: 3px solid rgba(255, 255, 255, 0.6);
        color: white;
        font-size: 20px;
        font-weight: bold;
        display: flex;
        justify-content: center;
        align-items: center;
        user-select: none;
        touch-action: manipulation;
        outline: none;
    }

    #btn-action { /* A键 */
        background: rgba(255, 82, 82, 0.6); /* 红色半透明 */
    }

    #btn-bag { /* B键 */
        background: rgba(33, 150, 243, 0.6); /* 蓝色半透明 */
    }

    .action-btn:active {
        transform: scale(0.95);
        filter: brightness(1.2);
    }
    
    /* 调整 Hotbar 位置以避开按钮 */
    #hotbar-container {
        bottom: 10px;
    }
}

/* 物品捡起提示：电脑版垂直居中，移动版放在头像下方 */
#item-notification-container {
    position: fixed;
    top: 50%;           /* 垂直中间 */
    left: 10px;         /* 左侧对齐 */
    transform: translateY(-50%); /* 垂直居中 */
    z-index: 100;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.item-notification {
    background: transparent;
    color: #2c3e50;
    padding: 8px 12px;
    border-radius: 0;
    font-size: 16px;
    min-width: 180px;
    box-shadow: none;
    border: none;
    animation: fadeIn 0.6s ease-out, fadeOut 0.6s ease-in 2.4s;
    animation-fill-mode: both;
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    font-weight: 500;
    opacity: 0.85;
}

.item-notification-icon {
    width: 24px;
    height: 24px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    flex-shrink: 0;
    opacity: 0.85;
    filter: 
        drop-shadow(-1px -1px 0 rgba(255, 255, 255, 0.9))
        drop-shadow(1px -1px 0 rgba(255, 255, 255, 0.9))
        drop-shadow(-1px 1px 0 rgba(255, 255, 255, 0.9))
        drop-shadow(1px 1px 0 rgba(255, 255, 255, 0.9))
        drop-shadow(0 0 2px rgba(255, 255, 255, 0.8));
}

.item-notification-text {
    flex: 1;
    color: #2c3e50;
    font-weight: 500;
    letter-spacing: 0.3px;
    text-shadow: 
        -1px -1px 0 rgba(255, 255, 255, 0.8),
        1px -1px 0 rgba(255, 255, 255, 0.8),
        -1px 1px 0 rgba(255, 255, 255, 0.8),
        1px 1px 0 rgba(255, 255, 255, 0.8),
        0 0 2px rgba(255, 255, 255, 0.6);
}

.item-notification-count {
    color: #27ae60;
    font-weight: 600;
    text-shadow: 
        -1px -1px 0 rgba(255, 255, 255, 0.8),
        1px -1px 0 rgba(255, 255, 255, 0.8),
        -1px 1px 0 rgba(255, 255, 255, 0.8),
        1px 1px 0 rgba(255, 255, 255, 0.8),
        0 0 2px rgba(255, 255, 255, 0.6);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 0.85;
        transform: translateY(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 0.85;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-5px);
    }
}

/* 小地图样式 */
#minimap-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 248, 225, 0.95);
    border: 4px solid #8d6e63;
    border-radius: 10px;
    padding: 15px;
    z-index: 200;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    display: none;
}

#minimap-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

#minimap-header span {
    font-weight: bold;
    color: #5d4037;
    font-size: 18px;
}

#minimap-close-btn {
    background: #f44336;
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

#minimap-close-btn:hover {
    background: #d32f2f;
}

#minimap-canvas {
    border: 2px solid #8d6e63;
    border-radius: 5px;
    background: #87CEEB;
    display: block;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

#minimap-hint {
    text-align: center;
    margin-top: 10px;
    color: #8d6e63;
    font-size: 12px;
}

/* 手机版样式 */
@media (max-width: 768px) {
    #item-notification-container {
        left: 10px;        /* 移动版：左侧对齐 */
        top: 50%;          /* 垂直中间 */
        transform: translateY(-50%); /* 垂直居中 */
        right: auto;
    }
    
    .item-notification {
        font-size: 13px;
        padding: 6px 10px;
        min-width: 150px;
    }
    
    .item-notification-icon {
        width: 20px;
        height: 20px;
    }
    
    #minimap-container {
        width: 90%;
        max-width: 400px;
    }
    
    #minimap-canvas {
        width: 100%;
        height: auto;
    }
}
