/*
 * Mixer (redesign 2026-11). Self-contained: every rule is scoped to the
 * board that mixerController renders with the `mx-v2` class, so the legacy
 * mixer rules in styles.css no longer shape the strips. Only the container
 * overrides below need !important, because the legacy dock rules use it.
 */

#mixerBoard.mx-v2 {
  display: block !important;
  grid-template-columns: none !important;
  gap: 0 !important;
  height: 100%;
  min-height: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
}

.mx-board {
  container: mx-board / size;
  --mx-w: 8.6rem;
  --mx-w-wide: 13.6rem;
  --mx-line: rgba(255, 248, 232, 0.09);
  --mx-ink: #f4efe4;
  --mx-ink-2: #c9c2b3;
  --mx-ink-3: #a7a197;
  --mx-ink-4: #7d776b;
  --mx-mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, monospace;
  display: flex;
  height: 100%;
  min-height: 0;
  background: #0b0b09;
  color: var(--mx-ink);
  font-size: 13px;
}

#mixerBoard .mx-scroll {
  flex: 1 1 auto !important;
  width: auto !important;
  max-width: none !important;
  display: flex;
  gap: 0.9rem;
  min-width: 0 !important;
  min-height: 0;
  padding: 0.55rem 0.6rem 0.5rem;
  overflow: auto !important;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
  scrollbar-width: thin;
  scrollbar-color: rgba(212, 168, 85, 0.45) transparent;
}

.mx-group {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  gap: 0.35rem;
  min-height: 0;
}

.mx-group-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  height: 1rem;
  color: #b99a5c;
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
}

.mx-group-label span {
  color: var(--mx-ink-4);
}

/* The row is bound to the board height, so each strip is exactly as tall
   as the screen allows and only the open inserts rack gives up space. */
.mx-row {
  display: flex;
  flex: 1 1 0;
  gap: 0.4rem;
  min-height: 0;
}

.mx-master-pin {
  padding: 0.55rem 0.6rem 0.5rem;
  border-left: 1px solid #24221c;
  background: #0e0e0c;
  box-shadow: -14px 0 24px rgba(0, 0, 0, 0.35);
}

/* Strip */

