:root {
  --bg: #0e0f12;
  --panel: #17191e;
  --ink: #e6e7ea;
  --muted: #9aa0aa;
  --brand: #6ea8fe;
  --accent: #a4f2a8;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font:
    14px/1.4 system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    Arial,
    sans-serif;
}

header {
  padding: 16px;
  border-bottom: 1px solid #262a31;
  background: linear-gradient(180deg, #13161b 0%, #101217 100%);
  position: sticky;
  top: 0;
  z-index: 2;
}

h1 {
  font-size: 16px;
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.2px;
}

main {
  padding: 16px;
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
  max-width: 100%;
  margin: 0 auto;
}

.row {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(3, 1fr);
}

fieldset {
  border: 1px solid #262a31;
  border-radius: 12px;
  padding: 12px;
  background: var(--panel);
}

legend {
  padding: 0 6px;
  color: var(--muted);
}

/* Universal slider-control component */
slider-control {
  display: grid;
  grid-template-columns: 100px 1fr 50px;
  gap: 6px;
  align-items: center;
  margin: 8px 0;

  .label {
    color: var(--ink);
    font-size: 14px;
  }

  .slider {
    width: 100%;
  }

  .value {
    color: var(--muted);
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-size: 14px;
  }
}

input[type='range'] {
  width: 100%;
}

.bar {
  display: flex;
  gap: 8px;
  align-items: center;
}

button,
.btn {
  border: 1px solid #2b3038;
  background: #1a1d23;
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition:
    transform 0.04s ease,
    background 0.2s;

  &:hover {
    background: #1f232b;
  }

  &:active {
    transform: scale(0.98);
  }
}

#kbd {
  position: relative;
  height: 140px;
  padding: 8px;
  background: var(--bg);
  border-radius: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  margin: 0 auto;

  button {
    position: relative;
    border: 1px solid #2b3038;
    cursor: pointer;
    user-select: none;
    font-size: 10px;
    font-weight: 500;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 8px;
    transition:
      transform 0.02s ease,
      background 0.1s;

    &.white-key {
      width: 32px;
      height: 120px;
      background: linear-gradient(180deg, #fafafa 0%, #e8e8e8 100%);
      color: #666;
      border-radius: 0 0 4px 4px;
      z-index: 1;
      box-shadow:
        0 2px 4px rgba(0, 0, 0, 0.2),
        inset 0 -2px 4px rgba(0, 0, 0, 0.1);

      &:hover {
        background: linear-gradient(180deg, #f5f5f5 0%, #ddd 100%);
      }

      &:active,
      &.note-on {
        background: linear-gradient(180deg, #6ea8fe 0%, #5a8fd8 100%);
        color: white;
        transform: translateY(2px);
        box-shadow:
          0 1px 2px rgba(0, 0, 0, 0.3),
          inset 0 1px 3px rgba(0, 0, 0, 0.2);
      }
    }

    &.black-key {
      width: 22px;
      height: 75px;
      background: linear-gradient(180deg, #2a2a2a 0%, #1a1a1a 100%);
      color: #999;
      border-radius: 0 0 3px 3px;
      position: absolute;
      z-index: 2;
      box-shadow:
        0 3px 6px rgba(0, 0, 0, 0.5),
        inset 0 -1px 2px rgba(255, 255, 255, 0.1);

      &:hover {
        background: linear-gradient(180deg, #353535 0%, #202020 100%);
      }

      &:active,
      &.note-on {
        background: linear-gradient(180deg, #4a7fba 0%, #3a6fa0 100%);
        color: white;
        transform: translateY(2px);
        box-shadow:
          0 2px 4px rgba(0, 0, 0, 0.6),
          inset 0 1px 2px rgba(0, 0, 0, 0.3);
      }
    }
  }
}

#kbd-inner {
  display: flex;
  position: relative;
  margin: 0 auto;
  width: fit-content;
}

.note-on {
  outline: 2px solid var(--brand);
}

.small {
  color: var(--muted);
  font-size: 12px;
}

footer {
  padding: 16px;
  color: var(--muted);
  text-align: center;
}

.split {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr auto;
  align-items: center;
}

.pill {
  padding: 2px 8px;
  border: 1px solid #2b3038;
  border-radius: 999px;

  &.green {
    background: #4caf50 !important;
    color: #000 !important;

    * {
      color: #000 !important;
    }
  }

  &.orange {
    background: #ffaa00 !important;
    color: #000 !important;

    * {
      color: #000 !important;
    }
  }

  &.red {
    background: #ff4444 !important;
    color: #000 !important;

    * {
      color: #000 !important;
    }
  }
}

.midi-mapping {
  margin-top: 16px;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #1f2430;
  background: #0d1018;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.midi-mapping-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;

  h4 {
    margin: 0;
    font-size: 14px;
    color: var(--accent);
  }
}

.midi-mapping-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
  padding-right: 4px;
}

.midi-mapping-row {
  display: grid;
  grid-template-columns: 1fr 80px auto;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #1b202b;
  background: #090c12;

  &.learning {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px rgba(164, 242, 168, 0.25);
  }
}

.midi-mapping-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.midi-mapping-name {
  font-size: 13px;
  font-weight: 600;
  color: #f1f4ff;
}

.midi-mapping-meta {
  font-size: 11px;
  color: var(--muted);
}

.midi-mapping-cc {
  input {
    width: 72px;
    padding: 4px 6px;
    border-radius: 6px;
    border: 1px solid #1f2430;
    background: #0e1119;
    color: #e5e9f0;
    font-size: 12px;
    text-align: center;

    &:disabled {
      opacity: 0.6;
      cursor: not-allowed;
    }
  }
}

.midi-mapping-actions {
  display: flex;
  gap: 8px;
}

.midi-mapping-btn {
  background: #1f2430;
  border: 1px solid #2b313d;
  color: #d6dde8;
  font-size: 11px;
  cursor: pointer;
  transition:
    border 0.15s ease,
    background 0.15s ease;

  &:hover {
    border-color: var(--accent);
  }
}

.midi-learn-status {
  margin-top: 4px;

  &.active {
    color: var(--accent);
  }
}

/* MIDI device checkbox styling */
input[type='checkbox'] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

#midiDevices {
  max-height: 200px;
  overflow-y: auto;

  &::-webkit-scrollbar {
    width: 8px;
  }

  &::-webkit-scrollbar-track {
    background: var(--bg);
    border-radius: 4px;
  }

  &::-webkit-scrollbar-thumb {
    background: #2b3038;
    border-radius: 4px;

    &:hover {
      background: #3a4048;
    }
  }
}

/* Select element styling */
select {
  width: 100%;
  padding: 4px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid #262a31;
  border-radius: 4px;
}

/* Inline style utilities */
.mb-8 {
  margin-bottom: 8px;
}

.mt-8 {
  margin-top: 8px;
}

.tabular-nums {
  font-variant-numeric: tabular-nums;
}

/* ========================================
   FX Chain Styles
   ======================================== */

.fx-section {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 16px;
  margin-top: 8px;
}

.fx-library-container,
.fx-chain-container {
  h3 {
    font-size: 12px;
    margin: 0 0 8px 0;
    color: var(--muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }
}

/* FX Library (left column) */
.fx-library {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.fx-library-item {
  background: var(--bg);
  border: 1px solid #262a31;
  border-radius: 8px;
  padding: 10px 12px;
  cursor: grab;
  transition: all 0.15s ease;
  user-select: none;

  &:hover {
    background: #13161b;
    border-color: var(--brand);
    transform: translateX(2px);
  }

  &:active {
    cursor: grabbing;
  }

  .fx-name {
    font-size: 13px;
    color: var(--ink);
    font-weight: 500;
  }
}

/* FX Chain (right column) */
.fx-chain {
  min-height: 120px;
  border: 2px dashed #262a31;
  border-radius: 8px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;

  &:empty + .fx-empty-state {
    display: block;
  }
}

.fx-empty-state {
  display: none;
  text-align: center;
  padding: 20px;
  color: var(--muted);
}

/* Individual FX item in chain */
.fx-chain-item {
  background: var(--bg);
  border: 1px solid #2b3038;
  border-radius: 8px;
  padding: 10px;
  cursor: move;
  transition: all 0.15s ease;

  &.dragging {
    opacity: 0.5;
    transform: rotate(2deg);
    pointer-events: none; /* Prevent slider interaction during drag */
  }

  &:hover {
    border-color: var(--brand);
  }

  &.fx-disabled {
    opacity: 0.5;

    .fx-header {
      opacity: 0.6;
    }
  }
}

/* FX item header */
.fx-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid #1f232b;
}

.fx-drag-handle {
  color: var(--muted);
  font-size: 16px;
  cursor: grab;
  user-select: none;
  line-height: 1;

  &:active {
    cursor: grabbing;
  }
}

.fx-title {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.fx-toggle {
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 6px;
  min-width: 40px;

  &[data-enabled='true'] {
    background: var(--brand);
    border-color: var(--brand);
    color: var(--bg);
  }

  &[data-enabled='false'] {
    background: #1a1d23;
    border-color: #2b3038;
    color: var(--muted);
  }
}

.fx-remove {
  padding: 4px 8px;
  font-size: 16px;
  line-height: 1;
  color: var(--muted);
  border-radius: 6px;

  &:hover {
    color: #ff6b6b;
    border-color: #ff6b6b;
  }
}

/* FX parameters */
.fx-parameters {
  display: grid;
  gap: 6px;
}

.fx-param {
  display: grid;
  grid-template-columns: 80px 1fr 70px;
  gap: 8px;
  align-items: center;

  label {
    font-size: 12px;
    color: var(--muted);
  }

  input[type='range'] {
    width: 100%;
  }
}

.fx-param-value {
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.two-column {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.three-column {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .fx-section {
    grid-template-columns: 1fr;
  }

  .fx-library {
    flex-direction: row;
    flex-wrap: wrap;
  }
}

/* ========================================
   Modulation Matrix Styles
   ======================================== */

.matrix-grid {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.matrix-slot {
  display: grid;
  grid-template-columns: 24px 140px 20px 160px 1fr 60px;
  gap: 8px;
  align-items: center;
  padding: 8px;
  background: #13161b;
  border-radius: 6px;
  border: 1px solid #262a31;
}

.matrix-slot-number {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  font-weight: 600;
}

.matrix-source,
.matrix-dest {
  font-size: 13px;
  padding: 4px 6px;
}

.matrix-arrow {
  color: var(--brand);
  font-size: 14px;
  text-align: center;
}

.matrix-amount {
  width: 100%;
  cursor: ew-resize;
}

.matrix-amount-value {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  user-select: none;
}

.matrix-amount-value:hover {
  color: var(--ink);
}

.matrix-amount-value:active {
  color: var(--accent);
}

@media (max-width: 1024px) {
  .matrix-slot {
    grid-template-columns: 24px 120px 20px 140px 1fr 50px;
    gap: 6px;
  }
}
