*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --red: #ff2d2d;
  --red-dim: rgba(255,45,45,0.15);
  --bg: #060606;
  --glass: rgba(6,6,6,0.82);
  --glass-light: rgba(255,255,255,0.06);
  --border: rgba(255,255,255,0.08);
  --text: #f0f0f0;
  --text-dim: #666;
  --ctrl-h: 50px;
  --r: 10px;
  font-family: 'Syne', sans-serif;
}

html, body {
  width: 100%; height: 100%;
  background: var(--bg);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  color: var(--text);
}

/* ── Stage ── */
#stage {
  position: fixed; inset: 0;
  background: #000;
  user-select: none;
}

/* ── Dual video crossfade ── */
.vid-layer {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

#vid-a { opacity: 1; z-index: 1; }
#vid-b { opacity: 0; z-index: 2; }
.layer-active { z-index: 3 !important; }

/* ── Loading overlay ── */
#loader {
  position: absolute; inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

#loader.visible { opacity: 1; pointer-events: all; }

.loader-ring {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.08);
  border-top-color: var(--red);
  animation: spin 0.8s linear infinite;
  position: relative;
}

.loader-ring::after {
  content: '';
  position: absolute; inset: 5px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.04);
  border-top-color: rgba(255,45,45,0.4);
  animation: spin 1.4s linear infinite reverse;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loader-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
  font-family: 'DM Mono', monospace;
}

/* ── Gradients ── */
#grad-top {
  position: absolute; top: 0; left: 0; right: 0; height: 130px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.8) 0%, transparent 100%);
  pointer-events: none; z-index: 15;
  opacity: 0; transition: opacity 0.3s ease;
}

#grad-bottom {
  position: absolute; bottom: 0; left: 0; right: 0; height: 300px;
  background: linear-gradient(to top, rgba(0,0,0,0.97) 0%, rgba(0,0,0,0.4) 55%, transparent 100%);
  pointer-events: none; z-index: 15;
  opacity: 0; transition: opacity 0.3s ease;
}

#stage.ui-on #grad-top,
#stage.ui-on #grad-bottom,
#stage.paused #grad-top,
#stage.paused #grad-bottom { opacity: 1; }

/* ── Title bar ── */
#title-bar {
  position: absolute; top: 0; left: 0; right: 0;
  padding: 22px 24px 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0;
  opacity: 0;
  transition: opacity 0.3s ease;
}

#stage.ui-on #title-bar,
#stage.paused #title-bar { opacity: 1; }

.tb-track {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--red);
  font-family: 'DM Mono', monospace;
}

.tb-dot { color: rgba(255,255,255,0.2); margin: 0 12px; font-size: 10px; }

.tb-name {
  font-size: 14px;
  font-weight: 500;
  color: rgba(255,255,255,0.75);
  letter-spacing: 0.02em;
}

.tb-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.2);
  font-family: 'DM Mono', monospace;
}

/* ── Playlist drawer ── */
#playlist-drawer {
  position: absolute;
  top: 0; right: 0;
  width: 270px; height: 100%;
  background: rgba(6,6,6,0.94);
  backdrop-filter: blur(28px);
  border-left: 1px solid var(--border);
  z-index: 60;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

#playlist-drawer.open { transform: translateX(0); }

.pl-header {
  padding: 20px 18px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pl-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-dim);
  font-family: 'DM Mono', monospace;
}

.pl-close {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: none; border: none;
  cursor: pointer;
  color: rgba(255,255,255,0.4);
  transition: background 0.15s, color 0.15s;
}
.pl-close:hover { background: var(--glass-light); color: #fff; }

.pl-list { flex: 1; overflow-y: auto; padding: 8px 0; }
.pl-list::-webkit-scrollbar { width: 3px; }
.pl-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.pl-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 18px;
  cursor: pointer;
  transition: background 0.12s;
  position: relative;
}

.pl-item:hover { background: var(--glass-light); }
.pl-item.active { background: rgba(255,45,45,0.07); }
.pl-item.active::before {
  content: '';
  position: absolute; left: 0; top: 20%; bottom: 20%;
  width: 2px;
  background: var(--red);
  border-radius: 2px;
}

.pl-num {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
  font-family: 'DM Mono', monospace;
  width: 18px;
  flex-shrink: 0;
}

.pl-item.active .pl-num { color: var(--red); }

.pl-info { flex: 1; min-width: 0; }

.pl-name {
  font-size: 13px;
  font-weight: 500;
  color: rgba(255,255,255,0.82);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pl-item.active .pl-name { color: #fff; }

.pl-dur {
  font-size: 11px;
  color: var(--text-dim);
  font-family: 'DM Mono', monospace;
  flex-shrink: 0;
  min-width: 36px;
  text-align: right;
}

/* Loading dot for unknown durations */
.pl-dur.loading {
  animation: durPulse 1.2s ease-in-out infinite;
}
@keyframes durPulse { 0%,100%{opacity:0.3} 50%{opacity:0.7} }

/* ── Center feedback ── */
#center-fb {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none; z-index: 25;
}

#center-icon {
  width: 72px; height: 72px;
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  opacity: 0;
  backdrop-filter: blur(8px);
}

