/* ── Tokens ─────────────────────────────────────────────────────── */
:root {
  --music-hue:   220;        /* updated each frame by JS */
  --bg:          #04040a;
  --surface:     rgba(255,255,255,0.04);
  --surface-hi:  rgba(255,255,255,0.08);
  --border:      rgba(0,220,255,0.13);
  --cyan:        #00e5ff;
  --cyan-dim:    rgba(0,229,255,0.35);
  --purple:      #bf00ff;
  --pink:        #ff006e;
  --text:        #eeeeff;
  --text-dim:    rgba(238,238,255,0.42);
  --text-mute:   rgba(238,238,255,0.2);
  --radius:      12px;
  --sidebar-w:   340px;
}

/* ── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  height: 100vh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

button { font-family: inherit; }

/* ── Background canvas ──────────────────────────────────────────── */
#bg-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

/* ── Toast ──────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  top: 76px;
  right: 22px;
  z-index: 300;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 18px;
  background: rgba(4,4,16,0.88);
  border: 1px solid rgba(0,229,255,0.28);
  border-radius: 10px;
  backdrop-filter: blur(16px);
  font-size: 13px;
  font-weight: 500;
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transform: translateX(calc(100% + 30px));
  opacity: 0;
  transition: transform 0.32s cubic-bezier(0.4,0,0.2,1), opacity 0.32s ease;
  pointer-events: none;
}
#toast.show { transform: translateX(0); opacity: 1; }
#toast-icon { color: var(--cyan); flex-shrink: 0; font-size: 15px; }

/* ── Sidebar overlay ────────────────────────────────────────────── */
#sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(3px);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
}
#sidebar-overlay.visible { opacity: 1; pointer-events: all; }

/* ── Sidebar ────────────────────────────────────────────────────── */
#sidebar {
  position: fixed;
  left: calc(-1 * var(--sidebar-w) - 20px);
  top: 0;
  width: var(--sidebar-w);
  height: 100%;
  background: rgba(5,5,14,0.97);
  backdrop-filter: blur(24px);
  border-right: 1px solid var(--border);
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: left 0.3s cubic-bezier(0.4,0,0.2,1);
}
#sidebar.open { left: 0; }

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 22px 17px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-title {
  font-family: 'Orbitron', monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 4px;
  color: var(--cyan);
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  padding: 5px 7px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}
.close-btn:hover { color: var(--text); background: var(--surface-hi); }

/* ── Collections list ───────────────────────────────────────────── */
#collections-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#collections-list::-webkit-scrollbar { width: 3px; }
#collections-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.collection-item {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 13px 22px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}
.collection-item:hover {
  background: var(--surface-hi);
  border-left-color: rgba(0,229,255,0.35);
}
.collection-item.active {
  background: rgba(0,229,255,0.06);
  border-left-color: var(--cyan);
}

.col-icon { font-size: 15px; opacity: 0.6; flex-shrink: 0; color: var(--cyan); }
.col-name {
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.collection-item.active .col-name { color: var(--cyan); }


@keyframes bar-bounce {
  from { transform: scaleY(0.4); }
  to   { transform: scaleY(1.2); }
}

.sidebar-msg {
  padding: 20px 22px;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.6;
}
.err-msg { color: #ff6090; }

/* ── App shell ──────────────────────────────────────────────────── */
#app {
  position: relative;
  z-index: 1;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 26px;
  border-bottom: 1px solid var(--border);
  background: rgba(4,4,10,0.8);
  backdrop-filter: blur(14px);
  flex-shrink: 0;
  gap: 16px;
}

.hdr-left  { display: flex; align-items: center; gap: 17px; flex-shrink: 0; }
.hdr-right { display: flex; align-items: center; gap: 9px; flex-shrink: 0; }

#hdr-center {
  flex: 1;
  min-width: 0;
  text-align: center;
}
#mini-track-info {
  font-size: 11.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.3px;
  flex: 1;
  text-align: center;
}
#mini-track-info .mini-name { color: var(--text); font-weight: 500; }

#menu-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 37px;
  height: 37px;
  border-radius: 9px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, box-shadow 0.2s, color 0.2s;
}
#menu-btn:hover {
  border-color: var(--cyan-dim);
  box-shadow: 0 0 18px rgba(0,229,255,0.2);
  color: var(--cyan);
}

.logo {
  font-family: 'Orbitron', monospace;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 3px;
}
.logo-accent { color: var(--cyan); }

.vol-icon { opacity: 0.5; flex-shrink: 0; }

input[type=range] {
  -webkit-appearance: none;
  width: 84px;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  background: var(--cyan);
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(0,229,255,0.8);
  transition: transform 0.1s;
}
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.35); }
input[type=range]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  background: var(--cyan);
  border: none;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(0,229,255,0.8);
}

/* ── Main player ────────────────────────────────────────────────── */
#player {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 60px;
  padding: 36px 48px;
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
  min-height: 0;
}

/* ── Art ring ───────────────────────────────────────────────────── */
#art-section { flex-shrink: 0; }

