/* Hardware MIDI: the MIDI button in the top bar and its panel. */

.midi-btn { display: inline-flex; align-items: center; gap: 7px; }
.midi-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3a1309;
  box-shadow: 0 0 0 1px #000;
  transition: background 0.05s, box-shadow 0.05s;
}
.midi-led.on { background: #ff6a2a; box-shadow: 0 0 0 1px #000, 0 0 8px 2px rgba(255, 106, 42, 0.75); }
.midi-btn.off .midi-led { opacity: 0.45; }
.midi-count {
  min-width: 16px;
  padding: 1px 4px;
  border-radius: 8px;
  background: #0b0c0d;
  font: 600 9.5px var(--mono);
  color: var(--vfd);
  text-align: center;
}

.midi-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  width: min(560px, calc(100vw - 32px));
  max-height: min(70vh, 640px);
  border: 1px solid #2c3236;
  border-radius: 6px;
  background: #101315;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.7);
  color: #dfe2e5;
}
.mp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid #23282c;
  font: 700 10px var(--font);
  letter-spacing: 0.24em;
}
.mp-body { overflow: auto; padding: 4px 14px 12px; }

.mp-section { margin-top: 10px; }
.mp-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0 0 6px;
  font: 700 9px var(--font);
  letter-spacing: 0.22em;
  color: var(--rail-dim);
}
.mp-title small { font: 600 9px var(--font); letter-spacing: 0.06em; text-transform: none; color: #6f767d; }
.mp-empty, .mp-hint, .mp-off p { margin: 4px 0; font: 11px/1.45 var(--font); color: #8b9198; }
.mp-hint { margin-top: 12px; font-size: 10px; }
.mp-off { padding: 10px 0 2px; }
.mp-enable { margin-top: 6px; }

.mp-row {
  display: grid;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 5px;
  background: #171b1e;
}
.mp-row + .mp-row { margin-top: 6px; }
.mp-row.gone { opacity: 0.55; }
.mp-row.off { opacity: 1; }
.mp-row.off .mp-name { color: #8b9198; text-decoration: none; }
.mp-onoff {
  flex: none;
  width: 38px;
  height: 22px;
  border: 0;
  border-radius: 4px;
  background: #2a2e33;
  color: #8b9198;
  font: 700 9px var(--font);
  letter-spacing: 0.12em;
  cursor: pointer;
}
.mp-onoff.on { background: #1f5f53; color: #e6fff8; box-shadow: 0 0 8px rgba(77, 255, 160, 0.25); }
.mp-onoff:hover { filter: brightness(1.2); }
.mp-onoff:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.mp-state.mp-kept { color: #8b9198; }
/* MAPPINGS, controller by controller: its name, LOAD ▾ / SAVE… (mapping presets), then its mappings. */
.mp-ctl { display: grid; gap: 4px; margin-top: 8px; }
.mp-ctl-head { display: flex; align-items: center; gap: 8px; padding: 0 2px; }
.mp-ctl-head .mp-name { flex: 0 1 auto; }
.mp-ctl-head .mp-preset:first-of-type { margin-left: auto; }
.mp-preset { height: 22px; padding: 0 9px; font-size: 9px; }
.mp-preset:disabled { opacity: 0.45; cursor: default; }
.mp-port { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mp-led {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #3a1309;
  box-shadow: 0 0 0 1px #000;
}
.mp-led.on { background: #ff6a2a; box-shadow: 0 0 0 1px #000, 0 0 7px 2px rgba(255, 106, 42, 0.75); }
.mp-name { overflow: hidden; font: 600 12px var(--mono); text-overflow: ellipsis; white-space: nowrap; color: var(--vfd); }
.mp-row.gone .mp-name { color: #9aa0a6; text-decoration: line-through; }
.mp-state { font: 700 8.5px var(--font); letter-spacing: 0.14em; color: #ff8a6a; }
.mp-channel { margin-left: auto; }

.mp-links { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.mp-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  padding: 0 2px 0 9px;
  border-radius: 12px;
  background: #22343a;
  font: 600 11px var(--font);
  color: #dff6f1;
}
.mp-chip.keys { background: #3b2f18; color: #ffe2b8; }
.mp-chip-name { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mp-chip-x {
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.mp-chip-x:hover { background: rgba(255, 255, 255, 0.12); }
.mp-chip-x:focus-visible, .mp-add:focus-visible, .mp-channel:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.mp-add, .mp-channel {
  height: 24px;
  padding: 0 6px;
  border: 1px solid #0a0b0c;
  border-radius: 4px;
  background: #2a2e33;
  color: #dfe2e5;
  font: 600 11px var(--font);
}
.mp-add { max-width: 100%; }
.mp-add:disabled { opacity: 0.5; }

@media (max-width: 640px) {
  .midi-panel { position: fixed; top: 64px; left: 16px; right: 16px; width: auto; }
}

/* ------------------------------------------------------------ MIDI learn */

.learn-btn.on {
  background: linear-gradient(180deg, #7a4a12, #4e2f0b);
  color: #ffe2b8;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 0 10px rgba(255, 170, 60, 0.45);
}

/* Learn mode: every mappable control is outlined; clicking picks it. */
.midi-learning .midi-learnable {
  outline: 2px dashed rgba(255, 179, 71, 0.55);
  outline-offset: 2px;
  cursor: crosshair !important;
}
.midi-learning .midi-learnable * { cursor: crosshair !important; }
.midi-learnable:hover { outline-color: #ffb347; outline-style: solid; }
.midi-learn-target {
  outline: 3px solid #ffb347 !important;
  outline-offset: 2px;
  animation: midi-learn-pulse 0.9s ease-in-out infinite;
}
@keyframes midi-learn-pulse { 50% { outline-color: rgba(255, 179, 71, 0.25); } }
@media (prefers-reduced-motion: reduce) { .midi-learn-target { animation: none; } }

/* A mapped control: a small badge; in learn mode it names the CC. */
.midi-mapped { position: relative; }
.midi-mapped::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  z-index: 3;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ffb347;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.7), 0 0 5px rgba(255, 179, 71, 0.7);
  pointer-events: none;
}
.midi-learning .midi-mapped::after {
  content: attr(data-midi);
  width: auto;
  height: auto;
  padding: 0 3px;
  border-radius: 3px;
  font: 700 8px/12px var(--mono);
  color: #1a1206;
}

/* Soft takeover: the hardware knob has not reached the control yet — turn this way. */
.midi-pickup::before {
  content: attr(data-pickup);
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(16, 19, 21, 0.55);
  font: 700 18px/1 var(--font);
  color: #ffb347;
  text-shadow: 0 0 8px rgba(255, 179, 71, 0.8);
  pointer-events: none;
}
.midi-pickup { position: relative; }

/* Mappings in the MIDI panel. */
.mp-tools { display: flex; gap: 6px; margin-bottom: 6px; }
.mp-learn.on { background: linear-gradient(180deg, #7a4a12, #4e2f0b); color: #ffe2b8; }
.mp-map .mp-port { gap: 6px; }
.mp-source { font: 600 11px var(--mono); color: #ffcf8a; white-space: nowrap; }
.mp-arrow { color: #6f767d; }
.mp-target { overflow: hidden; font: 600 11.5px var(--font); text-overflow: ellipsis; white-space: nowrap; }
.mp-mode { padding: 1px 5px; border-radius: 3px; background: #2a2e33; font: 700 8px var(--font); letter-spacing: 0.12em; color: #9aa0a6; }
.mp-map .mp-chip-x { margin-left: auto; flex: none; color: #c9cdd2; }
