/* ============================================================================
   CortexDJ — Web Mixer (Phase 2) stylesheet
   Dark, modern brand: near-black canvas, cyan->violet accent gradient.
   Mobile-first; decks stack on phones and sit left/right on wider screens.
   Touch-first: large hit targets, no hover-only affordances.
   ========================================================================== */

:root {
  /* Brand palette */
  --bg:        #0a0a0f;   /* near-black canvas */
  --panel:     #12121a;   /* deck panel */
  --panel-2:   #171722;   /* raised control wells */
  --line:      #23232f;   /* hairlines / inactive tracks */
  --text:      #e9e9f2;
  --muted:     #8a8aa0;
  --cyan:      #22d3ee;
  --violet:    #8b5cf6;
  /* The accent gradient reused everywhere (thumbs, wordmark, buttons) */
  --accent:    linear-gradient(135deg, var(--cyan), var(--violet));
  --accent-soft: linear-gradient(135deg, rgba(34,211,238,.18), rgba(139,92,246,.18));

  --radius:    14px;
  --radius-sm: 10px;
  --tap:       52px;      /* minimum comfortable touch target */

  /* Safe-area insets (notched iOS) */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  /* pad for notches; leave room for nothing else since layout is flow */
  padding: calc(var(--safe-t)) var(--safe-r) calc(var(--safe-b)) var(--safe-l);
  /* Stop iOS from letting the whole page rubber-band while dragging faders */
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

/* Disallow accidental text selection when hammering the transport on touch */
button, label, .deck-label, .brand, .xf-title, .xf-labels { user-select: none; -webkit-user-select: none; }

/* ============================ TOP BAR ============================ */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.03), transparent);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.back {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--text);
  text-decoration: none;
  font-size: 20px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.back:active { background: #1f1f2c; }

.brand {
  display: flex;
  align-items: baseline;
  gap: 2px;
  font-weight: 800;
  font-size: 20px;
  letter-spacing: .2px;
}
.brand-cortex { color: var(--text); }
.brand-dj {
  background: var(--accent);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-sub {
  margin-left: 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
}

.beta {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  max-width: 45%;
  line-height: 1.3;
}

/* ============================ LAYOUT ============================ */
.decks {
  display: grid;
  grid-template-columns: 1fr;          /* phones: single column, decks stack */
  gap: 14px;
  padding: 14px;
  max-width: 1200px;
  margin: 0 auto;
}

/* Tablet / desktop: Deck A | Mixer | Deck B */
@media (min-width: 820px) {
  .decks {
    grid-template-columns: 1fr minmax(190px, 240px) 1fr;
    align-items: start;
    gap: 18px;
  }
}

/* ============================ DECK PANEL ============================ */
.deck {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.deck-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.deck-label {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--muted);
}
/* Accent the deck label with the gradient for a touch of brand */
.deck[data-deck] .deck-label {
  background: var(--accent);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  opacity: .9;
}

.bpm { display: flex; align-items: baseline; gap: 5px; }
.bpm b { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.bpm small { font-size: 11px; color: var(--muted); letter-spacing: 1px; }

.track-name {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: .85;
  min-height: 18px;
}

/* --- Waveform canvas --- */
.wave {
  display: block;
  width: 100%;
  height: 92px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  touch-action: none;      /* let us handle drag-to-scrub without page panning */
  cursor: pointer;
}
@media (min-width: 820px) { .wave { height: 110px; } }

.time {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-top: -4px;
}

/* --- Transport row --- */
.transport {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr;
  gap: 8px;
}

/* ============================ BUTTONS ============================ */
.btn {
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .3px;
  min-height: var(--tap);
  padding: 0 14px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  position: relative;
  transition: background .12s ease, transform .06s ease, box-shadow .12s ease;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.btn[disabled] { opacity: .5; pointer-events: none; }

.btn-load { background: var(--accent-soft); border-color: rgba(139,92,246,.4); }
.btn-load input { position: absolute; width: 1px; height: 1px; opacity: 0; }

/* Play button turns gradient-filled when active (deck is playing) */
.btn-play.active {
  background: var(--accent);
  border-color: transparent;
  color: #06060a;
  box-shadow: 0 4px 18px -6px rgba(34,211,238,.6);
}

.btn-cue { color: var(--cyan); }
.btn-cue:active { background: #1c2530; }

/* ============================ SLIDERS (range inputs) ============================ */
/* One shared look for every range; big thumb for fingers. */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 34px;                 /* tall hit area */
  background: transparent;
  margin: 0;
  touch-action: none;          /* precise drags, no page scroll hijack */
  cursor: pointer;
}
/* WebKit / Blink track + thumb */
input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background: var(--line);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px; height: 26px;
  margin-top: -9px;            /* centre on the 8px track */
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0a0a0f;
  box-shadow: 0 2px 8px -1px rgba(0,0,0,.6);
}
/* Firefox track + thumb */
input[type="range"]::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  background: var(--line);
}
input[type="range"]::-moz-range-thumb {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0a0a0f;
}

/* --- Tempo row --- */
.tempo-row label, .fader-row label, .eq-band label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--muted);
}
.tempo-row .val, .eq-band .val {
  margin-left: auto;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
.tempo-row { display: flex; flex-direction: column; gap: 2px; }

/* --- EQ block: three labelled bands --- */
.eq {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.eq-band {
  display: grid;
  grid-template-columns: 46px 1fr 34px;
  align-items: center;
  gap: 8px;
}
.eq-band label { justify-content: flex-start; }
.eq-band .val { margin-left: 0; text-align: right; font-size: 12px; }

/* --- Volume (channel) fader --- */
.fader-row { display: flex; flex-direction: column; gap: 2px; }

/* ============================ CENTER MIXER ============================ */
.mixer-center {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: stretch;
}
/* On phones the center strip sits between the two decks with a bit more presence */
@media (max-width: 819px) {
  .mixer-center { order: 0; }
}

.btn-sync {
  min-height: 54px;
  background: var(--panel-2);
  border-color: rgba(34,211,238,.35);
  color: var(--cyan);
  flex-direction: column;
  gap: 0;
  line-height: 1.1;
}
.btn-sync small { font-size: 10px; color: var(--muted); letter-spacing: 1px; }
.btn-sync:active { background: #16202a; }

/* Crossfader block */
.xf { display: flex; flex-direction: column; gap: 6px; }
.xf-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  padding: 0 4px;
}
.xf-title {
  text-align: center;
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--muted);
  font-weight: 700;
}
/* Give the crossfader a beefier thumb — it is the star control */
#crossfader { height: 44px; }
#crossfader::-webkit-slider-runnable-track {
  height: 10px;
  background: linear-gradient(90deg, rgba(34,211,238,.5), var(--line) 45%, var(--line) 55%, rgba(139,92,246,.5));
}
#crossfader::-webkit-slider-thumb { width: 34px; height: 34px; margin-top: -12px; }
#crossfader::-moz-range-track {
  height: 10px;
  background: linear-gradient(90deg, rgba(34,211,238,.5), var(--line) 45%, var(--line) 55%, rgba(139,92,246,.5));
}
#crossfader::-moz-range-thumb { width: 34px; height: 34px; }

/* AUTO-MIX — the hero action */
.btn-automix {
  min-height: 70px;
  background: var(--accent);
  color: #06060a;
  border: none;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: .5px;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
  box-shadow: 0 8px 26px -10px rgba(139,92,246,.7);
}
.btn-automix small { font-size: 10px; font-weight: 700; color: rgba(6,6,10,.7); letter-spacing: 1px; }
/* Progress sheen: a translucent overlay whose width tracks --p (0%..100%) */
.btn-automix .progress {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: var(--p, 0%);
  background: rgba(255,255,255,.22);
  pointer-events: none;
  transition: width .08s linear;
}
.btn-automix.busy { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 8px 30px -8px rgba(34,211,238,.9); } }

/* ============================ TOAST ============================ */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  transform: translateX(-50%) translateY(20px);
  background: #1b1b28;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 10px 30px -8px rgba(0,0,0,.7);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 50;
  max-width: 88vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
