:root {
  --ink: #d8f2ea;
  --ink-muted: #a9d7c8;
  --deep-blue: #132c3e;
  --deep-green: #0f342a;
  --panel-bg: rgba(12, 37, 42, 0.62);
  --panel-border: rgba(108, 205, 182, 0.32);
  --accent: #36be9d;
  --accent-2: #5cc3ff;
  --danger: #f06f74;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  background:
    radial-gradient(80rem 42rem at -10% -20%, rgba(92, 195, 255, 0.2) 0%, rgba(19, 44, 62, 0) 60%),
    radial-gradient(72rem 38rem at 120% 120%, rgba(54, 190, 157, 0.22) 0%, rgba(15, 52, 42, 0) 58%),
    linear-gradient(135deg, #132c3e 0%, #0f342a 100%);
}

.app-shell {
  width: min(1220px, 95vw);
  margin: 1.4rem auto 2rem;
  display: grid;
  gap: 1rem;
}

.panel {
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  background: var(--panel-bg);
  backdrop-filter: blur(4px);
  box-shadow: 0 20px 46px rgba(6, 18, 21, 0.34);
  padding: 1rem;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.15rem 0.35rem 0.35rem;
}

.logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
  filter: drop-shadow(0 5px 10px rgba(12, 34, 43, 0.5));
}

h1,
h2 {
  margin: 0 0 0.35rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

p {
  margin: 0;
  color: var(--ink-muted);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

button,
select,
input[type="number"] {
  border: 1px solid rgba(92, 195, 255, 0.32);
  border-radius: 10px;
  color: var(--ink);
  background: rgba(11, 32, 40, 0.72);
  padding: 0.56rem 0.8rem;
  font-family: inherit;
  font-size: 0.93rem;
}

button {
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  background: rgba(30, 70, 80, 0.82);
}

button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.transport-symbol-btn {
  width: 2.35rem;
  height: 2.35rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.02rem;
  line-height: 1;
}

#startBtn {
  background: linear-gradient(140deg, rgba(54, 190, 157, 0.85), rgba(43, 130, 130, 0.8));
  border-color: rgba(124, 244, 203, 0.5);
  font-size: 1.14rem;
}

#stopBtn {
  border-color: rgba(240, 111, 116, 0.38);
  font-size: 0.88rem;
}

.icon-toggle {
  width: 2.05rem;
  height: 2.05rem;
  border-radius: 999px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.08rem;
  line-height: 1;
}

.icon-toggle {
  font-size: 1.5rem;
}

#resetDefaultsBtn {
  margin-left: auto;
}

.icon-loop {
  font-size: 1.15rem;
}

.icon-loop.loop-active {
  background: rgba(54, 190, 157, 0.35);
  border-color: rgba(124, 244, 203, 0.7);
  box-shadow: 0 0 0 1px rgba(124, 244, 203, 0.22) inset;
}

.reset-btn {
  border-radius: 10px;
  padding: 0.5rem 0.8rem;
  min-width: 4.8rem;
}

.play-mode-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
  align-items: center;
}

.play-mode-option {
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
  white-space: nowrap;
  color: var(--ink);
  font-size: 0.82rem;
}

.play-mode-option input[type="radio"] {
  margin: 0;
  accent-color: var(--accent);
}

.selection-panel {
  margin-top: 0.15rem;
}

.synth-panel {
  margin-top: 0.9rem;
  padding-top: 0.85rem;
  border-top: 1px solid rgba(108, 205, 182, 0.22);
}

.synth-panel-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.synth-panel-title {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
  color: #ccf3e7;
  letter-spacing: 0.01em;
}

.icon-toggle-secondary {
  margin-left: auto;
  width: 1.95rem;
  height: 1.95rem;
  font-size: 1.35rem;
}

.synth-selection-panel {
  margin-top: 0.55rem;
}

.synth-row-grid {
  display: grid;
  gap: 0.75rem;
  align-items: end;
}

.synth-row-voice,
.synth-row-envelope,
.synth-row-amp-envelope {
  grid-template-columns: repeat(4, minmax(140px, 1fr));
}

.synth-row-filter {
  grid-template-columns: repeat(5, minmax(120px, 1fr));
}

.synth-row-envelope {
  margin-top: 0.4rem;
}

.synth-row-dynamics {
  margin-top: 0.75rem;
  grid-template-columns: minmax(220px, 1fr) minmax(140px, 220px) auto;
  justify-content: space-between;
  align-items: end;
}

