/* Dark by default (U4) - this runs on a second screen in the background. */
:root {
  color-scheme: dark;
  --bg: #0e0f12;
  --panel: #16181d;
  --row: #1b1e24;
  --line: #262a33;
  --text: #e6e8ec;
  --muted: #878e9c;
  --accent: #6ea8fe;
  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  /* min-height, not height. At exactly 100% the fixed panels above the library
     could add up to more than the viewport, crushing it to nothing while the
     document itself had no overflow to scroll. */
  min-height: 100%;
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

.spacer {
  flex: 1;
}

.muted {
  color: var(--muted);
}
.ok {
  color: var(--ok);
}
.warn {
  color: var(--warn);
}
.bad {
  color: var(--bad);
}
.nowrap {
  white-space: nowrap;
}

/* --- chrome --------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--line);
  flex: none;
}

.topbar h1 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.version,
.selection {
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.banner {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
  background: #1d1a12;
}

.banner.bad {
  background: #1f1414;
}

.banner code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

main {
  /* Grows into spare room but never shrinks below the library's minimum, so
     the page scrolls instead of squeezing it away. */
  flex: 1 0 auto;
  min-height: 22rem;
  padding: 1rem;
  display: flex;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

/* --- library -------------------------------------------------------- */

.library-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem;
  border-bottom: 1px solid var(--line);
  flex: none;
}

input[type="search"] {
  flex: 0 1 22rem;
  padding: 0.35rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  font: inherit;
}

input[type="search"]:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  padding: 0.35rem 0.7rem;
  background: var(--row);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--muted);
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

.scan-status {
  padding: 0 0.6rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.scan-status:not(:empty) {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--line);
}

.working {
  color: var(--accent);
}

.table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

table.library {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

table.library th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 0;
  font-weight: 600;
  color: var(--muted);
}

table.library th button {
  width: 100%;
  background: none;
  border: 0;
  border-radius: 0;
  padding: 0.5rem 0.6rem;
  color: inherit;
  font: inherit;
  font-weight: 600;
  text-align: inherit;
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

table.library th.num button {
  justify-content: flex-end;
}

table.library th.sorted button {
  color: var(--text);
}

.caret {
  font-size: 0.6rem;
}

table.library td {
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 24rem;
}

table.library tbody tr[data-id] {
  cursor: pointer;
}

table.library tbody tr:hover {
  background: var(--row);
}

table.library tbody tr.selected {
  background: #1e2a3d;
  box-shadow: inset 3px 0 0 var(--accent);
}

table.library tbody tr.selected td.title {
  color: var(--accent);
}

table.library tbody tr.missing td {
  color: var(--muted);
  text-decoration: line-through;
}

td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

td.title {
  color: var(--text);
}

td.bpm {
  color: var(--ok);
}

td.bpm.manual {
  color: var(--accent);
}

td.empty {
  text-align: center;
  padding: 2rem;
}

/* --- shared range inputs -------------------------------------------- */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--line);
}

input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--line);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  margin-top: -4px;
  border-radius: 50%;
  background: var(--accent);
}

input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
}

input[type="range"]:disabled::-webkit-slider-thumb {
  background: var(--muted);
}

input[type="range"]:disabled::-moz-range-thumb {
  background: var(--muted);
}

.library-foot {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border-top: 1px solid var(--line);
  flex: none;
  font-size: 0.8rem;
}

td.bpm-cell {
  cursor: text;
}

input.bpm-edit {
  width: 4.5rem;
  padding: 0.1rem 0.25rem;
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 3px;
  color: var(--text);
  font: inherit;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* --- decks ---------------------------------------------------------- */

.decks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  padding: 1rem 1rem 0;
  flex: none;
}

.deck {
  padding: 0.6rem;
  gap: 0.5rem;
  border-color: var(--line);
  transition: border-color 120ms ease;
}

.deck.playing {
  border-color: #2f4f7a;
}

.deck.drop-target {
  border-color: var(--accent);
  background: #182231;
}

