:root {
  --primary: #ff6a00;
  --primary-dark: #e85d00;
  --text: #222;
  --muted: #8a8f98;
  --border: #e6e6e6;
  --bg: #f2f4f7;
  --card: #fff;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
}
a { color: inherit; text-decoration: none; }

/* 顶部栏 */
.appbar {
  display: flex; align-items: center; gap: 16px;
  height: 56px; padding: 0 18px;
  background: #fff; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.appbar .back { color: #6b7280; font-size: 14px; padding: 6px 10px; border-radius: 8px; }
.appbar .back:hover { background: #fff4ec; color: var(--primary); }
.appbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 16px; }
.appbar .mark {
  width: 32px; height: 32px; border-radius: 9px; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary), #ff9a4d); color: #fff; font-size: 13px; font-weight: 800;
}
.appbar-right { margin-left: auto; }
.appbar .ghost { font-size: 13px; color: #6b7280; padding: 6px 12px; border: 1px solid var(--border); border-radius: 8px; }
.appbar .ghost:hover { border-color: var(--primary); color: var(--primary); }

/* 布局 */
.app {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  max-width: 1500px;
  margin: 0 auto;
  align-items: stretch;
  min-height: calc(100vh - 56px);
}
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.controls { padding: 6px 18px 18px; position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow: auto; }
@media (max-width: 960px) { .controls { position: static; max-height: none; } }

.sec { padding: 16px 0; border-bottom: 1px solid #f0f1f3; }
.sec:last-child { border-bottom: none; padding-bottom: 4px; }
.sec h3 {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 12px; font-size: 14px; font-weight: 700; color: #374151;
}
.step {
  width: 20px; height: 20px; border-radius: 50%; background: #fff1e6; color: var(--primary);
  font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center; flex: none;
}

/* 上传 */
.dropzone {
  display: block; border: 1.5px dashed #d7dbe0; border-radius: 12px; cursor: pointer;
  background: #fafbfc; transition: border-color .15s, background .15s; overflow: hidden;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: #fff8f3; }
.dz-inner { padding: 26px 16px; text-align: center; }
.dz-ico { font-size: 26px; color: var(--primary); line-height: 1; margin-bottom: 6px; }
.dz-t1 { font-size: 14px; font-weight: 600; }
.dz-t2 { font-size: 12px; color: var(--muted); margin-top: 2px; }
.dz-preview { position: relative; padding: 10px; }
.dz-preview canvas { width: 100%; max-height: 180px; object-fit: contain; border-radius: 8px; background: #fff; }
.dz-change {
  position: absolute; right: 16px; bottom: 16px; font-size: 12px; padding: 5px 10px;
  border: none; border-radius: 7px; background: rgba(0,0,0,.62); color: #fff; cursor: pointer;
}

/* 分段按钮 */
.seg { display: flex; gap: 6px; background: #f4f5f7; padding: 4px; border-radius: 10px; margin-bottom: 10px; }
.seg button {
  flex: 1; border: none; background: transparent; padding: 8px 6px; border-radius: 7px;
  font-size: 13px; color: #6b7280; cursor: pointer; font-weight: 600;
}
.seg button.on { background: #fff; color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* 控件行 */
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 0; }
.row > label { font-size: 13px; color: #4b5563; flex: 1; }
.row > label b { color: var(--primary); font-weight: 700; }
.row select, .row input[type=number] {
  height: 34px; border: 1px solid var(--border); border-radius: 8px; padding: 0 10px;
  font-size: 13px; color: #374151; background: #fff; max-width: 150px;
}
.row select { min-width: 150px; }
.row input[type=range] { flex: 1; accent-color: var(--primary); max-width: 160px; }
.row input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--primary); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 label { font-size: 12px; color: #6b7280; display: flex; flex-direction: column; gap: 4px; }
.grid2 input {
  height: 34px; border: 1px solid var(--border); border-radius: 8px; padding: 0 10px; font-size: 14px;
}
.adv { margin-top: 8px; border-top: 1px dashed #eceef1; padding-top: 8px; }
.adv summary { cursor: pointer; font-size: 13px; color: #6b7280; user-select: none; padding: 4px 0; }
.adv summary:hover { color: var(--primary); }
#rowEdge.hide, #rowBin.hide { display: none; }

/* 按钮 */
.btn {
  display: block; width: 100%; margin-top: 8px; padding: 11px 14px; border-radius: 9px;
  border: 1px solid var(--border); background: #fff; color: #374151; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-dark); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.hint { font-size: 12px; color: var(--muted); margin-top: 10px; }

/* 舞台 */
.stage { display: flex; flex-direction: column; min-height: 620px; overflow: hidden; }
.stage-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--border); flex: 1; }
@media (max-width: 720px) { .stage-grid { grid-template-columns: 1fr; } }
.canvas-card { background: #fff; display: flex; flex-direction: column; min-width: 0; }
.card-h {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid #f0f1f3; font-size: 13px; font-weight: 700; color: #374151;
}
.card-h .muted { font-weight: 400; font-size: 12px; color: var(--muted); }
.canvas-box { position: relative; flex: 1; min-height: 300px; display: flex; align-items: center; justify-content: center; background: #fbfbfc; }
.canvas-box canvas { max-width: 100%; max-height: 100%; display: block; }
#resultCanvas { image-rendering: pixelated; width: 100%; height: 100%; object-fit: contain; }
#webglCanvas { width: 100%; height: 100%; display: block; cursor: grab; }
#webglCanvas:active { cursor: grabbing; }
.empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #b6bcc4; font-size: 13px; pointer-events: none;
}
.empty.hide { display: none; }
.statusbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; border-top: 1px solid var(--border); font-size: 12.5px; color: #4b5563; background: #fff;
}
.statusbar .muted { color: var(--muted); }
