:root {
  color-scheme: dark;
  --bg: #090909;
  --surface: #111111;
  --raised: #171717;
  --line: #2b2b2b;
  --line-strong: #3a3a3a;
  --muted: #7b7d82;
  --text: #eeeeea;
  --acid: #ff4b55;
  --best: #52a8ff;
  --best-key: #8bc9ff;
  --cyan: #a5a6aa;
  --radius-control: 3px;
  --radius-card: 4px;
  --topbar-height: 64px;
  --white-key: 34px;
  --black-key: 21px;
  --browser-width-expanded: 208px;
  --browser-width: var(--browser-width-expanded);
  --recordings-width-expanded: 260px;
  --recordings-width: var(--recordings-width-expanded);
  --keyboard-height: 220px;
  --keyboard-top: calc(100vh - var(--keyboard-height));
}

:root.sidebar-collapsed { --browser-width: 0px; }
:root.recordings-collapsed { --recordings-width: 0px; }

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f0f0ed;
  --surface: #f7f7f4;
  --raised: #ffffff;
  --line: #cacac5;
  --line-strong: #aaa9a3;
  --muted: #67696e;
  --text: #1c1d20;
  --cyan: #55575c;
  --best: #006fd6;
  --best-key: #a8d6ff;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Manrope", system-ui, sans-serif;
  transition: background-color .14s ease, color .14s ease;
}

button, select { font: inherit; }

main { position: relative; min-height: 100vh; padding-bottom: var(--keyboard-height); display: flex; flex-direction: column; }

header, .sound-browser, .sound-rack, .effects-rack, .recordings-rack, .keyboard-section, select, button, input {
  transition: background-color .14s ease, color .14s ease, border-color .14s ease;
}

#noteStream {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  pointer-events: none;
}

header {
  position: relative;
  z-index: 12;
  height: var(--topbar-height);
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  border-bottom: 0;
  pointer-events: none;
}
header::before { content: ""; position: absolute; z-index: 0; top: 0; right: 0; bottom: 0; width: max(0px, calc(var(--recordings-width) - 10px)); border-left: 1px solid var(--line); background: var(--surface); pointer-events: none; }

