:root {
  --bg: #0c1018;
  --panel: #161f30;
  --border: #2d3f5c;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #4a9eff;
  --accent-dim: #2a5a9a;
  --msx-rule: #3b3bff;
  --msx-cyan: #6ec8ff;
  --eq-bg: #080c12;
  --fx-accent: #e89448;
  --fx-accent-dim: #a85828;
  --fx-panel-bg: #141008;
  --fx-header-bg: #181008;
  --ui-radius: 6px;
  --panel-header-height: 2rem;
  /* Shared columns: Add keyframe / Key · Duplicate / Chord · Delete */
  --morph-action-cols: 8.75rem 5.25rem 4rem;
  --morph-action-gap: 0.35rem;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem 0.75rem;
  border-bottom: 3px solid var(--msx-rule);
}

.header-main {
  min-width: 0;
}

header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

header p {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.header-patch-actions {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 0.5rem;
  padding-top: 0.15rem;
}

.patch-btn {
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--accent-dim);
  border-radius: var(--ui-radius);
  background: var(--accent-dim);
  color: #fff;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.patch-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.patch-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  width: 100%;
  max-width: none;
  margin: 0;
  align-content: stretch;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

main > .wave-editor-host {
  grid-column: 1;
  grid-row: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

main > .adsr-editor-host {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

main > .morph-editor-host {
  grid-column: 1;
  grid-row: 2;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

main > .morph-options-host {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

main > .keyboard-panel {
  grid-column: 1;
  grid-row: 3;
  min-width: 0;
  overflow: visible;
}

main > .fx-panel {
  grid-column: 2;
  grid-row: 3;
  min-width: 0;
  align-self: start;
  display: flex;
  flex-direction: column;
}

.wave-editor-panel,
.adsr-editor-panel {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
}

.adsr-editor-graph {
  flex: 1 1 0;
  min-height: 120px;
  min-width: 0;
  position: relative;
  overflow: hidden;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--ui-radius);
  overflow: hidden;
}

.voice-select-panel {
  padding: 0;
}

.voice-select-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: #121820;
}

.voice-select-header h2 {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #c744f6;
}

.voice-select-source {
  margin: 0;
  font-size: 0.6875rem;
  color: var(--muted);
}

.voice-select-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.65rem 1rem;
  padding: 0.6rem 0.75rem;
}

.voice-select-label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
  min-width: 12rem;
}

.voice-select-caption {
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.voice-picker {
  position: relative;
}

.voice-picker-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  min-height: 2rem;
  padding: 0.3rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: var(--ui-radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
  text-align: left;
}

.voice-picker-trigger:hover:not(:disabled) {
  border-color: #c744f6;
}

.voice-picker-trigger:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.voice-picker.open .voice-picker-trigger {
  border-color: #c744f6;
  box-shadow: 0 0 0 1px rgba(199, 68, 246, 0.35);
}

.voice-picker-face {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex: 1;
  min-width: 0;
}

.voice-picker-thumb,
.voice-option-thumb {
  flex-shrink: 0;
  display: block;
  width: 56px;
  height: 18px;
  border-radius: 2px;
  background: rgba(8, 12, 18, 0.55);
}

.voice-picker-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.voice-picker-chevron {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.voice-picker-menu {
  position: absolute;
  z-index: 40;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  max-height: min(20rem, 45vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  margin: 0;
  padding: 0.25rem 0;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: var(--ui-radius);
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.voice-picker-menu-floating {
  z-index: 1200;
  overscroll-behavior: contain;
}

.voice-picker-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 1.75rem;
  padding: 0.3rem 0.45rem;
  cursor: pointer;
  font-size: 0.8125rem;
}

.voice-picker-option:hover {
  background: rgba(199, 68, 246, 0.1);
}

.voice-picker-option.selected {
  background: rgba(199, 68, 246, 0.18);
  color: #c744f6;
}

.voice-option-text {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}

.voice-option-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.voice-option-meta {
  flex-shrink: 0;
  font-size: 0.6875rem;
  color: var(--muted);
}

.voice-picker-option.selected .voice-option-meta {
  color: #c744f6;
}

.voice-browse-btn {
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--ui-radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
}

.voice-browse-btn:hover:not(:disabled) {
  border-color: #c744f6;
  color: #c744f6;
}

.voice-browse-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.voice-dialog {
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--ui-radius);
  background: var(--panel);
  color: var(--text);
  max-width: min(28rem, 92vw);
  width: 100%;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.voice-dialog::backdrop {
  background: rgba(8, 12, 18, 0.72);
}

.voice-dialog-inner {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.voice-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: #121820;
}

.voice-dialog-header h3 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
}

.voice-dialog-close {
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--ui-radius);
  background: var(--bg);
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.voice-dialog-close:hover {
  color: var(--text);
  border-color: var(--accent);
}

.voice-dialog-meta {
  margin: 0;
  padding: 0.45rem 0.75rem;
  font-size: 0.75rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.voice-dialog-list-wrap {
  max-height: min(20rem, 50vh);
  overflow: auto;
}

.voice-dialog-list {
  list-style: none;
  margin: 0;
  padding: 0.35rem 0;
}

.voice-dialog-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2rem;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  font-size: 0.8125rem;
}

.voice-dialog-item .voice-option-text {
  flex: 1;
  min-width: 0;
}

.voice-dialog-item:hover {
  background: rgba(199, 68, 246, 0.1);
}

.voice-dialog-item.selected {
  background: rgba(199, 68, 246, 0.18);
  color: #c744f6;
}

.voice-dialog-item.selected .voice-option-meta {
  color: #c744f6;
}

.voice-dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  border-top: 1px solid var(--border);
  background: #121820;
}

.voice-dialog-footer button {
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--ui-radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
}

.voice-dialog-load {
  border-color: #c744f6;
  color: #c744f6;
}

.voice-dialog-load:hover {
  background: rgba(199, 68, 246, 0.12);
}

.wave-editor-host {
  min-height: 0;
}

.wave-editor-header,
.morph-editor-header,
.adsr-editor-header,
.keyboard-panel-header,
.morph-options-header,
.fx-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  height: var(--panel-header-height);
  min-height: var(--panel-header-height);
  padding: 0 0.75rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.wave-editor-header,
.morph-editor-header,
.keyboard-panel-header,
.morph-options-header {
  background: #121820;
}

.adsr-editor-header {
  background: #0a1410;
}

.fx-panel-header {
  background: var(--fx-header-bg);
}

.wave-editor-header h2,
.morph-editor-header h2,
.adsr-editor-header h2,
.keyboard-panel-header h2,
.morph-options-header h2,
.fx-panel-header h2 {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.wave-editor-header h2,
.morph-editor-header h2,
.keyboard-panel-header h2,
.morph-options-header h2 {
  color: #c744f6;
}

.adsr-editor-header h2 {
  color: #2a9d5c;
}

.fx-panel-header h2 {
  color: var(--fx-accent);
}

.harmony-readout {
  display: inline-grid;
  grid-template-columns: var(--morph-action-cols);
  gap: var(--morph-action-gap);
  align-items: center;
  margin-left: auto;
  flex-shrink: 0;
}

.detected-key,
.detected-chord {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.03em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}

.detected-key {
  color: var(--msx-cyan);
}

.detected-chord {
  color: #c744f6;
}

.morph-editor-hint,
.adsr-rate {
  font-size: 0.625rem;
  line-height: 1;
  color: var(--muted);
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.morph-editor-hint {
  flex-shrink: 0;
}

.wave-reset-btn {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--ui-radius);
  padding: 0.15rem 0.45rem;
  cursor: pointer;
  font-size: 0.6875rem;
  line-height: 1.2;
  flex-shrink: 0;
}

.wave-reset-btn:hover {
  border-color: var(--accent);
}

.wave-reset-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.morph-editor-host {
  min-height: 0;
}

.morph-editor-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.morph-timeline-wrap {
  position: relative;
  flex: 0 0 auto;
  height: 84px;
  overflow: hidden;
  border-bottom: none;
  background: #121820;
  padding: 0;
}

.morph-source-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.65rem 1rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: #121820;
}

.morph-source-label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 7rem;
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.morph-source-label select {
  font: inherit;
  font-size: 0.8125rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--ui-radius);
  padding: 0.35rem 0.5rem;
  text-transform: none;
  letter-spacing: normal;
}

.morph-voice-host {
  flex: 1;
  min-width: 14rem;
}

.voice-select-embed {
  padding: 0;
}

.voice-select-embed .voice-select-bar {
  padding: 0;
  align-items: flex-end;
}

.morph-timeline-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: ew-resize;
  touch-action: none;
}

