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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #1a1a1a;
    font-family: 'Microsoft YaHei', 'PingFang SC', sans-serif;
}

#game-container {
    width: 100%;
    height: 100%;
    position: relative;
}

#game-container canvas {
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* UI 覆盖层 */
#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#ui-overlay > * {
    pointer-events: auto;
}

/* 通用面板样式 */
.ui-panel {
    background: linear-gradient(180deg, rgba(30, 20, 15, 0.95) 0%, rgba(15, 10, 8, 0.98) 100%);
    border: 2px solid #8b7355;
    border-radius: 10px;
    padding: 12px 16px;
    color: #fff;
    font-size: 14px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* 玩家信息 - 左上角 */
#player-info {
    position: absolute;
    top: 16px;
    left: 16px;
    min-width: 220px;
    padding: 14px 18px;
}

#player-info .character-name {
    font-size: 22px;
    font-weight: bold;
    color: #ffd700;
    margin-bottom: 6px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    gap: 8px;
}

#player-info .character-name::before {
    content: '⚔️';
    font-size: 18px;
}

#player-info .location {
    color: #c9a86c;
    font-size: 13px;
    margin-bottom: 12px;
    padding-left: 2px;
}

#player-info .location::before {
    content: '📍';
    margin-right: 4px;
}

/* 状态条容器 */
.status-bars {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* 单个状态条 */
.status-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-bar .bar-label {
    font-size: 12px;
    color: #aaa;
    min-width: 36px;
    text-align: right;
}

.status-bar .bar-bg {
    flex: 1;
    height: 10px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 5px;
    overflow: hidden;
    border: 1px solid rgba(139, 115, 85, 0.3);
}

.status-bar .bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

.status-bar.hp .bar-fill {
    background: linear-gradient(90deg, #8b2323 0%, #ff4444 100%);
}

.status-bar.morale .bar-fill {
    background: linear-gradient(90deg, #1a5f5f 0%, #4ecdc4 100%);
}

.status-bar .bar-value {
    font-size: 12px;
    color: #fff;
    min-width: 50px;
    text-align: left;
}

/* 右上角控制区 */
#top-right-controls {
    position: absolute;
    top: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-end;
}

/* 镜头控制 */
#camera-control {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
}

#camera-control label {
    color: #c9a86c;
    font-size: 13px;
    white-space: nowrap;
}

#camera-control select {
    background: linear-gradient(180deg, #3d2f26 0%, #2d1f16 100%);
    color: #ffd700;
    border: 1px solid #8b7355;
    padding: 6px 28px 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    min-width: 100px;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23c9a86c' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

#camera-control select:hover {
    border-color: #c9a86c;
}

#camera-control select:focus {
    outline: none;
    border-color: #ffd700;
    box-shadow: 0 0 0 2px rgba(255, 215, 0, 0.2);
}

#camera-control select option {
    background: #2d1f16;
    color: #fff;
}

/* 资源显示 */
#resources {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 14px;
    min-width: 150px;
}

#resources .resource-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

#resources .resource-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #aaa;
}

#resources .resource-value {
    font-size: 15px;
    font-weight: bold;
    font-family: 'Consolas', monospace;
}

#resources .money .resource-value {
    color: #ffd700;
}

#resources .reputation .resource-value {
    color: #ff6b6b;
}

/* 工具栏 - 右下角 */
#toolbar {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: flex;
    gap: 12px;
    padding: 12px 14px;
    background: linear-gradient(180deg, rgba(30, 20, 15, 0.9) 0%, rgba(15, 10, 8, 0.95) 100%);
    border: 2px solid #8b7355;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
}

.tool-btn {
    padding: 10px 16px;
    background: linear-gradient(180deg, #5a4738 0%, #3d2f26 100%);
    border: 2px solid #8b7355;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 90px;
    justify-content: center;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    position: relative;
    overflow: hidden;
}

.tool-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.1) 0%, transparent 100%);
    border-radius: 6px 6px 0 0;
}

.tool-btn:hover:not(.disabled) {
    background: linear-gradient(180deg, #6a5748 0%, #4d3f36 100%);
    border-color: #c9a86c;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.tool-btn:active:not(.disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.tool-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: linear-gradient(180deg, #3a2f28 0%, #2d2520 100%);
    border-color: #5a4a3e;
}

.tool-btn.disabled::after {
    content: '🔒';
    position: absolute;
    font-size: 10px;
    top: 2px;
    right: 4px;
    opacity: 0.6;
}

/* 快捷键提示 */
.tool-btn .hotkey {
    font-size: 10px;
    color: #c9a86c;
    background: rgba(0, 0, 0, 0.3);
    padding: 1px 5px;
    border-radius: 3px;
    margin-left: 4px;
}

/* 对话框 */
#dialog-box {
    position: absolute;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    max-width: 800px;
    background: linear-gradient(180deg, rgba(20, 15, 10, 0.98) 0%, rgba(10, 8, 6, 0.99) 100%);
    border: 3px solid #8b7355;
    border-radius: 16px;
    padding: 24px 28px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}

#dialog-box .speaker-name {
    font-size: 18px;
    color: #ffd700;
    margin-bottom: 12px;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 8px;
}

#dialog-box .speaker-name::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 20px;
    background: linear-gradient(180deg, #ffd700 0%, #c9a86c 100%);
    border-radius: 2px;
}

#dialog-box .dialog-text {
    font-size: 16px;
    line-height: 1.7;
    color: #f0f0f0;
    min-height: 60px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

#dialog-box .dialog-options {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.dialog-option {
    padding: 12px 18px;
    background: linear-gradient(90deg, rgba(139, 115, 85, 0.2) 0%, rgba(139, 115, 85, 0.05) 100%);
    border: 1px solid #8b7355;
    border-left: 4px solid #c9a86c;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
}

