:root,
[data-theme="dark"] {
  --bg: #0b0e16;
  --bg2: #0d1320;
  --panel: rgba(255, 255, 255, 0.04);
  --panel-solid: #111726;
  --border: rgba(255, 255, 255, 0.09);
  --text: #e8eaf0;
  --muted: #9aa3b2;
  --accent: #5b8cff;
  --accent2: #22d3a6;
  --shadow: rgba(91, 140, 255, 0.25);
}

[data-theme="light"] {
  --bg: #f4f6fb;
  --bg2: #ffffff;
  --panel: rgba(15, 23, 42, 0.03);
  --panel-solid: #ffffff;
  --border: rgba(15, 23, 42, 0.10);
  --text: #1f2733;
  --muted: #64748b;
  --accent: #3b6cf6;
  --accent2: #12a583;
  --shadow: rgba(59, 108, 246, 0.20);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }

body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(91,140,255,0.18) 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(34,211,166,0.14) 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100%;
  transition: background-color .3s ease, color .3s ease;
}

/* 顶栏 */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 22px; border-bottom: 1px solid var(--border);
  background: var(--panel); flex: none;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
}
.brand h1 { font-size: 16px; margin: 0; letter-spacing: .4px; }
.badge {
  font-size: 11px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px;
}
.spacer { flex: 1; }

/* 顶栏中间视觉风格选择器 */
.skin-pick { position: relative; margin: 0 auto; }

/* 主题切换 */
.theme { display: flex; gap: 4px; background: var(--panel-solid); border: 1px solid var(--border); border-radius: 999px; padding: 3px; }
.theme button {
  cursor: pointer; border: none; background: transparent; color: var(--muted);
  font-size: 12px; padding: 5px 11px; border-radius: 999px; transition: all .2s;
}
.theme button.active { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; }

/* 顶栏视觉风格选择器 */
.skin-toggle {
  cursor: pointer; border: 1px solid var(--border); background: var(--panel-solid);
  color: var(--text); font-size: 12px; padding: 6px 12px; border-radius: 999px;
  display: none; align-items: center; gap: 6px; transition: all .2s;
}
.skin-toggle:hover { border-color: var(--accent); }
.skin-toggle .caret { font-size: 10px; opacity: .7; }

/* 桌面：直接横着摊开 */
.skin-row {
  display: flex; flex-wrap: nowrap; gap: 6px; align-items: center;
  max-width: 64vw; overflow-x: auto; scrollbar-width: thin;
}
.skin-row .skin { min-width: 52px; padding: 7px 4px; font-size: 11px; flex: none; }

