:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0b0c0e;
  color: #f3f4f6;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at top left, #1f2429 0, #0b0c0e 42rem); }
button, input, select { font: inherit; }
button, select { border: 1px solid #353b42; background: #181b1f; color: #f3f4f6; border-radius: 12px; min-height: 46px; padding: 0 18px; }
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: #606a75; background: #20242a; }
button:disabled { opacity: .42; cursor: default; }
button.primary { background: #f3f4f6; color: #111214; border-color: #f3f4f6; font-weight: 700; }
button.danger { border-color: #5b3c3c; color: #e7b9b9; }
.shell { width: min(1040px, calc(100% - 28px)); margin: 0 auto; padding: 28px 0 36px; }
.hero { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; padding: 28px 4px 24px; }
.eyebrow, .section-label { margin: 0 0 8px; font-size: 12px; letter-spacing: .13em; text-transform: uppercase; color: #929aa4; }
h1 { margin: 0; font-size: clamp(42px, 8vw, 82px); line-height: .95; letter-spacing: -.055em; }
.subtitle { margin: 15px 0 0; color: #aeb5bd; font-size: 15px; }
.state { display: inline-flex; align-items: center; justify-content: center; min-width: 86px; padding: 8px 11px; border: 1px solid #343a40; border-radius: 999px; font-size: 11px; letter-spacing: .12em; font-weight: 800; }
.state-ready { border-color: #5f7f69; background: #17231b; color: #bde7c7; }
.state-starting { border-color: #7a7047; background: #241f13; color: #eadb9f; }
.state-error { border-color: #815555; background: #281717; color: #f1b4b4; }
.panel { border: 1px solid #2b3036; background: rgba(19, 21, 24, .84); border-radius: 18px; padding: 22px; box-shadow: 0 18px 60px rgba(0,0,0,.18); }
.controls { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 24px; }
h2 { margin: 0 0 8px; font-size: 24px; letter-spacing: -.025em; }
.status { margin: 0; color: #aeb5bd; white-space: pre-wrap; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }

.sound-overview { margin-top: 12px; }
.sound-heading-row { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.patch-state { border: 1px solid #343a40; border-radius: 999px; padding: 7px 10px; color: #9ba4ad; font-size: 11px; }
.patch-state.edited { color: #eadb9f; border-color: #6f653d; background: #211d12; }
.sound-selectors { display: grid; grid-template-columns: minmax(220px, 2fr) minmax(160px, 1fr) auto; gap: 12px; margin-top: 18px; align-items: end; }
.sound-selectors label, .quality-readout { display: grid; gap: 7px; color: #89929c; font-size: 12px; }
.sound-selectors select { width: 100%; }
.quality-readout strong { min-height: 46px; display: flex; align-items: center; padding: 0 13px; border: 1px solid #343a40; border-radius: 12px; color: #d8dde2; text-transform: capitalize; }
.provenance { margin: 11px 0 0; color: #707983; font-size: 11px; }
.macros { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 18px; }
.macro-control { display: grid; grid-template-columns: 1fr auto; gap: 8px; border: 1px solid #292e34; background: rgba(10,12,14,.55); border-radius: 14px; padding: 14px; }
.macro-control span { color: #aeb5bd; font-size: 12px; }
.macro-control strong { font-size: 12px; font-variant-numeric: tabular-nums; }
.macro-control input { grid-column: 1 / -1; width: 100%; accent-color: currentColor; }
.advanced-sound { margin-top: 16px; border-top: 1px solid #282d32; padding-top: 14px; }
.advanced-sound > summary { cursor: pointer; color: #bec4cb; font-weight: 650; user-select: none; }
#detailed-sound { margin-top: 14px; }
.brk-sound-panel { max-width: none; margin: 0; padding: 0; color: #f3f4f6; background: transparent; }
.brk-sound-header { display: none; }
.brk-sound-pages { gap: 7px; margin-bottom: 14px; }
.brk-sound-pages button { min-height: 38px; padding: 0 12px; font-size: 12px; }
.brk-sound-pages button[aria-pressed="true"] { text-decoration: none; background: #e7e7e2; color: #111214; border-color: #e7e7e2; }
.brk-sound-page { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.brk-sound-group { border-color: #30363d; border-radius: 12px; background: rgba(9,11,13,.46); }
.brk-sound-group h3 { color: #aeb5bd; }
.brk-sound-control { grid-template-columns: minmax(100px, 1fr) auto minmax(120px, 1.2fr) auto; }
.brk-sound-control-input { accent-color: currentColor; }
.brk-sound-control select { min-height: 34px; padding: 0 8px; border-radius: 8px; }

.instrument-panel { margin-top: 12px; overflow: hidden; transition: opacity .16s ease; }
.instrument-disabled { opacity: .62; }
.instrument-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; }
.active-notes { border: 1px solid #343a40; border-radius: 999px; padding: 7px 10px; color: #9ba4ad; font-size: 11px; white-space: nowrap; }
.play-controls { display: grid; grid-template-columns: auto minmax(180px, 1fr) auto auto; align-items: end; gap: 12px; margin: 20px 0 18px; }
.octave-control, .velocity-control { display: grid; gap: 8px; color: #9ba4ad; font-size: 12px; }
.stepper { display: grid; grid-template-columns: 46px 64px 46px; align-items: center; }
.stepper button { border-radius: 10px; padding: 0; }
.stepper strong { text-align: center; font-size: 16px; color: #f3f4f6; }
.velocity-control input { width: 100%; min-height: 46px; accent-color: currentColor; }
#sustain.latched { background: #e9e6d7; color: #141517; border-color: #e9e6d7; }
.piano { position: relative; height: clamp(150px, 28vw, 230px); background: #08090a; border: 1px solid #343940; border-radius: 14px; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.piano-white-row { display: flex; width: 100%; height: 100%; }
.piano-key { border-radius: 0; padding: 0; min-height: 0; touch-action: none; }
.piano-key.white { flex: 1 1 0; height: 100%; border: 0; border-right: 1px solid #83878c; background: linear-gradient(#f3f1eb, #c9c8c2); color: #151617; position: relative; z-index: 1; }
.piano-key.white:last-child { border-right: 0; }
.piano-key.white span { position: absolute; bottom: 9px; left: 50%; transform: translateX(-50%); font-size: 10px; color: #666; }
.piano-black-layer { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.piano-key.black { position: absolute; top: 0; height: 62%; pointer-events: auto; background: linear-gradient(#272a2e, #090a0b); border: 1px solid #020303; box-shadow: 0 6px 9px rgba(0,0,0,.32); }
.piano-key.white.active { background: linear-gradient(#d9e6dc, #9db5a5); }
.piano-key.black.active { background: linear-gradient(#6f8e78, #263c2d); }
.keyboard-legend { display: flex; justify-content: space-between; gap: 16px; margin-top: 10px; font-size: 10px; color: #727b84; font-variant-numeric: tabular-nums; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; margin-top: 12px; }
.metric { min-height: 92px; border: 1px solid #24292e; border-radius: 15px; padding: 16px; background: rgba(14,16,18,.76); display: flex; flex-direction: column; justify-content: space-between; gap: 12px; }
.metric span { color: #858e98; font-size: 12px; }
.metric strong { font-size: 18px; font-variant-numeric: tabular-nums; text-transform: capitalize; }
.error-panel { margin-top: 12px; border-color: #6d4141; background: #211313; }
#error-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; color: #f0b6b6; font-size: 12px; line-height: 1.5; }
footer { display: flex; justify-content: space-between; gap: 16px; padding: 18px 4px 0; color: #69717a; font-size: 11px; }
@media (max-width: 820px) {
  .controls { grid-template-columns: 1fr; }
  .button-row { justify-content: stretch; }
  .button-row button { flex: 1 1 140px; }
  .sound-selectors { grid-template-columns: 1fr 1fr; }
  .quality-readout { grid-column: 1 / -1; }
  .macros { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .play-controls { grid-template-columns: 1fr 1fr; }
  .metrics { grid-template-columns: repeat(2, minmax(0,1fr)); }
  footer { flex-direction: column; }
}
@media (max-width: 560px) {
  .hero { flex-direction: column; }
  .sound-selectors { grid-template-columns: 1fr; }
  .quality-readout { grid-column: auto; }
  .keyboard-legend { flex-direction: column; gap: 4px; }
  .brk-sound-control { grid-template-columns: minmax(90px,1fr) auto; }
  .brk-sound-control-input { grid-column: 1 / -1; }
}
@media (max-width: 430px) {
  .shell { width: min(100% - 20px, 1040px); padding-top: 12px; }
  .panel { padding: 17px; border-radius: 15px; }
  .play-controls { grid-template-columns: 1fr 1fr; gap: 9px; }
  .velocity-control { grid-column: 1 / -1; }
  .metrics { gap: 9px; }
  .metric { min-height: 82px; padding: 13px; }
  .piano { height: 165px; }
  .macros { grid-template-columns: 1fr 1fr; }
}
