/* Headphone Frequency Lab — 深色为主，克制、无装饰 */
:root {
  --bg: #0b0c10;
  --panel: #111319;
  --panel-2: #15181f;
  --line: #242835;
  --line-soft: #1a1e28;
  --text: #e7e9ef;
  --dim: #969cab;
  --dim2: #6a7182;
  --line-strong: #3c4256;
  --accent: #7aa2f7;
  --accent-soft: #7aa2f722;
  --ok: #7cc47f;
  --warn: #e0b341;
  --radius: 12px;
  --mono: "Cascadia Mono", "Consolas", "SFMono-Regular", ui-monospace, monospace;
  --sans: "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;

  /* 图表专用 */
  --chart-bg: #0f1116;
  --chart-grid: #22262f;
  --chart-grid-minor: #191c23;
  --chart-zero: #3a4052;
  --sw-a: #7aa2f7;
  --sw-b: #ff7b9c;
}

html[data-theme="light"] {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --panel-2: #fafbfd;
  --line: #e2e5ec;
  --line-soft: #eef0f5;
  --text: #16181f;
  --dim: #5c6375;
  --dim2: #8a90a0;
  --line-strong: #c2c8d6;
  --accent: #3f6fd8;
  --accent-soft: #3f6fd815;
  --ok: #2f8a45;
  --warn: #a8760d;

  --chart-bg: #ffffff;
  --chart-grid: #e6eaf2;
  --chart-grid-minor: #f0f2f7;
  --chart-zero: #bfc5d2;
  --sw-a: #3f6fd8;
  --sw-b: #d64570;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; }

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 348px;
  grid-template-rows: auto auto minmax(520px, 1fr) auto;
  gap: 14px 16px;
  max-width: 1720px;
  margin: 0 auto;
  padding: 18px 20px 30px;
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line-soft);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.logo {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--accent);
  background: var(--panel);
  flex: none;
}

.brand-txt { min-width: 0; }

h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--dim2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions { display: flex; gap: 8px; }

/* ---------------- 按钮 ---------------- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 7px 13px;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; }
.btn.icon { padding: 7px 10px; font-size: 15px; line-height: 1; }
.btn.sm { padding: 5px 9px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: default; }

.linkbtn {
  border: 0; background: none; color: var(--dim2);
  font-size: 12px; cursor: pointer; padding: 2px 4px; font-family: inherit;
}
.linkbtn:hover { color: var(--accent); }

/* ---------------- 选择区 ---------------- */
.pickers {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
}

.pick {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  min-width: 0;
}

.pick-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--dim2);
  text-transform: uppercase; letter-spacing: .8px;
}
.pick-label { flex: 1; }

