:root {
  --bg: #0a0d13;
  --bg2: #0f131b;
  --panel: #11151d;
  --line: #232a36;
  --line2: #2f3949;
  --text: #e7edf6;
  --dim: #8b98ab;
  --dim2: #5e6b7e;
  --accent: #f5b942;
  --accent2: #22d3ee;
  --danger: #ef4444;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  height: 54px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: linear-gradient(180deg, #12171f, #0d1117);
  border-bottom: 1px solid var(--line);
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 8px; }
.brand .logo { color: var(--accent); font-size: 18px; }
.brand b { font-size: 15px; letter-spacing: .3px; }
.brand .sub { color: var(--dim2); font-size: 12px; }

.actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.divider { width: 1px; height: 20px; background: var(--line2); margin: 0 4px; }

/* ---------------- 按钮 ---------------- */
.btn {
  appearance: none;
  border: 1px solid var(--line2);
  background: #171d26;
  color: var(--text);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: .15s;
  white-space: nowrap;
}
.btn:hover { background: #1e2733; border-color: #3b4759; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a1205; font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: #ffb4b4; border-color: #4a2226; }
.btn.danger:hover { background: #2a1417; }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn.wide { width: 100%; margin-top: 8px; }
.btn.select { padding: 6px 8px; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------------- 布局 ---------------- */
.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 372px;
}

/* ---------------- 舞台 ---------------- */
.stage {
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 600px at 50% 0%, #131a24 0%, #0a0d13 70%);
}

.stage-inner {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  position: relative;
}

canvas#view {
  display: block;
  border-radius: 4px;
  box-shadow: 0 18px 60px rgba(0,0,0,.55), 0 0 0 1px rgba(255,255,255,.06);
  cursor: crosshair;
  touch-action: none;
}

.empty {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--dim);
}
.empty.show { display: flex; }
.empty-icon { font-size: 40px; opacity: .5; }
.empty p { margin: 0; }

kbd {
  border: 1px solid var(--line2);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 5px;
  font: 11px ui-monospace, monospace;
  color: var(--dim);
  background: #0d1117;
}

.statusbar {
  flex: 0 0 auto;
  height: 30px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  border-top: 1px solid var(--line);
  color: var(--dim2);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  background: #0b0e14;
}
.statusbar b { color: var(--dim); font-weight: 500; }

/* ---------------- 侧栏 ---------------- */
.panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
}

.tabs { display: flex; flex: 0 0 auto; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--dim);
  padding: 11px 0;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.panel-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.pane { display: none; padding: 14px; }
.pane.active { display: block; }

/* ---------------- 表单 ---------------- */
.group {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px 12px;
  margin-bottom: 12px;
  background: #0d1117;
}
.group h4 {
  margin: 2px 0 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--dim);
  letter-spacing: .5px;
  text-transform: uppercase;
}

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
  font-size: 13px;
  color: var(--dim);
}
.field > span { flex: 0 0 84px; }
.field > span b { color: var(--text); font-weight: 500; font-variant-numeric: tabular-nums; }
.field.inline { justify-content: space-between; }
/* 开关类长标签不换行，勾选框靠右 */
.field.inline > span { flex: 0 0 auto; white-space: nowrap; }
.field:last-child { margin-bottom: 0; }

input[type="number"], input[type="text"], select {
  flex: 1 1 auto;
  min-width: 0;
  background: #0a0e14;
  border: 1px solid var(--line2);
  border-radius: 7px;
  color: var(--text);
  padding: 6px 8px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
input[type="number"]:focus, input[type="text"]:focus, select:focus { border-color: var(--accent); }

/* 数字框按内容收窄（不拉满整行），数值右对齐便于比较 */
input[type="number"] {
  flex: 0 1 84px;
  min-width: 60px;
  max-width: 84px;
  text-align: right;
  padding-right: 6px;
  font-variant-numeric: tabular-nums;
}

input[type="color"] {
  width: 42px;
  height: 28px;
  padding: 2px;
  border: 1px solid var(--line2);
  border-radius: 7px;
  background: #0a0e14;
  cursor: pointer;
}

input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: var(--accent);
  height: 18px;
}

input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid2 .field > span { flex: 0 0 auto; white-space: nowrap; }

.row { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }

.hint { color: var(--dim2); font-size: 12px; margin: 8px 0; line-height: 1.6; }
.hint code {
  background: #0a0e14;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 4px;
  font: 11px ui-monospace, monospace;
}
.err { color: #ff9b9b; font-size: 12px; margin: 8px 0 0; white-space: pre-wrap; font-family: ui-monospace, monospace; }

/* ---------------- 区域列表 ---------------- */
.area-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  max-height: 34vh;
  overflow: auto;
}

.area-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: .12s;
  font-size: 13px;
}
.area-item:hover { background: #151b24; }
.area-item.active { background: #1b2430; border-color: var(--accent); }
.area-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: 0 0 auto; }
.area-item .nm { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.area-item .tag { font-size: 11px; color: var(--dim2); font-variant-numeric: tabular-nums; }
.area-item .x {
  border: 0; background: transparent; color: var(--dim2);
  cursor: pointer; font-size: 14px; line-height: 1; padding: 2px 4px; border-radius: 4px;
}
.area-item .x:hover { color: #ff9b9b; background: #2a1417; }
.area-empty { color: var(--dim2); font-size: 12px; padding: 10px 4px; line-height: 1.7; }

/* ---------------- 配置 ---------------- */
textarea#json {
  width: 100%;
  height: 42vh;
  min-height: 220px;
  resize: vertical;
  background: #080b10;
  color: #cfe3ff;
  border: 1px solid var(--line2);
  border-radius: 8px;
  padding: 10px;
  font: 12px/1.55 ui-monospace, "SFMono-Regular", Consolas, monospace;
  outline: none;
  tab-size: 2;
}
textarea#json:focus { border-color: var(--accent); }
textarea#json.bad { border-color: var(--danger); }

details.doc { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
details.doc summary { cursor: pointer; color: var(--dim); font-size: 12px; }
details.doc pre {
  background: #080b10;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  overflow: auto;
  font: 11px/1.5 ui-monospace, monospace;
  color: #9fb4cf;
  max-height: 340px;
}

/* ---------------- toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translate(-50%, 20px);
  background: #1b2430;
  border: 1px solid var(--line2);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 9px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: .2s;
  z-index: 99;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- 全屏预览模式 ---------------- */
body.raw .topbar, body.raw .panel, body.raw .statusbar { display: none; }
body.raw .workspace { grid-template-columns: 1fr; }
body.raw .stage { background: #fff; }
body.raw .stage-inner { padding: 0; }
body.raw canvas#view { border-radius: 0; box-shadow: none; }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: minmax(0, 1fr) 320px; }
  .brand .sub { display: none; }
}
