/* =========================================================================
   Nigi DJ — shared YouTube + MP3 queue, dark club aesthetic
   ========================================================================= */

:root {
  --bg:        #0f0d16;
  --panel:     #17131f;
  --panel-2:   #1e1929;
  --input:     #221d2e;
  --text:      #f1eef7;
  --text-dim:  #9891ab;
  --border:    #2c2638;
  --hover:     #241f30;
  --accent:    #ff3d78;
  --accent-2:  #7c5cff;
  --accent-ink:#ffffff;
  --danger:    #ff5c6d;
  --ok:        #35d19a;
  --shadow:    0 10px 30px rgba(0,0,0,.45);
  --shadow-sm: 0 2px 8px rgba(0,0,0,.35);
  --radius:    16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; }

body {
  font-family: "Heebo", -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(255,61,120,.12), transparent 60%),
    radial-gradient(1000px 500px at 100% 0%, rgba(124,92,255,.14), transparent 55%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  padding-inline: 16px;
  padding-block: max(16px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-bottom));
}

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input, select { font: inherit; color: inherit; }
svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
::selection { background: var(--accent); color: #fff; }

/* ---------- gate ---------- */
.gate {
  min-height: calc(100vh - 40px);
  display: flex; align-items: center; justify-content: center;
}
.gate-card {
  width: 100%; max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.gate-logo {
  font-size: 22px; font-weight: 800;
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 10px;
}
.gate-logo span { background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.gate-lede { color: var(--text-dim); font-size: 14px; line-height: 1.55; margin-bottom: 24px; }
#gate-form { display: flex; flex-direction: column; gap: 6px; }
#gate-form label { font-size: 12.5px; color: var(--text-dim); margin-top: 10px; }
#gate-form input {
  background: var(--input); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 13px; font-size: 15px; outline: none;
}
#gate-form input:focus { border-color: var(--accent); }
.gate-room-row { display: flex; gap: 8px; }
.gate-room-row input { flex: 1; }
#gate-room-new {
  background: var(--input); border: 1px solid var(--border); border-radius: 10px;
  padding: 0 14px; font-size: 13px; color: var(--text-dim); white-space: nowrap;
}
#gate-room-new:hover { color: var(--text); border-color: var(--accent-2); }
.btn-primary {
  margin-top: 20px; padding: 12px; border-radius: 10px; font-weight: 700; font-size: 15px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: #fff;
  box-shadow: 0 6px 20px -6px rgba(255,61,120,.55);
}
.btn-primary:active { transform: translateY(1px); }

/* ---------- topbar ---------- */
.app { max-width: 1080px; margin-inline: auto; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 6px 18px;
  flex-wrap: wrap;
}
.brand { font-size: 18px; font-weight: 800; display: flex; align-items: center; gap: 7px; }
.brand span { background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.room-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 999px;
  padding: 7px 14px; font-family: "IBM Plex Mono", monospace; font-size: 13px;
  color: var(--text-dim); direction: ltr;
}
.room-chip:hover { color: var(--text); border-color: var(--accent-2); }
.room-chip svg { width: 14px; height: 14px; flex: none; }
.users { display: flex; gap: 6px; flex-wrap: wrap; }
.user-pill {
  font-size: 12px; padding: 5px 10px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text-dim);
}
.header-tools { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.device-picker {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 999px;
  padding: 7px 12px; color: var(--text-dim);
}
.device-picker select {
  background: none; border: 0; color: inherit; font-size: 12.5px; max-width: 150px;
}
.btn-tv {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 14px; font-size: 13px; font-weight: 600; color: var(--text);
}
.btn-tv:hover { border-color: var(--accent-2); color: var(--accent-2); }
.btn-tv svg { width: 15px; height: 15px; flex: none; }

/* ---------- layout ---------- */
.layout { display: block; }

/* ---------- decks + mixer ---------- */
.decks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas: "left right" "mixer mixer";
  gap: 14px;
  align-items: stretch;
  margin-bottom: 18px;
  /* Deck L/R is a spatial convention, not a text direction — force LTR
     column order so deck-left renders physically on the left even
     though the page is RTL (grid column 1 is the rightmost in RTL). */
  direction: ltr;
}
.deck { direction: rtl; }
.deck-left { grid-area: left; }
.deck-right { grid-area: right; }
.mixer { grid-area: mixer; }
@media (max-width: 640px) {
  .decks { grid-template-columns: 1fr; grid-template-areas: "left" "right" "mixer"; }
}

