/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #1a1a1a;
    color: #ffffff;
    overflow: hidden;
    height: 100vh;
}

/* 工具栏样式 */
.toolbar {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    position: relative;
}

.toolbar-section {
    display: flex;
    align-items: center;
    gap: 20px;
}

.toolbar h1 {
    font-size: 1.2em;
    color: #ecf0f1;
}

.project-info {
    display: flex;
    gap: 10px;
}

.project-info input,
.project-info select {
    padding: 5px 10px;
    border: 1px solid #34495e;
    border-radius: 4px;
    background: #2c3e50;
    color: #ecf0f1;
}

.toolbar-buttons {
    display: flex;
    gap: 10px;
}

/* 按钮样式 */
.btn-primary, .btn-secondary, .btn-success, .btn-info, .btn-danger {
    padding: 8px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 500;
    transition: all 0.3s ease;
}

.btn-primary { background: #3498db; color: white; }
.btn-secondary { background: #95a5a6; color: white; }
.btn-success { background: #27ae60; color: white; }
.btn-info { background: #17a2b8; color: white; }
.btn-danger { background: #e74c3c; color: white; }

/* 选中态（条件/移动/向导按钮） */
.btn-selected {
    background: #2ecc71 !important;
    color: #1a1a1a !important;
    box-shadow: 0 0 0 2px rgba(46,204,113,0.35) inset;
}

/* 统一主按钮尺寸与配色 */
.toolbar-buttons .unified {
    min-width: 110px;
    background: #2d6cdf; /* 统一蓝色 */
}
.toolbar-buttons .unified:hover {
    background: #2459bd;
}

.btn-primary:hover { background: #2980b9; transform: translateY(-1px); }
.btn-secondary:hover { background: #7f8c8d; transform: translateY(-1px); }
.btn-success:hover { background: #219a52; transform: translateY(-1px); }
.btn-info:hover { background: #138496; transform: translateY(-1px); }
.btn-danger:hover { background: #c0392b; transform: translateY(-1px); }

/* 主容器样式 */
.main-container {
    display: flex;
    height: calc(100vh - 60px);
    background-color: #1a1a1a; /* 视口剩余区域也使用同色背景 */
    background-image: radial-gradient(circle, #444 1px, transparent 1px); /* 小点网格 */
    background-size: 20px 20px;
    background-position: 0 0;
}

/* 节点面板样式 */
.node-palette {
    width: 250px;
    min-width: 250px; /* 🔧 强制最小宽度 */
    max-width: 250px; /* 🔧 强制最大宽度 */
    flex-shrink: 0; /* 🔧 防止被压缩 */
    background: #2c3e50;
    padding: 15px;
    overflow-y: auto;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
    z-index: 1000; /* 🔧 提高z-index */
    position: relative; /* 🎯 确保z-index生效 */
}

.node-palette h3 {
    color: #ecf0f1;
    margin-bottom: 15px;
    text-align: center;
    font-size: 1.1em;
}

.node-category {
    margin-bottom: 20px;
}

.node-category h4 {
    color: #bdc3c7;
    margin-bottom: 10px;
    font-size: 0.9em;
    border-bottom: 1px solid #34495e;
    padding-bottom: 5px;
}

.node-item {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    margin-bottom: 8px;
    border-radius: 6px;
    cursor: grab;
    transition: all 0.3s ease;
    border: 1px solid transparent;
    user-select: none; /* 禁止文本选择 */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.node-item:hover {
    background: #34495e;
    border-color: #3498db;
    transform: translateX(5px);
}

.node-item:active {
    cursor: grabbing;
}

.node-preview {
    width: 120px;
    height: 35px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85em;
    font-weight: bold;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    white-space: nowrap;
    overflow: hidden;
    gap: 6px;
}

/* 拖拽预览样式 */
.drag-preview {
    pointer-events: none;
    z-index: 10000;
}

.drag-preview .node {
    width: 120px;
    min-height: 50px;
    background: linear-gradient(135deg, #34495e, #2c3e50);
    border: 2px solid #3498db;
    border-radius: 8px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
    transform: rotate(-2deg);
}

.drag-preview .node-header {
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: white;
    font-weight: bold;
    font-size: 0.9em;
}

.drag-preview .start-node { border-color: #27ae60; }
.drag-preview .checkpoint-node { border-color: #3498db; }
.drag-preview .teleport-node { border-color: #8e44ad; }
.drag-preview .end-node { border-color: #e74c3c; }
.drag-preview .dialogue-node { border-color: #9b59b6; }
.drag-preview .choice-node { border-color: #f39c12; }

/* 节点预览颜色 */
.start-node { background: linear-gradient(135deg, #27ae60, #2ecc71); }
.checkpoint-node { background: linear-gradient(135deg, #3498db, #5dade2); }
.teleport-node { background: linear-gradient(135deg, #8e44ad, #af7ac5); }

/* 锁定节点视觉提示 */
.blueprint-node.locked {
  outline: 2px dashed #f1c40f;
  outline-offset: -2px;
}
.end-node { background: linear-gradient(135deg, #e74c3c, #ec7063); }
.dialogue-node { background: linear-gradient(135deg, #9b59b6, #bb8fce); }
.choice-node { background: linear-gradient(135deg, #f39c12, #f7dc6f); }
.event-node { background: linear-gradient(135deg, #e67e22, #f8c471); }
.reward-node { background: linear-gradient(135deg, #f1c40f, #f4d03f); }
.success-node { background: linear-gradient(135deg, #27ae60, #58d68d); }
.failure-node { background: linear-gradient(135deg, #e74c3c, #f1948a); }
.good-ending-node { background: linear-gradient(135deg, #8e44ad, #d7bde2); }
.bad-ending-node { background: linear-gradient(135deg, #2c3e50, #85929e); }

/* 画布容器样式 */
.canvas-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #1a1a1a;
    position: relative;
}

.canvas-header {
    background: #2c3e50;
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #34495e;
}

.canvas-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

.canvas-controls button {
    padding: 5px 10px;
    border: 1px solid #34495e;
    border-radius: 3px;
    background: #34495e;
    color: #ecf0f1;
    cursor: pointer;
    font-size: 0.8em;
    transition: background 0.3s ease;
}

.canvas-controls button:hover {
    background: #3498db;
}

#zoomLevel {
    color: #bdc3c7;
    font-size: 0.9em;
    min-width: 50px;
    text-align: center;
}

.canvas-info {
    display: flex;
    gap: 15px;
    font-size: 0.9em;
    color: #bdc3c7;
}

.canvas-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden; /* 🎯 容器裁剪，内部可滚动 */
    --grid-size: 20px; /* 可缩放的网格尺寸（随缩放改变） */
    --grid-offset-x: 0px; /* 网格随画布平移的偏移 */
    --grid-offset-y: 0px;
    background-color: #1a1a1a;
    background-image: radial-gradient(circle, #444 1px, transparent 1px);
    background-size: var(--grid-size) var(--grid-size);
    background-position: var(--grid-offset-x) var(--grid-offset-y);
    /* 🔧 修复：确保不影响flex布局 */
    min-width: 0; /* 防止flex子元素溢出 */
    contain: layout style paint; /* 性能优化 */
    cursor: grab; /* 空白区域默认显示抓手，提示可拖动画布 */
}

.canvas-wrapper:active {
    cursor: grabbing;
}

.canvas-wrapper.dragging-canvas {
    /* 拖拽中给予轻微的对比度提升，强化“抓住了画布”的视觉反馈 */
    filter: brightness(1.08);
}

.connection-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* 由子元素决定是否接收事件，空白区域透传到下层节点 */
    z-index: 3; /* 置于画布上方，便于命中；具体命中范围由命中层控制 */
    overflow: visible; /* 防止长路径被裁切 */
}

.canvas {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    background: transparent;
    overflow: visible;
    z-index: 2; /* 节点在连线之上，确保优先交互 */
    transform-origin: 0 0;
    outline: none; /* 去掉任何默认轮廓，避免出现"工作区"边框感 */
}

/* 实际节点样式 */
.blueprint-node {
    position: absolute;
    min-width: 120px;
    background: #2c3e50;
    border: 2px solid #34495e;
    border-radius: 8px;
    padding: 10px;
    cursor: move;
    user-select: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    z-index: 5; /* 节点永远覆盖连线 */
}

/* 拖拽中的节点立即跟随鼠标（关闭过渡） */
.blueprint-node.dragging-node {
    transition: none !important;
}

.blueprint-node:hover {
    border-color: #3498db;
    box-shadow: 0 6px 20px rgba(52, 152, 219, 0.3);
}

.blueprint-node.selected {
    border-color: #f39c12;
    box-shadow: 0 6px 20px rgba(243, 156, 18, 0.4);
}

.node-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-weight: bold;
    font-size: 0.9em;
}

.node-icon {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8em;
    color: white;
}

.node-content {
    font-size: 0.8em;
    color: #bdc3c7;
    line-height: 1.3;
}

.node-ports {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
}

/* 区域端口（取代多个小点） */
.port-area {
    position: absolute;
    top: -2px;
    width: 12px;
    height: calc(100% + 4px);
    border-radius: 6px;
    opacity: 0.3;
    cursor: crosshair;
    transition: opacity 0.2s ease;
}
.port-area:hover { opacity: 0.6; }
.port-area.input { left: -6px; background: #2ecc71; }
.port-area.output { right: -6px; background: #e74c3c; }

/* 属性面板样式 */
.properties-panel {
    width: 300px;
    min-width: 300px; /* 🔧 强制最小宽度 */
    max-width: 300px; /* 🔧 强制最大宽度 */
    flex-shrink: 0; /* 🔧 防止被压缩 */
    background: #2c3e50;
    padding: 15px;
    overflow-y: auto;
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.3);
    z-index: 1000; /* 🔧 提高z-index */
    position: relative; /* 🎯 确保z-index生效 */
}

.properties-panel h3 {
    color: #ecf0f1;
    margin-bottom: 15px;
    text-align: center;
    font-size: 1.1em;
}

.no-selection {
    text-align: center;
    color: #7f8c8d;
    padding: 20px;
    font-style: italic;
}

.property-group {
    margin-bottom: 20px;
}

.property-group h4 {
    color: #bdc3c7;
    margin-bottom: 10px;
    font-size: 0.9em;
    border-bottom: 1px solid #34495e;
    padding-bottom: 5px;
}

.property-item {
    margin-bottom: 10px;
}

.property-item label {
    display: block;
    color: #95a5a6;
    font-size: 0.8em;
    margin-bottom: 3px;
}

.property-item input,
.property-item select,
.property-item textarea {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #34495e;
    border-radius: 4px;
    background: #34495e;
    color: #ecf0f1;
    font-size: 0.85em;
}

.property-item input:focus,
.property-item select:focus,
.property-item textarea:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 5px rgba(52, 152, 219, 0.3);
}

/* 连接线样式 */
.connection-line {
    stroke: #4da3ff; /* 统一为与脚本一致的默认颜色 */
    stroke-width: 5;
    fill: none;
    cursor: pointer;
    pointer-events: none; /* 事件交由命中层处理，避免干扰节点交互 */
    transition: all 0.2s ease;
}

/* 悬停高亮由命中层触发并在脚本中设置到可见线 */

/* 命中层：更粗的透明描边用于更容易命中 */
.connection-hit {
    stroke: transparent;
    stroke-width: 16;
    fill: none;
    pointer-events: stroke; /* 仅在描边区域接收事件 */
}

/* 🗑️ 移除连线选中样式，因为只使用双击删除 */

/* 🗑️ 移除连接提示动画，因为只使用双击删除 */

/* 模态框样式 */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
}

.modal-content {
    background-color: #2c3e50;
    margin: 5% auto;
    padding: 0;
    border-radius: 8px;
    width: 80%;
    max-width: 800px;
    max-height: 80%;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.modal-header {
    background: #34495e;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #2c3e50;
}

.modal-header h2 {
    color: #ecf0f1;
    font-size: 1.2em;
}

.close {
    color: #bdc3c7;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s ease;
}

.close:hover {
    color: #e74c3c;
}

.modal-body {
    padding: 20px;
    max-height: 60vh;
    overflow-y: auto;
}

#jsonPreview {
    background: #1a1a1a;
    color: #e2e8f0;
    padding: 15px;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-size: 0.85em;
    line-height: 1.4;
    margin-bottom: 15px;
    overflow-x: auto;
}

/* 响应式设计 */
@media (max-width: 1024px) {
    .node-palette {
        width: 200px;
    }
    
    .properties-panel {
        width: 250px;
    }
}

@media (max-width: 768px) {
    .toolbar {
        flex-direction: column;
        height: auto;
        padding: 10px;
    }
    
    .toolbar-section {
        width: 100%;
        justify-content: center;
        margin-bottom: 10px;
    }
    
    .toolbar-section:last-child {
        margin-bottom: 0;
    }
    
    .main-container {
        height: calc(100vh - 120px);
    }
    
    .node-palette,
    .properties-panel {
        display: none;
    }
    
    .canvas-container {
        width: 100%;
    }
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #2c3e50;
}

::-webkit-scrollbar-thumb {
    background: #34495e;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #3498db;
}

/* 动画效果 */
@keyframes nodeAppear {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.blueprint-node {
    animation: nodeAppear 0.3s ease-out;
}

/* 拖拽时的样式 */
.dragging {
    opacity: 0.7;
    transform: rotate(5deg);
    z-index: 1000;
}

.drag-over {
    background: rgba(52, 152, 219, 0.1);
    border: 2px dashed #3498db;
}

/* 坐标选择器样式 */
.coordinate-selector {
    width: 400px;
    max-height: 500px;
}

.selector-content {
    padding: 15px 0;
}

.stage-info {
    font-size: 14px;
    font-weight: bold;
    color: #4a9eff;
    margin-bottom: 15px;
    text-align: center;
}

.coordinate-list {
    max-height: 300px;
    overflow-y: auto;
}

.coordinate-item {
    background: #2c3144;
    border: 1px solid #3a3f51;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.coordinate-item:hover {
    border-color: #4a9eff;
    background: #323752;
}

.coordinate-item-name {
    font-weight: bold;
    color: #4a9eff;
    font-size: 14px;
    margin-bottom: 5px;
}

.coordinate-item-info {
    font-size: 12px;
    color: #b0b0b0;
    line-height: 1.4;
}

.coordinate-item-pos {
    color: #4a9eff;
    font-family: 'Courier New', monospace;
}

.coordinate-item-desc {
    margin-top: 5px;
    color: #d4d4dc;
}

.modal-footer {
    margin-top: 15px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 15px;
    border-top: 1px solid #3a3f51;
}

/* 坐标管理器样式 */
.coordinate-manager {
    max-width: 800px;
    max-height: 90vh;
}

.manager-content {
    padding: 20px;
    max-height: 70vh;
    overflow-y: auto;
}

.stage-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #34495e;
}

.stage-tab {
    padding: 8px 15px;
    border: none;
    border-radius: 20px;
    background: #34495e;
    color: #bdc3c7;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9em;
    white-space: nowrap;
}

.stage-tab:hover {
    background: #4a5f7a;
    color: #ecf0f1;
}

.stage-tab.active {
    background: #3498db;
    color: #ffffff;
    font-weight: bold;
}

.coordinate-manager-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #34495e;
    border-radius: 6px;
    padding: 10px;
    background: #2c3e50;
    margin-bottom: 20px;
}

.manager-coordinate-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    margin-bottom: 8px;
    background: #34495e;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.manager-coordinate-item:hover {
    background: #4a5f7a;
}

.manager-coordinate-item:last-child {
    margin-bottom: 0;
}

.coordinate-info {
    flex: 1;
}

.coordinate-actions {
    display: flex;
    gap: 8px;
}

.coordinate-actions button {
    padding: 4px 8px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.8em;
    transition: all 0.2s ease;
}

.edit-coord-btn {
    background: #f39c12;
    color: white;
}

.edit-coord-btn:hover {
    background: #e67e22;
}

.delete-coord-btn {
    background: #e74c3c;
    color: white;
}

.delete-coord-btn:hover {
    background: #c0392b;
}

/* 快速坐标识别样式 */
.quick-coord-section {
    background: #2a3d52;
    border: 2px solid #3498db;
    border-radius: 8px;
    padding: 15px;
    margin-top: 15px;
    margin-bottom: 15px;
}

.quick-coord-section h4 {
    color: #3498db;
    margin-bottom: 12px;
    font-size: 1em;
}

.quick-coord-row {
    position: relative;
}

.quick-coord-input {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #34495e;
    border-radius: 6px;
    background: #34495e;
    color: #ecf0f1;
    font-size: 0.9em;
    font-family: 'Courier New', monospace;
    transition: all 0.3s ease;
}

.quick-coord-input:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 8px rgba(52, 152, 219, 0.3);
    background: #3a526b;
}

.quick-coord-input::placeholder {
    color: #7f8c8d;
    font-style: italic;
}

.quick-coord-help {
    font-size: 0.8em;
    color: #95a5a6;
    margin-top: 8px;
    padding-left: 5px;
    transition: all 0.2s ease;
}

/* 解析状态样式 */
.quick-coord-success .quick-coord-input {
    border-color: #27ae60;
    background: #2a4d3a;
}

.quick-coord-error .quick-coord-input {
    border-color: #e74c3c;
    background: #4d2a2a;
}

.add-coordinate-section {
    background: #34495e;
    border-radius: 8px;
    padding: 15px;
    margin-top: 15px;
}

.add-coordinate-section h4 {
    color: #3498db;
    margin-bottom: 15px;
}

.add-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.form-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.form-row label {
    min-width: 50px;
    color: #bdc3c7;
    font-weight: bold;
}

.form-row input {
    padding: 8px 12px;
    border: 1px solid #2c3e50;
    border-radius: 4px;
    background: #2c3e50;
    color: #ecf0f1;
    font-size: 0.9em;
}

.form-row input[type="text"] {
    flex: 1;
    min-width: 150px;
}

.form-row input[type="number"] {
    width: 80px;
}

.form-row input:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 5px rgba(52, 152, 219, 0.3);
}

.btn-warning {
    background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%);
    color: white;
}

.btn-warning:hover {
    background: linear-gradient(135deg, #e67e22 0%, #d35400 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.empty-coordinates {
    text-align: center;
    color: #7f8c8d;
    padding: 30px;
    font-style: italic;
}
