:root {
  --bg: #0b0d10;
  --panel: #14171c;
  --panel2: #1a1e25;
  --edge: #262c36;
  --text: #d7dde6;
  --dim: #7a8494;
  --accA: #00d5ff;
  --accB: #ff7a00;
  --green: #2ee56b;
  --red: #ff3b47;
  --amber: #ffcc00;
  font-size: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: radial-gradient(1200px 600px at 50% -10%, #151a22 0%, var(--bg) 60%);
  color: var(--text);
  font-family: "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
  overflow-x: auto;
  user-select: none;
}

/* ---------- mixer header (branding / master / fade) ---------- */
.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #fff;
}
.logo span { color: var(--accA); }

.master-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--panel2);
  border: 1px solid var(--edge);
  border-radius: 8px;
  padding: 8px;
}
.master-label { font-size: 9px; color: var(--dim); letter-spacing: 2px; }
#masterVol { width: 100%; }

.autofade { display: flex; gap: 5px; align-items: center; }
.autofade .btn { flex: 1; }

/* ---------- EQ ---------- */
.eq-block {
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: var(--panel2);
  border: 1px solid var(--edge);
  border-radius: 8px;
  padding: 8px;
}
.eq-band {
  display: flex;
  align-items: center;
  gap: 6px;
}
.eq-band label {
  width: 26px;
  font-size: 9px;
  letter-spacing: 1px;
  color: var(--dim);
}
.eq-band input[type="range"] { flex: 1; min-width: 0; }
.btn.kill {
  padding: 3px 7px;
  font-size: 9px;
}
.btn.kill.on { background: var(--red); border-color: var(--red); color: #fff; }
#eqEnable.on { border-color: var(--green); color: var(--green); }

/* ---------- layout ---------- */
#console {
  display: grid;
  grid-template-columns: 1fr 210px 1fr;
  gap: 12px;
  padding: 12px;
  min-width: 1080px;
}

