/* MASTER section — Master Level knob over the master L/R meter, centred between the channel
   strips of every docked mixer (Library Console, Classic, City skins, Neon Nights). Markup and
   behaviour: studio.js masterSectionHtml() / _placeMasterSection(). */

/* Neutral silver on purpose: deck 1 is gold and deck 2 blue, so the master must look like
   neither — it is the whole mix. */
.mixer-master {
  --mm-accent: #e6e1d3;
  --mm-boost: #ff9a3c;
  --mm-knob: 2.15rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 0.24rem;
  min-width: 0;
  min-height: 0;
  padding: 0.36rem 0.1rem 0.3rem;
  box-sizing: border-box;
  border: 1px solid rgba(230, 225, 211, 0.42);
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(0, 0, 0, 0.55) 70%);
  color: var(--mm-accent);
}

.mixer-master-title {
  font-size: 0.56rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* Knob: value arc on the ring, rotating cap with a pointer, a 0 dB mark outside the ring. */
.mixer-master-knob {
  position: relative;
  flex: 0 0 auto;
  width: var(--mm-knob);
  height: var(--mm-knob);
  margin: 0.12rem 0;
  border-radius: 50%;
  /* Arc: silver up to 0 dB (position 0.5, 12 o'clock), orange for any boost beyond it. */
  background: conic-gradient(
    from -135deg,
    var(--mm-accent) 0deg calc(min(var(--master-pos, 0), 0.5) * 270deg),
    var(--mm-boost) 0deg calc(var(--master-pos, 0) * 270deg),
    rgba(255, 255, 255, 0.14) 0deg 270deg,
    transparent 0deg
  );
  cursor: ns-resize;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.mixer-master-knob.is-boost + .mixer-master-val {
  color: var(--mm-boost);
}
.mixer-master-knob::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  height: 4px;
  margin: -2px 0 0 -1px;
  border-radius: 1px;
  background: currentColor;
  /* 0 dB = position 0.5 → −135° + 0.5 × 270° = straight up */
  transform: rotate(0deg) translateY(calc(var(--mm-knob) / -2 - 3px));
  pointer-events: none;
}
.mixer-master-cap {
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 28%, #3c3c3f 0%, #1b1b1d 58%, #0b0b0c 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 2px 5px rgba(0, 0, 0, 0.85);
  transform: rotate(calc(-135deg + var(--master-pos, 0) * 270deg));
  pointer-events: none;
}
.mixer-master-cap::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 2px;
  width: 2px;
  height: 42%;
  margin-left: -1px;
  border-radius: 1px;
  background: #f4efe2;
  box-shadow: 0 0 4px color-mix(in srgb, var(--mm-accent) 70%, transparent);
}
/* The real control: a range input under the face (focus, arrow keys, screen readers). */
.mixer-master-knob input[type="range"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
}
.mixer-master-knob:has(input:focus-visible) {
  outline: 2px solid var(--mm-accent);
  outline-offset: 3px;
}
.mixer-master-knob.is-dragging .mixer-master-cap {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 0 0 1px var(--mm-accent), 0 2px 5px rgba(0, 0, 0, 0.85);
}

.mixer-master-val {
  font-size: 0.6rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  white-space: nowrap;
  color: #f2ead2;
}

/* Master L/R meter: the gradient is fixed to the bar; the level reveals it from the bottom. */
.mixer-master-meter {
  display: flex;
  justify-content: center;
  gap: 3px;
  flex: 1 1 1.6rem;
  min-height: 0.8rem;
  max-height: 3.4rem;
  width: 100%;
}
.mixer-master-bar {
  position: relative;
  width: 0.38rem;
  height: 100%;
  box-sizing: border-box;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--mm-accent) 45%, #222);
  border-radius: 2px;
  background: #000;
}
.mixer-master-bar > i {
  position: absolute;
  inset: 0;
  background: linear-gradient(0deg, #22ff55 0%, #a8ff2a 45%, #ffe600 70%, #ff9a00 86%, #ff3030 100%);
  clip-path: inset(calc(100% - var(--level, 0%)) 0 0 0);
}

.mixer-master-clip {
  flex: 0 0 auto;
  padding: 0.1rem 0.24rem;
  border: 1px solid rgba(255, 48, 48, 0.32);
  border-radius: 2px;
  font-size: 0.5rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255, 90, 90, 0.4);
}
.mixer-master-clip[data-state="hot"] {
  border-color: rgba(255, 176, 32, 0.75);
  color: #ffb020;
}
.mixer-master-clip[data-state="clip"] {
  border-color: #ff3030;
  background: #e01e1e;
  color: #fff;
  box-shadow: 0 0 8px rgba(255, 48, 48, 0.75);
}

