/* KECRAFT · 工作台（默认夜间，html[data-theme="light"] 为白天） */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  color-scheme: dark;
  --bg: #0d1016; --panel: #151a22; --panel2: #1a212b;
  --line: rgba(255,255,255,0.09); --line2: rgba(255,255,255,0.18);
  --text: #e8eaf0; --muted: #8a93a3; --dim: #5c6572;
  --accent: #37c8a3; --accent-dim: rgba(55,200,163,0.15);
  --warn: #e2b93b; --bad: #e2604b;
  --primary-ink: #06231b;          /* 主按钮上的文字色 */
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef0f3; --panel: #ffffff; --panel2: #f2f4f7;
  --line: rgba(15,23,42,0.10); --line2: rgba(15,23,42,0.20);
  --text: #1f2733; --muted: #5b6774; --dim: #8a94a1;
  --accent: #17a184; --accent-dim: rgba(23,161,132,0.12);
  --warn: #a4790b; --bad: #cc4a35;
  --primary-ink: #ffffff;
}
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 13px/1.6 -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}

/* 顶栏 */
.topbar { display: flex; align-items: center; gap: 14px; padding: 10px 18px; border-bottom: 1px solid var(--line); }
.brand { font-size: 16px; font-weight: 600; letter-spacing: 2px; display: flex; align-items: center; gap: 8px; }
.brandLogo { width: 26px; height: 26px; border-radius: 6px; object-fit: cover; background: #fff; flex: none; }
.brand .en { color: var(--accent); font-size: 12px; letter-spacing: 3px; }
.crumb { color: var(--muted); }
.spacer { flex: 1; }
.save { color: var(--dim); font-size: 12px; }

/* 按钮 */
.btn { border: 1px solid var(--line2); background: transparent; color: var(--text); border-radius: 8px; padding: 7px 14px; cursor: pointer; font-size: 13px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--primary-ink); font-weight: 600; }
.btn.ghost.sm { padding: 4px 10px; font-size: 12px; }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }

/* 显隐开关按钮（手机预览 / 壳预览）：开=实心强调色+亮灯，关=虚线灰底+暗灯，一眼能分 */
.btn.toggle {
  display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap; flex: none;
  font-weight: 600; transition: background .15s, border-color .15s, color .15s;
}
.btn.toggle .led {
  width: 8px; height: 8px; border-radius: 50%; flex: none;
  background: var(--dim); transition: background .15s, box-shadow .15s;
}
.btn.toggle .st {
  font-style: normal; font-size: 11px; line-height: 1.4; padding: 0 6px;
  border-radius: 999px; background: var(--panel2); color: var(--muted);
}
.btn.toggle.on {
  background: var(--accent); border-color: var(--accent); color: var(--primary-ink);
}
.btn.toggle.on .led { background: var(--primary-ink); box-shadow: 0 0 0 3px rgba(255,255,255,0.35); }
.btn.toggle.on .st { background: rgba(0,0,0,0.22); color: var(--primary-ink); }
.btn.toggle.off {
  background: transparent; border-style: dashed; color: var(--muted);
}
.btn.toggle.off .led { background: transparent; box-shadow: inset 0 0 0 1.5px var(--dim); }
.btn.toggle.off .st { background: transparent; box-shadow: inset 0 0 0 1px var(--line2); color: var(--dim); }
.btn.toggle.off:hover { color: var(--text); border-color: var(--accent); }

/* 三栏 */
.workbench { flex: 1; display: grid; grid-template-columns: var(--steps-w, 264px) 1fr 292px; min-height: 0; position: relative; }

/* 左栏宽度拖拽柄（骑在左栏与画布交界线上） */
#stepsDrag {
  position: absolute; top: 0; bottom: 0;
  left: var(--steps-w, 264px); width: 9px; margin-left: -4px;
  cursor: col-resize; z-index: 6; touch-action: none;
}
#stepsDrag:hover, body.col-resizing #stepsDrag { background: linear-gradient(90deg, transparent, var(--accent-dim), transparent); }
body.col-resizing { cursor: col-resize; user-select: none; -webkit-user-select: none; }