#center-icon.pop { animation: iconPop 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards; }

@keyframes iconPop {
  0%   { opacity: 0; transform: scale(0.5); }
  25%  { opacity: 1; transform: scale(1.1); }
  60%  { opacity: 1; transform: scale(0.96); }
  100% { opacity: 0; transform: scale(1.02); }
}

/* ── Unmute overlay ── */
#unmute {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 35; cursor: pointer;
  pointer-events: all;
}

#unmute.gone { display: none; }

#unmute-btn {
  display: flex; align-items: center; gap: 10px;
  background: rgba(6,6,6,0.75);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 50px;
  padding: 14px 26px;
  font-family: 'Syne', sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(16px);
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
  pointer-events: none;
}

#unmute-btn:hover {
  background: rgba(255,45,45,0.15);
  border-color: rgba(255,45,45,0.4);
  transform: scale(1.04);
}

/* ── Controls ── */
#controls {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 0 20px max(env(safe-area-inset-bottom, 0px), 20px);
  z-index: 20;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease;
}

#stage.ui-on #controls,
#stage.paused #controls { opacity: 1; pointer-events: all; }

@media (hover: hover) {
  #stage.cursor-gone { cursor: none; }
}

/* ── Progress ── */
#prog-area {
  padding: 14px 0 10px;
  cursor: pointer;
  position: relative;
}

#prog-track {
  height: 3px;
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
  position: relative;
  transition: height 0.18s ease;
}

#prog-area:hover #prog-track,
#prog-area.scrubbing #prog-track { height: 5px; }

#prog-buffer {
  position: absolute; height: 100%;
  background: rgba(255,255,255,0.18);
  border-radius: 3px; width: 0%;
  pointer-events: none;
  transition: width 0.3s linear;
}

#prog-fill {
  position: absolute; height: 100%;
  background: var(--red);
  border-radius: 3px; width: 0%;
  pointer-events: none;
}

#prog-thumb {
  position: absolute; top: 50%; right: -7px;
  transform: translateY(-50%) scale(0);
  width: 14px; height: 14px;
  background: #fff;
  border-radius: 50%;
  pointer-events: none;
  transition: transform 0.18s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.6);
}

#prog-area:hover #prog-thumb,
#prog-area.scrubbing #prog-thumb { transform: translateY(-50%) scale(1); }

#prog-tip {
  position: absolute;
  bottom: calc(100% + 12px);
  background: rgba(8,8,8,0.92);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 500;
  font-family: 'DM Mono', monospace;
  color: #fff;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateY(5px);
  transition: opacity 0.15s, transform 0.15s;
  left: 0;
}

#prog-area:hover #prog-tip,
#prog-area.scrubbing #prog-tip { opacity: 1; transform: translateY(0); }

/* ── Buttons row ── */
#btns {
  display: flex;
  align-items: center;
  gap: 0;
  height: var(--ctrl-h);
}

.btn {
  background: none; border: none; cursor: pointer;
  width: 42px; height: 42px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  color: rgba(255,255,255,0.65);
  transition: color 0.15s, background 0.15s, transform 0.12s;
  flex-shrink: 0;
  touch-action: manipulation;
}

.btn:hover { color: #fff; background: rgba(255,255,255,0.07); }
.btn:active { transform: scale(0.87); }
.btn:disabled { opacity: 0.18 !important; cursor: default; pointer-events: none; }

svg { display: block; }

#spacer { flex: 1; }

/* volume */
#vol-group { display: flex; align-items: center; }

#vol-wrap {
  width: 0; overflow: hidden;
  transition: width 0.22s ease;
  display: flex; align-items: center;
}

#vol-group:hover #vol-wrap,
#vol-group:focus-within #vol-wrap { width: 78px; }

input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 70px; height: 3px;
  background: rgba(255,255,255,0.2);
  border-radius: 3px;
  outline: none; cursor: pointer; margin-left: 4px;
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px; height: 13px;
  background: #fff; border-radius: 50%;
  box-shadow: 0 1px 5px rgba(0,0,0,0.5);
}

input[type=range]::-moz-range-thumb {
  width: 13px; height: 13px;
  background: #fff; border: none; border-radius: 50%;
}

#time-disp {
  font-size: 12px;
  font-weight: 400;
  font-family: 'DM Mono', monospace;
  color: rgba(255,255,255,0.5);
  white-space: nowrap;
  padding: 0 10px;
  letter-spacing: 0.04em;
  min-width: 90px;
}

#time-disp .sep { color: rgba(255,255,255,0.18); }