.deck, .queue-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.deck { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; }
.deck-left { border-top: 2px solid var(--accent); }
.deck-right { border-top: 2px solid var(--accent-2); }

.deck-vinyl-wrap { position: relative; width: 100%; display: flex; justify-content: center; padding-top: 6px; }
.deck-vinyl {
  width: 128px; height: 128px; border-radius: 50%;
  background: repeating-radial-gradient(circle at center, #2b2438 0 2px, #1a1626 2px 5px);
  border: 2px solid var(--border);
  position: relative;
  display: flex; align-items: center; justify-content: center;
  animation: spin 5s linear infinite;
  animation-play-state: paused;
  box-shadow: var(--shadow-sm);
}
.deck-vinyl.spinning { animation-play-state: running; }
.deck-art {
  display: none;
  width: 56px; height: 56px; border-radius: 50%; object-fit: cover;
  background: var(--panel-2);
}
.deck-art.has-src { display: block; }
.deck-vinyl.is-file { display: flex; align-items: center; justify-content: center; }
.deck-vinyl.is-file::after {
  content: "🎵"; position: absolute; font-size: 20px; opacity: .8;
}
.deck-vinyl.is-file.has-art::after { content: ""; }
.deck-hole { position: absolute; width: 10px; height: 10px; border-radius: 50%; background: var(--bg); border: 1px solid var(--border); }
.deck-tonearm {
  position: absolute; top: 4px; right: -6px;
  width: 46px; height: 6px; border-radius: 4px;
  background: linear-gradient(90deg, var(--border), var(--text-dim));
  transform-origin: right center; transform: rotate(28deg);
  transition: transform .3s ease;
}
.deck-tonearm::before {
  content: ""; position: absolute; right: -5px; top: 50%; translate: 0 -50%;
  width: 14px; height: 14px; border-radius: 50%; background: var(--panel-2); border: 2px solid var(--text-dim);
}
.deck-vinyl-wrap:has(.spinning) .deck-tonearm { transform: rotate(6deg); }
.deck-tonearm-flip { right: auto; left: -6px; transform: rotate(-28deg) scaleX(-1); }
.deck-vinyl-wrap:has(.spinning) .deck-tonearm-flip { transform: rotate(-6deg) scaleX(-1); }
@keyframes spin { to { transform: rotate(360deg); } }

.deck-text { min-width: 0; width: 100%; }
.deck-title { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.deck-channel { font-size: 12px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

.progress-row { display: flex; align-items: center; gap: 9px; width: 100%; }
.pg-time { font-family: "IBM Plex Mono", monospace; font-size: 11.5px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.progress-track { position: relative; flex: 1; display: flex; align-items: center; height: 22px; }
.progress-mark {
  position: absolute; top: 50%; translate: -50% -50%; width: 3px; height: 12px; border-radius: 2px;
  background: #ffd23f; box-shadow: 0 0 0 1px rgba(0,0,0,.4); pointer-events: none; z-index: 1;
}

/* seek scrubber — a real <input type=range> so it drags smoothly with
   mouse or touch, with its filled portion drawn via a JS-updated
   background gradient (--fill, set as a percentage in updateProgress). */
.seek-range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 5px; border-radius: 999px; background: var(--panel-2);
  --fill: 0%;
  background-image: linear-gradient(90deg, var(--accent), var(--accent-2));
  background-size: var(--fill) 100%;
  background-repeat: no-repeat;
  cursor: pointer; outline: none;
}
.seek-range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; border: 2px solid var(--accent-2); box-shadow: var(--shadow-sm);
  cursor: grab; margin-top: 0;
}
.seek-range::-webkit-slider-thumb:active { cursor: grabbing; }
.seek-range::-moz-range-track { height: 5px; border-radius: 999px; background: transparent; }
.seek-range::-moz-range-progress { height: 5px; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.seek-range::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 2px solid var(--accent-2);
  box-shadow: var(--shadow-sm); cursor: grab;
}

.deck-controls, .controls { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
.ctrl-btn {
  width: 38px; height: 38px; border-radius: 50%; background: var(--panel-2);
  display: flex; align-items: center; justify-content: center; color: var(--text);
}
.ctrl-btn svg { width: 17px; height: 17px; }
.ctrl-btn:hover { background: var(--hover); }
.ctrl-btn-main {
  width: 46px; height: 46px; background: var(--panel-2); color: var(--text); border: 2px solid var(--border);
}
.ctrl-btn-main svg { width: 19px; height: 19px; }
.ctrl-btn-main.side-left { border-color: var(--accent); }
.ctrl-btn-main.side-right { border-color: var(--accent-2); }
.ctrl-btn-mark { color: #ffd23f; }
.ctrl-btn-mark:hover { background: rgba(255,210,63,.15); }
.speed-select {
  height: 38px; border-radius: 19px; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text-dim); font-size: 12px; font-family: "IBM Plex Mono", monospace; padding: 0 8px;
}
.speed-select:hover { color: var(--text); border-color: var(--accent-2); }
.yt-hidden { position: absolute; width: 2px; height: 2px; overflow: hidden; opacity: .01; pointer-events: none; left: -9999px; top: -9999px; }

/* ---------- mixer (horizontal, below both decks) ---------- */
.mixer {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 22px;
  display: flex; align-items: center; gap: 14px;
}
.mixer-label {
  font-size: 12px; font-weight: 700; color: var(--text-dim); font-family: "IBM Plex Mono", monospace;
  width: 16px; text-align: center; flex: none;
}
.mixer-label:first-child { color: var(--accent); }
.mixer-label:last-child { color: var(--accent-2); }
.crossfader { flex: 1; accent-color: var(--accent-2); height: 6px; }

/* ---------- add / upload / search ---------- */
.add-form { display: flex; gap: 8px; }
#add-input {
  flex: 1; background: var(--input); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 13px; font-size: 14.5px; outline: none; min-width: 0;
}
#add-input:focus { border-color: var(--accent); }
.btn-upload, .btn-add {
  width: 42px; border-radius: 10px; flex: none;
  display: flex; align-items: center; justify-content: center;
}
.btn-upload { background: var(--panel-2); border: 1px solid var(--border); color: var(--text-dim); }
.btn-upload:hover { color: var(--text); border-color: var(--accent-2); }
.btn-add {
  font-size: 20px; font-weight: 700; line-height: 1;
  background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: #fff;
}
.upload-progress {
  position: relative; margin-top: 8px; height: 26px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--border); overflow: hidden;
  display: flex; align-items: center;
}
.upload-progress-fill { position: absolute; inset: 0; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); opacity: .35; transition: width .15s ease; }
#upload-progress-label { position: relative; margin-inline-start: 10px; font-size: 12px; color: var(--text); }
/* ---------- youtube search panel (below the library) ---------- */
.search-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  margin-top: 16px;
}
.search-panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.search-panel-head h2 { font-size: 14px; color: var(--text-dim); font-weight: 600; }
.search-panel-msg { color: var(--text-dim); font-size: 13.5px; text-align: center; padding: 20px 10px; line-height: 1.6; }
.search-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px;
}
.search-card {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
  cursor: pointer; text-align: center; transition: border-color .15s ease;
}
.search-card:hover { border-color: var(--accent-2); }
.search-card-thumb-wrap { position: relative; aspect-ratio: 16/9; background: var(--panel); }
.search-card-thumb-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.search-card-add {
  position: absolute; inset: 0; margin: auto; width: 38px; height: 38px; border-radius: 50%;
  background: rgba(15,13,22,.55); color: #fff; display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .15s ease;
}
.search-card:hover .search-card-add { opacity: 1; }
.search-card-add svg { width: 18px; height: 18px; }
.search-card-body { padding: 8px 10px 10px; }
.sc-title { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.35; min-height: 2.7em; }
.sc-channel { font-size: 11px; color: var(--text-dim); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.queue-head { display: flex; align-items: center; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.queue-head h2 { font-size: 14px; color: var(--text-dim); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.queue-count {
  background: var(--panel-2); border-radius: 999px; padding: 1px 8px; font-size: 12px;
  font-family: "IBM Plex Mono", monospace; color: var(--text);
}
.playlist-tools { margin-inline-start: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.playlist-tools select {
  background: var(--input); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; font-size: 12.5px; max-width: 130px;
}
.btn-ghost {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 11px; font-size: 12.5px; color: var(--text-dim);
}
.btn-ghost:hover { color: var(--text); border-color: var(--accent-2); }
.btn-update { border-color: #ffd23f; color: #ffd23f; }
.btn-update:hover { background: rgba(255,210,63,.15); color: #ffd23f; border-color: #ffd23f; }
.queue-hint { font-size: 12px; color: var(--text-dim); margin-top: 6px; line-height: 1.5; }

/* ---------- queue list ---------- */
.queue-list { list-style: none; margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.queue-empty { color: var(--text-dim); font-size: 13.5px; text-align: center; padding: 26px 10px; }
.queue-item {
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  align-items: center; gap: 8px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 8px;
  /* Same spatial-vs-text-direction split as .decks: the load-left button
     must sit physically under deck-left (left side) regardless of RTL. */
  direction: ltr;
}
.qi-body { direction: rtl; }
.queue-item.playing-left { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.queue-item.playing-right { border-color: var(--accent-2); box-shadow: 0 0 0 1px var(--accent-2) inset; }
.queue-item.dragging { opacity: .4; }

.qi-reorder { display: flex; flex-direction: column; gap: 2px; }
.qi-move, .qi-handle-wrap {
  width: 20px; height: 16px; border-radius: 4px; color: var(--text-dim);
  display: flex; align-items: center; justify-content: center;
}
.qi-move:hover { background: var(--hover); color: var(--text); }
.qi-move svg { width: 11px; height: 11px; }
.qi-handle { color: var(--text-dim); cursor: grab; }
.qi-handle svg { width: 15px; height: 15px; }

.qi-body { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 3px; min-width: 0; padding: 0 4px; }
.qi-thumb-wrap { position: relative; }
.qi-thumb { width: 64px; height: 48px; border-radius: 8px; object-fit: cover; background: var(--panel); }
.qi-thumb.qi-thumb-file { display: flex; align-items: center; justify-content: center; font-size: 20px; }
.qi-start-badge {
  position: absolute; bottom: -4px; right: -4px;
  background: #ffd23f; color: #241d05; font-size: 9.5px; font-weight: 700;
  border-radius: 999px; padding: 1px 5px; font-family: "IBM Plex Mono", monospace;
}
.qi-title { font-size: 13.5px; font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qi-meta { font-size: 11px; color: var(--text-dim); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.qi-load {
  flex: none; width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel); border: 2px solid var(--border); color: var(--text-dim);
}
.qi-load svg { width: 18px; height: 18px; }
.qi-load-left:hover, .qi-load-left.active { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--panel)); }
.qi-load-right:hover, .qi-load-right.active { border-color: var(--accent-2); color: var(--accent-2); background: color-mix(in srgb, var(--accent-2) 14%, var(--panel)); }
.qi-load-right svg { transform: scaleX(-1); }

.qi-side-end { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.qi-remove {
  flex: none; width: 26px; height: 26px; border-radius: 50%; color: var(--text-dim); font-size: 15px;
  display: flex; align-items: center; justify-content: center;
}
.qi-remove:hover { background: rgba(255,92,109,.15); color: var(--danger); }

@media (max-width: 560px) {
  .queue-item { grid-template-columns: auto 1fr auto; grid-template-areas: "loadL body loadR" "reorder body remove"; row-gap: 6px; }
  .qi-load-left { grid-area: loadL; }
  .qi-body { grid-area: body; }
  .qi-load-right { grid-area: loadR; }
  .qi-reorder { grid-area: reorder; flex-direction: row; }
  .qi-side-end { grid-area: remove; flex-direction: row; justify-self: end; }
}

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: max(18px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 18px; font-size: 13.5px; box-shadow: var(--shadow); z-index: 50;
  max-width: calc(100vw - 32px); text-align: center;
}