/* 左栏步骤 */
.steps { border-right: 1px solid var(--line); overflow-y: auto; padding: 12px; background: var(--panel); }
.step { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.stepHead { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 10px; }
.stepHead .num { width: 20px; height: 20px; border-radius: 50%; background: var(--accent-dim); color: var(--accent); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; }
.lbl { display: block; color: var(--muted); font-size: 12px; margin: 8px 0 4px; }
.hint { color: var(--dim); font-size: 11.5px; margin: 4px 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.field { min-width: 0; }
input, select, textarea {
  width: 100%; background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 7px; padding: 6px 8px; font-size: 13px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
.wide { width: 100%; }
.rangeRow { display: flex; align-items: center; gap: 8px; }
.rangeRow input { padding: 0; }
.rangeRow b { min-width: 34px; text-align: right; font-weight: 500; }
.chk { display: flex; align-items: center; gap: 6px; margin-top: 10px; color: var(--muted); }
.chk input { width: auto; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); vertical-align: 1px; }
.modBtns { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 10px; }
.addBtn { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; color: var(--text); cursor: pointer; text-align: left; }
.addBtn:hover { border-color: var(--accent); }
.addBtn small { color: var(--dim); font-size: 11px; }
.swatches { display: flex; gap: 7px; flex-wrap: wrap; }
.swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatch.active { border-color: var(--text); }
/* 中间画布 */
.stage { display: flex; flex-direction: column; min-width: 0; }
.stageBar { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 3px; }
.tab { border: none; background: transparent; color: var(--muted); padding: 5px 13px; border-radius: 6px; cursor: pointer; font-size: 12.5px; }
.tab.active { background: var(--accent-dim); color: var(--accent); }
.pane { display: none; flex: 1; position: relative; min-height: 0; }
.pane.active { display: block; }
.pane canvas { width: 100%; height: 100%; display: block; }
#pane3d { overflow: hidden; transition: background 0.25s; }
#pane3d canvas { display: block; }

/* 3D 背景主题（背景由 CSS 画，canvas 保持透明） */
#pane3d.bg-dark { background: var(--bg); }
#pane3d.bg-dots {
  background-color: #f0f1f4;
  background-image: radial-gradient(circle, #c8cdd5 1.1px, transparent 1.1px);
  background-size: 16px 16px;
}
#pane3d.bg-white { background: #ffffff; }

/* 3D 区全屏（类切换实现，iOS Safari 对任意元素无原生 Fullscreen API） */
.fsBtn { display: none; }
.fsExit {
  position: absolute; right: 14px; bottom: 18px; z-index: 40;
  display: none; padding: 11px 18px; border-radius: 999px;
  border: 1px solid var(--line2); background: rgba(10, 13, 18, 0.62); color: #fff;
  font-size: 14px; cursor: pointer; backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px); touch-action: manipulation;
}
.stage.fs { position: fixed; inset: 0; z-index: 1000; height: 100dvh !important; min-height: 0; max-height: none; }
.stage.fs .fsExit { display: block; }
.stage.fs .stageBar .muted { display: none; }
@media (max-width: 900px) {
  .fsBtn { display: inline-block; min-height: 40px; }
}

/* 右栏 */
.props { border-left: 1px solid var(--line); overflow-y: auto; padding: 14px; background: var(--panel); }
.secTitle { font-weight: 600; margin-bottom: 6px; }
.pad { padding: 4px 0; }
.muted { color: var(--dim); font-size: 12px; }
.check { padding: 6px 8px; border-radius: 7px; margin-bottom: 6px; font-size: 12px; }
.check.ok { background: rgba(55,200,163,0.10); color: var(--accent); }
.check.bad { background: rgba(226,96,75,0.12); color: var(--bad); }

/* 底部导航条（占位） */
.pager { position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 4px 14px; color: var(--muted); font-size: 12px; }

/* ============================================
   平板（1024 以下）：三栏收窄，先不做结构改动
   ============================================ */
@media (max-width: 1200px) and (min-width: 901px) {
  .workbench { grid-template-columns: 220px 1fr 240px; }
  #stepsDrag { display: none; }
  .steps { padding: 10px; }
  .props { padding: 12px; }
}

/* ============================================
   手机（900 以下）：单列纵向流，3D 吸顶
   结构顺序 = 顶栏 → 3D 画布（吸顶） → 步骤 → 属性/安全检查
   ============================================ */
@media (max-width: 900px) {
  html { -webkit-text-size-adjust: 100%; }
  body { display: block; overflow: auto; height: auto; min-height: 100%; }

  .topbar { padding: 8px 12px; gap: 8px; }
  .topbar .crumb, .topbar .save { display: none; }
  .topbar .btn { white-space: nowrap; }
  .topbar #shareBtn, .topbar #exportBtn { padding: 8px 10px; font-size: 12px; }
  .topbar #themeBtn .themeTxt { display: none; }
  .brand { font-size: 14px; letter-spacing: 1px; }
  .brand .en { display: none; }
  .btn { padding: 8px 12px; }
  .btn.primary { padding: 8px 14px; }

  .workbench { display: flex; flex-direction: column; }
  #stepsDrag { display: none; }

  /* 3D / 图纸区：吸顶，滚参数时始终能看见 */
  .stage {
    order: 0; position: sticky; top: 0; z-index: 10;
    height: 46vh; min-height: 250px; max-height: 460px;
    background: var(--bg); border-bottom: 1px solid var(--line);
  }
  .stageBar {
    padding: 6px 10px;
    flex-wrap: wrap; gap: 8px; justify-content: flex-start;
    row-gap: 6px;
  }
  .stageBar .muted { display: none; }
  .stageBar .btn { white-space: nowrap; min-height: 38px; }
  /* 第 1 行：三个视图 tab 占满整行 */
  .tabs { order: -1; flex: 1 1 100%; }
  .tab { flex: 1; text-align: center; padding: 9px 6px; font-size: 13px; white-space: nowrap; }
  /* 第 2 行起：开关 + 功能按钮自然换行，禁止被压成竖排 */
  .stageBar > .btn { flex: 0 0 auto; }

  /* 画布自己吃手势，避免旋转模型时页面跟着滚 */
  .pane canvas { touch-action: none; }

  .steps { order: 1; border-right: none; padding: 10px; overflow: visible; }
  .props {
    order: 2; border-left: none; border-top: 1px solid var(--line);
    padding: 12px; overflow: visible;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }

  .step { padding: 10px; margin-bottom: 10px; }
  .stepHead { margin-bottom: 8px; }
  .lbl { margin: 10px 0 5px; }

  /* 16px 是 iOS 聚焦不自动放大的下限，别改小 */
  input, select, textarea { font-size: 16px; padding: 9px 10px; }
  .chk input { min-height: 0; }
  .chk { font-size: 13px; gap: 8px; }
  .rangeRow { gap: 10px; }
  .rangeRow b { min-width: 38px; }

  .addBtn { min-height: 44px; justify-content: center; align-items: center; }
  .modBtns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .swatch { width: 32px; height: 32px; }
  .swatches { gap: 10px; }
  .btn.ghost.sm { padding: 9px 12px; font-size: 13px; }
}

/* 重置方案确认弹窗 */
.modalMask {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(6, 9, 14, 0.62);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(2px);
}
.modalMask[hidden] { display: none; }
.modalBox {
  width: min(360px, calc(100vw - 48px));
  background: var(--panel); border: 1px solid var(--line2);
  border-radius: 14px; padding: 20px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
}
.modalTitle { font-size: 15px; font-weight: 600; margin-bottom: 8px; }
.modalText { color: var(--muted); font-size: 12.5px; line-height: 1.7; margin-bottom: 18px; }
.modalBtns { display: flex; gap: 10px; justify-content: flex-end; }
.btn.dangerSolid {
  background: var(--bad); border-color: var(--bad);
  color: #fff; font-weight: 600;
}
.btn.dangerSolid:hover { filter: brightness(1.1); }
