:root {
  --bg: #0b0d12;
  --bg-2: #11141c;
  --panel: rgba(20, 24, 34, 0.86);
  --line: #262b38;
  --line-soft: #1c212c;
  --text: #e6e9f0;
  --text-dim: #9aa3b2;
  --accent: #6d8dff;
  --accent-2: #8faaff;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* 中央画布背景微渐变，保持暗色工作氛围 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1200px 600px at 30% -10%, rgba(109, 141, 255, 0.10), transparent 60%),
    radial-gradient(900px 500px at 90% 110%, rgba(139, 92, 246, 0.08), transparent 60%);
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, #0e1118 0%, rgba(14, 17, 24, 0.7) 100%);
  backdrop-filter: blur(8px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.brand-mark {
  width: 34px;
  height: 34px;
  color: var(--accent-2);
  flex: 0 0 auto;
}
.brand-text h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.3px;
  line-height: 1.1;
}
.brand-text p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-dim);
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.export-group {
  display: flex;
  gap: 8px;
  margin-left: 6px;
  padding-left: 14px;
  border-left: 1px solid var(--line);
}

/* ---------- 按钮 ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:hover {
  border-color: #3a4254;
}
.btn:active {
  transform: translateY(1px);
}
.btn-primary {
  background: linear-gradient(180deg, #5f7dff, #4b66e8);
  border-color: transparent;
  color: #fff;
}
.btn-primary:hover {
  background: linear-gradient(180deg, #6c88ff, #556fef);
}
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border-color: var(--line);
}
.btn-ghost:hover:not(:disabled) {
  color: var(--text);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-block {
  width: 100%;
  margin-top: 8px;
}

/* ---------- 工作区布局 ---------- */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr minmax(230px, 290px) minmax(250px, 300px);
  gap: 1px;
  min-height: 0;
  background: var(--line-soft);
}
.viewport {
  position: relative;
  overflow: hidden;
  background: #0a0c10;
}
.viewport canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

/* ---------- 拖拽提示 ---------- */
.drop-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding: 24px;
  color: var(--text-dim);
  transition: opacity 0.25s;
  pointer-events: none;
}
.drop-hint svg {
  color: var(--accent);
  opacity: 0.85;
  margin-bottom: 4px;
}
.drop-hint strong {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.drop-hint span {
  font-size: 13px;
  max-width: 380px;
}
.drop-hint.dragover {
  outline: 2px dashed var(--accent);
  outline-offset: -14px;
  border-radius: var(--radius);
  background: rgba(109, 141, 255, 0.06);
}
.drop-hint.hidden {
  opacity: 0;
  visibility: hidden;
}

.badge {
  position: absolute;
  top: 14px;
  left: 14px;
  max-width: 60%;
  padding: 8px 12px;
  background: rgba(13, 16, 22, 0.75);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-dim);
  backdrop-filter: blur(6px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hud-hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 20px;
  background: rgba(13, 16, 22, 0.6);
  border: 1px solid var(--line-soft);
  font-size: 12px;
  color: var(--text-dim);
  backdrop-filter: blur(4px);
}

/* ---------- 面板（预览 / 控制） ---------- */
.preview-pane,
.panel {
  background: var(--panel);
  backdrop-filter: blur(8px);
  min-height: 0;
}
.preview-pane {
  display: flex;
  flex-direction: column;
}
.pane-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 16px 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-dim);
  border-bottom: 1px solid var(--line-soft);
  gap: 8px;
}
.pane-head .pane-sub {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-dim);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.preview-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  min-height: 0;
}
.preview-body img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 6px 18px rgba(0, 0, 0, 0.35));
}
.preview-empty {
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
}

.panel {
  overflow: hidden;
}
.panel-scroll {
  height: 100%;
  overflow-y: auto;
  padding: 8px 16px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.panel-scroll::-webkit-scrollbar {
  width: 8px;
}
.panel-scroll::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 4px;
}

.group {
  padding: 14px 0;
  border-bottom: 1px solid var(--line-soft);
}
.group:first-child {
  padding-top: 6px;
}
.group:last-child {
  border-bottom: none;
}
.group-title {
  margin: 0 0 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-dim);
}
.group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  min-height: 20px;
}
.group-head .group-title {
  margin: 0;
}
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-2);
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.btn-icon:hover {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(109, 141, 255, 0.1);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 13px;
}
.field:last-child {
  margin-bottom: 0;
}
.field-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text);
}
.val {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent-2);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent) var(--p, 30%), #262c3a var(--p, 30%), #262c3a 100%);
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  cursor: pointer;
  transition: transform 0.1s;
}
input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.12);
}
input[type="range"]::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  cursor: pointer;
}

/* 开关 */
.toggler {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.toggler input {
  position: absolute;
  opacity: 0;
  height: 0;
  width: 0;
}
.switch {
  width: 36px;
  height: 20px;
  border-radius: 20px;
  background: #262c3a;
  position: relative;
  cursor: pointer;
  flex: 0 0 auto;
  transition: background 0.18s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #cdd3df;
  transition: transform 0.18s, background 0.18s;
}
.toggler input:checked + .switch {
  background: var(--accent);
}
.toggler input:checked + .switch::after {
  transform: translateX(16px);
  background: #fff;
}
.toggler input:focus-visible + .switch {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* 独立图层图例 */
.layer-tip {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.layer-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.layer-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  border-radius: 20px;
  font-size: 11px;
  color: var(--text);
}
.layer-chip i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.15);
}
.layer-chip em {
  font-style: normal;
  font-family: var(--mono);
  color: var(--text-dim);
  font-size: 10px;
}
.layer-chip.off {
  opacity: 0.45;
  border-color: var(--line);
}
.layer-chip.off i {
  filter: grayscale(1);
}
.layer-toggle {
  background: none;
  border: none;
  padding: 0;
  margin-left: 2px;
  width: 18px;
  height: 18px;
  line-height: 1;
  border-radius: 50%;
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.layer-toggle:hover {
  background: var(--line);
  color: var(--text);
}
.layer-chip:not(.off) .layer-toggle {
  color: #58d68d;
}

/* 统计 */
.stats {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.stats div {
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.stats dt {
  font-size: 11px;
  color: var(--text-dim);
}
.stats dd {
  margin: 3px 0 0;
  font-family: var(--mono);
  font-size: 14px;
}

/* 抽屉里的 bevel 选项收起 */
#bevelOpts {
  overflow: hidden;
  transition: max-height 0.25s ease, opacity 0.2s ease;
  max-height: 240px;
  opacity: 1;
}
#bevelOpts.closed {
  max-height: 0;
  opacity: 0;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(16px);
  padding: 10px 18px;
  background: #141824;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.error {
  border-color: #7f2b2b;
  color: #ff9b9b;
}
.toast.success {
  border-color: #2a5f3d;
  color: #9fe0b8;
}

/* ---------- 响应式 ---------- */
@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr 260px;
  }
  .preview-pane {
    display: none;
  }
  .topbar-actions {
    width: 100%;
  }
}
@media (max-width: 780px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .panel {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: 280px;
    transform: translateX(100%);
    transition: transform 0.25s;
    z-index: 20;
  }
  .panel.open {
    transform: translateX(0);
  }
  .hud-hint {
    display: none;
  }
}