:root {
  color-scheme: light;
  --bg: #eef0f3;
  --surface: #ffffff;
  --panel: #f8fafc;
  --surface-strong: #e9edf3;
  --text: #171a20;
  --muted: #626c7a;
  --line: #cfd5df;
  --line-soft: #e5e8ee;
  --card-bg: var(--surface);
  --control-bg: var(--surface);
  --control-border: var(--line);
  --control-bg-muted: var(--surface-strong);
  --slider-track-top: #f8fafc;
  --slider-track-bottom: #d6dbe4;
  --blue: #2563eb;
  --cyan: #087c8f;
  --green: #0d8f62;
  --red: #c24132;
  --shadow: 0 1px 2px rgba(25, 35, 50, 0.08);
  --chart-bg: #ffffff;
  --chart-text: #344054;
  --chart-muted: #667085;
  --chart-border: #344054;
  --grid-line: #e4e8ef;
  --zero-line: #98a2b3;
  --sum-curve: #111827;
  --marker-ring: #ffffff;
  --crosshair: rgba(15, 23, 42, 0.56);
  --tooltip-bg: #111827;
  --tooltip-text: #ffffff;
  --active-channel-color: #2563eb;
  --active-channel-ui: var(--active-channel-color);
  --active-channel-panel: color-mix(in srgb, var(--active-channel-color), var(--panel) 92%);
}