#synthTestBtn {
  min-width: 4.6rem;
  font-size: 0.84rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  align-self: end;
}

#synthTestBtn.is-holding {
  background: rgba(54, 190, 157, 0.34);
  border-color: rgba(124, 244, 203, 0.65);
  box-shadow: 0 0 0 1px rgba(124, 244, 203, 0.2) inset;
  transform: translateY(0);
}

.synth-row-divider {
  margin-top: 0.75rem;
  margin-bottom: 0.75rem;
  border-top: 1px solid rgba(108, 205, 182, 0.16);
}

.synth-voice2-toggle,
.synth-inline-end {
  align-self: start;
  white-space: nowrap;
}

.control-disabled {
  opacity: 0.55;
}

.control-grid {
  margin-top: 0.9rem;
  display: grid;
  grid-template-columns: repeat(6, minmax(90px, 1fr));
  gap: 0.75rem;
  align-items: start;
}

.scale-control-row {
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid rgba(108, 205, 182, 0.22);
  display: grid;
  grid-template-columns: auto auto auto;
  gap: 0.75rem;
  align-items: end;
  justify-content: start;
}

.scale-control-row label {
  justify-self: start;
}

.scale-control-row #scaleRoot {
  width: 8ch;
}

.scale-control-row #scaleMode {
  width: 25ch;
}

.scale-control-row #playScaleBtn {
  justify-self: end;
}

.pitch-detector-grid {
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid rgba(108, 205, 182, 0.22);
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 0.75rem;
  align-items: start;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.86rem;
  color: var(--ink-muted);
  min-width: 0;
}

.pitch-detector-option[hidden] {
  display: none !important;
}

label.inline {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 0.45rem;
  color: var(--ink);
}

.playback-toggle {
  font-size: 0.84rem;
  white-space: nowrap;
}

.pitch-downsample-toggle {
  font-size: 0.84rem;
  white-space: nowrap;
  align-self: start;
}

input[type="checkbox"] {
  accent-color: var(--accent);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

#noteDerivation {
  width: 100%;
  min-width: 0;
}

#scaleRoot {
  width: 100%;
  min-width: 0;
}

#scaleMode {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

#pitchDetector {
  width: 100%;
  min-width: 0;
}

.status-panel {
  display: grid;
  gap: 0.6rem;
}

#statusText {
  color: #ccf3e7;
  font-weight: 500;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem 1.2rem;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

canvas {
  width: 100%;
  height: auto;
  border: 1px solid rgba(108, 205, 182, 0.2);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(6, 18, 27, 0.92), rgba(4, 14, 15, 0.88));
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th,
td {
  text-align: left;
  padding: 0.42rem 0.45rem;
  border-bottom: 1px solid rgba(108, 205, 182, 0.2);
}

thead th {
  color: #bbefe0;
  font-weight: 600;
  letter-spacing: 0.02em;
}

tbody td {
  color: var(--ink-muted);
}

.app-footer {
  text-align: center;
  font-size: 0.88rem;
  color: var(--ink-muted);
  padding: 0.2rem 0.35rem 0.1rem;
}

.app-footer .repo-link,
.app-footer .repo-link:link,
.app-footer .repo-link:visited,
.app-footer .repo-link:hover,
.app-footer .repo-link:active {
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff;
}

.app-footer .repo-link {
  text-decoration: underline;
  text-decoration-color: rgba(255, 255, 255, 0.45);
}

.app-footer .repo-link:hover {
  text-decoration-color: rgba(255, 255, 255, 0.88);
}

@media (max-width: 700px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .logo {
    width: 58px;
    height: 58px;
  }

  .stats {
    gap: 0.45rem 0.8rem;
    font-size: 0.82rem;
  }

  .control-grid {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
    gap: 0.75rem;
  }

  .scale-control-row {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

  .scale-control-row #scaleRoot,
  .scale-control-row #scaleMode {
    width: 100%;
  }

  .scale-control-row #playScaleBtn {
    justify-self: stretch;
    grid-column: 1 / -1;
  }

  .pitch-detector-grid {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

  .synth-row-voice,
  .synth-row-filter,
  .synth-row-envelope,
  .synth-row-amp-envelope {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

  .synth-row-dynamics {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }

  #synthTestBtn {
    width: 100%;
  }
}
