:root {
  --bg: #f6f8fb;
  --card: #ffffff;
  --border: #e6e9ef;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --shadow: 0 1px 3px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.05);
  --rapid: #ff0000;
  --approach: #0000ff;
  --engage: #ff8000;
  --stepover: #00ff00;
  --cut: #00ffff;
  --retract: #ff80c0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  overflow: hidden;
}

/* 顶部栏 */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
.topbar-hint { color: var(--muted); font-size: 13px; }
.back {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
}
.back:hover { color: var(--accent); }

/* 布局 */
.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: calc(100vh - 53px);
}

/* 左侧面板 */
.panel {
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  border-right: 1px solid var(--border);
  background: var(--bg);
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 12px; font-size: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

/* 通用元素 */
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.row > label:first-child {
  min-width: 70px;
  color: var(--muted);
  font-size: 13px;
  flex-shrink: 0;
}
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 0; }
.val { color: var(--accent); font-weight: 600; font-size: 13px; }

input[type="range"] { flex: 1; min-width: 80px; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 13px; cursor: pointer; }
.check input { accent-color: var(--accent); }
.check-row { gap: 14px; }

/* 按钮 */
.btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-primary:disabled:hover { background: var(--accent); }
.btn-block { width: 100%; }

/* 拖拽区 */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 24px 16px;
  text-align: center;
  transition: border-color .2s, background .2s;
  cursor: pointer;
}
.drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.drop-zone:hover { border-color: var(--accent); }
.drop-icon { font-size: 32px; margin-bottom: 8px; }
.drop-zone p { margin: 4px 0; color: var(--muted); font-size: 13px; }
.drop-sub { font-size: 12px !important; }

.paste-area { margin-top: 12px; }
.paste-area textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  font-family: "SFMono-Regular", Consolas, monospace;
  resize: vertical;
  outline: none;
}
.paste-area textarea:focus { border-color: var(--accent); }

/* 路径列表 */
.badge {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.path-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
}
.path-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcfe;
  cursor: pointer;
  transition: border-color .15s;
}
.path-item:hover { border-color: var(--accent); }
.path-item.active { border-color: var(--accent); background: var(--accent-soft); }
.path-item input[type="checkbox"] { accent-color: var(--accent); flex-shrink: 0; }
.path-name {
  font-size: 12px;
  font-weight: 500;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.path-meta { font-size: 11px; color: var(--muted); flex-shrink: 0; }

/* 图例 */
.legend {
  display: inline-block;
  width: 14px;
  height: 3px;
  border-radius: 2px;
  vertical-align: middle;
}
.legend.rapid { background: var(--rapid); }
.legend.approach { background: var(--approach); }
.legend.engage { background: var(--engage); }
.legend.stepover { background: var(--stepover); }
.legend.cut { background: var(--cut); }
.legend.retract { background: var(--retract); }

/* 统计 */
.stats { display: flex; flex-direction: column; gap: 6px; }
.stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  padding: 4px 0;
  border-bottom: 1px solid #f0f1f5;
}
.stat-row:last-child { border-bottom: none; }
.stat-row span:first-child { color: var(--muted); }
.stat-row span:last-child { font-weight: 500; }

/* 右侧 3D 预览 */
.viewer-pane {
  display: flex;
  flex-direction: column;
  background: #1a1d24;
  min-width: 0;
}
.viewer-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
#canvas3d {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.viewer-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #6b7280;
  pointer-events: none;
}
.viewer-hint p { margin: 4px 0; font-size: 16px; }
.viewer-hint-sub { font-size: 13px !important; color: #4b5563 !important; }

.coord-display {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: rgba(0,0,0,.6);
  color: #e5e7eb;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-family: "SFMono-Regular", Consolas, monospace;
  pointer-events: none;
}

/* 动画控制栏 */
.anim-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: #22262e;
  border-top: 1px solid #2d323c;
}
.anim-bar .btn {
  background: #2d323c;
  border-color: #3a404c;
  color: #e5e7eb;
}
.anim-bar .btn:hover { border-color: var(--accent); }
.anim-bar .btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.anim-progress-label, .anim-speed-label {
  color: #9ca3af;
  font-size: 12px;
  white-space: nowrap;
}
#progress { flex: 1; }
#speed { width: 80px; }

/* 响应式 */
@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: auto;
  }
  body { overflow: auto; }
  .panel { max-height: 50vh; border-right: none; border-bottom: 1px solid var(--border); }
  .viewer-pane { height: 60vh; }
}