.morph-timeline-canvas.dragging-kf {
  cursor: grabbing;
}

.morph-editor-header {
  position: relative;
  justify-content: space-between;
}

.morph-editor-header .morph-scrub-wrap {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: min(14rem, 42%);
  min-width: 8rem;
  padding: 0;
  border: 0;
  background: transparent;
  z-index: 1;
  pointer-events: none;
}

.morph-editor-header .morph-scrub-wrap > * {
  pointer-events: auto;
}

.morph-editor-header .morph-scrub {
  flex: 1;
  width: auto;
  min-width: 0;
  accent-color: #c744f6;
}

.morph-editor-header .morph-scrub-readout {
  min-width: 2.25rem;
  font-size: 0.6875rem;
}

.morph-scrub-wrap,
.morph-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--border);
  background: #121820;
  font-size: 0.8125rem;
}

.morph-options-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.morph-options-body {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.55rem;
  padding: 0.65rem 0.75rem;
  background: #121820;
  font-size: 0.8125rem;
}

.morph-options-body .morph-check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.morph-options-body .morph-option-param {
  display: grid;
  grid-template-columns: 3.75rem 1fr auto;
  align-items: center;
  gap: 0.35rem;
}

.morph-option-param-label {
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.morph-options-body .morph-speed {
  width: 100%;
  accent-color: #c744f6;
}

.morph-speed-readout {
  min-width: 3rem;
  text-align: right;
  font-size: 0.75rem;
  color: #c744f6;
  font-variant-numeric: tabular-nums;
}

.morph-scrub-label,
.morph-pair-label,
.morph-curve-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.625rem;
  letter-spacing: 0.04em;
}