/* Neon Nights' centre meters already are the master L/R meters — no duplicate here. */
html[data-skin="swagg-neon-nights"] .mixer-master {
  justify-content: center;
}
html[data-skin="swagg-neon-nights"] .mixer-master-meter {
  display: none;
}

/* ---- Placement in the channel-strip grid (beats the skins' !important strip rules) ---- */
/* 2 decks: 1 | MASTER | 2 */
html[data-skin] .mixer-panel [data-el="shell-mixer-vol"].has-master {
  grid-template-columns: minmax(0, 1fr) var(--mm-col, 3.1rem) minmax(0, 1fr) !important;
}
html[data-skin] .mixer-panel [data-el="shell-mixer-vol"].has-master > .mixer-master {
  grid-column: 2 !important;
  grid-row: 1 !important;
}
html[data-skin] .mixer-panel [data-el="shell-mixer-vol"].has-master > .mixer-channel[data-mixer-ch="deck1"] {
  grid-column: 1 !important;
}
html[data-skin] .mixer-panel [data-el="shell-mixer-vol"].has-master > .mixer-channel[data-mixer-ch="deck2"] {
  grid-column: 3 !important;
}
/* 4 decks, 2 × 2 (A side 1/3 | MASTER | B side 2/4) */
html[data-skin] .mixer-panel[data-deck-count="4"] [data-el="shell-mixer-vol"].has-master {
  grid-template-columns: minmax(0, 1fr) var(--mm-col, 3.1rem) minmax(0, 1fr) !important;
}
html[data-skin] .mixer-panel[data-deck-count="4"] [data-el="shell-mixer-vol"].has-master > .mixer-master {
  grid-column: 2 !important;
  grid-row: 1 / span 2 !important;
}
html[data-skin] .mixer-panel[data-deck-count="4"] [data-el="shell-mixer-vol"].has-master > .mixer-channel[data-mixer-ch="deck1"] {
  grid-column: 1 !important;
  grid-row: 1 !important;
}
html[data-skin] .mixer-panel[data-deck-count="4"] [data-el="shell-mixer-vol"].has-master > .mixer-channel[data-mixer-ch="deck2"] {
  grid-column: 3 !important;
  grid-row: 1 !important;
}
html[data-skin] .mixer-panel[data-deck-count="4"] [data-el="shell-mixer-vol"].has-master > .mixer-channel[data-mixer-ch="deck3"] {
  grid-column: 1 !important;
  grid-row: 2 !important;
}
html[data-skin] .mixer-panel[data-deck-count="4"] [data-el="shell-mixer-vol"].has-master > .mixer-channel[data-mixer-ch="deck4"] {
  grid-column: 3 !important;
  grid-row: 2 !important;
}
/* 4 decks in the compact dock (one row): 1 · 2 | MASTER | 3 · 4 */
html[data-skin] .mixer-panel.is-dock-compact[data-deck-count="4"] [data-el="shell-mixer-vol"].has-master {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) var(--mm-col, 3.1rem) minmax(0, 1fr) minmax(0, 1fr) !important;
  grid-template-rows: minmax(0, 1fr) !important;
}
html[data-skin] .mixer-panel.is-dock-compact[data-deck-count="4"] [data-el="shell-mixer-vol"].has-master > .mixer-master {
  grid-column: 3 !important;
  grid-row: 1 !important;
}
html[data-skin] .mixer-panel.is-dock-compact[data-deck-count="4"] [data-el="shell-mixer-vol"].has-master > .mixer-channel[data-mixer-ch="deck1"] {
  grid-column: 1 !important;
  grid-row: 1 !important;
}
html[data-skin] .mixer-panel.is-dock-compact[data-deck-count="4"] [data-el="shell-mixer-vol"].has-master > .mixer-channel[data-mixer-ch="deck2"] {
  grid-column: 2 !important;
  grid-row: 1 !important;
}
html[data-skin] .mixer-panel.is-dock-compact[data-deck-count="4"] [data-el="shell-mixer-vol"].has-master > .mixer-channel[data-mixer-ch="deck3"] {
  grid-column: 4 !important;
  grid-row: 1 !important;
}
html[data-skin] .mixer-panel.is-dock-compact[data-deck-count="4"] [data-el="shell-mixer-vol"].has-master > .mixer-channel[data-mixer-ch="deck4"] {
  grid-column: 5 !important;
  grid-row: 1 !important;
}
