/* ============================================================
   关卡编辑器样式（作用域于 #editor-view，避免污染主程序）
   迁移自 level-editor.html，所有选择器加 #editor-view 前缀
   ============================================================ */

#editor-view {
  /* 编辑器专用 CSS 变量（主程序 :root 未定义这些） */
  --bg: #0b1020;
  --panel: rgba(15, 23, 42, 0.6);
  --panel-2: rgba(24, 33, 59, 0.7);
  --line: rgba(255, 255, 255, 0.1);
  --text: #e5eefc;
  --muted: #97a6c6;
  --accent: #22c55e;
  --accent-2: #3b82f6;
  --danger: #ef4444;
  --warn: #facc15;
  --radius: 18px;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  --grid: rgba(148, 163, 184, 0.12);

  /* 原 body 布局：整屏覆盖、flex 纵向 */
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-size: 12px;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(59,130,246,.18), transparent 35%),
    radial-gradient(circle at top right, rgba(34,197,94,.15), transparent 30%),
    linear-gradient(180deg, #070d1a 0%, #0b1020 100%);
}

#editor-view * { box-sizing: border-box; }

/* 函数棋同款：得意黑字体（作用域，不影响主程序） */
#editor-view,
#editor-view * { font-family: 'SmileySans', 'Segoe UI', 'Microsoft YaHei', sans-serif !important; }

/* 等宽保留：坐标 / JSON 输入框与代码 */
#editor-view input,
#editor-view textarea,
#editor-view select,
#editor-view pre,
#editor-view code,
#editor-view .mono,
#editor-view .export-box { font-family: 'Courier New', 'Consolas', monospace !important; }

/* 函数棋同款：动态渐变背景 */
#editor-view::before {
  content: '';
  position: absolute;
  inset: -50%;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 30% 40%, rgba(30,64,175,0.13) 0%, transparent 65%),
    radial-gradient(ellipse at 70% 60%, rgba(88,28,135,0.10) 0%, transparent 65%),
    radial-gradient(ellipse at 50% 50%, rgba(6,182,212,0.05) 0%, transparent 55%),
    radial-gradient(ellipse at 60% 30%, rgba(15,23,42,0.4) 0%, transparent 70%);
  animation: bgDrift 16s ease-in-out infinite alternate;
}
@keyframes bgDrift {
  0%   { transform: translate(0, 0) scale(1); }
  25%  { transform: translate(4%, -2%) scale(1.04); }
  50%  { transform: translate(-2%, 3%) scale(1.02); }
  75%  { transform: translate(1%, -4%) scale(1.05); }
  100% { transform: translate(-3%, 1%) scale(1); }
}

#editor-view header {
  flex-shrink: 0;
  padding: 10px 20px 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  position: relative;
  z-index: 40;
}
#editor-view h1 {
  margin: 0;
  font-size: 18px;
  background: linear-gradient(135deg, #A0F1D8, #848BCF);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
#editor-view .subtitle { color: var(--muted); font-size: 11px; margin-top: 2px; letter-spacing: 0.5px; }

#editor-view .wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  padding: 0;
}
#editor-view .left,
#editor-view .center,
#editor-view .right {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#editor-view .center { position: absolute; inset: 8px; overflow: hidden; }
#editor-view .left { position: absolute; top: 8px; bottom: 8px; left: 8px; width: 300px; overflow-y: auto; z-index: 20; box-shadow: 0 16px 44px rgba(0,0,0,0.45); }
#editor-view .right { position: absolute; top: 8px; bottom: 8px; right: 8px; width: 300px; overflow-y: auto; z-index: 20; box-shadow: 0 16px 44px rgba(0,0,0,0.45); }

/* 函数棋同款：玻璃面板 */
#editor-view .card {
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
#editor-view .card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(59,130,246,0.25), transparent);
  pointer-events: none;
  z-index: 1;
}

#editor-view .section { padding: 10px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
#editor-view .section:last-child { border-bottom: 0; }
#editor-view .section.stretch { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }
#editor-view label { display:block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }

/* 函数棋同款：玻璃输入框 */
#editor-view input,
#editor-view select,
#editor-view textarea {
  font: inherit;
  width: 100%;
  padding: 6px 8px;
  outline: none;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: border-color .2s, box-shadow .2s;
}
#editor-view input:focus,
#editor-view select:focus,
#editor-view textarea:focus {
  border-color: rgba(59, 130, 246, 0.5);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}
#editor-view textarea { min-height: 60px; resize: none; line-height: 1.4; }
/* 数据类 textarea 配合自动增高（auto-grow）：隐藏原生滚动条，由 JS 撑高 */
#editor-view #targetCells,
#editor-view #forbiddenCells,
#editor-view #lockedElements { overflow: hidden; }