.midi-controls { position: relative; z-index: 1; width: auto; display: flex; gap: 9px; align-items: center; justify-content: flex-end; pointer-events: auto; }
.midi-controls button { flex: 0 0 auto; height: 30px; padding: 0 9px; font-size: 10px; }
.midi-menu-wrap { position: relative; }
.midi-controls #midiButton { position: relative; width: 30px; padding: 0; }
.midi-controls #midiButton svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.midi-controls #midiButton[aria-expanded="true"] { color: var(--acid); border-color: var(--acid); }
.midi-controls #midiButton .status-dot { position: absolute; top: 3px; right: 3px; width: 4px; height: 4px; }
.midi-menu { position: absolute; z-index: 20; top: calc(100% + 6px); right: 0; width: 224px; border: 1px solid var(--line-strong); background: var(--surface); }
.midi-menu[hidden] { display: none; }
.midi-menu-heading { height: 28px; padding: 0 8px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); font: 500 7px/1 "DM Mono", monospace; letter-spacing: .1em; }
.midi-menu-heading span { color: var(--text); }
.midi-menu-heading small { color: var(--muted); font: inherit; }
.midi-device-list { max-height: 196px; overflow-y: auto; }
.midi-device-option { position: relative; width: 100%; height: 32px; padding: 0 24px 0 17px; display: block; overflow: hidden; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; color: var(--muted); background: transparent; font: 500 9px/1 "DM Mono", monospace; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.midi-device-option::before { content: ""; position: absolute; top: 50%; left: 8px; width: 3px; height: 3px; transform: translateY(-50%); background: #55575b; }
.midi-device-option:hover { color: var(--text); background: var(--raised); }
.midi-device-option.selected { color: var(--text); background: #1b1516; }
.midi-device-option.selected::before { background: var(--acid); }
.midi-device-option.selected::after { content: "✓"; position: absolute; top: 50%; right: 8px; transform: translateY(-50%); color: var(--acid); }
.midi-device-empty { margin: 0; padding: 12px 8px; color: var(--muted); font: 400 8px/1.4 "DM Mono", monospace; }
.midi-controls .midi-refresh { width: 100%; height: 30px; padding: 0 8px; display: flex; align-items: center; gap: 7px; border: 0; border-radius: 0; color: var(--muted); background: transparent; }
.midi-controls .midi-refresh:hover { color: var(--text); background: var(--raised); }
.midi-controls .midi-refresh svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.3; }
.midi-controls .theme-toggle { width: 30px; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; }
.midi-controls .theme-toggle:hover { border: 0; background: transparent; }
.midi-controls .theme-toggle:focus-visible { outline: 1px solid currentColor; outline-offset: 2px; }
:root[data-theme="light"] .midi-controls .theme-toggle { color: var(--muted); }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: #55575b; }
.status-dot.connected { background: var(--acid); }
select, button { border: 1px solid var(--line); color: var(--text); background: var(--raised); border-radius: var(--radius-control); height: 32px; padding: 0 10px; font-size: 11px; cursor: pointer; }
select { max-width: min(260px, 35vw); }
button:hover, select:hover { border-color: var(--line-strong); background: #1c1c1c; }
button:focus-visible, select:focus-visible, input:focus-visible, [tabindex]:focus-visible { outline: 1px solid var(--acid); outline-offset: 2px; }

.sound-browser {
  position: fixed;
  z-index: 7;
  top: 0;
  height: var(--keyboard-top);
  left: 0;
  width: var(--browser-width-expanded);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--surface);
  transition: transform .18s ease, background-color .14s ease, border-color .14s ease;
}
:root.sidebar-collapsed .sound-browser { transform: translateX(-100%); pointer-events: none; }
.sidebar-toggle { position: fixed; z-index: 14; top: calc(var(--topbar-height) + 8px); left: var(--browser-width); width: 22px; height: 36px; padding: 0; display: grid; place-items: center; border-left: 0; border-radius: 0 2px 2px 0; color: var(--muted); background: var(--surface); transition: left .18s ease, background-color .14s ease, color .14s ease, border-color .14s ease; }
.sidebar-toggle:hover { color: var(--text); background: var(--raised); }
.sidebar-toggle svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: square; stroke-linejoin: miter; transition: transform .18s ease; }
:root.sidebar-collapsed .sidebar-toggle svg { transform: rotate(180deg); }
.browser-heading { padding: 14px 12px 12px; border-bottom: 1px solid var(--line); }
.browser-heading > span { display: block; margin-bottom: 9px; color: var(--acid); font: 600 9px/1 "DM Mono", monospace; letter-spacing: .22em; }
.browser-heading strong { display: block; overflow: hidden; color: var(--cyan); font: 500 11px/1.3 "DM Mono", monospace; text-overflow: ellipsis; white-space: nowrap; }
.sound-power-row { display: flex; align-items: flex-end; gap: 10px; }
.browser-heading .sound-toggle { width: 30px; height: 30px; padding: 0; border-radius: var(--radius-control); }
.browser-heading .volume-control { flex: 0 0 auto; width: 96px; }
.browser-heading .volume-control input[type="range"] { width: 96px; }
.sound-toggle svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sound-toggle svg path:first-child { fill: currentColor; stroke: none; }
.sound-list { flex: 0 0 auto; min-height: 0; padding: 0; overflow: visible; }
.sound-choice {
  position: relative;
  width: 100%;
  height: 34px;
  margin-bottom: 0;
  padding: 0 11px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  color: #9ca2ad;
  text-align: left;
}
.sound-choice > i { flex: 0 0 auto; width: 2px; height: 14px; border-radius: 0; background: #45474c; }
.sound-choice > span { min-width: 0; overflow: hidden; font-size: 10px; font-style: normal; text-overflow: ellipsis; white-space: nowrap; }
.sound-choice small { display: block; margin-top: 5px; color: #555c68; font: 500 7px/1 "DM Mono", monospace; letter-spacing: .13em; }
.sound-choice:hover { color: var(--text); background: #161616; }
.sound-choice.active { color: #fff; border-color: var(--line); background: #1b1516; }
.sound-choice.active > i { background: var(--acid); }
.sound-choice.active small { color: #bf7479; }
.custom-sound-row { margin-bottom: 0; }
.custom-sound-row .sound-choice { margin-bottom: 0; }
.sample-root-select { display: none; width: calc(100% - 16px); min-width: 0; max-width: none; height: 26px; margin: 5px 8px; padding: 0 22px 0 8px; border-radius: var(--radius-control); color: var(--text); font: 500 8px/1 "DM Mono", monospace; }
.custom-sound-row.active .sample-root-select { display: block; }
.browser-import { padding: 8px; border-bottom: 1px solid var(--line); }
.add-sample-button { display: flex; align-items: center; justify-content: flex-start; gap: 7px; height: 30px; padding: 0 9px; border: 1px solid var(--line); border-radius: var(--radius-control); color: var(--muted); background: transparent; font-size: 9px; cursor: pointer; }
.add-sample-button b { color: var(--acid); font-size: 14px; font-weight: 400; }
.add-sample-button:hover { color: var(--text); border-color: var(--line-strong); }

.sound-rack, .hero, .keyboard-section { margin-left: var(--browser-width); margin-right: var(--recordings-width); }

.sound-rack {
  position: absolute;
  z-index: 12;
  top: 0;
  left: var(--browser-width);
  right: var(--recordings-width);
  height: var(--topbar-height);
  min-height: var(--topbar-height);
  margin: 0;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  overflow: visible;
  border-bottom: 1px solid var(--line);
  background: transparent;
  scrollbar-width: thin;
  scrollbar-color: #353b45 transparent;
}
.sound-controls { min-width: max-content; display: flex; align-items: flex-end; justify-content: flex-end; gap: 7px; flex-wrap: nowrap; }
.control-group { display: flex; flex-direction: column; gap: 4px; color: #717379; font: 500 7px/1 "DM Mono", monospace; letter-spacing: .1em; }
.control-group select { min-width: 160px; height: 30px; padding: 0 26px 0 9px; }
.mic-menu-wrap { position: relative; }
.mic-input-group select { min-width: 176px; max-width: 210px; }
.mic-dot { width: 4px; height: 4px; border-radius: 50%; background: #555c68; }
.mic-dot.live { background: var(--acid); }
.midi-controls .mic-button { position: relative; width: 30px; height: 30px; padding: 0; display: grid; place-items: center; font-size: 10px; }
.mic-button svg { display: block; width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.mic-button .mic-dot { position: absolute; top: 3px; right: 3px; }
.mic-button.live { color: var(--acid); border-color: var(--acid); background: var(--raised); }
.mic-button[aria-expanded="true"] { color: var(--acid); border-color: var(--acid); }
.mic-menu { position: absolute; z-index: 20; top: 0; right: calc(100% + 6px); left: auto; width: 242px; border: 1px solid var(--line-strong); background: var(--surface); }
.mic-menu[hidden] { display: none; }
.mic-menu-heading { height: 28px; padding: 0 8px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); font: 500 7px/1 "DM Mono", monospace; letter-spacing: .1em; }
.mic-menu-heading span { color: var(--text); }
.mic-menu-heading em { color: var(--muted); font: inherit; font-style: normal; }
.mic-menu-heading em.live { color: var(--acid); }
.mic-menu .mic-power { width: 100%; height: 32px; padding: 0 8px; display: flex; align-items: center; gap: 8px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; color: var(--muted); background: transparent; text-align: left; }
.mic-menu .mic-power:hover { color: var(--text); background: var(--raised); }
.mic-power i { width: 5px; height: 5px; background: #555c68; }
.mic-power.live { color: var(--text); }
.mic-power.live i { background: var(--acid); }
.mic-menu .control-group { padding: 8px; gap: 6px; border-bottom: 1px solid var(--line); }
.mic-menu .control-group select { width: 100%; min-width: 0; max-width: none; }
.mic-menu .mic-sensitivity { width: 100%; }
.mic-menu .mic-sensitivity input[type="range"] { width: 100%; }
.mic-mode-group select { min-width: 112px; }
.metronome-controls { display: flex; align-items: center; gap: 4px; margin-left: 4px; padding-left: 8px; border-left: 1px solid var(--line); }
.midi-controls > .metronome-controls { margin-right: 2px; margin-left: 0; padding-right: 9px; padding-left: 0; border-right: 1px solid var(--line); border-left: 0; }
.metronome-tempo { display: flex; flex-direction: row; align-items: center; gap: 3px; }
.midi-controls .metronome-toggle { flex: 0 0 30px; width: 30px; height: 30px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius-control); }
.metronome-toggle svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.metronome-toggle.active { color: #160406; border-color: var(--acid); background: var(--acid); }
.metronome-toggle.beat { transform: scale(1.08); }
.metro-bpm { display: flex; align-items: center; height: 30px; }
.metro-bpm input { width: 38px; height: 30px; padding: 0 2px; border: 0; border-radius: 0; color: var(--text); background: transparent; font: 500 11px/1 "DM Mono", monospace; text-align: center; cursor: ns-resize; appearance: textfield; }
.metro-bpm input::-webkit-inner-spin-button,
.metro-bpm input::-webkit-outer-spin-button { margin: 0; appearance: none; }
.metro-bpm input:focus { outline: 1px solid var(--acid); outline-offset: 2px; }
.meter-control { height: 30px; display: flex; align-items: center; gap: 0; color: var(--text); font: 500 11px/1 "DM Mono", monospace; }
.meter-value { width: 20px; height: 30px; padding: 0; border: 0; border-radius: 0; color: inherit; background: transparent; font: inherit; text-align: center; cursor: ns-resize; }
.meter-value:hover { border: 0; color: var(--acid); background: transparent; }
.meter-value:focus,
.meter-value:focus-visible { outline: 0; color: var(--acid); background: transparent; }
.meter-slash { color: #68707d; }
.volume-control { width: 96px; }
.volume-control input[type="range"] { width: 96px; }
input[type="range"] { width: 116px; height: 30px; margin: 0; appearance: none; color: var(--acid); background: transparent; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: var(--line-strong); }
input[type="range"]::-webkit-slider-thumb { width: 10px; height: 10px; margin-top: -4px; appearance: none; border: 0; border-radius: 50%; background: var(--acid); }
input[type="range"]::-moz-range-track { height: 2px; border: 0; background: var(--line-strong); }
input[type="range"]::-moz-range-progress { height: 2px; background: var(--acid); }
input[type="range"]::-moz-range-thumb { width: 10px; height: 10px; border: 0; border-radius: 50%; background: var(--acid); }
input[type="range"]:focus-visible { outline: 1px solid var(--acid); outline-offset: 2px; }
.upload-button, .sound-toggle { display: inline-flex; align-items: center; justify-content: center; height: 30px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--radius-control); color: #b9bec7; background: var(--raised); font-size: 10px; cursor: pointer; white-space: nowrap; }
.upload-button:hover { border-color: var(--line-strong); }
.sound-toggle.on { color: #0b0d12; border-color: var(--acid); background: var(--acid); }
.recorder-controls { display: flex; align-items: center; gap: 6px; margin-left: 4px; padding-left: 14px; border-left: 1px solid var(--line); }
.record-button, .download-button { height: 30px; padding: 0 9px; font-size: 9px; }
.record-button { display: inline-flex; align-items: center; gap: 7px; }
.record-button i { width: 7px; height: 7px; border-radius: 50%; background: var(--acid); }
.record-button.recording { color: #fff; border-color: var(--acid); background: #281416; }
.record-button.recording i { animation: record-pulse 1s ease-in-out infinite; }
.record-time { min-width: 38px; color: #707784; font: 500 9px/1 "DM Mono", monospace; text-align: center; }
.recording + .record-time { color: #ff7c84; }
.download-button { color: var(--text); }
.download-button:disabled { color: #4f555f; cursor: not-allowed; opacity: .55; }
@keyframes record-pulse { 50% { opacity: .3; } }

.effects-rack {
  position: relative;
  flex: 0 0 auto;
  min-height: 0;
  padding: 8px 10px 9px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 4px;
  overflow: visible;
  border-top: 1px solid var(--line);
  background: var(--surface);
  scrollbar-width: thin;
  scrollbar-color: #353b45 transparent;
}
.effects-heading-row { min-height: 20px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.effects-label { color: var(--text); font: 600 10px/1 "DM Mono", monospace; letter-spacing: .1em; }
.effects-rack .control-group { width: 100%; gap: 3px; }
.effects-rack .control-group > span { color: var(--muted); font: 500 9px/1.15 "DM Mono", monospace; letter-spacing: .08em; }
.effects-rack .control-group select { width: 100%; min-width: 0; max-width: none; }
.fx-jog { --jog-position: 6%; position: relative; width: 100%; height: 48px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-control); background: var(--raised); cursor: ns-resize; touch-action: none; user-select: none; }
.fx-jog::before,
.fx-jog::after { content: ""; position: absolute; z-index: 1; right: 27px; left: 25px; height: 1px; background: var(--line); pointer-events: none; }
.fx-jog::before { top: 16px; }
.fx-jog::after { bottom: 16px; }
.fx-jog-window { position: absolute; inset: 0 27px 0 25px; display: grid; grid-template-rows: 16px 16px 16px; align-items: center; overflow: hidden; text-align: left; pointer-events: none; }
.fx-jog-window span { overflow: hidden; color: #686b72; font: 500 8px/1 "DM Mono", monospace; letter-spacing: .03em; text-overflow: ellipsis; white-space: nowrap; }
.fx-jog-window strong { overflow: hidden; color: var(--text); font: 500 10px/1 "DM Mono", monospace; letter-spacing: 0; text-overflow: ellipsis; white-space: nowrap; }
.fx-jog-arrows { position: absolute; top: 0; bottom: 0; left: 0; width: 20px; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 8px 0; border-right: 1px solid var(--line); pointer-events: none; }
.fx-jog-arrows i { width: 5px; height: 5px; border-top: 1px solid var(--muted); border-left: 1px solid var(--muted); transform: rotate(45deg); }
.fx-jog-arrows i:last-child { transform: rotate(225deg); }
.fx-jog.at-start .fx-jog-arrows i:first-child,
.fx-jog.at-end .fx-jog-arrows i:last-child { opacity: .2; }
.fx-jog-rail { position: absolute; top: 0; right: 0; bottom: 0; width: 22px; display: flex; flex-direction: column; align-items: flex-end; justify-content: space-between; padding: 5px 6px; border-left: 1px solid var(--line); pointer-events: none; }
.fx-jog-rail i { width: 5px; height: 1px; background: #55585f; }
.fx-jog-rail i:nth-child(3) { width: 9px; background: var(--muted); }
.fx-jog-rail b { position: absolute; top: var(--jog-position); right: 4px; width: 12px; height: 2px; transform: translateY(-50%); background: var(--acid); transition: top .12s ease; }
.fx-jog select.vertical-drag-select { position: absolute; z-index: 3; inset: 0; width: 100%; height: 100%; padding: 0; appearance: none; border: 0; opacity: 0; cursor: ns-resize; touch-action: none; user-select: none; }
.fx-jog:hover { border-color: var(--line-strong); }
.fx-jog:has(select:focus-visible) { outline: 1px solid var(--acid); outline-offset: 2px; }
.fx-jog.dragging { border-color: var(--acid); }
.fx-jog.dragging .fx-jog-current { color: var(--acid); }
.fx-jog.dragging .fx-jog-rail b { transition: none; }
.color-xy-pad { --xy-x: 50%; --xy-y: 50%; position: relative; width: 100%; height: 64px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-control); background: var(--raised); cursor: crosshair; touch-action: none; user-select: none; }
.color-xy-pad:hover { border-color: var(--line-strong); }
.color-xy-pad:focus-visible { outline: 1px solid var(--acid); outline-offset: 2px; }
.color-xy-pad.dragging { border-color: var(--acid); }
.color-xy-axis-x,
.color-xy-axis-y { position: absolute; background: var(--line-strong); pointer-events: none; }
.color-xy-axis-x { top: 50%; right: 0; left: 0; height: 1px; }
.color-xy-axis-y { top: 0; bottom: 0; left: 50%; width: 1px; }
.color-xy-cursor { position: absolute; z-index: 2; top: calc(100% - var(--xy-y)); left: var(--xy-x); width: 11px; height: 11px; transform: translate(-50%, -50%); border: 1px solid var(--acid); background: var(--raised); pointer-events: none; }
.color-xy-cursor::before,
.color-xy-cursor::after { content: ""; position: absolute; top: 50%; left: 50%; background: var(--acid); transform: translate(-50%, -50%); }
.color-xy-cursor::before { width: 15px; height: 1px; }
.color-xy-cursor::after { width: 1px; height: 15px; }
.color-xy-readout { position: absolute; z-index: 3; top: 5px; left: 6px; display: grid; grid-template-columns: auto 28px auto 24px; gap: 3px; padding: 3px 4px; color: var(--text); background: var(--raised); font: 500 8px/1 "DM Mono", monospace; pointer-events: none; }
.color-xy-readout b { color: var(--acid); font-weight: 500; }
.color-xy-readout output { color: inherit; font: inherit; }
.color-xy-label-x,
.color-xy-label-y { position: absolute; z-index: 1; color: #55585f; font: 500 6px/1 "DM Mono", monospace; letter-spacing: .08em; pointer-events: none; }
.color-xy-label-x { right: 5px; bottom: 4px; }
.color-xy-label-y { top: 5px; right: 4px; writing-mode: vertical-rl; }
.color-xy-pad.dragging .color-xy-cursor { background: var(--acid); }
.effects-rack .fx-slider { width: 100%; }
.effects-rack input[type="range"] { width: 100%; height: 26px; }
.effects-rack output { color: #9ca3ad; }
.rack-divider { flex: 0 0 auto; width: 100%; height: 1px; margin: 1px 0; background: var(--line); }
.beat-control-row { width: 100%; display: grid; grid-template-columns: 42px minmax(0, 1fr); align-items: start; gap: 6px; }
.effects-rack .beat-control-row .control-group { width: auto; min-width: 0; }
.beat-duration-control { --beat-depth: 50%; --beat-pulse: 0; position: relative; width: 100%; height: 48px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-control); background: var(--raised); cursor: ns-resize; touch-action: none; user-select: none; }
.beat-duration-control:focus-visible { outline: 1px solid var(--acid); outline-offset: 2px; }
.beat-duration-block { position: absolute; top: 3px; bottom: 3px; left: 50%; width: 66%; min-width: 46px; transform: translateX(-50%); display: flex; align-items: center; justify-content: center; overflow: hidden; border: 1px solid var(--acid); background: #151313; border-radius: 1px; color: var(--text); transition: width .12s ease; }
.beat-duration-block::after { content: ""; position: absolute; z-index: 1; inset: 0; border: 1px solid rgba(255,105,114,.9); background: rgba(255,75,85,.12); box-shadow: inset 0 0 14px 3px rgba(255,75,85,.92); opacity: var(--beat-pulse); pointer-events: none; }
.beat-duration-control.dragging-duration { cursor: ew-resize; }
.beat-duration-control.dragging-duration .beat-duration-block { transition: none; }
.beat-duration-control.dragging-depth .beat-combined-value { color: var(--acid); }
.beat-depth-fill { position: absolute; right: 0; bottom: 0; left: 0; height: var(--beat-depth); background: rgba(255,75,85,.12); pointer-events: none; }
.beat-depth-marker { position: absolute; z-index: 1; right: 0; left: 0; top: calc(100% - var(--beat-depth)); height: 1px; background: var(--acid); pointer-events: none; }
.beat-combined-value { position: relative; z-index: 2; display: flex; align-items: baseline; gap: 5px; padding: 3px 5px; background: var(--raised); font: 500 9px/1 "DM Mono", monospace; pointer-events: none; }
.beat-combined-value output { color: inherit; font: inherit; }
.beat-combined-value small { color: var(--muted); font: inherit; }
.beat-handle { position: absolute; top: -1px; bottom: -1px; width: 12px; cursor: ew-resize; }
.beat-handle { z-index: 3; }
.beat-handle::after { content: ""; position: absolute; top: 12px; bottom: 12px; width: 1px; background: var(--acid); border-radius: 0; }
.beat-handle.left { left: -1px; }
.beat-handle.left::after { left: 4px; }
.beat-handle.right { right: -1px; }
.beat-handle.right::after { right: 4px; }
.effects-rack .bpm-control input { width: 100%; }
.effects-rack #resetEffects { width: auto; height: 20px; flex: 0 0 auto; padding: 0 6px; font-size: 7px; }
.bpm-control input { width: 66px; height: 30px; padding: 0 8px; border: 1px solid var(--line); border-radius: var(--radius-control); color: var(--text); background: var(--raised); font: 500 10px "DM Mono", monospace; }
.effects-rack .beat-fx-bpm { width: 42px; align-self: flex-start; }
.effects-rack .beat-fx-bpm input { width: 42px; height: 30px; padding: 0 2px; border: 0; border-radius: 0; color: var(--text); background: transparent; font: 500 11px/1 "DM Mono", monospace; text-align: center; cursor: ns-resize; appearance: textfield; }
.effects-rack .beat-fx-bpm input::-webkit-inner-spin-button,
.effects-rack .beat-fx-bpm input::-webkit-outer-spin-button { margin: 0; appearance: none; }
.effects-rack .beat-fx-bpm input:focus { outline: 1px solid var(--acid); outline-offset: 2px; }

.recordings-rack { position: fixed; z-index: 7; top: var(--topbar-height); right: 0; width: var(--recordings-width-expanded); height: calc(var(--keyboard-top) - var(--topbar-height)); padding: 0; display: flex; flex-direction: column; align-items: stretch; gap: 0; border-left: 1px solid var(--line); background: var(--surface); transition: transform .18s ease, background-color .14s ease, border-color .14s ease; }
:root.recordings-collapsed .recordings-rack { transform: translateX(100%); pointer-events: none; }
.recordings-toggle { position: fixed; z-index: 14; top: calc(var(--topbar-height) + 8px); right: var(--recordings-width); width: 22px; height: 36px; padding: 0; display: grid; place-items: center; border-right: 0; border-radius: 2px 0 0 2px; color: var(--muted); background: var(--surface); transition: right .18s ease, background-color .14s ease, color .14s ease, border-color .14s ease; }
.recordings-toggle:hover { color: var(--text); background: var(--raised); }
.recordings-toggle svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: square; stroke-linejoin: miter; transition: transform .18s ease; }
:root.recordings-collapsed .recordings-toggle svg { transform: rotate(180deg); }
.recordings-rack::before { content: ""; position: absolute; top: calc(-1 * var(--topbar-height)); left: -1px; width: 1px; height: var(--topbar-height); background: var(--line); pointer-events: none; }
.recordings-rack .recorder-controls { width: 100%; margin: 0; padding: 9px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; border-left: 0; border-bottom: 1px solid var(--line); }
.recordings-rack .record-button { width: 100%; justify-content: center; }
.recordings-rack .record-time { align-self: center; }
.recordings-heading { flex: 0 0 auto; padding: 11px 10px 9px; display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 7px; border-bottom: 1px solid var(--line); }
.recordings-heading span { color: var(--text); font: 600 8px/1 "DM Mono", monospace; letter-spacing: .1em; }
.recordings-heading small { color: #555c68; font: 500 8px/1 "DM Mono", monospace; letter-spacing: .1em; }
.recordings-list { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: stretch; gap: 0; overflow-x: hidden; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #353535 transparent; }
.recordings-empty { margin: 0; padding: 12px 10px; color: #5d5f64; font: 400 9px/1.4 "DM Mono", monospace; }
.take-card { flex: 0 0 auto; width: 100%; min-width: 0; padding: 9px 10px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; }
.take-card.playing { border-color: var(--line); background: #1c1415; }
.take-info { min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.take-info strong { max-width: 100px; overflow: hidden; color: #d7d9dc; font: 500 10px/1 "DM Mono", monospace; text-overflow: ellipsis; white-space: nowrap; }
.take-info small { color: #686f7a; font: 500 8px/1 "DM Mono", monospace; }
.take-actions { display: grid; grid-template-columns: repeat(4, 26px); gap: 2px; }
.take-actions button { width: 26px; height: 26px; padding: 0; border-radius: 2px; color: #9da3ad; font: 500 11px/1 "DM Mono", monospace; }
.take-actions button[data-action="piano"] { color: var(--acid); }
.take-actions button[data-action="audio-play"] { color: var(--text); }
.take-actions button:disabled { color: #484e57; opacity: .55; cursor: not-allowed; }

.hero { --fifths-size: min(400px, calc(100vw - var(--browser-width) - var(--recordings-width) - 64px), calc(100vh - var(--keyboard-height) - 124px)); position: relative; z-index: 6; flex: 1 1 auto; min-height: 0; padding: 20px 24px 16px; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; text-align: center; background-image: linear-gradient(to top, transparent 31px, rgba(255,255,255,.035) 32px); background-size: 32px 32px; }
.hero.note-grid-hidden { background-image: none; }
.history-controls { position: absolute; z-index: 8; right: 10px; bottom: 10px; display: flex; align-items: center; gap: 2px; padding: 3px; border: 1px solid var(--line); background: var(--surface); }
.history-controls button { width: 26px; height: 26px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 1px; color: var(--muted); background: transparent; font: 500 11px/1 "DM Mono", monospace; }
.history-controls button:hover { color: var(--text); background: var(--raised); }
.history-controls button.active { color: var(--acid); border-color: transparent; }
.history-controls #keyboardFollowToggle[aria-pressed="true"] { color: var(--best); }
.history-controls #keyWidthToggle { cursor: ew-resize; touch-action: none; }
.history-controls #keyWidthToggle.dragging { color: var(--acid); background: var(--raised); }
.history-controls .rainbow-view-toggle svg path:nth-child(1) { stroke: #ff5364; }
.history-controls .rainbow-view-toggle svg path:nth-child(2) { stroke: #50c878; }
.history-controls .rainbow-view-toggle svg path:nth-child(3) { stroke: #58a6ff; }
.history-controls .rainbow-view-toggle[aria-pressed="true"] { background: var(--raised); }
.history-controls svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: square; stroke-linejoin: miter; }
.history-controls .history-play-icon { fill: currentColor; stroke: none; }
.history-controls [data-state="playing"] .history-play-icon,
.history-controls [data-state="paused"] .history-pause-icon { display: none; }
.history-controls output { min-width: 44px; padding: 0 4px; color: var(--muted); font: 500 8px/1 "DM Mono", monospace; letter-spacing: .04em; text-align: right; }
.history-return-live { position: absolute; z-index: 9; right: 16px; bottom: 58px; width: 52px; height: 58px; padding: 7px 0 5px; display: flex; flex-direction: column; align-items: center; justify-content: space-between; border: 1px solid var(--acid); border-radius: var(--radius-control); color: var(--acid); background: var(--surface); }
.history-return-live[hidden] { display: none; }
.history-return-live svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: square; stroke-linejoin: miter; }
.history-return-live span { font: 500 7px/1 "DM Mono", monospace; letter-spacing: .12em; }
.history-return-live:hover { color: #fff; border-color: var(--acid); background: var(--acid); }
.history-return-live:active svg { transform: translateY(2px); }
.eyebrow { width: var(--fifths-size); margin: 0; color: var(--muted); font: 500 8px/1 "DM Mono", monospace; letter-spacing: .12em; text-align: left; }
.fifths-stage { position: relative; width: var(--fifths-size); aspect-ratio: 1; margin: 8px 0; }
.fifths-wheel { position: absolute; inset: 5%; border: 1px solid var(--line-strong); border-radius: 50%; }
.fifths-wheel::before { content: ""; position: absolute; inset: 25%; border: 1px solid var(--line); border-radius: 50%; }
.fifths-node { position: absolute; width: 58px; min-height: 40px; padding: 2px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; transform: translate(-50%, -50%); border: 0; border-radius: 0; color: var(--muted); background: transparent; font-family: "DM Mono", monospace; transition: color .14s ease, transform .14s ease; }
.fifths-degree { min-height: 7px; max-width: 56px; overflow: hidden; color: var(--acid); font-size: 6.5px; font-weight: 600; line-height: 1; letter-spacing: .02em; text-overflow: ellipsis; white-space: nowrap; }
.fifths-degree:empty { visibility: hidden; }
.fifths-node strong,
.fifths-node small { display: block; max-width: 56px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fifths-node strong { font-size: 9px; font-weight: 500; line-height: 1.1; }
.fifths-node small { color: #626a77; font-size: 7px; line-height: 1.1; }
.fifths-node.suggested { z-index: 1; color: var(--text); outline: 1px solid rgba(255,75,85,.72); outline-offset: 1px; background: #1b1516; transform: translate(-50%, -50%); }
.fifths-node.suggested-major strong,
.fifths-node.suggested-minor small { color: var(--text); text-decoration: underline; text-decoration-color: var(--acid); text-underline-offset: 2px; }
.fifths-node.suggested::after { content: ""; position: absolute; top: -2px; right: -2px; width: 5px; height: 5px; background: var(--acid); }
.fifths-node.strongest { z-index: 3; outline-color: var(--best); background: #111b25; }
.fifths-node.strongest::after { background: var(--best); }
.fifths-node.strongest .fifths-degree { color: var(--best); }
.fifths-node.strongest-major strong,
.fifths-node.strongest-minor small { color: var(--best); text-decoration-color: var(--best); }
.fifths-node.current { z-index: 2; color: var(--acid); outline: 0; background: transparent; transform: translate(-50%, -50%) scale(1.08); }
.fifths-node.current::after { display: none; }
.fifths-node.current-major strong,
.fifths-node.current-minor small { padding: 0 0 2px; border-radius: 0; color: var(--acid); background: transparent; border-bottom: 1px solid var(--acid); }
.fifths-node.current-minor strong { color: var(--muted); }
.fifths-node.current-minor small { font-size: 8px; }
.chord-wrap { position: absolute; inset: 27%; display: flex; align-items: center; justify-content: center; min-height: 0; }
h1 { margin: 4px 0 0; font-size: clamp(66px, 10vw, 138px); line-height: .95; letter-spacing: -.065em; font-weight: 500; }
.fifths-stage h1 { min-width: 0; max-width: none; font-size: clamp(38px, 5.2vw, 72px); overflow-wrap: normal; letter-spacing: -.055em; white-space: nowrap; }
#inversion { color: var(--muted); font-size: clamp(24px, 4vw, 54px); font-weight: 500; margin-left: 5px; }
.fifths-stage #inversion { color: var(--muted); font-size: clamp(14px, 1.8vw, 24px); }
.spelling { width: var(--fifths-size); min-height: 20px; margin: 12px 0 0; color: var(--muted); font: 400 10px/1.4 "DM Mono", monospace; letter-spacing: .02em; text-align: left; }
.harmony-legend { width: var(--fifths-size); margin: 2px 0 0; color: #626a77; font: 500 6.5px/1.2 "DM Mono", monospace; letter-spacing: .06em; text-align: left; }
.harmony-legend span { color: var(--best); }

.keyboard-section { position: fixed; z-index: 6; right: 0; bottom: 0; left: 0; height: var(--keyboard-height); margin-left: 0; margin-right: 0; border-top: 1px solid var(--line-strong); border-bottom: 1px solid var(--line); background: var(--surface); }

.keyboard-viewport { position: relative; z-index: 6; overflow-x: auto; overflow-y: hidden; padding-top: 40px; scrollbar-width: thin; scrollbar-color: #353b45 transparent; cursor: grab; scroll-behavior: smooth; }
.keyboard-viewport.dragging { cursor: grabbing; scroll-behavior: auto; user-select: none; }
.keyboard { position: relative; height: 188px; margin: 0 auto; }
.key { position: absolute; top: 0; border: 1px solid #292929; border-radius: 0; cursor: pointer; touch-action: none; user-select: none; transition: background .06s, transform .06s; }
.key.white { width: var(--white-key); height: 184px; z-index: 1; background: #e9e9e4; }
.key.black { width: var(--black-key); height: 112px; z-index: 2; background: #080808; border-color: #000; }
.key.white.suggested-next,
.key.black.suggested-next { background: var(--best-key); }
.key.suggested-next .number { color: #18344e; }
.key.white.octave-start::before { content: ""; position: absolute; z-index: 3; top: 0; bottom: 0; left: -2px; width: 2px; background: var(--acid); pointer-events: none; }
.key.white.active, .key.black.active { background: var(--acid); transform: translateY(2px); }
.key.active .number { color: #fff; }
:root.rainbow-notes .key.white:not(.active):not(.suggested-next) { background: color-mix(in srgb, var(--note-color) 34%, #e9e9e4); }
:root.rainbow-notes .key.black:not(.active):not(.suggested-next) { background: color-mix(in srgb, var(--note-color) 42%, #080808); }
:root.rainbow-notes .key.white.active,
:root.rainbow-notes .key.black.active { background: var(--note-color); }
:root.rainbow-notes .key.active .number { color: var(--note-ink); }
.key .number { position: absolute; top: 8px; left: 0; width: 100%; text-align: center; color: #71767d; font: 500 7px/1 "DM Mono", monospace; }
.key.black .number { top: 7px; color: #8a9099; }
.note-badge { position: absolute; top: -28px; left: 50%; transform: translateX(-50%); padding: 4px 6px; color: #170405; background: var(--acid); border-radius: 1px; font: 500 9px/1 "DM Mono", monospace; white-space: nowrap; }
.note-badge::after { content: ""; position: absolute; left: 50%; bottom: -4px; transform: translateX(-50%); border: 4px solid transparent; border-top-color: var(--acid); border-bottom: 0; }
:root.rainbow-notes .note-badge { color: var(--note-ink); background: var(--note-color); }
:root.rainbow-notes .note-badge::after { border-top-color: var(--note-color); }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

:root[data-theme="light"] select,
:root[data-theme="light"] button,
:root[data-theme="light"] .metro-bpm input,
:root[data-theme="light"] .bpm-control input,
:root[data-theme="light"] .upload-button,
:root[data-theme="light"] .sound-toggle { background: var(--raised); }
:root[data-theme="light"] button:hover,
:root[data-theme="light"] select:hover { background: #ecece8; }
:root[data-theme="light"] .sound-browser,
:root[data-theme="light"] .recordings-rack { background: var(--surface); backdrop-filter: none; }
:root[data-theme="light"] .sound-rack { background: transparent; backdrop-filter: none; }
:root[data-theme="light"] .effects-rack { background: var(--surface); }
:root[data-theme="light"] .keyboard-section { background: var(--surface); }
:root[data-theme="light"] .fifths-node { background: transparent; }
:root[data-theme="light"] .fifths-node.suggested { outline-color: rgba(255,75,85,.72); background: #f3e1e1; }
:root[data-theme="light"] .fifths-node.strongest { outline-color: var(--best); background: #e4f1fc; }
:root[data-theme="light"] .fifths-node.current { color: var(--acid); background: transparent; }
:root[data-theme="light"] .sound-choice { color: #59616d; }
:root[data-theme="light"] .sound-choice > i { background: #aeb3bc; }
:root[data-theme="light"] .sound-choice.active > i { background: var(--acid); }
:root[data-theme="light"] .sound-choice:hover { background: #ecece8; }
:root[data-theme="light"] .sound-choice.active { color: #28191c; background: #f3e1e1; }
:root[data-theme="light"] .add-sample-button:hover { color: var(--text); }
:root[data-theme="light"] .upload-button,
:root[data-theme="light"] .sound-toggle { color: #4f5863; }
:root[data-theme="light"] .sound-toggle.on { color: #fff; background: var(--acid); }
:root[data-theme="light"] .midi-device-option.selected { background: #f3e1e1; }
:root[data-theme="light"] .metro-bpm input { background: transparent; }
:root[data-theme="light"] .meter-value { background: transparent; }
:root[data-theme="light"] .effects-rack .beat-fx-bpm input { background: transparent; }
:root[data-theme="light"] .control-group,
:root[data-theme="light"] .beat-readout { color: #697280; }
:root[data-theme="light"] .take-card { background: transparent; }
:root[data-theme="light"] .take-card.playing { background: #f3e1e1; }
:root[data-theme="light"] .history-controls { background: var(--surface); }
:root[data-theme="light"] .hero { background-image: linear-gradient(to top, transparent 31px, rgba(0,0,0,.045) 32px); }
:root[data-theme="light"] .hero.note-grid-hidden { background-image: none; }
:root[data-theme="light"] .beat-duration-block { background: #f3dfe0; }
:root[data-theme="light"] .take-info strong { color: #30343a; }
:root[data-theme="light"] .recordings-empty,
:root[data-theme="light"] .recordings-heading small,
:root[data-theme="light"] .record-time { color: #747b86; }
:root[data-theme="light"] .key { border-color: #b7b4b1; }
:root[data-theme="light"] .key.white { background: #fffdfa; }
:root[data-theme="light"] .key.black { background: #26262b; border-color: #1c1c20; }
:root[data-theme="light"] .key.white.suggested-next,
:root[data-theme="light"] .key.black.suggested-next { background: var(--best-key); }
:root[data-theme="light"] .key.white.active,
:root[data-theme="light"] .key.black.active { background: var(--acid); }
:root[data-theme="light"].rainbow-notes .key.white:not(.active):not(.suggested-next) { background: color-mix(in srgb, var(--note-color) 30%, #fffdfa); }
:root[data-theme="light"].rainbow-notes .key.black:not(.active):not(.suggested-next) { background: color-mix(in srgb, var(--note-color) 42%, #26262b); }
:root[data-theme="light"].rainbow-notes .key.white.active,
:root[data-theme="light"].rainbow-notes .key.black.active { background: var(--note-color); }

@media (min-width: 701px) and (max-width: 1100px) {
  :root { --browser-width-expanded: 180px; --recordings-width-expanded: 224px; }
  .sound-controls { gap: 5px; }
  .volume-control,
  .volume-control input[type="range"] { width: 72px; }
  .hero { padding-right: 16px; padding-left: 16px; }
}

@media (max-width: 700px) {
  :root { --browser-width-expanded: 142px; --recordings-width-expanded: 0px; }
  main { padding-bottom: 0; }
  header { height: auto; min-height: var(--topbar-height); gap: 12px; }
  .midi-controls { width: auto; flex: 1; justify-content: flex-end; }
  #midiButton { padding: 0; }
  .sound-browser { top: 0; }
  .sound-browser { height: 100vh; overflow-y: hidden; }
  .browser-heading { padding: 16px 11px 13px; }
  .sound-list { padding: 6px; }
  .sound-choice { height: 34px; padding: 0 7px; gap: 7px; }
  .sound-choice > span { font-size: 9px; }
  .browser-import { padding: 8px; }
  .add-sample-button { font-size: 8px; }
  .sound-rack { align-items: flex-start; flex-direction: column; gap: 12px; }
  .sound-rack { position: relative; top: auto; left: auto; right: auto; height: auto; min-height: var(--topbar-height); margin-left: var(--browser-width); margin-right: 0; overflow: visible; }
  .sound-controls { width: 100%; min-width: 0; justify-content: flex-start; flex-wrap: wrap; }
  .control-group select { min-width: 145px; max-width: 48vw; }
  .browser-heading .volume-control { width: 68px; }
  .browser-heading .volume-control input[type="range"] { width: 68px; }
  .recorder-controls { width: 100%; margin-left: 0; padding: 10px 0 0; border-left: 0; border-top: 1px solid var(--line); }
  .effects-rack { flex: 0 1 360px; min-height: 230px; padding: 12px 8px 14px; overflow-y: auto; }
  .recordings-rack { position: relative; top: auto; right: auto; bottom: auto; width: auto; height: auto; max-height: 230px; margin-left: var(--browser-width); padding: 12px 10px; border-left: 0; border-bottom: 1px solid var(--line); }
  :root.recordings-collapsed .recordings-rack { display: none; }
  .recordings-rack::before { display: none; }
  .keyboard-section { position: relative; right: auto; bottom: auto; left: auto; height: auto; margin-left: var(--browser-width); }
  .hero { flex: none; min-height: 300px; padding-top: 55px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
