:root {
  --ink: #17211f;
  --muted: #6b7772;
  --line: #d8dfda;
  --paper: #f5f7f2;
  --panel: #ffffff;
  --lime: #c9f36a;
  --coral: #ff765f;
  --teal: #176c65;
  --shadow: 0 18px 45px rgba(23, 33, 31, .09);
  font-family: "Avenir Next", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: radial-gradient(circle at 8% 0%, #e4f0d4, transparent 34%), var(--paper); }
button, input, select { font: inherit; }
button { cursor: pointer; }
.shell { width: min(1380px, calc(100% - 40px)); margin: 0 auto; padding: 42px 0 56px; }
.topbar { display: flex; justify-content: space-between; gap: 32px; align-items: end; margin-bottom: 34px; }
.eyebrow { margin: 0 0 8px; color: var(--teal); font: 700 11px/1.2 "Courier New", monospace; letter-spacing: 1.5px; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 10px; font: 700 clamp(32px, 5vw, 64px)/.95 Georgia, serif; letter-spacing: 0; }
h2 { margin: 0; font: 700 25px/1 Georgia, serif; }
.subhead { max-width: 560px; margin: 0; color: var(--muted); font-size: 16px; }
.connection { display: flex; align-items: center; gap: 10px; white-space: nowrap; color: var(--muted); font-size: 13px; }
.topbar-right { display: flex; flex-direction: column; align-items: flex-end; gap: 12px; }
.lang-toggle {
  min-height: 30px; padding: 0 16px; border: 1px solid var(--line); border-radius: 20px;
  background: transparent; color: var(--muted); font: 700 11px/1 "Courier New", monospace;
  letter-spacing: 1.2px; text-transform: uppercase; cursor: pointer;
  transition: color .18s, border-color .18s, background .18s;
}
.lang-toggle:hover { color: var(--teal); border-color: var(--teal); background: #fff; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: #aab4ae; }
.status-dot.connected { background: #48a943; box-shadow: 0 0 0 5px #dff1d9; }
.button { border: 0; border-radius: 5px; min-height: 42px; padding: 0 16px; font-weight: 700; white-space: nowrap; transition: transform .18s, box-shadow .18s, background .18s; }
.button:hover { transform: translateY(-2px); box-shadow: 0 8px 16px rgba(23,33,31,.12); }
.button-primary { margin-left: 8px; background: var(--ink); color: white; }
.button-dark { background: var(--ink); color: white; }
.button-accent { background: var(--lime); color: var(--ink); }
.button-quiet { background: #edf1ec; color: var(--ink); }
.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.metric { min-height: 105px; padding: 20px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); }
.metric span { display: block; color: var(--muted); font-size: 13px; }
.metric strong { display: block; margin-top: 14px; font: 700 30px/1 Georgia, serif; }
.workspace { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); gap: 18px; }
.panel { background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); }
.actions-panel, .trace-panel { min-height: 580px; padding: 26px; }
.panel-heading { display: flex; justify-content: space-between; gap: 16px; align-items: start; }
.subsection-heading { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); }
.subsection-heading h3 { margin: 0; font: 700 18px/1 Georgia, serif; }
.helper { margin: 18px 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.actions-list { display: grid; gap: 10px; max-height: 375px; overflow: auto; padding-right: 3px; }
.action-row { display: grid; grid-template-columns: 36px 1.1fr .9fr .9fr 1fr 1fr 34px; gap: 7px; align-items: center; padding: 9px; background: #f3f6f0; border-left: 3px solid var(--lime); }
.action-row input, .action-row select, .trace-controls input { width: 100%; min-width: 0; height: 36px; padding: 0 8px; border: 1px solid var(--line); border-radius: 3px; background: white; color: var(--ink); }
.action-row input:disabled, .action-row select:disabled { opacity: .4; background: #eef1ec; cursor: not-allowed; }
.action-index { color: var(--muted); font: 700 12px "Courier New", monospace; text-align: center; }
.remove-action { width: 30px; height: 30px; padding: 0; border: 0; border-radius: 3px; background: #ffe4dd; color: #a43c2d; font-size: 18px; }
.panel-footer, .trace-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.panel-footer .button:first-child { margin-right: auto; }
.pill { padding: 7px 10px; border-radius: 30px; background: #edf1ec; color: var(--muted); font: 700 11px "Courier New", monospace; text-transform: uppercase; }
.canvas-wrap { position: relative; overflow: hidden; border: 1px solid var(--line); background: #f8faf6; }
canvas { display: block; width: 100%; height: auto; aspect-ratio: 12 / 7; touch-action: none; cursor: crosshair; }
.canvas-hint { position: absolute; right: 12px; bottom: 10px; color: #9ca8a0; font: 11px "Courier New", monospace; pointer-events: none; }
.trace-controls label { display: flex; align-items: center; gap: 7px; margin-right: auto; color: var(--muted); font-size: 13px; }
.trace-controls input { width: 80px; }
.console { margin-top: 18px; padding: 22px 26px; }
.console pre { height: 100px; overflow: auto; margin: 16px 0 0; padding: 12px; background: #17211f; color: #c9f36a; font: 12px/1.5 "Courier New", monospace; white-space: pre-wrap; }
.empty { padding: 34px 12px; border: 1px dashed var(--line); color: var(--muted); text-align: center; font-size: 13px; }
@media (max-width: 900px) { .topbar { align-items: start; flex-direction: column; } .topbar-right { width: 100%; } .connection { width: 100%; justify-content: space-between; } .summary-grid { grid-template-columns: repeat(2, 1fr); } .workspace { grid-template-columns: 1fr; } }
@media (max-width: 620px) { .shell { width: min(100% - 24px, 1380px); padding-top: 26px; } .summary-grid { gap: 8px; } .metric { min-height: 88px; padding: 14px; } .metric strong { margin-top: 10px; font-size: 24px; } .actions-panel, .trace-panel, .console { padding: 18px; } .action-row { grid-template-columns: 25px 1fr 1fr 1fr; } .action-row input:nth-of-type(3), .action-row input:nth-of-type(4), .action-row select, .remove-action { grid-column: span 1; } .action-row input:nth-of-type(3), .action-row input:nth-of-type(4) { grid-row: 2; } .remove-action { grid-row: 1; grid-column: 4; justify-self: end; } .trace-controls { align-items: stretch; } .trace-controls label { width: 100%; } .trace-controls .button { flex: 1; } }
/* ============ 组合键动作行 (Pedal actions) ============ */
.key-row { display: flex; flex-direction: column; gap: 9px; padding: 10px; background: #f3f6f0; border-left: 3px solid var(--lime); }
.key-top { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.mod-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.mod-chip { min-height: 32px; padding: 0 11px; border: 1px solid var(--line); border-radius: 4px; background: #fff; color: var(--muted); font: 700 11px/1 "Courier New", monospace; cursor: pointer; }
.mod-chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.key-slots { display: flex; flex-wrap: wrap; gap: 6px; }
.key-slot { width: 92px; height: 34px; padding: 0 6px; border: 1px solid var(--line); border-radius: 3px; background: #fff; color: var(--ink); }
.capture-btn { min-height: 36px; padding: 0 12px; border: 0; border-radius: 4px; background: var(--teal); color: #fff; font-weight: 700; }
.capture-btn.listening { background: var(--coral); }
.key-bottom { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding-top: 8px; border-top: 1px dashed var(--line); }
.key-bottom label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.key-bottom select { width: 104px; height: 32px; padding: 0 8px; border: 1px solid var(--line); border-radius: 3px; background: #fff; color: var(--ink); }
.key-bottom input { width: 70px; height: 32px; padding: 0 8px; border: 1px solid var(--line); border-radius: 3px; background: #fff; color: var(--ink); }
.key-bottom input:disabled { opacity: .4; background: #eef1ec; cursor: not-allowed; }
/* ---- 鼠标按钮行 / 默认行 / 时间解释 ---- */
.mouse-chip.active { background: var(--teal); color: #fff; border-color: var(--teal); }
.base-row { border-left-color: #d8c36a; }
.base-badge { padding: 6px 11px; border-radius: 30px; background: #e8f1ec; color: var(--teal); font: 700 11px/1 "Courier New", monospace; text-transform: uppercase; }
.base-note { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.restore-base { width: 100%; margin-top: 4px; }
.sync-hint { margin: 0 0 6px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.key-bottom .time-field { margin-right: 2px; }
.timing-note { flex: 1 1 100%; color: var(--coral); font-size: 11px; line-height: 1.4; }


.trace-tools { justify-content: space-between; }
.trace-tools label { margin-right: auto; }
/* ---- 缩放：紧凑参数框 ---- */
.scale-form { display: flex; flex-wrap: wrap; gap: 8px 22px; align-items: center; }
.scale-field { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; }

.scale-field input { width: 84px; height: 36px; padding: 0 8px; border: 1px solid var(--line); border-radius: 3px; background: #fff; color: var(--ink); }
.scale-field.res input { width: 70px; }
.scale-ops { margin-top: 2px; }
.scale-ops { align-items: center; justify-content: space-between; }
.scale-ops > .scale-field { margin-right: auto; }
.scale-k { margin: 6px 0 0; color: var(--teal); font: 13px/1.4 "Courier New", monospace; }
.scale-pane .seg-summary { margin: 8px 0 0; }
#scaleToggleButton.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.scale-field { white-space: nowrap; flex: 0 0 auto; }
.scale-field input { flex: 0 0 auto; }
.scale-form { column-gap: 18px; row-gap: 8px; }


.scale-field select { height: 36px; padding: 0 6px; border: 1px solid var(--line); border-radius: 3px; background: #fff; color: var(--ink); }
.scale-field.res { align-items: center; }
.res-custom { display: inline-flex; gap: 6px; align-items: center; }
.res-custom[hidden] { display: none; }
.res-custom input { width: 70px; }

.scale-pane details.scale-fold { margin-top: 10px; }
.scale-pane details.scale-fold summary { cursor: pointer; color: var(--teal); font: 700 13px/1.4 Georgia, serif; }
.scale-pane details.scale-fold[open] summary { margin-bottom: 8px; }
.scale-pane details.scale-fold .scale-form { margin-top: 8px; }
.scale-pane details.scale-fold .scale-k { margin: 8px 0 0; }

.scale-pane > details.scale-fold { margin-top: 0; }
.scale-pane .scale-ops { margin-top: 12px; }

/* 层级区分：参数配置折叠内容=浅色子卡片(缩进+左teal条)；常显计算区用分隔线作为外层 */
.scale-pane > .param-box {
  margin: 0 0 6px;
  padding: 12px;
  background: #f2f6f0;
  border: 1px solid var(--line);
  border-left: 3px solid var(--teal);
  border-radius: 6px;
}
.param-group + .param-group { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); }
.param-group-title { margin: 0 0 4px; color: var(--muted); font: 700 11px/1.4 "Courier New", monospace; text-transform: uppercase; letter-spacing: .5px; }
.param-help { margin: 0 0 8px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.param-group .scale-form { margin: 0; }
.scale-pane > .scale-ops {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.help-ico { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; border-radius: 50%; background: #dfe7df; color: var(--teal); font: 700 10px/1 "Courier New", monospace; cursor: help; flex: 0 0 auto; }
.help-ico:hover { background: var(--teal); color: #fff; }

/* 幅度行：常显，置于画布工具行与操作之间 */
.amp-row { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.amp-row .scale-field { margin-right: auto; }
.grid-bar { margin-top: 10px; padding-top: 0; border-top: 0; }
.grid-bar .scale-field { margin-right: auto; }

/* ---- 语言切换时按钮位置稳定：右对齐 + 固定按钮宽度，避免文本长度变化导致按钮左右移动 ---- */
.trace-panel > .trace-controls:last-of-type { justify-content: flex-end; }  /* 仅按钮行：整组贴右 */
#clearTraceButton, #uploadTraceButton { min-width: 140px; white-space: nowrap; }    /* 清除/上传按钮等宽 */
/* 顶栏连接区固定宽度，切换语言不位移 */
#statusText { display: inline-block; min-width: 100px; text-align: center; }
#connectButton, #bleConnectButton { min-width: 124px; }
@media (max-width: 620px) {
  .button { white-space: normal; }                   /* 移动端窄屏允许换行，避免溢出 */
  #statusText, #connectButton, #bleConnectButton,
  #clearTraceButton, #uploadTraceButton { min-width: 0; white-space: normal; }  /* 移动端恢复自适应 */
}