.deck.nudging .wave-detail {
  box-shadow: inset 0 0 0 1px var(--accent);
}

.deck-head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.deck-id {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--accent);
}

.deck-title {
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.wave-overview,
.wave-detail {
  display: block;
  width: 100%;
  background: var(--bg);
  border-radius: 3px;
}

.wave-overview {
  height: 56px;
  cursor: crosshair;
}

.wave-detail {
  height: 110px;
  cursor: grab;
  touch-action: none;
}

.wave-detail.shoving {
  cursor: grabbing;
}

.deck-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.deck-time {
  font-size: 0.8rem;
  white-space: nowrap;
}

.nudge {
  display: flex;
  gap: 0.2rem;
}

.nudge button {
  padding: 0.35rem 0.5rem;
  font-size: 0.7rem;
}

.tempo {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.2rem;
  min-width: 13rem;
}

.tempo-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.tempo-row button {
  padding: 0.15rem 0.4rem;
  font-size: 0.7rem;
}

.tempo-row button.active {
  border-color: var(--accent);
  color: var(--accent);
}

.deck-bpm {
  flex: 1;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--ok);
}

.deck-bpm.muted {
  font-size: 0.85rem;
  font-weight: 400;
}

.tempo-fader {
  width: 100%;
}

.tempo-pct {
  font-size: 0.7rem;
  text-align: right;
}

.deck-status {
  font-size: 0.8rem;
  min-height: 1rem;
}

.keyhint {
  font-size: 0.75rem;
}

.keyhint b {
  color: var(--text);
  font-weight: 600;
}

@media (max-width: 900px) {
  .decks {
    grid-template-columns: 1fr;
  }
}

/* --- collapsible panels ---------------------------------------------- */

.panel-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 0.5rem;
}

.panel-title {
  font-size: 0.68rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.panel-head button {
  margin-left: auto;
  padding: 0.1rem 0.5rem;
  font-size: 0.68rem;
}

.collapsed .panel-body {
  display: none;
}

.collapsed .panel-head {
  padding-bottom: 0;
  border-bottom: 0;
  margin-bottom: 0;
}

/* --- mixer ---------------------------------------------------------- */

.mixer-panel {
  flex: none;
  margin: 1rem 1rem 0;
  padding: 0.7rem;
  gap: 0.6rem;
}

.mixer-strips {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 1.25rem;
  align-items: stretch;
}

.strip {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.5rem;
  background: #12141a;
  border: 1px solid var(--line);
  border-radius: 5px;
}

.strip-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.strip-id {
  font-weight: 700;
  color: var(--accent);
  font-size: 0.9rem;
}

.strip-head button {
  padding: 0.1rem 0.45rem;
  font-size: 0.65rem;
}

.eq-row {
  display: flex;
  justify-content: space-around;
  gap: 0.4rem;
}

.trim-row {
  display: flex;
  justify-content: center;
  padding-top: 0.2rem;
  border-top: 1px solid var(--line);
}

/* --- knobs and faders ----------------------------------------------- */

.knob-ctl,
.fader-ctl {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  cursor: ns-resize;
  user-select: none;
  touch-action: none;
  border-radius: 5px;
  padding: 0.15rem;
  outline: none;
}

.knob-ctl:focus-visible,
.fader-ctl:focus-visible {
  box-shadow: 0 0 0 2px var(--accent);
}

.knob-ctl svg {
  width: 46px;
  height: 46px;
  display: block;
}

.knob-bg {
  fill: none;
  stroke: var(--line);
  stroke-width: 4;
  stroke-linecap: round;
}

.knob-arc {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
}

.knob-body {
  fill: var(--row);
  stroke: var(--line);
  stroke-width: 1;
}

.knob-pointer {
  stroke: var(--text);
  stroke-width: 2;
  stroke-linecap: round;
}

.knob-ctl.grabbing .knob-body,
.fader-ctl.grabbing .fader-cap {
  filter: brightness(1.4);
}

.ctl-name {
  font-size: 0.6rem;
  letter-spacing: 0.09em;
  color: var(--muted);
}

.ctl-value {
  font-size: 0.68rem;
  color: var(--text);
}

.fader-track {
  position: relative;
  width: 26px;
  height: 96px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
}

.fader-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(to top, #24405f, #35618f);
}

.fader-cap {
  position: absolute;
  left: 2px;
  right: 2px;
  height: 14px;
  border-radius: 3px;
  background: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

.fader-cap::after {
  content: "";
  position: absolute;
  left: 3px;
  right: 3px;
  top: 6px;
  height: 1px;
  background: #555;
}

.master {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
  min-width: 12rem;
}

.master-body {
  display: flex;
  align-items: flex-end;
  gap: 0.9rem;
}

.meter {
  position: relative;
  width: 100%;
  height: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
}

.meter-rms {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: linear-gradient(to right, var(--ok), var(--warn) 82%, var(--bad));
  transition: width 60ms linear;
}

.meter-peak {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--text);
}

.meter.clipping {
  border-color: var(--bad);
  box-shadow: 0 0 0 1px var(--bad);
}

.rec {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  padding-bottom: 1.4rem;
}

#mx-rec.recording {
  border-color: var(--bad);
  color: var(--bad);
}