body.dark-theme {
  color-scheme: dark;
  --bg: #181a1f;
  --surface: #24272d;
  --panel: #20242b;
  --surface-strong: #2b3038;
  --text: #e8edf4;
  --muted: #aeb7c4;
  --line: #3b424d;
  --line-soft: #313741;
  --card-bg: #25282f;
  --control-bg: #22252b;
  --control-border: #454c57;
  --control-bg-muted: #2a3038;
  --slider-track-top: #2e343d;
  --slider-track-bottom: #252a32;
  --blue: #60a5fa;
  --cyan: #22d3ee;
  --green: #35d07f;
  --red: #f87171;
  --shadow: none;
  --chart-bg: #181a1f;
  --chart-text: #d9e1ec;
  --chart-muted: #aeb7c4;
  --chart-border: #aab4c2;
  --grid-line: #2e3540;
  --zero-line: #7d8796;
  --sum-curve: #f1f5f9;
  --marker-ring: #181a1f;
  --crosshair: rgba(215, 224, 236, 0.46);
  --tooltip-bg: #d8dee8;
  --tooltip-text: #171a20;
  --active-channel-ui: color-mix(in srgb, var(--active-channel-color), #9aa4b2 34%);
  --active-channel-panel: color-mix(in srgb, var(--active-channel-color), var(--panel) 91%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-header {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto minmax(160px, 1fr);
  align-items: center;
  min-height: 46px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, #fbfcfe 0%, #f0f3f8 48%, #eef1f6 100%);
}

.dark-theme .app-header {
  background: linear-gradient(90deg, #222 0%, #1f2228 50%, #1b1c20 100%);
}

.dark-theme .top-tabs {
  background: #222731;
}

.brand {
  display: inline-flex;
  align-items: flex-end;
  gap: 9px;
  color: var(--text);
  font-size: 15px;
  text-decoration: none;
}

.brand-title {
  font-weight: 400;
  line-height: 1;
  padding-bottom: 2px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.brand-mark img {
  display: block;
  height: 30px;
  width: auto;
}

/* 暗色模式下反转 Logo 配色，确保仍清晰 */
.dark-theme .brand-mark img {
  filter: invert(1);
}

.top-tabs {
  display: inline-flex;
  height: 34px;
  align-items: center;
  justify-self: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  padding: 2px;
}

.tab-link {
  display: inline-flex;
  min-width: 92px;
  height: 28px;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
}

.tab-link:hover,
.tab-link.active {
  background: rgba(37, 99, 235, 0.12);
  color: var(--blue);
}

.header-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

button {
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid rgba(37, 99, 235, 0.18);
  border-radius: 4px;
  background: rgba(37, 99, 235, 0.1);
  color: #1d4ed8;
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
}

button:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.simulator-workspace {
  display: grid;
  grid-template-rows: minmax(320px, 58fr) 40px minmax(220px, 42fr);
  height: calc(100vh - 46px);
  min-height: 620px;
}

.chart-panel {
  min-height: 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  background: var(--chart-bg);
  cursor: crosshair;
}

.channel-panel {
  display: flex;
  align-items: end;
  border-bottom: 0;
  position: relative;
  background: var(--chart-bg);
  padding: 6px 10px 0;
}

.channel-tabs {
  display: flex;
  align-items: flex-end;
  gap: 0;
  width: 100%;
  position: relative;
  z-index: 1;
}

.channel-tab {
  display: grid;
  grid-template-columns: auto 26px 26px auto auto;
  align-items: center;
  flex: 0 0 auto;
  min-height: 32px;
  border: 1px solid;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  --tab-edge: color-mix(in srgb, var(--channel-color), var(--line) 70%);
  --tab-fill: color-mix(in srgb, var(--channel-color), var(--surface-strong) 90%);
  border-color: var(--tab-edge);
  background: var(--tab-fill);
  color: color-mix(in srgb, var(--channel-color), var(--muted) 62%);
  padding: 3px 14px;
  opacity: 1;
  position: relative;
  transform: none;
  gap: 4px;
  cursor: pointer;
}

.channel-tab + .channel-tab {
  margin-left: -18px;
  padding-left: 30px;
}

.dark-theme .channel-tab {
  --tab-edge: color-mix(in srgb, var(--channel-color), var(--line) 82%);
  --tab-fill: color-mix(in srgb, var(--channel-color), var(--surface-strong) 94%);
  color: color-mix(in srgb, var(--channel-color), var(--muted) 58%);
}

.channel-tab.active {
  --tab-edge: var(--active-channel-ui);
  --tab-fill: var(--active-channel-panel);
  border-color: var(--tab-edge);
  border-bottom: 1px solid var(--tab-fill);
  background: var(--tab-fill);
  border-bottom-right-radius: 0;
  border-bottom-left-radius: 0;
  color: var(--active-channel-ui);
  opacity: 1;
  position: relative;
  z-index: 2;
  min-height: 40px;
  transform: translateY(1px);
  box-shadow: 0 -1px 0 color-mix(in srgb, var(--channel-color), transparent 62%);
}

.channel-tab.active::after,
.channel-tab.active::before {
  position: absolute;
  bottom: -1px;
  width: 8px;
  height: 8px;
  content: "";
  pointer-events: none;
}

.channel-tab.active::after {
  right: -8px;
  background: radial-gradient(
    circle at top right,
    transparent 0 7px,
    var(--tab-edge) 7px 8px,
    var(--tab-fill) 8px
  );
}

.channel-tab.active::before {
  left: -8px;
  background: radial-gradient(
    circle at top left,
    transparent 0 7px,
    var(--tab-edge) 7px 8px,
    var(--tab-fill) 8px
  );
}

.channel-visible {
  display: grid;
  min-width: 22px;
  min-height: 22px;
  max-width: 22px;
  max-height: 22px;
  height: 22px;
  width: 22px;
  border-width: 1px;
  border-style: solid;
  place-items: center;
  border-color: color-mix(in srgb, var(--channel-color), var(--line) 30%);
  background: color-mix(in srgb, var(--channel-color), var(--surface) 88%);
  color: var(--channel-color);
  padding: 0;
  font-size: 13px;
  font-weight: 850;
  justify-self: start;
}

.dark-theme .channel-visible {
  background: color-mix(in srgb, var(--channel-color), #222731 84%);
}

.channel-visible.active {
  border-color: var(--channel-color);
  background: color-mix(in srgb, var(--channel-color), transparent 84%);
  color: var(--channel-color);
}

.channel-visible:hover {
  border-color: var(--channel-color);
  color: var(--channel-color);
}

.channel-polarity {
  display: grid;
  min-width: 22px;
  min-height: 22px;
  max-width: 22px;
  max-height: 22px;
  height: 22px;
  width: 22px;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--channel-color), var(--line) 30%);
  border-radius: 4px;
  background: color-mix(in srgb, var(--channel-color), var(--surface) 88%);
  color: color-mix(in srgb, var(--channel-color), var(--muted) 48%);
  padding: 0;
  font-size: 13px;
  font-weight: 850;
  line-height: 1;
}

.dark-theme .channel-polarity {
  background: color-mix(in srgb, var(--channel-color), #222731 84%);
}

.channel-polarity:hover {
  border-color: var(--channel-color);
  color: var(--channel-color);
}

.channel-polarity.active {
  border-color: var(--channel-color);
  background: color-mix(in srgb, var(--channel-color), transparent 84%);
  color: var(--channel-color);
}

.channel-name {
  display: flex;
  align-items: center;
  min-height: 24px;
  margin-right: 14px;
  border: 0;
  background: transparent;
  color: inherit;
  justify-content: flex-start;
  padding: 0;
  font-size: 20px;
  font-weight: 850;
  line-height: 24px;
  text-align: left;
}

.channel-name:hover {
  color: inherit;
}

.channel-gain {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  justify-self: center;
}

.channel-gain-input {
  width: 46px;
  height: 24px;
  border: 1px solid color-mix(in srgb, var(--channel-color), var(--line) 30%);
  border-radius: 4px;
  background: color-mix(in srgb, var(--channel-color), var(--surface) 88%);
  color: inherit;
  padding: 0 4px;
  font-size: 13px;
  font-weight: 800;
  text-align: center;
  appearance: textfield;
  -moz-appearance: textfield;
}

.channel-gain-input:focus {
  outline: none;
  border-color: var(--channel-color);
}

.channel-gain-input::-webkit-inner-spin-button,
.channel-gain-input::-webkit-outer-spin-button {
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
}

.dark-theme .channel-gain-input {
  background: color-mix(in srgb, var(--channel-color), #222731 84%);
}

.channel-zero-gap {
  justify-self: center;
  display: grid;
  place-items: center;
  min-width: 46px;
  height: 24px;
  padding: 0 4px;
  border: 1px dashed color-mix(in srgb, var(--channel-color), var(--line) 24%);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
  cursor: default;
}

.channel-zero-gap.is-hot {
  color: #dc2626;
}

.dark-theme .channel-zero-gap.is-hot {
  color: #f97373;
}

.eq-panel {
  min-height: 0;
  overflow: auto;
  border-top: 1px solid var(--active-channel-ui);
  border-radius: 0;
  background: var(--active-channel-panel);
  padding: 11px 10px 10px;
}

.band-strip {
  display: grid;
  grid-template-columns: repeat(9, minmax(118px, 1fr));
  gap: 8px;
  min-width: 1120px;
  height: 100%;
}

.band-row {
  display: grid;
  grid-template-rows: 29px 30px 30px minmax(70px, 1fr);
  gap: 4px;
  min-height: 166px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card-bg);
}

.band-row.muted {
  background: color-mix(in srgb, var(--surface), var(--panel) 52%);
}

.dark-theme .band-row.muted {
  background: #20242a;
}

.band-row.muted > *:not(.gain-fader) {
  opacity: 0.42;
}

.band-row.muted .gain-line,
.band-row.muted .vertical-slider {
  opacity: 0.42;
}

.band-row.muted .band-actions {
  opacity: 1;
}

.band-label {
  display: grid;
  min-height: 26px;
  width: 30px;
  place-items: center;
  font-size: 14px;
  font-weight: 850;
  line-height: 1;
}

select,
.number-input {
  width: 100%;
  min-height: 30px;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  background: var(--control-bg);
  color: var(--text);
  padding: 0 8px;
}

.type-control,
.number-control {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: center;
  gap: 5px;
}

.number-control span,
.gain-fader span,
.band-actions span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.number-control span,
.gain-fader span {
  justify-self: center;
  text-align: center;
  width: 30px;
}

.number-input {
  min-height: 26px;
  padding: 0 6px;
  text-align: center;
  appearance: textfield;
  -moz-appearance: textfield;
}

.number-input::-webkit-inner-spin-button,
.number-input::-webkit-outer-spin-button {
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
}

.compact-select {
  min-height: 26px;
  padding: 0 6px;
  text-align: center;
}

.gain-fader {
  display: grid;
  grid-template-rows: 30px minmax(42px, 1fr);
  gap: 3px;
  min-height: 70px;
}

.gain-line {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: center;
  gap: 5px;
}

.gain-readout {
  display: grid;
  align-items: center;
}

.vertical-slider {
  display: grid;
  min-height: 68px;
  place-items: center;
  touch-action: none;
}

.slider-track {
  position: relative;
  width: 8px;
  height: 64px;
  border: 1px solid var(--control-border);
  border-radius: 999px;
  background: linear-gradient(180deg, var(--slider-track-top) 0%, var(--slider-track-bottom) 100%);
}

.slider-fill {
  position: absolute;
  right: -1px;
  bottom: -1px;
  left: -1px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--active-channel-ui), var(--slider-track-bottom) 18%);
}

.slider-thumb {
  position: absolute;
  left: 50%;
  width: 18px;
  height: 18px;
  border: 2px solid var(--active-channel-ui);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.1);
  transform: translate(-50%, 50%);
}

.dark-theme .slider-thumb {
  background: #252a32;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.28);
}

.vertical-slider.disabled .slider-fill {
  background: #cbd5e1;
}

.vertical-slider.disabled .slider-thumb {
  border-color: #d7dde7;
  background: #dfe5ee;
  box-shadow: none;
}

.fader-body {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  min-height: 52px;
}

.band-actions {
  display: grid;
  gap: 5px;
  justify-self: end;
  width: 48px;
}

.band-action {
  min-height: 25px;
  padding: 0 4px;
  border-color: var(--control-border);
  background: var(--control-bg-muted);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.band-action.active {
  border-color: color-mix(in srgb, var(--active-channel-ui), #111827 18%);
  background: color-mix(in srgb, var(--active-channel-ui), transparent 82%);
  color: var(--active-channel-ui);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--active-channel-ui), transparent 82%);
}

.disabled-gain > .gain-line,
.disabled-gain .vertical-slider {
  opacity: 0.45;
}

@media (max-width: 860px) {
  body {
    overflow: auto;
  }

  .app-header {
    grid-template-columns: 1fr;
    gap: 8px;
    padding-block: 10px;
  }

  .top-tabs,
  .header-actions {
    justify-self: stretch;
  }

  .tab-link,
  .header-actions button {
    flex: 1;
  }

  .simulator-workspace {
    height: auto;
    min-height: 0;
    grid-template-rows: 52vh auto auto;
  }
}