#art-ring {
  position: relative;
  width: 240px;
  height: 240px;
}

/* Percentage inset so the canvas auto-scales at every breakpoint.
   22% each side → canvas = 144% of art-ring.
   innerR / canvas-half = 50% / 144% = 0.347 — used in app.js */
#radial-canvas {
  position: absolute;
  inset: -22%;
  width: 144%;
  height: 144%;
  pointer-events: none;
}


#art-circle {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid rgba(0,229,255,0.14);
  box-shadow:
    inset 0 0 50px rgba(0,0,0,0.55),
    0 0 40px rgba(0,229,255,0.08);
  transition: border-color 0.5s, box-shadow 0.5s;
}
#art-circle.playing {
  border-color: rgba(0,229,255,0.3);
  box-shadow:
    inset 0 0 40px rgba(0,0,0,0.35),
    0 0 60px rgba(0,229,255,0.22),
    0 0 120px rgba(191,0,255,0.1);
}

/* Inner canvas visualizer — fills the circle */
#art-inner-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ── Info section ───────────────────────────────────────────────── */
#info-section {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Track title + meta */
#track-meta { display: flex; flex-direction: column; gap: 9px; }

#track-title-wrap {
  overflow: hidden;
  white-space: nowrap;
  position: relative;
}
/* Fade-out right edge when marquee is active */
#track-title-wrap.scrolling::after {
  content: '';
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 40px;
  background: linear-gradient(to right, transparent, var(--bg));
  pointer-events: none;
}

#track-title {
  font-family: 'Orbitron', monospace;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.4px;
  line-height: 1.2;
  display: inline-block;
  white-space: nowrap;
}
#track-title.scrolling {
  animation: marquee-scroll 14s ease-in-out infinite;
  padding-right: 60px;
}
@keyframes marquee-scroll {
  0%, 12%   { transform: translateX(0); }
  88%, 100% { transform: translateX(var(--scroll-dist, 0px)); }
}

.meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
#track-collection {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 3px;
  color: var(--cyan);
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#track-counter {
  font-family: 'Orbitron', monospace;
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 1px;
  flex-shrink: 0;
}

/* ── EQ canvas ──────────────────────────────────────────────────── */
#eq-wrap {
  position: relative;
  height: 80px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(0,0,0,0.32);
  overflow: hidden;
}
#eq-canvas { display: block; width: 100%; height: 100%; }

/* CRT scanline overlay */
#eq-wrap::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 2px,
    rgba(0,0,0,0.1) 2px,
    rgba(0,0,0,0.1) 3px
  );
  pointer-events: none;
  border-radius: var(--radius);
}

/* ── Seek bar ───────────────────────────────────────────────────── */
#seek-track {
  height: 4px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  cursor: pointer;
  position: relative;
  margin-bottom: 9px;
}
#seek-track:hover #seek-thumb { transform: translateY(-50%) scale(1.5); }

#seek-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg,
    hsl(calc(var(--music-hue) - 45), 100%, 32%),
    hsl(var(--music-hue), 100%, 52%),
    hsl(calc(var(--music-hue) + 35), 100%, 68%)
  );
  border-radius: 2px;
  position: relative;
  box-shadow: 0 0 10px hsla(var(--music-hue), 100%, 65%, 0.45);
}

#seek-thumb {
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 0 10px hsl(var(--music-hue), 100%, 70%);
  transition: transform 0.12s;
}

#time-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.3px;
}

/* ── Transport ──────────────────────────────────────────────────── */
#transport {
  display: flex;
  align-items: center;
  gap: 14px;
}

.t-spacer { flex: 1; }

.t-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}
.t-btn:hover {
  border-color: rgba(191,0,255,0.45);
  color: var(--text);
  box-shadow: 0 0 16px rgba(191,0,255,0.2);
}

/* Loop toggle */
.t-mode {
  width: 38px;
  height: 38px;
  color: var(--text-mute);
  border-color: rgba(255,255,255,0.06);
}
.t-mode.on {
  color: var(--cyan);
  border-color: var(--cyan-dim);
  box-shadow: 0 0 14px rgba(0,229,255,0.2);
}
.t-mode:hover { border-color: rgba(0,229,255,0.25); color: var(--text-dim); }
.t-mode.on:hover { box-shadow: 0 0 22px rgba(0,229,255,0.3); }

/* Play button */
.t-play {
  width: 68px;
  height: 68px;
  border-color: rgba(0,229,255,0.4);
  color: var(--cyan);
  box-shadow: 0 0 24px rgba(0,229,255,0.22);
}
.t-play:hover {
  background: rgba(0,229,255,0.07);
  border-color: var(--cyan);
  color: var(--cyan);
  box-shadow: 0 0 36px rgba(0,229,255,0.4);
}
.t-play.playing {
  background: rgba(0,229,255,0.05);
  animation: play-glow 2.8s ease-in-out infinite;
}
@keyframes play-glow {
  0%,100% { box-shadow: 0 0 24px rgba(0,229,255,0.22); }
  50%      { box-shadow: 0 0 48px rgba(0,229,255,0.55); }
}