/* ── Context menu ── */
#ctx {
  position: fixed;
  background: rgba(8,8,8,0.96);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 5px 0;
  min-width: 248px;
  z-index: 200;
  opacity: 0; transform: scale(0.93) translateY(-5px);
  pointer-events: none;
  transition: opacity 0.14s ease, transform 0.14s ease;
  backdrop-filter: blur(28px);
  box-shadow: 0 16px 48px rgba(0,0,0,0.8), 0 2px 8px rgba(0,0,0,0.4);
}

#ctx.open { opacity: 1; transform: scale(1) translateY(0); pointer-events: all; }

.ctx-sec {
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--text-dim); padding: 7px 14px 3px;
  font-family: 'DM Mono', monospace;
}

.ctx-row {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 14px;
  font-size: 13px; font-weight: 500;
  color: rgba(255,255,255,0.82);
  cursor: pointer; transition: background 0.1s;
}

.ctx-row:hover { background: var(--glass-light); }
.ctx-row:active { background: rgba(255,255,255,0.12); }

.ctx-ico { width: 16px; height: 16px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; opacity: 0.7; }
.ctx-row.accent .ctx-ico { opacity: 1; }
.ctx-row.accent > span:last-of-type { color: var(--red); }

.ctx-right { margin-left: auto; font-size: 11px; color: rgba(255,255,255,0.25); white-space: nowrap; font-family: 'DM Mono', monospace; }
.ctx-badge { font-size: 11px; font-weight: 600; background: var(--red-dim); color: var(--red); border-radius: 4px; padding: 2px 8px; letter-spacing: 0.04em; font-family: 'DM Mono', monospace; }

.ctx-div { height: 1px; background: var(--border); margin: 4px 0; }

/* ── Settings panel ── */
#settings {
  position: absolute;
  bottom: calc(var(--ctrl-h) + 20px);
  right: 20px;
  background: rgba(8,8,8,0.96);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 8px 0;
  min-width: 194px;
  z-index: 50;
  opacity: 0; transform: translateY(12px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  backdrop-filter: blur(24px);
}

#settings.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: all; }

.s-label {
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--text-dim); padding: 6px 16px 4px;
  font-family: 'DM Mono', monospace;
}

.s-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 16px;
  font-size: 13px; font-weight: 500;
  color: rgba(255,255,255,0.8);
  cursor: pointer; transition: background 0.12s; gap: 20px;
}

.s-item:hover { background: var(--glass-light); }
.s-val { color: var(--text-dim); font-size: 12px; font-weight: 400; font-family: 'DM Mono', monospace; }
.s-item.active .s-val { color: var(--red); }
.s-div { height: 1px; background: var(--border); margin: 4px 0; }

#speed-opts { display: none; flex-direction: column; }
#speed-opts.open { display: flex; }

.spd-opt {
  padding: 8px 16px 8px 28px;
  font-size: 13px; color: rgba(255,255,255,0.55);
  cursor: pointer; transition: background 0.12s; font-family: 'DM Mono', monospace;
}

.spd-opt:hover { background: var(--glass-light); color: #fff; }
.spd-opt.sel { color: var(--red); font-weight: 500; }

/* ── Copy pill ── */
#copy-pill {
  position: fixed;
  bottom: 92px; left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: rgba(8,8,8,0.95);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 12px 20px 12px 14px;
  display: flex; align-items: center; gap: 10px;
  pointer-events: none; z-index: 300;
  opacity: 0; transition: opacity 0.22s ease, transform 0.22s ease;
  box-shadow: 0 8px 32px rgba(0,0,0,0.7);
  backdrop-filter: blur(20px);
}

#copy-pill.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.pill-ck {
  width: 22px; height: 22px;
  background: #1db954;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.pill-texts { display: flex; flex-direction: column; gap: 1px; }
.pill-main { font-size: 13px; font-weight: 600; color: #fff; white-space: nowrap; }
.pill-sub {
  font-size: 11px; font-weight: 400; font-family: 'DM Mono', monospace;
  color: rgba(255,255,255,0.35); white-space: nowrap;
  max-width: 220px; overflow: hidden; text-overflow: ellipsis;
}

/* ── Track toast ── */
#track-toast {
  position: absolute;
  top: 70px; left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: rgba(8,8,8,0.88);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 12px; font-weight: 500;
  color: rgba(255,255,255,0.7);
  backdrop-filter: blur(16px);
  z-index: 30;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  white-space: nowrap;
}

#track-toast.show {
  opacity: 1; transform: translateX(-50%) translateY(0);
}

/* ── Loop indicator ── */
#loop-indicator {
  position: absolute;
  top: 20px; right: 66px;
  font-size: 10px;
  font-family: 'DM Mono', monospace;
  letter-spacing: 0.1em;
  color: var(--red);
  background: var(--red-dim);
  border: 1px solid rgba(255,45,45,0.25);
  border-radius: 4px;
  padding: 3px 8px;
  z-index: 20;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

#loop-indicator.visible { opacity: 1; }

@media (max-width: 500px) { #pip-btn { display: none; } }