/* 下拉选项配色：与玻璃深色主题一致 */
#editor-view select { color-scheme: dark; }
#editor-view select option {
  background-color: #0b1020;
  color: var(--text);
}
#editor-view select option:hover,
#editor-view select option:checked {
  background-color: rgba(59, 130, 246, 0.55);
  color: #ffffff;
}

#editor-view .row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#editor-view .row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
#editor-view .btnrow { display:flex; flex-wrap: wrap; gap: 5px; }

/* 函数棋同款：玻璃按钮系统 */
#editor-view button {
  position: relative;
  overflow: hidden;
  padding: 7px 10px;
  font-size: 12px;
  cursor: pointer;
  border-radius: 12px;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background-color: rgba(255, 255, 255, 0.05);
  background-image: radial-gradient(circle 60px at var(--gx, 50%) var(--gy, 50%), rgba(255, 255, 255, 0.06), transparent 70%);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: all 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94) !important;
}
#editor-view button::before {
  content: '';
  position: absolute;
  top: 0; left: 12%; right: 12%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.22), transparent);
  pointer-events: none;
  z-index: 2;
}
#editor-view button::after {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.07), transparent);
  transition: left 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  pointer-events: none;
  z-index: 1;
}
#editor-view button:hover:not(:disabled) {
  transform: translateY(-3px) !important;
  background-color: rgba(255, 255, 255, 0.12);
  border-color: rgba(59, 130, 246, 0.35);
  box-shadow: 0 6px 24px rgba(59, 130, 246, 0.25);
}
#editor-view button:hover::after { left: 100%; }
#editor-view button:active:not(:disabled) { transform: scale(0.98) !important; }
#editor-view button:disabled { opacity: 0.5; cursor: not-allowed; }
#editor-view button.primary {
  background-color: transparent;
  background-image: radial-gradient(circle 60px at var(--gx, 50%) var(--gy, 50%), rgba(255, 255, 255, 0.15), transparent 70%), linear-gradient(135deg, rgba(34,197,94,0.85), rgba(22,163,74,0.85));
  border-color: rgba(34, 197, 94, 0.2);
  color: #dce8e0;
}
#editor-view button.primary:hover:not(:disabled) { box-shadow: 0 6px 24px rgba(34, 197, 94, 0.35); border-color: rgba(34, 197, 94, 0.35); }
#editor-view button.good {
  background-color: transparent;
  background-image: radial-gradient(circle 60px at var(--gx, 50%) var(--gy, 50%), rgba(255, 255, 255, 0.15), transparent 70%), linear-gradient(135deg, rgba(34,197,94,0.85), rgba(22,163,74,0.85));
  border-color: rgba(34, 197, 94, 0.2);
  color: #08111c;
  font-weight: 700;
}
#editor-view button.ghost {
  background-color: rgba(255, 255, 255, 0.05);
  background-image: radial-gradient(circle 60px at var(--gx, 50%) var(--gy, 50%), rgba(255, 255, 255, 0.06), transparent 70%);
  border: 1px solid rgba(255, 255, 255, 0.1);
}
#editor-view button.danger {
  background-color: rgba(239, 68, 68, 0.12);
  background-image: radial-gradient(circle 60px at var(--gx, 50%) var(--gy, 50%), rgba(255, 255, 255, 0.06), transparent 70%);
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}
#editor-view button.danger:hover:not(:disabled) { background-color: rgba(239, 68, 68, 0.2); box-shadow: 0 6px 24px rgba(239, 68, 68, 0.3); border-color: rgba(239, 68, 68, 0.5); }

#editor-view .help { font-size: 10px; color: var(--muted); line-height: 1.4; }
#editor-view .toolbar { display:flex; gap: 5px; flex-wrap: wrap; align-items: center; }
#editor-view .toolbar .spacer { flex: 1; }

/* 侧栏隐藏与显示（面板浮于坐标系之上，显隐不影响画布大小与位置） */
#editor-view.left-hidden .left { display: none; }
#editor-view.right-hidden .right { display: none; }
@media (max-width: 900px), (orientation: portrait) and (max-width: 1024px) {
  #editor-view .left,
  #editor-view .right { width: min(300px, 84vw); }
}
#editor-view .panel-close {
  position: absolute;
  top: 8px; right: 8px;
  z-index: 12;
  width: 26px; height: 26px;
  padding: 0;
  border-radius: 50%;
  line-height: 1;
  font-size: 16px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--line);
  color: var(--muted);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
