:root {
  --bg-0: #0c0d12;
  --fg: #f2f3f7;
  --fg-dim: #9aa0ad;
  --accent: #6ea8fe;
  --row-active: rgba(110, 168, 254, 0.18);
  --surface: rgba(20, 22, 30, 0.55);
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--bg-0);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

/* Blurred dimmed background built from the current cover */
.bg {
  position: fixed;
  inset: -10%;
  z-index: -2;
  background-size: cover;
  background-position: center;
  filter: blur(48px) brightness(0.42) saturate(1.1);
  transform: scale(1.1);
  transition: background-image 0.4s ease;
}
.bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(12,13,18,0.35), rgba(12,13,18,0.78));
}

/* ---- Header / now playing ---- */
.now-playing {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px clamp(16px, 4vw, 40px);
  padding-top: max(16px, env(safe-area-inset-top));
  background: var(--surface);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.np-cover {
  width: 72px;
  height: 72px;
  aspect-ratio: 1;
  border-radius: 10px;
  object-fit: cover;
  background: #1b1e27;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  flex: 0 0 auto;
}

.np-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.np-title {
  margin: 0;
  font-size: clamp(1rem, 2.4vw, 1.35rem);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.visualizer {
  width: 240px;
  max-width: 60vw;
  height: 40px;
  display: block;
}

/* ---- Sort toolbar ---- */
.list-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 8px clamp(8px, 3vw, 32px);
}
.sort-label {
  font-size: 0.82rem;
  color: var(--fg-dim);
}
.sort-select {
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255, 255, 255, 0.08);
  color: var(--fg);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 6px 28px 6px 10px;
  font-size: 0.85rem;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%239aa0ad'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  background-size: 16px;
}
.sort-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.sort-select option {
  background: #15171f;
  color: var(--fg);
}

/* ---- Track list ---- */
.list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px clamp(8px, 3vw, 32px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  -webkit-overflow-scrolling: touch;
}

.row {
  display: grid;
  grid-template-columns: 48px 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s ease;
}
.row:hover { background: rgba(255, 255, 255, 0.05); }
.row:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.row.active { background: var(--row-active); }

.row-thumb {
  width: 48px;
  height: 48px;
  aspect-ratio: 1;
  border-radius: 8px;
  object-fit: cover;
  background: #1b1e27;
}

.row-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.row-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.98rem;
}
.row.active .row-title { color: var(--accent); font-weight: 600; }

.row-date {
  font-size: 0.76rem;
  color: var(--fg-dim);
  white-space: nowrap;
}

.row-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--fg);
  font-size: 1rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s ease, transform 0.1s ease;
}
.row-btn:hover { background: rgba(255, 255, 255, 0.16); }
.row-btn:active { transform: scale(0.92); }
a.row-btn { text-decoration: none; }

/* SVG icons inherit their button's color and stay click-transparent */
.ctrl-btn svg,
.row-btn svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: currentColor;
  pointer-events: none;
}
.ctrl-main svg { width: 26px; height: 26px; }
.row-btn svg { width: 18px; height: 18px; }

/* ---- Footer / controls ---- */
.controls {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px clamp(16px, 4vw, 40px);
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  background: var(--surface);
  backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.transport {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

.transport-main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.transport-side {
  display: flex;
  align-items: center;
}
.transport-right {
  justify-content: flex-end;
}

#shuffle.active {
  background: var(--accent);
  color: #0c0d12;
}
#shuffle.active:hover {
  background: #87b6ff;
}

.ctrl-btn {
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--fg);
  font-size: 1.1rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s ease, transform 0.1s ease;
}
.ctrl-btn:hover { background: rgba(255, 255, 255, 0.16); }
.ctrl-btn:active { transform: scale(0.92); }

.ctrl-main {
  width: 58px;
  height: 58px;
  background: var(--accent);
  color: #0c0d12;
  font-size: 1.35rem;
}
.ctrl-main:hover { background: #87b6ff; }

.seek {
  display: flex;
  align-items: center;
  gap: 12px;
}

.time {
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
  color: var(--fg-dim);
  min-width: 38px;
  text-align: center;
}

.seek-slider {
  flex: 1 1 auto;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--accent) 0%, var(--accent) var(--pct, 0%), rgba(255,255,255,0.15) var(--pct, 0%));
  cursor: pointer;
}
.seek-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--fg);
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
.seek-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: none;
  border-radius: 50%;
  background: var(--fg);
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 110px);
  transform: translateX(-50%) translateY(12px);
  background: rgba(20, 22, 30, 0.95);
  color: var(--fg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  border: 1px solid rgba(255,255,255,0.1);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 10;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 520px) {
  .visualizer { width: 160px; height: 34px; }
  .np-cover { width: 60px; height: 60px; }
}