.deck {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#deckA { box-shadow: inset 3px 0 0 var(--accA); }
#deckB { box-shadow: inset -3px 0 0 var(--accB); }

/* ---------- deck internals (generated by JS) ---------- */
.load-row { display: flex; gap: 6px; }
.load-row input[type="text"] {
  flex: 1;
  background: #0d1014;
  border: 1px solid var(--edge);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 8px;
  font-family: inherit;
  font-size: 12px;
}
.load-row input[type="text"]:focus { outline: 1px solid var(--accA); }
#deckB .load-row input[type="text"]:focus { outline-color: var(--accB); }

/* ---------- vinyl platter ---------- */
.vinyl-wrap {
  position: relative;
  width: min(72%, 260px);
  aspect-ratio: 1;
  margin: 6px auto 2px;
}
.vinyl {
  position: absolute; inset: 0;
  border-radius: 50%;
  overflow: hidden;
  background: #07090c;
  box-shadow: 0 0 0 1px #2a313d, 0 6px 18px #000d;
  will-change: transform;
}
.vinyl-media { position: absolute; inset: 0; }
.vinyl-media iframe {
  position: absolute;
  top: 0; left: 50%;
  height: 100%;
  width: 177.78%; /* 16:9 video covers the square disc */
  transform: translateX(-50%);
  border: 0;
}
.vinyl-grooves {
  position: absolute; inset: 0;
  border-radius: 50%;
  pointer-events: none;
  background:
    repeating-radial-gradient(circle at 50% 50%, #0000 0 5px, #0000004d 5px 6px),
    radial-gradient(circle at 50% 50%, #0000 52%, #000000b3 100%);
}
.vinyl-line {
  position: absolute;
  left: calc(50% - 1px); top: 0;
  width: 2px; height: 50%;
  transform-origin: bottom center;
  background: linear-gradient(#ffffffcc, #ffffff00 80%);
  pointer-events: none;
}
.vinyl-label {
  position: absolute;
  left: 50%; top: 50%;
  width: 30%; aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(#232a34, #12151b);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 800;
  color: #fff;
  box-shadow: 0 0 0 2px var(--edge);
  pointer-events: none;
}
#deckA .vinyl-label { box-shadow: 0 0 0 2px var(--accA); color: var(--accA); }
#deckB .vinyl-label { box-shadow: 0 0 0 2px var(--accB); color: var(--accB); }
.vinyl-spindle {
  position: absolute;
  left: calc(50% - 4px); top: calc(50% - 4px);
  width: 8px; height: 8px;
  border-radius: 50%;
  background: linear-gradient(#e8edf4, #8a94a4);
  box-shadow: 0 1px 2px #000c;
  pointer-events: none;
}
.vinyl-needle {
  position: absolute;
  top: -4px; left: calc(50% - 6px);
  width: 0; height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 9px solid var(--red);
  pointer-events: none;
  z-index: 2;
}
.video-shield {
  position: absolute; inset: 0;
  cursor: default;
  background: transparent;
}
.video-idle {
  position: absolute; inset: 0;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--dim); font-size: 11px; letter-spacing: 2px;
  background:
    repeating-radial-gradient(circle at 50% 50%, #0c0f13 0 5px, #0e1116 5px 10px);
  box-shadow: 0 0 0 1px var(--edge);
}

.track-title {
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #fff;
  min-height: 15px;
}

.readout {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  background: #0d1014;
  border: 1px solid var(--edge);
  border-radius: 6px;
  padding: 4px 10px;
  font-variant-numeric: tabular-nums;
}
.readout .time { font-size: 18px; color: #fff; }
.readout .remain { font-size: 12px; color: var(--dim); }
.readout .bpm { font-size: 18px; color: var(--green); }
.readout .bpm.unset { color: var(--dim); }
.readout .rate { font-size: 12px; color: var(--amber); }

.wave {
  width: 100%;
  height: 44px;
  display: block;
  background: #0d1014;
  border: 1px solid var(--edge);
  border-radius: 6px;
  cursor: crosshair;
}

/* ---------- transport ---------- */
.transport { display: flex; gap: 6px; }

.btn {
  background: linear-gradient(#232933, #1a1f27);
  border: 1px solid #313a47;
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 8px 10px;
  cursor: pointer;
}
.btn:hover { border-color: #46536a; }
.btn:active { transform: translateY(1px); }
.btn.small { font-size: 10px; padding: 5px 8px; }
.btn:disabled { opacity: 0.4; cursor: default; }

.btn-play { flex: 2; font-size: 14px; }
.btn-play.on { background: linear-gradient(#0f6e37, #0a5228); border-color: var(--green); color: #fff; box-shadow: 0 0 10px #2ee56b44; }
.btn-cue { flex: 2; font-size: 14px; }
.btn-cue.held { background: linear-gradient(#8a6a00, #6b5200); border-color: var(--amber); color: #fff; }
.btn-sync { flex: 1; }
.btn-sync.on { border-color: var(--accA); color: var(--accA); }
#deckB .btn-sync.on { border-color: var(--accB); color: var(--accB); }
.btn-tap { flex: 1; }

/* ---------- hot cues ---------- */
.pads {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.pad {
  aspect-ratio: 2.1 / 1;
  border-radius: 6px;
  border: 1px solid #313a47;
  background: #171b21;
  color: var(--dim);
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}
.pad .pad-time { font-size: 9px; font-weight: 400; opacity: 0.85; }
.pad.set { color: #06090c; border-color: transparent; box-shadow: 0 0 8px var(--pad-glow, transparent); }
.pad:active { transform: translateY(1px); }

/* ---------- loop / beat-jump ---------- */
.loop-row, .jump-row { display: flex; gap: 6px; }
.loop-row .btn, .jump-row .btn { flex: 1; padding: 6px 4px; font-size: 10px; }
.btn.loop-armed { border-color: var(--amber); color: var(--amber); }
.btn.loop-on { background: linear-gradient(#7a6100, #5c4900); border-color: var(--amber); color: #fff; }
.section-label {
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--dim);
  margin-top: 2px;
}

/* ---------- tempo strip ---------- */
.tempo-strip {
  display: flex;
  gap: 8px;
  align-items: stretch;
  background: var(--panel2);
  border: 1px solid var(--edge);
  border-radius: 8px;
  padding: 8px;
}
.tempo-fader-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
}
.tempo-fader { width: 100%; }
.tempo-scale {
  display: flex;
  justify-content: space-between;
  width: 100%;
  font-size: 9px;
  color: var(--dim);
}
.tempo-side {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 108px;
}
.tempo-side .row { display: flex; gap: 5px; }
.tempo-side .btn { flex: 1; padding: 5px 2px; font-size: 10px; }
.sel {
  background: #0d1014;
  border: 1px solid var(--edge);
  color: var(--text);
  border-radius: 5px;
  font-family: inherit;
  font-size: 10px;
  padding: 4px;
}
.bpm-input {
  width: 100%;
  background: #0d1014;
  border: 1px solid var(--edge);
  border-radius: 5px;
  color: var(--green);
  font-family: inherit;
  font-size: 12px;
  padding: 4px 6px;
  text-align: center;
}

/* ---------- mixer ---------- */
#mixer {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 10px;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.fader-group {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.mixer-top { display: flex; justify-content: space-evenly; }
.channel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.channel label { font-size: 11px; font-weight: 800; color: var(--dim); }
.channel:first-child label { color: var(--accA); }
.channel:last-child label { color: var(--accB); }

.vfader {
  writing-mode: vertical-lr;
  direction: rtl;
  width: 34px;
  height: 150px;
}

.mixer-mid { display: flex; flex-direction: column; gap: 6px; }
.xfader-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.xl { font-size: 12px; font-weight: 800; }
.xl.a { color: var(--accA); }
.xl.b { color: var(--accB); }
#xfader { width: 100%; }
.mix-hint { font-size: 9px; color: var(--dim); text-align: center; }

/* ---------- range styling ---------- */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  background: #0d1014;
  border: 1px solid var(--edge);
  border-radius: 4px;
}
input[type="range"]:not(.vfader)::-webkit-slider-runnable-track { height: 8px; }
input[type="range"].vfader::-webkit-slider-runnable-track { width: 8px; height: 100%; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 26px;
  border-radius: 3px;
  background: linear-gradient(#e8edf4, #aab4c2);
  border: 1px solid #5a6575;
  margin-top: -10px;
  box-shadow: 0 1px 3px #000a;
}
input[type="range"].vfader::-webkit-slider-thumb {
  width: 26px;
  height: 14px;
  margin-top: 0;
  margin-left: -10px;
}
#xfader::-webkit-slider-thumb { width: 18px; height: 30px; margin-top: -12px; }

/* ---------- help overlay ---------- */
#helpOverlay {
  position: fixed; inset: 0;
  background: #000a;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
#helpOverlay.hidden { display: none; }
.help-card {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 12px;
  padding: 20px 24px;
  max-width: 860px;
  max-height: 85vh;
  overflow: auto;
}
.help-card h2 { margin-bottom: 12px; letter-spacing: 2px; font-size: 16px; }
.help-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; margin-bottom: 14px; }
.help-grid h3 { font-size: 12px; color: var(--dim); margin-bottom: 6px; letter-spacing: 1px; }
.help-grid table { border-collapse: collapse; font-size: 11px; }
.help-grid td { padding: 3px 8px 3px 0; vertical-align: top; }
kbd {
  background: #232933;
  border: 1px solid #3a4452;
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
  font-family: inherit;
  font-size: 10px;
}
.help-note { font-size: 10px; color: var(--dim); margin-top: 8px; line-height: 1.5; max-width: 260px; }

/* ---------- library ---------- */
#library {
  margin: 0 12px 16px;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 1056px;
}
.lib-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.lib-title { font-size: 11px; font-weight: 800; letter-spacing: 1px; color: #fff; }
#libRows {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px 16px;
  max-height: 240px;
  overflow-y: auto;
}
.lib-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 6px;
  border-radius: 5px;
  font-size: 11px;
}
.lib-row:hover { background: #1c222b; }
.lib-row .n { color: var(--dim); width: 20px; text-align: right; font-size: 10px; }
.lib-row .t {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lib-row.loaded-a .t { color: var(--accA); }
.lib-row.loaded-b .t { color: var(--accB); }
.lib-row .btn { padding: 2px 9px; font-size: 10px; }
.lib-row .btn.to-a:hover { border-color: var(--accA); color: var(--accA); }
.lib-row .btn.to-b:hover { border-color: var(--accB); color: var(--accB); }

.flash { animation: flash 0.25s; }
@keyframes flash { 0% { filter: brightness(2); } 100% { filter: brightness(1); } }