.dialog-option:hover {
    background: linear-gradient(90deg, rgba(139, 115, 85, 0.4) 0%, rgba(139, 115, 85, 0.1) 100%);
    border-color: #c9a86c;
    padding-left: 22px;
}

/* 模态框通用 */
.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: linear-gradient(180deg, #2d1f16 0%, #1a0f0a 100%);
    border: 3px solid #8b7355;
    border-radius: 16px;
    padding: 40px;
    min-width: 400px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}

.modal-content h2 {
    color: #ffd700;
    margin-bottom: 30px;
    font-size: 32px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* 存档选择 */
.save-slots {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.save-slot {
    padding: 18px 24px;
    background: linear-gradient(90deg, rgba(139, 115, 85, 0.15) 0%, rgba(139, 115, 85, 0.05) 100%);
    border: 2px solid #8b7355;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.save-slot:hover {
    background: linear-gradient(90deg, rgba(139, 115, 85, 0.3) 0%, rgba(139, 115, 85, 0.1) 100%);
    border-color: #c9a86c;
    transform: translateX(4px);
}

.save-slot .slot-num {
    color: #ffd700;
    font-size: 18px;
    font-weight: bold;
}

.save-slot .slot-info {
    color: #888;
    font-size: 14px;
}

/* 加载界面 */
#loading-screen {
    background: rgba(0, 0, 0, 0.97);
}

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

.loading-text {
    font-size: 28px;
    color: #ffd700;
    margin-bottom: 24px;
    text-shadow: 0 2px 8px rgba(255, 215, 0, 0.3);
}

.loading-bar {
    width: 320px;
    height: 24px;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid #8b7355;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

.loading-bar .progress {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #8b7355 0%, #c9a86c 50%, #ffd700 100%);
    border-radius: 10px;
    transition: width 0.3s;
    box-shadow: 0 0 10px rgba(201, 168, 108, 0.5);
}

/* 聊天气泡 */
.chat-bubble {
    position: absolute;
    background: rgba(0, 0, 0, 0.85);
    border: 1px solid #8b7355;
    border-radius: 10px;
    padding: 10px 14px;
    color: #fff;
    font-size: 13px;
    max-width: 220px;
    pointer-events: none;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.chat-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #8b7355;
}

/* 响应式适配 */
@media (max-width: 768px) {
    #toolbar {
        flex-wrap: wrap;
        justify-content: flex-end;
        max-width: 200px;
        bottom: 12px;
        right: 12px;
        gap: 8px;
        padding: 10px;
    }

    .tool-btn {
        padding: 8px 12px;
        font-size: 12px;
        min-width: auto;
    }

    #player-info {
        min-width: 160px;
        top: 10px;
        left: 10px;
        padding: 10px 14px;
    }

    #player-info .character-name {
        font-size: 18px;
    }

    #camera-control, #resources {
        font-size: 12px;
        top: 10px;
        right: 10px;
    }

    #resources {
        top: 58px;
    }

    #dialog-box {
        width: 95%;
        bottom: 100px;
        padding: 16px 20px;
    }
}

/* 触摸设备优化 */
.touch-device #toolbar {
    opacity: 0.7;
}

.touch-device .tool-btn .hotkey {
    display: none;
}

/* 防止触摸时的文本选择 */
#game-container {
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* 响应式适配 - 平板和手机 */
@media (max-width: 768px) {
    /* 顶部UI紧凑布局 */
    #player-info {
        min-width: 140px;
        top: 8px;
        left: 8px;
        padding: 8px 12px;
    }

    #player-info .character-name {
        font-size: 16px;
    }

    #player-info .location {
        font-size: 11px;
    }

    .status-bar .bar-label {
        font-size: 10px;
        min-width: 30px;
    }

    .status-bar .bar-value {
        font-size: 10px;
        min-width: 40px;
    }

    /* 右上角控制区 */
    #top-right-controls {
        top: 8px;
        right: 8px;
    }

    #camera-control {
        padding: 6px 10px;
    }

    #camera-control label {
        font-size: 11px;
    }

    #camera-control select {
        font-size: 11px;
        padding: 4px 20px 4px 8px;
        min-width: 80px;
    }

    #resources {
        padding: 6px 10px;
        min-width: 120px;
    }

    #resources .resource-label {
        font-size: 11px;
    }

    #resources .resource-value {
        font-size: 13px;
    }

    /* 底部工具栏 - 移动端简化 */
    #toolbar {
        display: none;
    }

    /* 对话框适配 */
    #dialog-box {
        width: 95%;
        bottom: 80px;
        padding: 14px 16px;
    }

    #dialog-box .speaker-name {
        font-size: 15px;
    }

    #dialog-box .dialog-text {
        font-size: 14px;
        line-height: 1.5;
    }

    .dialog-option {
        padding: 10px 14px;
        font-size: 13px;
    }

    /* 存档选择适配 */
    .modal-content {
        min-width: auto;
        width: 90%;
        padding: 24px;
    }

    .modal-content h2 {
        font-size: 24px;
    }

    .save-slot {
        padding: 14px 18px;
    }

    .save-slot .slot-num {
        font-size: 16px;
    }

    .save-slot .slot-info {
        font-size: 12px;
    }
}

/* 超小屏幕适配 */
@media (max-width: 380px) {
    #player-info {
        min-width: 120px;
    }

    #player-info .character-name {
        font-size: 14px;
    }

    .status-bar .bar-bg {
        height: 8px;
    }
}

/* 横屏模式优化 */
@media (max-height: 500px) and (orientation: landscape) {
    #player-info {
        transform: scale(0.85);
        transform-origin: top left;
    }

    #top-right-controls {
        transform: scale(0.85);
        transform-origin: top right;
    }
}