.morph-scrub {
  width: 10rem;
  accent-color: #c744f6;
}

.morph-scrub-readout {
  min-width: 2.5rem;
  font-size: 0.75rem;
  color: #c744f6;
  font-variant-numeric: tabular-nums;
}

.morph-check {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--muted);
  cursor: pointer;
}

.morph-pin-btn,
.morph-add-btn,
.morph-dup-btn,
.morph-del-btn {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--ui-radius);
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  font-size: 0.75rem;
}

.morph-add-btn,
.morph-dup-btn,
.morph-del-btn {
  width: 100%;
  box-sizing: border-box;
  text-align: center;
}

.morph-pin-btn:hover,
.morph-add-btn:hover:not(:disabled),
.morph-dup-btn:hover:not(:disabled),
.morph-del-btn:hover {
  border-color: var(--accent);
}

.morph-add-btn:disabled,
.morph-dup-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.morph-pin-btn.active {
  border-color: #c744f6;
  color: #c744f6;
}

.morph-pin-group {
  display: inline-flex;
  gap: 0.35rem;
}

.morph-actions {
  display: inline-grid;
  grid-template-columns: var(--morph-action-cols);
  gap: var(--morph-action-gap);
  margin-left: auto;
  align-items: center;
}

.morph-bar select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--ui-radius);
  padding: 0.2rem 0.4rem;
  max-width: 9rem;
}

.adsr-editor-host {
  min-height: 0;
}

.adsr-editor-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.adsr-editor-host .adsr-editor-controls {
  grid-template-columns: 1fr;
  gap: 0.45rem;
  padding: 0.45rem 0.65rem;
}

.adsr-editor-host .adsr-param {
  grid-template-columns: 3.75rem 1fr auto;
  gap: 0.35rem;
}

.adsr-editor-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 0.65rem 1rem;
  padding: 0.6rem 0.75rem;
  border-top: 1px solid var(--border);
  background: #0a1410;
  flex-shrink: 0;
}

.adsr-param {
  display: grid;
  grid-template-columns: 4.5rem 1fr auto;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
}