#editor-view .panel-close:hover { background: rgba(239,68,68,0.18); color: #fecaca; border-color: rgba(239,68,68,0.4); }
#editor-view .left > .section:first-child,
#editor-view .right > .section:first-child { padding-top: 32px; }
#editor-view .panel-open {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 30;
  display: none;
  width: 36px; height: 36px;
  padding: 0;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  background: rgba(15,23,42,0.92);
  border: 1px solid var(--line);
  color: var(--text);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  align-items: center;
  justify-content: center;
}
/* 悬浮仅轻微上移（1px），且保留垂直居中 transform：用 button.panel-open:hover 与全局
   #editor-view button:hover:not(:disabled) 同特异性（1,2,1）且位于其后，确保覆盖成功，
   避免箭头按钮从居中位置被 translateY(-3px) 顶到 50% 线附近造成大幅跳动 */
#editor-view button.panel-open:hover {
  background: var(--accent-2);
  color: #fff;
  transform: translateY(calc(-50% - 1px)) !important;
}
#editor-view .panel-open-left { left: 8px; }
#editor-view .panel-open-right { right: 8px; }
#editor-view .panel-open svg { position: relative; z-index: 3; display: block; pointer-events: none; }
#editor-view.left-hidden .panel-open-left { display: flex; }
#editor-view.right-hidden .panel-open-right { display: flex; }

#editor-view .canvas-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 8px;
  gap: 6px;
}
#editor-view .canvas-frame {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #050b14;
}
#editor-view .mode-toggle {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 6;
  padding: 6px 10px;
  font-size: 11px;
  background-color: rgba(15, 23, 42, 0.78);
  border-color: rgba(255, 255, 255, 0.18);
}
/* 撤回按钮：位于「切换左键目标/禁止」按钮下方的圆形箭头按钮 */
#editor-view .editor-undo,
#editor-view .editor-fx {
  position: absolute;
  right: 8px;
  z-index: 6;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(15, 23, 42, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #e5e7eb;
  cursor: pointer;
}
#editor-view .editor-undo { top: 46px; }
/* fx 参考线按钮：位于撤回按钮下方 */
#editor-view .editor-fx {
  top: 88px;
  font-size: 13px;
  font-weight: 600;
  font-style: italic;
}
#editor-view .editor-fx:hover { border-color: rgba(34, 211, 238, 0.6); box-shadow: 0 0 12px rgba(34, 211, 238, 0.3); }
#editor-view .editor-fx.active {
  background-color: rgba(34, 211, 238, 0.16);
  border-color: rgba(34, 211, 238, 0.55);
  color: #cffafe;
}
#editor-view .editor-undo svg { position: relative; z-index: 3; display: block; }
#editor-view .editor-undo:hover:not(:disabled) {
  border-color: rgba(124, 219, 157, 0.6);
  box-shadow: 0 0 12px rgba(124, 219, 157, 0.3);
}

/* fx 函数参考线输入面板（画布左上角浮层，仅辅助设计） */
#editor-view .fx-panel {
  position: absolute;
  top: 8px;
  left: 10px;
  z-index: 6;
  width: 280px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(34, 211, 238, 0.35);
  backdrop-filter: blur(14px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
#editor-view .fx-panel input {
  width: 100%;
  padding: 6px 8px;
  font-size: 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  outline: none;
}
#editor-view .fx-panel input:focus { border-color: rgba(34, 211, 238, 0.6); }
#editor-view .fx-meta { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; gap: 6px; }
#editor-view .fx-hint { color: var(--muted); font-size: 10px; }
#editor-view .fx-clear {
  padding: 2px 8px;
  font-size: 10px;
  border-radius: 999px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fecaca;
  cursor: pointer;
}
#editor-view .fx-clear:hover { background: rgba(239, 68, 68, 0.25); }

/* 精度选择旁的小灰字提示 */
#editor-view .hint { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; line-height: 1.4; }

/* 实体方向键（D-pad）：画布左下角的十字方向键，作用等同键盘方向键 */
#editor-view .dpad {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 6;
  display: grid;
  grid-template-columns: repeat(3, 30px);
  grid-template-rows: repeat(3, 30px);
  gap: 3px;
}
#editor-view .dpad-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(15, 23, 42, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #e5e7eb;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
}
#editor-view .dpad-btn:hover { border-color: rgba(124, 219, 157, 0.6); box-shadow: 0 0 10px rgba(124, 219, 157, 0.3); }
#editor-view .dpad-btn:active { background-color: rgba(34, 197, 94, 0.25); }
#editor-view .dpad-btn#btnArrowUp { grid-column: 2; grid-row: 1; }
#editor-view .dpad-btn#btnArrowLeft { grid-column: 1; grid-row: 2; }
#editor-view .dpad-btn#btnArrowDown { grid-column: 2; grid-row: 3; }
#editor-view .dpad-btn#btnArrowRight { grid-column: 3; grid-row: 2; }