#mx-rec-status {
  font-size: 0.72rem;
}

/* --- crossfader ------------------------------------------------------ */

.crossfader-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.75rem;
}

.xf-end {
  font-weight: 600;
}

.xf-track {
  position: relative;
  padding: 0.35rem 0;
}

.xf-track input[type="range"] {
  width: 100%;
  display: block;
  position: relative;
  z-index: 1;
}

.xf-track input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(to right, #24405f, var(--line) 45%, var(--line) 55%, #24405f);
}

.xf-track input[type="range"]::-moz-range-track {
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(to right, #24405f, var(--line) 45%, var(--line) 55%, #24405f);
}

.xf-track input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 26px;
  margin-top: -9px;
  border-radius: 4px;
  background: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

.xf-track input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 26px;
  border: 0;
  border-radius: 4px;
  background: var(--text);
}

.xf-detent {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--muted);
  opacity: 0.5;
}

.mixer-note {
  font-size: 0.78rem;
  min-height: 1rem;
}

@media (max-width: 900px) {
  .mixer-strips {
    grid-template-columns: 1fr;
  }
}

/* --- auto-mix ------------------------------------------------------- */

.automix-panel {
  flex: none;
  margin: 1rem 1rem 0;
  padding: 0.6rem;
  gap: 0.5rem;
}

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

#am-arm.recording {
  border-color: var(--ok);
  color: var(--ok);
}

.am-temp {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  margin-left: auto;
}

.am-temp input {
  width: 9rem;
}

.am-status {
  display: grid;
  gap: 0.15rem;
  font-size: 0.85rem;
  padding: 0.3rem 0;
}

.am-status .muted {
  display: inline-block;
  min-width: 3rem;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.am-queued,
.am-message {
  font-size: 0.78rem;
  min-height: 1rem;
}

.chip {
  padding: 0.05rem 0.4rem;
  font-size: 0.7rem;
  border-radius: 10px;
}

.am-history {
  font-size: 0.78rem;
}

.am-history summary {
  cursor: pointer;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.am-history ul {
  margin: 0.4rem 0 0;
  padding-left: 1rem;
}

.am-history li {
  margin-bottom: 0.15rem;
}

.am-settings {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 0.2rem 0;
}

.am-setting {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
}

.am-setting input[type="range"] {
  width: 7rem;
}

/* --- login gate ------------------------------------------------------ */

.login-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 11, 14, 0.92);
  backdrop-filter: blur(3px);
}

.login-gate[hidden] {
  display: none;
}

.login-box {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  min-width: 18rem;
  padding: 1.5rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.login-box h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.75rem;
}

.login-field input {
  padding: 0.45rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  font: inherit;
}

.login-error:empty {
  display: none;
}

.login-error {
  font-size: 0.8rem;
}