.adsr-param-label {
  color: var(--muted);
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.adsr-param input[type='range'] {
  width: 100%;
  accent-color: #2a9d5c;
}

.adsr-param-value {
  min-width: 3.5rem;
  text-align: right;
  font-size: 0.75rem;
  color: #2a9d5c;
  font-variant-numeric: tabular-nums;
}

.wave-editor-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.wave-editor-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  padding: 0.5rem 0.75rem;
  background: #121820;
  border-top: 1px solid var(--border);
  font-size: 0.8125rem;
}

.wave-editor-controls label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.625rem;
  letter-spacing: 0.04em;
}

.wave-editor-controls select,
.wave-editor-controls button {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--ui-radius);
  padding: 0.25rem 0.5rem;
}

.wave-editor-controls button {
  cursor: pointer;
}

.wave-editor-controls button:hover {
  border-color: var(--accent);
}

.wave-editor-controls .snap-toggle.active {
  border-color: var(--accent);
  color: var(--accent);
}

.wave-editor-controls button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.wave-editor-controls button:disabled:hover {
  border-color: var(--border);
}

.fx-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--fx-panel-bg);
}

.fx-panel-body {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.65rem 0.75rem;
  background: var(--fx-header-bg);
  font-size: 0.8125rem;
}

.fx-check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--muted);
  cursor: pointer;
}

.fx-check input {
  accent-color: var(--fx-accent);
}

.fx-check:hover {
  color: var(--text);
}

.fx-param {
  display: grid;
  grid-template-columns: 3.75rem 1fr auto;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.fx-param-label {
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.fx-param input[type='range'] {
  width: 100%;
  accent-color: var(--fx-accent);
}

.fx-param input[type='range']:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.fx-select {
  width: 100%;
  min-width: 0;
  padding: 0.2rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 0.75rem;
}

.fx-select:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.fx-param-readout {
  min-width: 3.25rem;
  text-align: right;
  font-size: 0.75rem;
  color: var(--text);
}

.keyboard-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.keyboard-panel-body {
  padding: 0.65rem 0.75rem 0.5rem;
  font-size: 0.8125rem;
  color: var(--muted);
  line-height: 1.5;
}

.keyboard-controls-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.65rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--border);
}

.midi-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.midi-activity {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid var(--muted);
  background: var(--bg);
  flex-shrink: 0;
  transition: background 0.08s, border-color 0.08s, box-shadow 0.08s;
}

.midi-activity--active {
  background: var(--msx-cyan);
  border-color: var(--msx-cyan);
  box-shadow: 0 0 6px color-mix(in srgb, var(--msx-cyan) 55%, transparent);
}

.midi-enable-pill {
  margin: 0;
}

.midi-control-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0;
}

.midi-port-select,
.midi-channel-select {
  font: inherit;
  font-size: 0.75rem;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--ui-radius);
  padding: 0.2rem 0.35rem;
  max-width: 14rem;
}

.midi-channel-select {
  max-width: 3.5rem;
}

.midi-port-select:disabled,
.midi-channel-select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.midi-file-controls {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
}

.midi-file-btn {
  font: inherit;
  font-size: 0.75rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--ui-radius);
  padding: 0.2rem 0.55rem;
  cursor: pointer;
}

.midi-file-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.midi-file-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.midi-file-name {
  max-width: 10rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.75rem;
  color: var(--muted);
}

.midi-file-merge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.midi-file-merge input {
  margin: 0;
  accent-color: var(--accent);
}

.midi-unsupported-hint {
  font-size: 0.6875rem;
  color: var(--muted);
  font-style: italic;
}

.keyboard-playback-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem 0.75rem;
  margin-left: auto;
}

.keyboard-play-hint {
  font-size: 0.8125rem;
  color: var(--muted);
  text-align: right;
}

.keyboard-play-hint strong {
  color: var(--text);
  font-weight: 600;
}

.piano-keyboard-row {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  margin-top: 0.65rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  margin-bottom: 0;
}

.pitch-bend-host {
  flex-shrink: 0;
}

.pitch-bend-wheel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.12rem;
  height: 67px;
  min-height: 67px;
  user-select: none;
}

.pitch-bend-caption {
  font-size: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  line-height: 1;
}