/* 实体垃圾桶按钮：位于 D-pad 上方，删除选中区域的所有格子（等同 Delete/Backspace） */
#editor-view .editor-trash {
  position: absolute;
  left: 10px;
  bottom: 112px;
  z-index: 6;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(15, 23, 42, 0.78);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #fca5a5;
  cursor: pointer;
}
#editor-view .editor-trash:hover { border-color: rgba(239, 68, 68, 0.8); box-shadow: 0 0 12px rgba(239, 68, 68, 0.35); }
#editor-view .editor-trash:active { background-color: rgba(239, 68, 68, 0.25); }
#editor-view .editor-trash svg { position: relative; z-index: 3; display: block; }
#editor-view .editor-undo:disabled { opacity: 0.4; cursor: not-allowed; }
#editor-view canvas { width: 100%; height: 100%; display:block; }
#editor-view .legend {
  display:flex; flex-wrap: wrap; gap: 6px; color: var(--muted); font-size: 10px; flex-shrink: 0;
}
#editor-view .chip { display:inline-flex; align-items:center; gap: 3px; padding: 3px 6px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,255,255,0.03); font-size: 10px; }
#editor-view .dot { width: 7px; height: 7px; border-radius: 50%; display:inline-block; }
#editor-view .dot.target { background: var(--accent); }
#editor-view .dot.forbid { background: var(--danger); }
#editor-view .dot.lock { background: var(--warn); }
#editor-view .export-box { min-height: 70px; flex: 1; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px; }
#editor-view .status { font-size: 10px; color: var(--muted); margin-top: 4px; }
#editor-view .list { display:grid; gap: 5px; max-height: 140px; overflow:auto; }
#editor-view .item { display:grid; grid-template-columns: 1fr auto; gap: 5px; align-items:center; padding: 6px 8px; border:1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,0.03); font-size: 12px; }
#editor-view .item small { color: var(--muted); display:block; margin-top:1px; font-size:10px; }
#editor-view .tiny { font-size: 10px; color: var(--muted); }
#editor-view .right .export-section { flex-shrink: 0; display: flex; flex-direction: column; }
#editor-view .right .export-section.stretch { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#editor-view .right .export-section.stretch .export-box { flex: 1; min-height: 80px; resize: none; font-size: 11px; }
#editor-view .tools-section .btnrow { margin-top: 2px; }
#editor-view .tools-section .btnrow button { flex: 1; min-width: 0; padding: 6px 4px; font-size: 11px; }

/* 锁定元素快捷面板：点击元素即锁定/解锁 */
#editor-view .lock-element-panel { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
#editor-view .lock-element-panel .lock-el {
  min-width: 32px;
  padding: 4px 8px;
  font-size: 11px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text);
  cursor: pointer;
  font-family: 'Courier New', 'Consolas', monospace !important;
}
#editor-view .lock-element-panel .lock-el:hover:not(:disabled) {
  border-color: rgba(250, 204, 21, 0.45);
  transform: translateY(-2px) !important;
  box-shadow: 0 4px 14px rgba(250, 204, 21, 0.18);
}
#editor-view .lock-element-panel .lock-el.active {
  background: rgba(250, 204, 21, 0.16);
  border-color: rgba(250, 204, 21, 0.6);
  color: #fde047;
  box-shadow: 0 0 0 1px rgba(250, 204, 21, 0.25), 0 6px 18px rgba(250, 204, 21, 0.22);
}
#editor-view .lock-element-panel .lock-el.active::before {
  background: linear-gradient(90deg, transparent, rgba(250, 204, 21, 0.55), transparent);
}

/* 框选 / 路径涂满：glass 风格切换按钮 */
#editor-view button.toggle.active {
  background-color: rgba(34, 197, 94, 0.16);
  background-image: radial-gradient(circle 60px at var(--gx, 50%) var(--gy, 50%), rgba(255,255,255,0.12), transparent 70%);
  border-color: rgba(34, 197, 94, 0.5);
  color: #c6f6d5;
  box-shadow: 0 0 0 1px rgba(34,197,94,0.25), 0 6px 22px rgba(34,197,94,0.22);
}
#editor-view button.toggle.active::before {
  background: linear-gradient(90deg, transparent, rgba(34,197,94,0.5), transparent);
}

/* 函数棋同款：涟漪 + 滚动条 */
#editor-view .ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: scale(0);
  animation: rippleAnim 0.65s ease-out forwards;
  pointer-events: none;
  z-index: 3;
}
@keyframes rippleAnim { to { transform: scale(4); opacity: 0; } }
#editor-view ::-webkit-scrollbar { width: 8px; height: 8px; }
#editor-view ::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.2); border-radius: 8px; }
#editor-view ::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.35); }
#editor-view ::-webkit-scrollbar-track { background: transparent; }
