:root {
  --bg: #0f1420;
  --panel: #171e2e;
  --panel2: #1e2740;
  --border: #2a3654;
  --text: #e6ebf5;
  --muted: #8a97b3;
  --accent: #4f8cff;
  --accent2: #36d399;
  --danger: #ff6b6b;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 28px; color: var(--accent); }
.topbar h1 { font-size: 18px; margin: 0; }
.sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.status {
  font-size: 13px; color: var(--muted);
  background: var(--panel2); padding: 4px 10px; border-radius: 6px;
  border: 1px solid var(--border); margin-left: auto;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60%;
}
.layout {
  flex: 1; display: grid; grid-template-columns: 340px 1fr; gap: 1px;
  background: var(--border); min-height: 0;
}
.panel { background: var(--panel); min-height: 0; }
.panel.config { display: flex; flex-direction: column; padding: 14px; overflow: auto; gap: 6px; }
.panel.output { display: flex; flex-direction: column; padding: 0; min-height: 0; }

/* 顶部工具栏 */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-left: 20px; }
.tlabel { font-size: 12px; color: var(--muted); }
.toolbar select#preset {
  width: 260px; padding: 8px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--panel2); color: var(--text); font-size: 13px;
}
.tbtn {
  padding: 8px 14px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--panel2); color: var(--text); cursor: pointer; font-size: 13px; white-space: nowrap;
}
.tbtn:hover { border-color: var(--accent); }
.tbtn.primary { background: linear-gradient(90deg, var(--accent), #6f6bff); color: #fff; border: none; }
.tbtn.ghost { background: transparent; }
.badge {
  font-size: 12px; color: var(--accent2); background: rgba(54, 211, 153, .12);
  border: 1px solid rgba(54, 211, 153, .3); padding: 4px 10px; border-radius: 20px; white-space: nowrap;
}
.badge.code { color: var(--accent); background: rgba(79, 140, 255, .12); border-color: rgba(79, 140, 255, .35); }
.badge.ok { color: var(--accent2); background: rgba(54, 211, 153, .12); border-color: rgba(54, 211, 153, .4); }
.badge.err { color: var(--danger); background: rgba(255, 107, 107, .12); border-color: rgba(255, 107, 107, .4); }
.spacer { flex: 1; }

/* 顶部运行按钮 */
.runbtn.top { width: auto; margin: 0; padding: 10px 24px; }
.config label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; }
.config input, .config select, .config textarea {
  width: 100%; padding: 8px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--panel2); color: var(--text);
  font-size: 13px;
}
.config textarea { height: 200px; resize: vertical; font-family: "JetBrains Mono", Consolas, monospace; }
.hint { font-size: 11px; color: var(--muted); margin: 4px 0 0; }
.tabs { display: flex; gap: 8px; }
.tab {
  flex: 1; padding: 8px; border: 1px solid var(--border); background: var(--panel2);
  color: var(--muted); border-radius: 6px; cursor: pointer; font-size: 13px;
}
.tab.active { color: #fff; border-color: var(--accent); background: #1b2a4a; }
hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.checks { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.chk { font-size: 13px; color: var(--text); display: inline-flex; align-items: center; gap: 8px; }
.modal-body .chk input { width: auto; }
.param { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11px; margin-left: 6px; opacity: .85; }
.runbtn {
  width: 250px; margin-top: 14px; align-self: center; padding: 12px; font-size: 15px; font-weight: 600;
  color: #fff; background: linear-gradient(90deg, var(--accent), #6f6bff);
  border: none; border-radius: 8px; cursor: pointer;
}
.runbtn:hover { filter: brightness(1.08); }
.output { display: flex; flex-direction: column; padding: 0; }
.out-head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; font-size: 13px; color: var(--muted);
  border-bottom: 1px solid var(--border); background: var(--panel2);
}
.out-title { color: var(--text); font-weight: 600; }
.console {
  flex: 1; margin: 0; padding: 16px; overflow: auto;
  font-family: "JetBrains Mono", Consolas, monospace; font-size: 13px;
  line-height: 1.5; white-space: pre-wrap; word-break: break-word; color: #cfe3ff;
}

/* 右侧输出区：上=程序运行结果，下=调试（可拖拽分隔条调整上下高度） */
.panel.output { padding: 0; }
.out-top {
  flex: 0 0 auto;            /* 高度由分隔条拖拽控制（JS 设置 px） */
  display: flex; flex-direction: column; min-height: 0;
  overflow: hidden;
}
.out-top .console { flex: 1; }
.out-bottom {
  flex: 1 1 0;               /* 占据剩余空间 */
  display: flex; flex-direction: column; min-height: 0;
}

/* 可拖拽分隔条 */
.out-splitter {
  flex: 0 0 10px; height: 10px; cursor: row-resize; position: relative;
  background: var(--panel2);
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  transition: background .15s;
}
.out-splitter::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 36px; height: 3px; transform: translate(-50%, -50%);
  border-radius: 2px; background: var(--border);
  box-shadow: 0 -4px 0 var(--border), 0 4px 0 var(--border);
}
.out-splitter:hover, .out-splitter.dragging {
  background: var(--accent);
}
.out-splitter:hover::after, .out-splitter.dragging::after {
  background: #fff; box-shadow: 0 -4px 0 #fff, 0 4px 0 #fff;
}
.dbg-body {
  flex: 1; min-height: 0; overflow: auto; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.foot { padding: 8px 20px; font-size: 11px; color: var(--muted); background: var(--panel); border-top: 1px solid var(--border); }

/* 模态子页面 */
.modal { position: fixed; inset: 0; background: rgba(5, 8, 15, .72); display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; z-index: 50; overflow: auto; }
/* 三级子窗口（解读说明）必须盖在二级结果窗之上 */
#helpModal { z-index: 60; }
.modal[hidden] { display: none; }
.modal-card { width: min(780px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); display: flex; flex-direction: column; max-height: 88vh; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 16px; margin: 0; }
.modal-x { background: transparent; border: none; color: var(--muted); font-size: 18px; cursor: pointer; line-height: 1; }
.modal-x:hover { color: var(--text); }
.modal-body { padding: 20px; overflow: auto; }
.modal-body label:not(.chk) { display: block; font-size: 13px; color: var(--text); margin: 12px 0 4px; }
.modal-body input, .modal-body select, .modal-body textarea {
  width: 100%; padding: 8px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--panel2); color: var(--text); font-size: 13px;
}
.modal-body textarea { resize: vertical; font-family: "JetBrains Mono", Consolas, monospace; }
#code { height: 320px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }

/* ===== 左侧设置区 ===== */
.brand { padding: 4px 2px 8px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.brand .logo { font-size: 24px; }
.brand h1 { font-size: 15px; }
.brand .sub { font-size: 11px; }
.grp { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.grp-title { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 4px 0 2px 40px; }
.lbtn {
  width: 250px; align-self: center; text-align: center; padding: 11px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel2); color: var(--text);
  cursor: pointer; font-size: 14px; transition: border-color .15s, background .15s;
}
.lbtn:hover { border-color: var(--accent); background: #1b2742; }
.lbtn:active { transform: translateY(1px); }
.badge {
  margin-top: 4px; font-size: 12px; color: var(--accent2);
  background: rgba(54, 211, 153, .12); border: 1px solid rgba(54, 211, 153, .3);
  padding: 6px 10px; border-radius: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.badge.code { color: var(--accent); background: rgba(79, 140, 255, .12); border-color: rgba(79, 140, 255, .35); }
.badge.elf { color: #f5b942; background: rgba(245, 185, 66, .12); border-color: rgba(245, 185, 66, .35); }
.badge.ok { color: var(--accent2); background: rgba(54, 211, 153, .12); border-color: rgba(54, 211, 153, .4); }
.badge.err { color: var(--danger); background: rgba(255, 107, 107, .12); border-color: rgba(255, 107, 107, .4); }
.spacer { flex: 1; min-height: 8px; }

/* 配置子窗口：高级参数全部展开，无折叠、无方框 */
.adv-grp { margin: 6px 0; }
.adv-legend {
  font-size: 13px; color: var(--text); font-weight: 600;
  margin: 18px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border);
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* 拖拽上传区 */
.dropzone {
  border: 2px dashed var(--border); border-radius: 10px; padding: 28px 12px; text-align: center;
  color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s; font-size: 13px;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone.over { border-color: var(--accent2); background: rgba(54, 211, 153, .08); color: var(--text); }

/* 分析结果（图表）渲染 */
.modal-card.wide { width: min(960px, 100%); }
.chart-title { font-size: 13px; color: var(--text); margin: 16px 0 8px; font-weight: 600; }
.empty { color: var(--muted); text-align: center; padding: 28px 10px; font-size: 14px; }
.report { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; max-height: 50vh; overflow: auto; font-family: "JetBrains Mono", Consolas, monospace; font-size: 12px; color: #cfe3ff; white-space: pre-wrap; word-break: break-word; }

/* 条形图（覆盖率 / 热点） */
.bar-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; font-size: 12px; }
.bar-label { width: 110px; color: var(--muted); text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { flex: 1; height: 16px; background: var(--bg); border-radius: 4px; overflow: hidden; border: 1px solid var(--border); }
.bar-fill { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #6f6bff); }
.bar-fill.csr-r { background: linear-gradient(90deg, #3b82f6, #60a5fa); }
.bar-fill.csr-w { background: linear-gradient(90deg, #ef4444, #f87171); }
.bar-val { width: 56px; text-align: right; color: var(--text); }
.chart-note { font-size: 12px; color: var(--muted); margin: 8px 0 4px; }

/* 火焰图（icicle） */
.flame-level { display: flex; gap: 2px; margin: 2px 0; }
.flame-cell { display: flex; flex-direction: column; min-width: 0; }
.flame-box {
  background: linear-gradient(90deg, #f6a, #f84); color: #1a1206; border-radius: 4px;
  padding: 5px 8px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border: 1px solid rgba(0,0,0,.2);
}
.flame-box b { font-weight: 700; }
.ftab { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 12px; }
.ftab th, .ftab td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.ftab th { color: var(--muted); font-weight: 600; }
.ftab td { color: var(--text); }

/* 功耗汇总卡片 */
.power-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 10px 0 16px; }
.ps-card { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 14px 12px; text-align: center; }
.ps-label { font-size: 11px; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .3px; }
.ps-val { font-size: 22px; font-weight: 700; color: var(--accent); }
.ps-unit { font-size: 11px; color: var(--muted); font-weight: 400; }

/* 解读说明（三级子窗口） */
.help-h { font-size: 14px; margin: 0 0 10px; color: var(--accent); }
.help-grid { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 6px 0; font-size: 13px; line-height: 1.65; }
.help-k { font-weight: 600; color: var(--muted); white-space: nowrap; vertical-align: top; }
.help-v { color: var(--text); }
.help-v b { color: var(--accent2); }
.help-eg { margin-top: 10px; padding: 10px 12px; background: var(--panel2); border-left: 3px solid var(--accent); border-radius: 4px; font-size: 13px; line-height: 1.7; color: var(--text); }
.help-eg b { color: var(--accent2); }
.help-eg code { background: rgba(79,140,255,.15); padding: 1px 4px; border-radius: 3px; font-size: 12px; }
.ab-p { font-size: 13px; line-height: 1.7; color: var(--text); margin: 0 0 12px; }

/* ===== 在线 GDB 调试终端 ===== */
.gdb-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.gdb-actions .tbtn { flex: 1; min-width: 104px; }
.gdb-regs {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; flex: 1 1 0; min-height: 0; overflow: auto;
}
.gdb-regs .reg-group { font-size: 12px; color: var(--muted); margin: 8px 0 4px; font-weight: 600; }
.gdb-regs .reg-group:first-child { margin-top: 0; }
.gdb-regs .reg-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px 12px; }
.gdb-regs .reg-item { font-family: "JetBrains Mono", Consolas, monospace; font-size: 12px; white-space: nowrap; }
.gdb-regs .reg-item .rn { color: var(--accent); }
.gdb-regs .reg-item .rv { color: #cfe3ff; }
/* 单步后值发生变化的寄存器高亮为红色 */
.gdb-regs .reg-item.changed .rn,
.gdb-regs .reg-item.changed .rv { color: var(--danger); }
.gdb-regs .reg-item.changed .rv { font-weight: 600; }

/* 调试控件未连接时置灰（初始状态；连接成功后由 app.js 移除 disabled） */
.gdb-actions .tbtn:disabled,
.gdb-cmdline input:disabled,
.gdb-cmdline button:disabled {
  opacity: .4; cursor: not-allowed; filter: grayscale(.45); pointer-events: none;
}
/* 调试进行中：左侧设置区所有按钮置灰，禁止交叉操作（断开后由 app.js 恢复） */
.panel.config button:disabled {
  opacity: .4; cursor: not-allowed; filter: grayscale(.5); pointer-events: none;
}
/* 调试日志复用顶部 #out（.console）控制台；行内着色 */
.console .line-err { color: var(--danger); }
.console .line-ok { color: var(--accent2); }
.console .line-sys { color: var(--muted); }
.console .line-asm { color: #7dd3fc; font-weight: 600; }
.gdb-cmdline { display: flex; gap: 8px; flex: 0 0 auto; }
.gdb-cmdline input { flex: 1; }