/* Buffering spinner */
#play-spinner {
  position: absolute;
  inset: 6px;
  border: 2px solid transparent;
  border-top-color: var(--cyan);
  border-right-color: rgba(0,229,255,0.3);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
#play-spinner.visible { opacity: 1; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Mini playlist ───────────────────────────────────────────────── */
#playlist-wrap {
  display: none;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(0,0,0,0.28);
  overflow: hidden;
  max-height: 260px;
  position: relative;
  z-index: 2;
}
#playlist-wrap.has-tracks { display: flex; }

#playlist-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 14px 6px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#playlist-label {
  font-family: 'Orbitron', monospace;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--text-dim);
}
#playlist-count {
  font-size: 10px;
  color: var(--text-mute);
  font-variant-numeric: tabular-nums;
}

#playlist-tracks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#playlist-tracks::-webkit-scrollbar { width: 3px; }
#playlist-tracks::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.pl-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  cursor: pointer;
  border-left: 2px solid transparent;
  min-width: 0;
  transition: background 0.12s, border-color 0.12s;
}
.pl-item:hover { background: var(--surface-hi); border-left-color: rgba(191,0,255,0.3); }
.pl-item.active {
  background: hsla(var(--music-hue), 100%, 60%, 0.08);
  border-left-color: hsl(var(--music-hue), 100%, 58%);
}

.pl-num {
  font-size: 10px;
  color: var(--text-mute);
  width: 18px;
  text-align: right;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.pl-name {
  font-size: 12.5px;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pl-item.active .pl-name { color: hsl(var(--music-hue), 100%, 80%); }

.pl-dur {
  font-size: 10px;
  color: var(--text-mute);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.3px;
}

/* Playing bars indicator in playlist */
.pl-bars {
  display: none;
  align-items: flex-end;
  gap: 1.5px;
  height: 11px;
  flex-shrink: 0;
}
.pl-item.active .pl-bars { display: flex; }
.pl-item.active .pl-num { display: none; }

.pl-bar {
  width: 2.5px;
  background: var(--cyan);
  border-radius: 1px;
  animation: bar-bounce 0.7s ease-in-out infinite alternate;
}
.pl-bar:nth-child(1) { height: 5px;  animation-delay: 0s; }
.pl-bar:nth-child(2) { height: 9px;  animation-delay: 0.15s; }
.pl-bar:nth-child(3) { height: 6px;  animation-delay: 0.3s; }

/* ── Responsive ─────────────────────────────────────────────────── */

/* Tablet / large phone */
@media (max-width: 760px) {
  /* Allow page to scroll so nothing gets clipped on short viewports */
  body { overflow-y: auto; height: auto; min-height: 100svh; }
  #app  { height: auto; min-height: 100svh; }

  #player {
    flex-direction: column;
    gap: 22px;
    padding: 20px 20px 36px;
    align-items: stretch;
  }

  /* Centre the art ring */
  #art-section {
    display: flex;
    justify-content: center;
    flex-shrink: 0;
  }

  #art-ring { width: 196px; height: 196px; }

  #info-section { width: 100%; gap: 18px; }

  #track-title { font-size: 16px; }

  #eq-wrap { height: 64px; }

  #playlist-tracks { grid-template-columns: 1fr; }
  #playlist-wrap { max-height: 220px; }

  /* Larger tap targets */
  .t-btn  { width: 52px; height: 52px; }
  .t-play { width: 72px; height: 72px; }
  .t-mode { width: 42px; height: 42px; }

  #key-hints { display: none; }
}

/* Small phones (≤480px) */
@media (max-width: 480px) {
  header { padding: 10px 14px; gap: 8px; }
  .logo  { font-size: 13px; letter-spacing: 2px; }

  /* Hide volume icon on small screens, keep slider */
  .vol-icon { display: none; }
  input[type=range] { width: 72px; }

  #player { padding: 14px 14px 28px; gap: 18px; }

  #art-ring { width: 162px; height: 162px; }

  #info-section { gap: 13px; }

  #track-title { font-size: 15px; }

  #eq-wrap { height: 56px; }

  #transport { gap: 10px; }
  .t-btn  { width: 46px; height: 46px; }
  .t-play { width: 64px; height: 64px; }
  .t-mode { width: 36px; height: 36px; }

  #playlist-wrap { max-height: 190px; }

  /* Sidebar nearly full-width on small phones */
  :root { --sidebar-w: 92vw; }
  #sidebar { left: calc(-92vw - 20px); }
  #sidebar.open { left: 0; }
}

/* Very small phones (≤360px) */
@media (max-width: 360px) {
  header { padding: 9px 12px; }
  .logo  { font-size: 12px; letter-spacing: 1.5px; }

  input[type=range] { width: 58px; }

  #art-ring { width: 144px; height: 144px; }

  #track-title { font-size: 14px; }

  #eq-wrap { height: 48px; }

  .t-btn  { width: 42px; height: 42px; }
  .t-play { width: 58px; height: 58px; }
  .t-mode { width: 32px; height: 32px; }

  #playlist-wrap { max-height: 160px; }
}