/* 移动 / 窄屏：收成弹出式 */
body.is-mobile .skin-toggle { display: inline-flex; }
body.is-mobile .skin-row {
  position: absolute; left: 50%; top: calc(100% + 10px); z-index: 60;
  width: min(296px, 86vw); padding: 14px; border-radius: 16px;
  background: var(--panel-solid); border: 1px solid var(--border);
  box-shadow: 0 18px 50px var(--shadow);
  display: none; flex-wrap: wrap; overflow: visible;
  transform: translateX(-50%);
  animation: skinPopIn .18s cubic-bezier(.16,1,.3,1);
}
body.is-mobile .skin-pick.open .skin-row { display: flex; }
body.is-mobile .skin-row .skin { min-width: 0; flex: 1 1 28%; }
@keyframes skinPopIn { from { opacity: 0; transform: translateX(-50%) translateY(-6px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }


/* 主体布局：左品种 / 中预览 / 右数据 */
.layout { flex: 1; display: flex; min-height: 0; }
.side {
  width: 250px; flex: none; padding: 20px;
  border-right: 1px solid var(--border); background: var(--panel);
  display: flex; flex-direction: column; gap: 18px; overflow-y: auto;
}
.panel-right {
  width: 400px; flex: none; padding: 22px;
  border-left: 1px solid var(--border); background: var(--panel);
  display: flex; flex-direction: column; gap: 16px; overflow-y: auto;
}
.data-block { display: flex; flex-direction: column; }
label.field { font-size: 12px; color: var(--muted); display: block; margin-bottom: 6px; }
.tpl-search {
  width: 100%; box-sizing: border-box; margin: 0 0 12px; padding: 9px 12px;
  font-size: 13px; border: 1px solid var(--border); border-radius: 10px;
  background: rgba(127,127,127,0.05); color: var(--text); outline: none;
}
.tpl-search:focus { border-color: var(--accent, #5b8cff); box-shadow: 0 0 0 3px rgba(91,140,255,0.18); }
.tpl-group { margin-bottom: 14px; }
.tpl-group-title {
  font-size: 11px; letter-spacing: .04em; color: var(--muted); text-transform: none;
  margin: 0 0 7px 2px; font-weight: 600; opacity: .85;
}
.tpl-row { display: flex; gap: 8px; flex-wrap: wrap; }
.tpl {
  flex: 1 1 30%; min-width: 92px; cursor: pointer; padding: 10px 8px; text-align: center;
  font-size: 13px; border: 1px solid var(--border); border-radius: 12px;
  background: rgba(127,127,127,0.04); color: var(--text); transition: all .2s cubic-bezier(.16,1,.3,1);
}
.tpl:hover { transform: translateY(-2px); }
.tpl.active {
  border-color: transparent; color: #fff;
  background: linear-gradient(135deg, rgba(91,140,255,.85), rgba(34,211,166,.85));
  box-shadow: 0 6px 20px var(--shadow);
}
textarea {
  width: 100%; height: 200px; resize: vertical;
  background: var(--bg2); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px; font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px; line-height: 1.5;
}

/* 视觉风格 chips */
.skin {
  cursor: pointer; padding: 9px 4px; text-align: center; min-width: 60px;
  font-size: 12px; border-radius: 12px; color: #fff; border: 1px solid transparent;
  background: linear-gradient(135deg, var(--c1), var(--c2));
  opacity: .5; transition: all .2s cubic-bezier(.16,1,.3,1);
}
.skin:hover { transform: translateY(-2px); opacity: .8; }
.skin.active { opacity: 1; box-shadow: 0 6px 18px var(--shadow); }

/* 标题输入 */
.text-in {
  width: 100%; background: var(--bg2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; font-size: 13px;
}
.text-in:focus { outline: none; border-color: var(--accent); }

/* 编辑器工具栏 */
.editor-tools { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.mini {
  cursor: pointer; border: 1px solid var(--border); background: var(--panel-solid);
  color: var(--muted); font-size: 11px; padding: 6px 10px; border-radius: 999px; transition: all .2s;
}
.mini:hover { color: var(--text); border-color: var(--accent); }

/* 导入拖拽区（显式上传入口） */
.dropzone {
  border: 1.5px dashed var(--border); border-radius: 14px;
  padding: 18px 14px; text-align: center; cursor: pointer;
  background: var(--panel); transition: all .2s cubic-bezier(.16,1,.3,1);
  margin-bottom: 10px;
}
.dropzone:hover { border-color: var(--accent); background: rgba(91,140,255,.07); }
.dropzone.drag { border-color: var(--accent); background: rgba(91,140,255,.14); transform: scale(1.01); }
.dropzone .dz-icon { font-size: 22px; line-height: 1; color: var(--accent); margin-bottom: 5px; }
.dropzone .dz-text strong { font-size: 13px; color: var(--text); }
.dropzone .dz-sub { display: block; margin-top: 3px; }

/* 数据表格 */
.editor { max-height: 420px; overflow: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--bg2); }
table.grid { border-collapse: collapse; width: 100%; font-size: 12px; }
table.grid th, table.grid td { border: 1px solid var(--border); padding: 4px 6px; text-align: center; }
table.grid th.corner, table.grid td:first-child { text-align: left; background: var(--panel); }
table.grid input {
  width: 100%; min-width: 64px; background: transparent; border: 1px solid transparent;
  color: var(--text); border-radius: 6px; padding: 5px 6px; font-size: 12px;
}
table.grid input:focus { outline: none; border-color: var(--accent); background: var(--panel); }
.th-in { display: flex; align-items: center; gap: 4px; }
.th-in input { flex: 1; text-align: center; }
/* 锁定列头（雷达图的「最大值」列不可改名 / 删除） */
.th-fixed { display: inline-block; padding: 5px 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.x {
  cursor: pointer; border: none; background: rgba(255,107,139,.15); color: #ff6b8b;
  border-radius: 6px; width: 22px; height: 22px; font-size: 11px; line-height: 1; transition: background .2s;
}
.x:hover { background: rgba(255,107,139,.32); }
.json-view { margin-top: 8px; }

/* 粘贴弹窗 */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-box { width: min(560px, 92vw); background: var(--panel-solid); border: 1px solid var(--border); border-radius: 16px; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.modal-box h3 { margin: 0 0 6px; font-size: 15px; }
.paste-area { width: 100%; height: 200px; resize: vertical; background: var(--bg2); color: var(--text); border: 1px solid var(--border); border-radius: 12px; padding: 12px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; line-height: 1.5; }
.modal-btns { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; }
.muted-sm { color: var(--muted); font-size: 11px; font-weight: normal; }
.btn {
  cursor: pointer; border: none; border-radius: 12px; padding: 11px 14px;
  font-size: 13px; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, var(--accent), #6f7bff);
  transition: transform .2s cubic-bezier(.16,1,.3,1), box-shadow .2s;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 8px 22px var(--shadow); }
.btn.ghost { background: rgba(127,127,127,0.08); border: 1px solid var(--border); color: var(--text); }
.btn.green { background: linear-gradient(135deg, var(--accent2), #16b88a); }
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.export-group { margin-top: 4px; padding-top: 14px; border-top: 1px dashed var(--border); }
.export-group .btns { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.export-group .btn.ghost { padding: 10px 8px; font-size: 12px; }
.seq-note { margin-top: 10px; line-height: 1.5; }
#status {
  font-size: 12px; color: var(--muted); min-height: 18px;
  padding: 8px 12px; border-radius: 10px; background: var(--panel);
}
.hint { font-size: 11px; color: var(--muted); line-height: 1.6; }

.stage { flex: 1; display: flex; align-items: center; justify-content: center; padding: 28px; min-width: 0; }
#chart {
  width: min(880px, 100%); height: 520px;
  border: 1px solid var(--border); border-radius: 18px; background: var(--panel);
}

/* 嵌入模式：隐藏左右栏，只留图表，撑满 iframe */
body.embed { background: transparent; }
body.embed .topbar, body.embed .side, body.embed .panel-right { display: none; }
body.embed .layout { display: block; }
body.embed .stage { padding: 0; height: 100vh; }
body.embed #chart { width: 100%; height: 100%; border: none; border-radius: 0; background: transparent; }

/* 窄屏回退 */
@media (max-width: 1280px) {
  .side { width: 208px; }
  .panel-right { width: 340px; }
}
@media (max-width: 1000px) {
  .topbar { flex-wrap: wrap; row-gap: 10px; justify-content: space-between; }
  .skin-pick { order: 3; width: 100%; margin: 2px 0 0; display: flex; justify-content: center; }
  .layout { flex-direction: column; overflow-y: auto; }
  .side, .panel-right { width: 100%; border: none; border-bottom: 1px solid var(--border); }
  .stage { min-height: 60vh; }
}
@media (max-width: 520px) {
  .topbar { padding: 12px 14px; }
  .brand h1 { font-size: 14px; }
  .badge { display: none; }
  .theme button { padding: 5px 8px; font-size: 11px; }
  .skin-toggle { padding: 5px 10px; font-size: 11px; }
  body.is-mobile .skin-row { width: min(280px, calc(100vw - 28px)); padding: 12px; }
}