.swatch {
  width: 10px; height: 10px; border-radius: 3px; flex: none;
  background: var(--sw, #888);
}

.combo { position: relative; }

.combo-input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.combo-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.combo-input::placeholder { color: var(--dim2); }

.combo-list {
  position: absolute;
  z-index: 40;
  top: calc(100% + 6px);
  left: 0; right: 0;
  max-height: min(64vh, 560px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong, #3c4256) transparent;
  margin: 0; padding: 4px;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 18px 40px #0009;
}
.combo-list::-webkit-scrollbar { width: 11px; }
.combo-list::-webkit-scrollbar-track { background: transparent; }
.combo-list::-webkit-scrollbar-thumb {
  background: #454c61; border-radius: 8px;
  border: 3px solid transparent; background-clip: padding-box;
}
.combo-list::-webkit-scrollbar-thumb:hover { background: #5a6280; background-clip: padding-box; }
html[data-theme="light"] .combo-list::-webkit-scrollbar-thumb { background: #c6ccd9; background-clip: padding-box; }
html[data-theme="light"] .combo-list::-webkit-scrollbar-thumb:hover { background: #aeb6c7; background-clip: padding-box; }

.combo-list li.more {
  cursor: default;
  color: var(--dim2);
  font-size: 12px;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 10px 5px;
  border-top: 1px solid var(--line-soft);
  margin-top: 4px;
  position: sticky; bottom: -4px;
  background: var(--panel);
}
.combo-list li.more .c-count { display: block; text-align: center; }
.combo-list li.more .c-name { flex: none; }

.combo-list li.more .c-toggle {
  color: var(--accent);
  cursor: pointer;
  border-bottom: 1px dashed currentColor;
  white-space: nowrap;
}
.combo-list li.more .c-toggle:hover { color: var(--text); }

.combo-list li {
  padding: 7px 10px;
  border-radius: 7px;
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.combo-list li .c-name {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.combo-list li .c-sub {
  font-size: 11px; color: var(--dim2);
  font-family: var(--mono); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 210px;
}
.combo-list li:hover { background: var(--panel-2); }
.combo-list li.on { background: var(--panel-2); box-shadow: inset 2px 0 0 var(--accent); }
.combo-list li.empty { color: var(--dim2); cursor: default; }
.combo-list mark { background: transparent; color: var(--accent); font-weight: 600; }

.pick-meta {
  font-size: 12px;
  color: var(--dim2);
  min-height: 18px;
  line-height: 1.5;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}

.chip {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 20px;
  border: 1px solid var(--line);
  color: var(--dim);
  font-family: var(--mono);
  white-space: nowrap;
}
.chip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.chip.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }

.swap {
  align-self: center;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--dim);
  font-size: 16px;
  cursor: pointer;
  transition: .15s;
  flex: none;
}
.swap:hover { color: var(--accent); border-color: var(--accent); transform: rotate(180deg); }

/* ---------------- 图表区 ---------------- */
.stage {
  grid-column: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px 10px;
  flex-wrap: wrap;
  justify-content: space-between;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
}
.tb-main { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; min-width: 0; }
.tb-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
/* 放不下一行时，操作组整体换到下一行并左对齐，避免只剩一个按钮孤零零靠右 */
@media (max-width: 1560px) {
  .toolbar { justify-content: flex-start; }
  .tb-actions { margin-left: 0; }
}

.seg {
  display: inline-flex;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}
.seg button {
  border: 0;
  background: transparent;
  color: var(--dim);
  font-family: inherit;
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
}
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px #0006; }
.seg.small button { padding: 5px 9px; font-size: 12px; }

.chk {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--dim); cursor: pointer; white-space: nowrap;
}
.chk input { accent-color: var(--accent); }

.yrange { display: flex; align-items: center; gap: 6px; }
.num {
  width: 54px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  padding: 5px 7px;
  font-family: var(--mono);
  font-size: 12px;
  text-align: center;
}
.num:disabled { opacity: .4; }
.dash, .unit { color: var(--dim2); font-size: 12px; }

.canvas-wrap {
  position: relative;
  flex: none;
  height: clamp(360px, 56vh, 700px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
#chart { display: block; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }

.empty-hint {
  position: absolute; inset: 0;
  display: grid; place-content: center; text-align: center;
  gap: 4px; pointer-events: none;
}
.empty-hint[hidden] { display: none; }
.empty-hint p { margin: 0; font-size: 14px; color: var(--dim); }
.empty-hint .dim { font-size: 12.5px; color: var(--dim2); }

.tooltip {
  position: absolute;
  pointer-events: none;
  z-index: 20;
  background: color-mix(in srgb, var(--panel) 94%, #000);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.65;
  box-shadow: 0 12px 30px #0008;
  min-width: 160px;
  max-width: 260px;
}
.tooltip[hidden] { display: none; }
.tooltip .tt-f {
  font-family: var(--mono); color: var(--accent);
  margin-bottom: 4px; font-size: 12px;
}
.tooltip .tt-row { display: flex; align-items: center; gap: 7px; }
.tooltip .tt-dot { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.tooltip .tt-n {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tooltip .tt-v { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.legend {
  display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center;
  min-height: 30px;
}
.legend .item {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 4px 8px 4px 9px;
  font-size: 12.5px;
  user-select: none;
}
.legend .item.off { opacity: .38; }
.legend .item .sw { width: 14px; height: 3px; border-radius: 2px; flex: none; }
.legend .item .nm { white-space: nowrap; }
.legend .item .mt,
.legend .item .pt {
  font-size: 11px; color: var(--dim2); font-family: var(--mono);
  white-space: nowrap;
}
.legend .item .pt { opacity: .8; }
.legend .item .icon {
  border: 0; background: none; color: var(--dim2);
  cursor: pointer; font-size: 12px; padding: 0 2px; font-family: var(--mono);
}
.legend .item .icon:hover { color: var(--accent); }

.chart-foot {
  font-size: 11.5px;
  color: var(--dim2);
  font-family: var(--mono);
  line-height: 1.6;
  min-height: 16px;
}

/* ---------------- 侧栏 ---------------- */
.side {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel h2 {
  margin: 0;
  padding: 10px 13px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .9px;
  text-transform: uppercase;
  color: var(--dim2);
  border-bottom: 1px solid var(--line-soft);
}
.panel-body { padding: 11px 13px; }
.panel-body .dim { color: var(--dim2); font-size: 12.5px; margin: 2px 0; }

/* 频段差异 */
.diff-head {
  display: flex; align-items: baseline; gap: 6px;
  flex-wrap: wrap; font-size: 12px; margin-bottom: 11px;
  line-height: 1.5;
}
.diffA { color: var(--sw-a); font-weight: 600; }
.diffB { color: var(--sw-b); font-weight: 600; }
.diffx { color: var(--dim2); }

.band-table { display: flex; flex-direction: column; gap: 9px; }
.band-row { display: flex; flex-direction: column; gap: 3px; }
.band-top { display: flex; align-items: baseline; gap: 6px; font-size: 12px; }
.band-name { color: var(--text); font-family: var(--mono); white-space: nowrap; font-size: 11.5px; }
.band-note {
  color: var(--dim2); font-size: 11px;
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.band-delta {
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  color: var(--dim); white-space: nowrap; font-size: 11.5px;
}
.band-delta.pos { color: var(--sw-a); }
.band-delta.neg { color: var(--sw-b); }

.bar {
  position: relative; height: 6px; border-radius: 3px;
  background: var(--line-soft);
  overflow: hidden;
}
.bar::before {
  content: ""; position: absolute; left: 50%; top: 0; bottom: 0;
  width: 1px; background: var(--line); transform: translateX(-.5px);
}
.bar-fill { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
.bar-fill.pos { left: 50%; background: var(--sw-a); }
.bar-fill.neg { right: 50%; background: var(--sw-b); }

.band-detail {
  font-size: 10.5px; color: var(--dim2);
  font-family: var(--mono); font-variant-numeric: tabular-nums;
}

.insights {
  margin: 12px 0 0; padding-left: 16px;
  font-size: 12px; color: var(--dim); line-height: 1.75;
}
.insights li { margin: 2px 0; }

/* 信息 */
.info-block { padding: 4px 0 10px; border-bottom: 1px solid var(--line-soft); }
.info-block:last-child { border-bottom: 0; padding-bottom: 0; }
.info-name {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; margin-bottom: 7px;
}
.info-name .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }

.kv { display: flex; flex-direction: column; gap: 1px; }
.kv-row { display: flex; gap: 8px; font-size: 12px; padding: 1.5px 0; }
.kv .k { color: var(--dim2); width: 78px; flex: none; }
.kv .v {
  flex: 1; min-width: 0;
  overflow-wrap: anywhere;
  font-family: var(--mono); font-size: 11.5px;
}

.skipped { margin-top: 10px; font-size: 12px; }
.skipped summary { cursor: pointer; color: var(--dim); font-size: 12px; }
.skipped p { margin: 4px 0 0; color: var(--dim2); font-size: 11px; line-height: 1.6; }

/* 预设 */
.preset-save { display: flex; gap: 6px; margin-bottom: 8px; }
.preset-save input {
  flex: 1; min-width: 0;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  padding: 6px 9px;
  outline: none;
}
.preset-save input:focus { border-color: var(--accent); }

.preset-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.preset-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 7px;
  font-size: 12.5px;
  border: 1px solid transparent;
}
.preset-list li:hover { background: var(--panel-2); border-color: var(--line); }
.preset-list li .p-name {
  flex: 1; min-width: 0; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.preset-list li .icon {
  border: 0; background: none; color: var(--dim2);
  cursor: pointer; font-size: 13px; padding: 0 2px; font-family: var(--mono);
}
.preset-list li .icon:hover { color: var(--warn); }

/* 追加曲线的浮层 */
.mini-dlg {
  position: fixed; left: 50%; top: 18%;
  transform: translateX(-50%);
  width: min(540px, 92vw);
  z-index: 90;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 26px 70px #000b, 0 0 0 100vmax #0007;
}
.mini-head {
  display: flex; align-items: center; gap: 10px;
  margin: 0 2px 8px;
}
.mini-title { flex: 1; font-size: 13px; font-weight: 600; }
.mini-close {
  border: 0; background: none; color: var(--dim2);
  font-size: 18px; line-height: 1; cursor: pointer; padding: 0 4px;
  font-family: inherit;
}
.mini-close:hover { color: var(--text); }
.mini-dlg .combo-list {
  position: relative;
  top: 8px; left: 0; right: 0;
  max-height: min(302px, 46vh);
  box-shadow: none;
}

/* ---------------- 页脚 ---------------- */
.footer {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line-soft);
  padding-top: 12px;
  display: grid;
  gap: 6px;
  font-size: 11.5px;
  color: var(--dim2);
  line-height: 1.6;
}
.footer strong { color: var(--dim); font-weight: 600; margin-right: 6px; }
.footer-note { max-width: 980px; }

/* ---------------- 通用 ---------------- */
.dim { color: var(--dim2); }
.small { font-size: 11.5px; }
.warn { color: var(--warn); }

/* 键盘可见焦点（鼠标点击不出现） */
.btn:focus-visible,
.seg button:focus-visible,
.swap:focus-visible,
.linkbtn:focus-visible,
.legend .item .icon:focus-visible,
.preset-list li .icon:focus-visible,
.combo-list li:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.combo-input:focus-visible,
.preset-save input:focus-visible,
.num:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------------- 响应式 ---------------- */
@media (max-width: 1180px) {
  .app { grid-template-columns: minmax(0, 1fr) 300px; }
  aside.side { width: 300px; position: static; max-height: none; overflow: visible; }
}

@media (max-width: 980px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(420px, auto) auto; }
  .stage, .side { grid-column: 1; }
  .side { flex-direction: row; flex-wrap: wrap; width: auto; }
  .side .panel { flex: 1 1 300px; }
  /* 差异分析优先占满整行，其余两个平分 */
  .side .panel:nth-child(1) { flex: 1 1 100%; }
  .band-table { display: grid; grid-template-columns: 1fr 1fr; gap: 9px 18px; }
  aside.side { position: static; max-height: none; overflow: visible; }
}

@media (max-width: 900px) {
  .band-table { grid-template-columns: 1fr; }
  .side .panel:nth-child(2), .side .panel:nth-child(3) { flex: 1 1 260px; }
}

@media (max-width: 760px) {
  .app { padding: 12px 12px 24px; gap: 10px; }
  .pickers { grid-template-columns: 1fr; }
  .swap { justify-self: center; transform: rotate(90deg); }
  .swap:hover { transform: rotate(270deg); }
  .toolbar { gap: 8px; }
  .tb-actions { margin-left: 0; }
  .side { flex-direction: column; flex-wrap: nowrap; }
  .side .panel { flex: 1 1 auto; width: 100%; }
  h1 { font-size: 14px; }
  .canvas-wrap { height: clamp(300px, 46vh, 460px); }
  .legend .item .mt { display: none; }
  .tooltip { max-width: 220px; }
}

@media (max-width: 430px) {
  .brand .logo { display: none; }
  .toolbar .btn, .toolbar .seg button { font-size: 12px; padding: 6px 9px; }
  .yrange .num { width: 46px; }
  .canvas-wrap { height: 340px; }
}

/* 窄屏下拉条目改为两行，型号不再被文件路径挤掉 */
@media (max-width: 620px) {
  .combo-list li { flex-direction: column; align-items: flex-start; gap: 2px; }
  .combo-list .c-name { width: 100%; }
  .combo-list .c-sub { max-width: 100%; font-size: 10.5px; }
}

.footer details summary { cursor: pointer; color: var(--dim); }
.footer details ul { margin: 6px 0 0; padding-left: 18px; }
.footer details li { margin: 2px 0; }
.footer details code { color: var(--text); }


aside.side { position: sticky; top: 14px; align-self: start; max-height: calc(100vh - 28px); overflow-y: auto; }
aside.side::-webkit-scrollbar { width: 8px; }
aside.side::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