.pitch-bend-track {
  position: relative;
  width: 0.72rem;
  flex: 1;
  min-height: 2.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: linear-gradient(180deg, #121820 0%, var(--bg) 45%, var(--bg) 55%, #121820 100%);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.35);
}

.pitch-bend-center-mark {
  position: absolute;
  left: 15%;
  right: 15%;
  top: 50%;
  height: 1px;
  margin-top: -0.5px;
  background: var(--border);
  pointer-events: none;
}

.pitch-bend-thumb {
  position: absolute;
  left: 50%;
  width: 0.55rem;
  height: 0.55rem;
  margin-left: -0.275rem;
  margin-top: -0.275rem;
  border-radius: 50%;
  background: var(--muted);
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  transition: top 0.04s linear, background 0.08s, border-color 0.08s;
  pointer-events: none;
}

.pitch-bend-wheel--active .pitch-bend-thumb {
  background: var(--msx-cyan);
  border-color: color-mix(in srgb, var(--msx-cyan) 70%, var(--border));
}

.pitch-bend-value {
  font-size: 0.5rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  line-height: 1;
  min-width: 1.6rem;
  text-align: center;
}

.pitch-bend-wheel--active .pitch-bend-value {
  color: var(--msx-cyan);
}

.piano-column {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.piano-keyboard-wrap {
  flex: 0 0 auto;
  min-width: 0;
}

.piano-keyboard-host {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  border-radius: var(--ui-radius);
  background: #1a1d22;
}

.piano-keyboard-canvas {
  display: block;
  width: 100%;
  min-width: 320px;
  height: 67px;
  cursor: default;
}

.falling-notes-wrap,
.falling-notes-host {
  position: relative;
  height: 140px;
  min-height: 140px;
  border-radius: var(--ui-radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #080c12;
}

.falling-notes-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.keyboard-panel-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.toggle-pill {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.toggle-pill input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.toggle-pill span {
  display: inline-block;
  padding: 0.25rem 0.55rem;
  font: inherit;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--ui-radius);
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.toggle-pill:hover span {
  border-color: var(--accent);
}

.toggle-pill input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.toggle-pill input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.octave-controls {
  display: inline-flex;
  align-items: center;
  gap: 0;
}

.octave-controls .octave-btn + .octave-btn {
  margin-left: -1px;
}

.octave-btn {
  min-width: 1.5rem;
  height: 1.75rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--ui-radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.octave-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.octave-label {
  min-width: 4.5rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.notes-off-btn {
  padding: 0.25rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--ui-radius);
  background: var(--bg);
  color: var(--muted);
  font: inherit;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.notes-off-btn:hover {
  border-color: #e67e22;
  color: #e67e22;
}

footer {
  padding: 0.35rem 1rem 0.75rem;
  border-top: 1px solid var(--border);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 0.55rem;
  color: var(--muted);
  line-height: 1.35;
  text-align: center;
}

footer a {
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

footer a:hover {
  color: var(--text);
}

.footer-disclaimer,
.footer-promo {
  display: block;
  margin-top: 0.45rem;
}

.footer-disclaimer {
  opacity: 0.85;
}

.context-menu {
  position: fixed;
  z-index: 1000;
  min-width: 10rem;
  padding: 0.25rem 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--ui-radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  display: none;
}

.context-menu.open {
  display: block;
}

.context-menu button {
  display: block;
  width: 100%;
  padding: 0.4rem 0.75rem;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.context-menu button:hover {
  background: rgba(74, 158, 255, 0.12);
}

.gear-menu {
  position: absolute;
  z-index: 20;
  min-width: 11rem;
  padding: 0.25rem 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--ui-radius);
  display: none;
}

.gear-menu.open {
  display: block;
}

.gear-menu label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  font-size: 0.8125rem;
  cursor: pointer;
}

.wave-editor-main {
  position: relative;
  flex: 1 1 0;
  min-height: 180px;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.gear-btn {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 10;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--ui-radius);
  background: rgba(18, 26, 36, 0.85);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
}

.gear-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

.hover-readout {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.2rem 0.45rem;
  font-size: 0.6875rem;
  color: var(--muted);
  background: rgba(18, 26, 36, 0.85);
  border: 1px solid var(--border);
  border-radius: 4px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s;
}

.hover-readout.visible {
  opacity: 1;
}
