:root {
  --bg: #0f1111;
  --surface: #181b1a;
  --surface-soft: #202422;
  --text: #f5f2ea;
  --muted: #a6aaa1;
  --green: #83dc94;
  --red: #f26f6f;
  --cyan: #63d3e6;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.28);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  overflow-x: hidden;
  background: linear-gradient(145deg, #0d0f0f 0%, #141716 52%, #0f1111 100%);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

.app-shell {
  min-height: 100vh;
  padding: clamp(16px, 2.4vw, 34px);
}

.workspace {
  width: min(1320px, 100%);
  max-width: 100vw;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2.6rem, 5vw, 4.7rem);
  line-height: 0.9;
}

h2 {
  font-size: 1rem;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(318px, 360px);
  gap: 16px;
  align-items: start;
}

.main-grid > *,
.transport > *,
.readout-grid > *,
.split-fields > *,
.knob-grid > *,
.note-strip-inner > * {
  min-width: 0;
}

.visual-column,
.side-stack,
.control-panel,
.tone-panel {
  width: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel,
.visual-stage {
  min-width: 0;
  border-radius: 8px;
  background: rgba(24, 27, 26, 0.94);
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.visual-stage {
  position: relative;
  min-height: min(64vh, 620px);
  overflow: hidden;
  background: #101212;
}

#spectrumCanvas {
  width: 100%;
  max-width: 100%;
  height: 100%;
  min-height: min(64vh, 620px);
  display: block;
}

.drop-zone {
  min-height: 128px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 7px;
  padding: 18px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  text-align: center;
  transition:
    background 160ms ease,
    transform 160ms ease;
}

.drop-zone:hover,
.drop-zone.is-dragging {
  background: #253029;
  transform: translateY(-1px);
}

.drop-zone input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.drop-icon {
  color: var(--green);
  font-size: 2rem;
  line-height: 1;
}

.transport {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.primary-btn,
.ghost-btn,
.mini-btn,
.export-btn {
  min-width: 0;
  min-height: 42px;
  border-radius: 8px;
  padding: 0 13px;
  overflow: hidden;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.primary-btn,
.export-btn {
  background: var(--green);
  color: #071009;
}

.ghost-btn,
.mini-btn {
  background: var(--surface-soft);
  color: var(--text);
}

.icon-btn {
  display: grid;
  place-items: center;
  padding: 0;
}

.stop-icon {
  width: 12px;
  height: 12px;
  display: block;
  border-radius: 2px;
  background: currentColor;
}

button:disabled {
  background: #1b1f1d;
  color: #8e948d;
}

.readout-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
  padding-top: 4px;
}

.readout:nth-child(n + 3) {
  display: none;
}

.readout {
  min-height: 48px;
  display: grid;
  align-content: center;
  gap: 3px;
}

.readout span,
.field span,
.knob-row label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
}

.knob-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
}

.readout strong {
  overflow: hidden;
  color: var(--text);
  font-size: 1rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.field {
  display: grid;
  gap: 7px;
}

.field select {
  width: 100%;
  height: 42px;
  border: 0;
  border-radius: 8px;
  background: #111312;
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

.split-fields {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.is-manual-key .split-fields {
  display: grid;
}

.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border-radius: 8px;
  background: #111312;
}

.mode-toggle label {
  min-width: 0;
}

.mode-toggle input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.mode-toggle span {
  min-height: 36px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

.mode-toggle input:checked + span {
  background: rgba(131, 220, 148, 0.14);
  color: var(--text);
}

.knob-row {
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}

.knob-control {
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 42%, #2d3430 0%, #171b19 68%),
    #171b19;
  box-shadow:
    inset 0 1px 2px rgba(255, 255, 255, 0.09),
    inset 0 -10px 20px rgba(0, 0, 0, 0.28),
    0 10px 24px rgba(0, 0, 0, 0.22);
  cursor: grab;
  touch-action: none;
}

.knob-control.is-turning {
  cursor: grabbing;
}

.knob-control:focus-visible {
  outline: 2px solid rgba(131, 220, 148, 0.7);
  outline-offset: 4px;
}

.knob-face {
  position: relative;
  width: 42px;
  height: 42px;
  display: block;
  border-radius: 50%;
  background:
    conic-gradient(from -135deg, rgba(131, 220, 148, 0.82) 0deg, rgba(131, 220, 148, 0.82) var(--knob-fill, 0deg), rgba(255, 255, 255, 0.08) var(--knob-fill, 0deg), rgba(255, 255, 255, 0.08) 270deg, transparent 270deg),
    #111312;
}

.knob-face::after {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: #202522;
}

.knob-indicator {
  position: absolute;
  left: calc(50% - 2px);
  top: 4px;
  z-index: 1;
  width: 4px;
  height: 12px;
  border-radius: 999px;
  background: var(--green);
  transform: rotate(var(--knob-angle, 0deg));
  transform-origin: 50% 17px;
}

.knob-meta {
  min-width: 0;
  flex: 1 1 auto;
  position: relative;
  display: grid;
  gap: 5px;
}

.octave-control {
  display: grid;
  grid-template-columns: 46px minmax(52px, 1fr);
  align-items: center;
  gap: 6px;
  min-height: 18px;
}

.octave-control span {
  color: rgba(245, 242, 234, 0.72);
  font-size: 0.68rem;
  font-weight: 850;
}

.octave-control input {
  width: 100%;
  height: 14px;
  margin: 0;
  accent-color: var(--green);
}

.knob-row output {
  position: absolute;
  left: 0;
  top: calc(100% + 5px);
  z-index: 3;
  min-width: max-content;
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(8, 10, 9, 0.92);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 850;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-3px);
  transition:
    opacity 140ms ease,
    transform 140ms ease;
  white-space: nowrap;
}

.knob-row:hover output,
.knob-row:focus-within output,
.knob-row:has(.knob-control.is-turning) output {
  opacity: 1;
  transform: translateY(0);
}

.knob-input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.export-btn {
  margin-top: 2px;
}

.note-strip {
  min-width: 0;
  padding: 2px 0 0;
}

.note-strip-inner {
  width: 100%;
  height: 132px;
  position: relative;
  display: block;
}

.piano-white-row {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.piano-key {
  position: relative;
  display: grid;
  align-content: end;
  justify-items: center;
  gap: 2px;
  overflow: hidden;
  padding: 10px 5px 12px;
  border-radius: 0 0 8px 8px;
  font-size: 0.8rem;
  font-weight: 900;
}

.piano-key::before {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: clamp(3px, var(--gain-strength, 4%), 20px);
  background: var(--cyan);
  opacity: 0.42;
}

.white-key {
  min-width: 0;
  min-height: 132px;
  background: linear-gradient(180deg, #f3f1e9 0%, #d8d6cc 72%, #bfc0b7 100%);
  color: #111513;
  box-shadow:
    inset 0 -12px 18px rgba(0, 0, 0, 0.12),
    0 12px 26px rgba(0, 0, 0, 0.2);
}

.black-key {
  position: absolute;
  left: var(--key-left);
  top: 0;
  z-index: 2;
  width: min(9.8%, 58px);
  height: 78%;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #252928 0%, #101211 68%, #070808 100%);
  color: var(--text);
  box-shadow:
    inset 0 -12px 16px rgba(0, 0, 0, 0.42),
    0 12px 22px rgba(0, 0, 0, 0.34);
}

.piano-key.is-core::before {
  background: var(--green);
}

.piano-key.is-core.white-key {
  background: linear-gradient(180deg, #f5f6ee 0%, #dcebd8 72%, #b8d5bd 100%);
}

.piano-key.is-scale::before {
  background: var(--cyan);
}

.piano-key.is-scale.white-key {
  background: linear-gradient(180deg, #f4f3eb 0%, #d6e3e3 72%, #b7cbd0 100%);
}

.piano-key.is-out::before {
  background: var(--red);
}

.piano-key.is-boost::before {
  background: var(--green);
  opacity: 0.58;
}

.piano-key.is-cut::before {
  background: var(--red);
  opacity: 0.58;
}

.piano-key.is-neutral::before {
  background: var(--cyan);
  opacity: 0.28;
}

.piano-key span {
  position: relative;
  z-index: 1;
}

.note-name {
  color: currentColor;
  font-size: 0.9rem;
}

.note-gain {
  font-size: 0.74rem;
  font-weight: 850;
}

.note-q {
  color: currentColor;
  opacity: 0.72;
  font-size: 0.68rem;
  font-weight: 800;
}

@media (max-width: 980px) {
  .main-grid {
    grid-template-columns: 1fr;
  }

  .side-stack {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .app-shell {
    overflow-x: hidden;
    padding: 14px;
  }

  .topbar,
  .side-stack {
    align-items: stretch;
    display: flex;
    flex-direction: column;
  }

  .visual-stage,
  #spectrumCanvas {
    min-height: 330px;
  }

  .transport,
  .readout-grid {
    grid-template-columns: 1fr;
  }

  .knob-grid {
    grid-template-columns: 1fr 1fr;
  }

  .is-manual-key .split-fields {
    grid-template-columns: 1fr;
  }

  .note-strip-inner {
    height: 142px;
  }

  .piano-white-row {
    gap: 3px;
  }

  .piano-key {
    padding: 8px 2px 10px;
  }

  .white-key {
    min-height: 142px;
  }

  .black-key {
    width: 9.4%;
    height: 66%;
  }

  .note-name {
    font-size: 0.78rem;
  }

  .note-gain {
    font-size: 0.62rem;
  }

  .note-q {
    display: none;
  }
}

@media (max-width: 520px) {
  .workspace {
    width: min(100%, 362px);
    margin-left: 0;
    margin-right: auto;
  }
}