.mx-strip {
  --c: var(--track-color, var(--gold));
  display: flex;
  flex: 0 0 var(--mx-w);
  flex-direction: column;
  min-height: 0;
  gap: 0.38rem;
  box-sizing: border-box;
  width: var(--mx-w);
  padding: 0.42rem;
  border: 1px solid var(--mx-line);
  border-top: 3px solid var(--c);
  border-radius: 0.6rem;
  background: linear-gradient(180deg, color-mix(in srgb, var(--c) 9%, #171714), #121210 42%);
}

.mx-strip.is-wide {
  flex-basis: var(--mx-w-wide);
  width: var(--mx-w-wide);
}

.mx-strip.is-selected {
  border-color: rgba(241, 201, 121, 0.55);
  border-top-color: var(--c);
  box-shadow: inset 0 0 0 1px rgba(241, 201, 121, 0.16);
}

.mx-strip.is-muted .mx-fader-zone,
.mx-strip.is-muted .mx-name {
  opacity: 0.55;
}

.mx-master {
  background: linear-gradient(180deg, #2a2112, #15120c 42%);
  border-color: rgba(212, 168, 85, 0.32);
}

.mx-head {
  all: unset;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 0.38rem;
  align-items: center;
  box-sizing: border-box;
  min-height: 2.1rem;
  cursor: grab;
}

div.mx-head {
  cursor: default;
}

.mx-head:focus-visible {
  outline: 2px solid var(--c);
  outline-offset: 2px;
  border-radius: 0.3rem;
}

.mx-num {
  grid-row: 1 / 3;
  min-width: 1.45rem;
  padding: 0.18rem 0.28rem;
  border-radius: 0.32rem;
  background: color-mix(in srgb, var(--c) 20%, transparent);
  color: var(--c);
  font-family: var(--mx-mono);
  font-size: 0.6rem;
  font-weight: 700;
  text-align: center;
}

.mx-name,
.mx-kind,
.mx-io {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mx-name {
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.15;
}

.mx-kind {
  color: var(--mx-ink-4);
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mx-io {
  flex: 0 0 auto;
  box-sizing: border-box;
  height: 1.45rem;
  padding: 0 0.42rem;
  border: 1px solid #24221c;
  border-radius: 0.36rem;
  background: #0c0c0a;
  color: var(--mx-ink-3);
  font-size: 0.62rem;
  line-height: 1.35rem;
}

.mx-route {
  display: grid;
  gap: 0.15rem;
  color: var(--mx-ink-4);
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mx-route select {
  box-sizing: border-box;
  width: 100%;
  height: 1.5rem;
  padding: 0 0.3rem;
  border: 1px solid #3c3220;
  border-radius: 0.36rem;
  background: #0c0c0a;
  color: var(--mx-ink-2);
  font: inherit;
  font-size: 0.66rem;
  letter-spacing: 0;
  text-transform: none;
}

.mx-spacer {
  flex: 0 0 auto;
}

/* Collapsible sections */

.mx-section {
  flex: 0 0 auto;
  min-height: 0;
  border: 1px solid #22201b;
  border-radius: 0.45rem;
  background: rgba(255, 248, 232, 0.03);
}

.mx-section-head {
  all: unset;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-sizing: border-box;
  width: 100%;
  height: 1.6rem;
  padding: 0 0.45rem;
  color: var(--mx-ink-2);
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
}

.mx-section-head:hover {
  color: var(--mx-ink);
}

.mx-section-head:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: -2px;
  border-radius: 0.45rem;
}

.mx-chevron {
  width: 0.8rem;
  height: 0.8rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.6;
}

.mx-slot-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem 0.35rem;
  padding: 0 0.35rem 0.38rem;
}

.mx-slot-chip {
  flex: 1 1 100%;
  min-width: 0;
  box-sizing: border-box;
  overflow: hidden;
  padding: 0.16rem 0.38rem;
  border: 1px solid #3a372f;
  border-radius: 0.3rem;
  background: #22201a;
  font-size: 0.64rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mx-slot-chip.is-bypassed {
  opacity: 0.5;
  text-decoration: line-through;
}

.mx-slot-chip.is-missing {
  border-color: #7a2e2b;
  color: #ffb3ae;
}

.mx-slot-empty,
.mx-slot-more,
.mx-native-chip {
  color: var(--mx-ink-4);
  font-size: 0.6rem;
}

.mx-native-chip {
  margin-left: auto;
}

.mx-native-chip.is-on {
  color: #e8bf6a;
}

.mx-strip > * {
  flex-shrink: 0;
}

.mx-inserts-section.is-open {
  display: flex;
  flex: 0 1 auto;
  flex-direction: column;
  min-height: 5.5rem;
}

/* The open rack is the only part of the strip that shrinks: it scrolls
   inside the strip so the fader, readout and M/S/REC never leave the
   screen, whatever the board height. */
.mx-rack {
  flex: 0 1 auto;
  min-height: 3.5rem;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.mx-rack .mixer-insert-body {
  display: grid !important;
  align-content: start;
  gap: 0.3rem;
  padding: 0.1rem 0.35rem 0.4rem !important;
  overflow: visible !important;
}

/* Sends and pan share one compact row layout */

.mx-sends {
  display: grid;
  gap: 0.28rem;
  padding: 0.36rem 0.4rem;
}

.mx-sends .tone-range,
.mx-pan {
  display: grid;
  grid-template-columns: 1.55rem minmax(0, 1fr) 2.1rem;
  align-items: center;
  gap: 0.28rem;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font-size: 0.6rem;
}

.mx-pan {
  flex: 0 0 auto;
  padding: 0 0.1rem;
}

.mx-sends .tone-range span,
.mx-pan span {
  color: var(--mx-ink-3);
  font-weight: 700;
}

.mx-sends .tone-range input,
.mx-pan input {
  width: 100%;
  min-width: 0;
  height: 1.1rem;
  margin: 0;
  accent-color: var(--c);
}

.mx-pan input {
  accent-color: #e8e2d4;
}

.mx-sends .tone-range output,
.mx-pan output {
  color: var(--mx-ink-2);
  font-family: var(--mx-mono);
  font-size: 0.6rem;
  text-align: right;
}

/* Fader, scale and meter */

.mx-fader-zone {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 0.3rem;
  min-height: 7.5rem;
}

.mx-fader-bank {
  --mx-cap-h: 2.1rem;
  display: grid;
  flex: 1 1 auto;
  grid-template-columns: 1.55rem 1.7rem auto;
  justify-content: center;
  gap: 0.3rem;
  min-height: 0;
  padding: 0.15rem 0;
}

.mx-scale {
  grid-column: 1;
  grid-row: 1;
  position: relative;
  margin: calc(var(--mx-cap-h) / 2) 0;
  color: var(--mx-ink-4);
  font-family: var(--mx-mono);
  font-size: 0.55rem;
}

.mx-scale span {
  position: absolute;
  right: 0;
  line-height: 1;
  transform: translateY(-50%);
}

.mx-fader-track {
  grid-column: 2;
  grid-row: 1;
  position: relative;
  min-height: 0;
}

.mx-fader-line {
  position: absolute;
  top: calc(var(--mx-cap-h) / 2);
  bottom: calc(var(--mx-cap-h) / 2);
  left: 50%;
  width: 4px;
  margin-left: -2px;
  border-radius: 2px;
  background: linear-gradient(0deg, var(--c) 0, var(--c) var(--range-fill, 0%), #2c2a24 var(--range-fill, 0%));
}

.mx-fader-cap {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc((100% - var(--mx-cap-h)) * var(--range-fill-ratio, 0));
  height: var(--mx-cap-h);
  border-radius: 0.32rem;
  background: linear-gradient(180deg, #ece6d9, #a39c8f);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  pointer-events: none;
}

.mx-fader-cap::after {
  content: "";
  position: absolute;
  left: 22%;
  right: 22%;
  top: 50%;
  height: 2px;
  margin-top: -1px;
  background: var(--c);
}

/* The real control sits on top, invisible, so dragging, keyboard and
   screen readers keep the native range behaviour on every engine. */
.mx-fader {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: ns-resize;
  writing-mode: vertical-lr;
  direction: rtl;
  touch-action: none;
}

.mx-fader-track:has(.mx-fader:focus-visible) .mx-fader-cap {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.mx-fader-bank .mixer-meter-stack {
  grid-column: 3;
  grid-row: 1;
  width: auto;
  position: relative;
  display: flex;
  gap: 2px;
  height: auto;
  min-height: 0;
  margin: calc(var(--mx-cap-h) / 2) 0;
  padding: 0;
}

.mx-fader-bank .mixer-vu {
  position: relative;
  width: 6px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border-radius: 3px;
  background: #050504;
}

.mx-fader-bank .mixer-vu span {
  position: absolute;
  inset: 0;
  background: linear-gradient(0deg, #8bd17c 0, #8bd17c 55%, #d4a855 78%, #ef5350 96%);
}

.mx-fader-bank .mixer-peak {
  position: absolute;
  top: -6px;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: 2px;
  background: #2c2a24;
}

.mx-fader-bank .mixer-peak.active {
  background: #ef5350;
}

.mx-fader-bank .mixer-vu-scale {
  display: none;
}

.mx-db {
  display: block;
  box-sizing: border-box;
  height: 1.5rem;
  border: 1px solid #24221c;
  border-radius: 0.36rem;
  background: #050504;
  color: var(--mx-ink);
  font-family: var(--mx-mono);
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.4rem;
  text-align: center;
}

.mx-master .mx-db {
  color: #e8bf6a;
  border-color: #3c3220;
}

.mx-master-device {
  font-size: 0.58rem;
}

/* Buttons */

.mx-buttons {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.25rem;
}

.mx-buttons.has-monitor {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.mx-buttons.is-pair {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.mx-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-width: 0;
  height: 1.75rem;
  padding: 0;
  border: 1px solid #2c2a24;
  border-radius: 0.36rem;
  background: #0e0e0c;
  color: #e8e2d4;
  font: inherit;
  font-size: 0.68rem;
  font-weight: 800;
  cursor: pointer;
}

.mx-btn:hover {
  border-color: #4a463c;
}

.mx-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.mx-btn svg {
  width: 0.95rem;
  height: 0.95rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.mx-rec i {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: #5a5348;
}

.mx-rec.is-on {
  border-color: #7a2e2b;
  background: #3a1a19;
}

.mx-rec.is-on i {
  background: #ef5350;
  box-shadow: 0 0 6px rgba(239, 83, 80, 0.7);
}

.mx-monitor.is-on {
  border-color: #2f5a60;
  background: #1d3236;
  color: #7fcbd6;
}

.mx-mute.is-on {
  border-color: #d4a855;
  background: #d4a855;
  color: #17130a;
}

.mx-solo.is-on {
  border-color: #64b5f6;
  background: #64b5f6;
  color: #0b1520;
}

/* A taller dock when the window allows it, so the fader keeps a usable
   throw. Short windows keep the legacy constrained heights. */
@media (min-width: 1100px) and (min-height: 761px) {
  body.mixer-dock-open .workspace {
    --mixer-dock-height: clamp(18rem, 50dvh, 30rem) !important;
  }

  body.mixer-dock-open.mixer-dock-inserts-open .workspace {
    --mixer-dock-height: clamp(23rem, 62dvh, 38rem) !important;
  }
}

/* Short boards: the input label and the quick sends step aside (both stay
   reachable: input in the track inspector, sends in the Inserts rack). */
@container mx-board (max-height: 400px) {
  .mx-io:not(.mx-master-device),
  .mx-route > span,
  .mx-master-device {
    display: none;
  }

  .mx-sends {
    display: none;
  }

  .mx-fader-zone {
    min-height: 6rem;
  }

  .mx-inserts-section.is-open {
    min-height: 3.8rem;
  }

  .mx-rack {
    min-height: 2.2rem;
  }
}

@container mx-board (max-height: 300px) {
  .mx-slot-summary,
  .mx-kind {
    display: none;
  }

  .mx-head {
    min-height: 1.5rem;
  }

  .mx-num {
    grid-row: 1;
  }

  .mx-strip {
    gap: 0.28rem;
    padding: 0.32rem;
  }

  .mx-fader-zone {
    min-height: 4.6rem;
  }

  .mx-scale span:nth-child(3) {
    display: none;
  }
}

/* Phones and small tablets: narrower strips, master stays pinned, the
   track lane scrolls sideways with the finger. */
@media (max-width: 760px) {
  .mx-board {
    --mx-w: 7.4rem;
    --mx-w-wide: 12.4rem;
    font-size: 12px;
  }

  .mx-scroll,
  .mx-master-pin {
    padding: 0.45rem 0.4rem 0.4rem;
  }

  .mx-btn {
    height: 2.1rem;
  }

  .mx-fader-zone {
    min-height: 8rem;
  }
}
