/* RMusic widget — bottom-control-bar layout.
 *
 * Three persistent regions:
 *   .background  fullscreen blurred backdrop (cover or default
 *                radial vignette before a track is picked)
 *   .container   middle LRC scroll area, click + drag to seek
 *   #controls    bottom-centered control bar with track meta +
 *                progress + transport + shuffle/loop
 *
 * Plus a top-right cluster: a single ⌕ button that toggles the
 * search panel. */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  height: 100%;
  background: #050505;
}
body {
  height: 100%;
  font-family: ui-sans-serif, system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #999;
  text-align: center;
  background: transparent;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.background {
  position: fixed;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  /* Default intro backdrop: a soft radial vignette that reads as a
   * blurred cover even before any track is selected. Once setBackdrop()
   * writes a real `url(...)`, the image replaces this. */
  background-image: radial-gradient(
    ellipse at 50% 40%,
    rgba(80, 100, 140, 0.35) 0%,
    rgba(30, 35, 50, 0.6) 35%,
    rgba(8, 10, 14, 0.95) 80%
  );
  filter: blur(30px) brightness(0.7);
  transform: scale(1.15);
  transition: background-image 0.6s ease;
  z-index: -1;
}

/* LRC scroll area ---------------------------------------------------
 *
 * `inset` leaves room for the top-right search button and the
 * bottom control bar (≈ 130 px). Touch action set to `pan-y` so we
 * can capture vertical drag as a seek gesture without conflicting
 * with the browser's default pinch-zoom. */
.container {
  position: absolute;
  top: 8%;
  left: 0;
  right: 0;
  bottom: 150px;
  overflow: hidden;
  color: #999;
  text-align: center;
  touch-action: pan-y;
  cursor: grab;
}
.container.dragging { cursor: grabbing; }
.container ul {
  transition: transform 0.45s ease;
  list-style: none;
}
.container.dragging ul { transition: none; }
.container li {
  height: 50px;
  line-height: 50px;
  filter: blur(1px);
  transition: filter 0.6s ease, color 0.6s ease, transform 0.6s ease;
  white-space: nowrap;
  overflow: hidden;
  padding: 0 24px;
  cursor: pointer;
}
.container li.active {
  color: #fff;
  transform: scale(1.8);
  filter: blur(0);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* Intro mode (no track loaded yet) — flex-center the static hint
 * lines instead of transform-scrolling them, and crisp them up. */
.container ul[data-intro] {
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 100%;
}
.container li.intro {
  filter: blur(0);
  opacity: 0.6;
  cursor: default;
}
.container li.intro.active { opacity: 1; }

/* Top-right ⌕ search toggle ----------------------------------------- */

#searchToggle {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(20, 20, 20, 0.55);
  color: #ddd;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
  z-index: 1001;
}
#searchToggle:hover,
#searchToggle:focus-visible {
  background: rgba(40, 40, 40, 0.75);
  color: #fff;
  transform: scale(1.05);
  outline: none;
}
#searchToggle.active {
  background: rgba(255, 255, 255, 0.92);
  color: #111;
}

/* Search panel ------------------------------------------------------ */

#search-panel {
  position: fixed;
  top: 64px;
  right: 16px;
  width: 320px;
  max-height: calc(100vh - 200px);
  background: rgba(15, 15, 15, 0.88);
  color: #ddd;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 14px;
  z-index: 999;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#search-panel[hidden] { display: none; }

.search-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.search-row label {
  width: 56px;
  flex: 0 0 56px;
  font-size: 12px;
  color: #999;
  text-align: left;
}
.search-row select,
.search-row input,
.search-row button {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #eee;
  padding: 6px 8px;
  border-radius: 5px;
  font: 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.search-row select,
.search-row input {
  flex: 1 1 auto;
  min-width: 0;
}
.search-row button {
  flex: 0 0 auto;
  background: rgba(255, 255, 255, 0.18);
  cursor: pointer;
  font-family: inherit;
}
.search-row button:hover { background: rgba(255, 255, 255, 0.28); }

.results-list {
  list-style: none;
  overflow-y: auto;
  max-height: 50vh;
  margin: 4px -6px 0 -6px;
}
.results-list li {
  display: flex;
  flex-direction: column;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
}
.results-list li:hover { background: rgba(255, 255, 255, 0.06); }
.results-list li.playing {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}
.results-list .row-title {
  font-size: 13px;
  color: inherit;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.results-list .row-author {
  font-size: 11px;
  color: #888;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

.search-status {
  font-size: 12px;
  color: #aaa;
  padding: 4px 6px;
}
.search-status[hidden] { display: none; }
.search-status.error { color: #ff8b6b; }

/* Bottom control bar ----------------------------------------------- */

#controls {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(680px, calc(100vw - 32px));
  padding: 14px 18px 12px 18px;
  background: rgba(12, 12, 14, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  z-index: 998;
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: #ccc;
}

#now-playing {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 6px;
  font-size: 13px;
  color: #ddd;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
#now-playing .sep { color: #777; }
#now-playing #now-author { color: #999; font-size: 12px; }

#progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.time {
  font: 11px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: #999;
  min-width: 36px;
  text-align: center;
  flex: 0 0 auto;
}
#progress-bar {
  position: relative;
  flex: 1 1 auto;
  height: 4px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 2px;
  cursor: pointer;
  touch-action: none;
}
#progress-bar:hover { height: 6px; transition: height 0.15s ease; }
#progress-buffered,
#progress-fill {
  position: absolute;
  inset: 0;
  height: 100%;
  border-radius: 2px;
  pointer-events: none;
}
#progress-buffered {
  background: rgba(255, 255, 255, 0.18);
  width: 0%;
}
#progress-fill {
  background: linear-gradient(90deg, #88b8ff, #c188ff);
  width: 0%;
}
#progress-thumb {
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  transform: translate(-50%, -50%);
  left: 0%;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
#progress-bar:hover #progress-thumb,
#progress-bar.dragging #progress-thumb { opacity: 1; }

#control-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
}
.ctrl-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: #ddd;
  cursor: pointer;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
.ctrl-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}
.ctrl-btn:active { transform: scale(0.94); }
.ctrl-btn:disabled,
.ctrl-btn[aria-disabled="true"] {
  color: #555;
  cursor: not-allowed;
  background: rgba(255, 255, 255, 0.02);
}
.ctrl-btn.ctrl-play {
  width: 48px;
  height: 48px;
  font-size: 18px;
  background: rgba(255, 255, 255, 0.92);
  color: #111;
  border-color: transparent;
}
.ctrl-btn.ctrl-play:hover {
  background: #fff;
  color: #000;
}
.ctrl-btn.ctrl-play.loading .ctrl-icon {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(0, 0, 0, 0.25);
  border-top-color: #111;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  /* Hide the literal play glyph behind the spinner. */
  color: transparent;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

#shuffleBtn[data-mode="on"],
#loopBtn[data-mode="all"],
#loopBtn[data-mode="single"] {
  background: rgba(120, 180, 255, 0.22);
  border-color: rgba(140, 190, 255, 0.6);
  color: #d6e8ff;
}

/* Small viewport tweaks -------------------------------------------- */

@media (max-width: 560px) {
  #search-panel {
    width: calc(100vw - 32px);
    right: 16px;
    top: 64px;
  }
  #controls {
    width: calc(100vw - 16px);
    padding: 10px 12px;
    bottom: max(8px, env(safe-area-inset-bottom));
    border-radius: 12px;
    gap: 8px;
  }
  #now-playing { font-size: 12px; }
  #now-playing #now-author { font-size: 11px; }
  #control-row { gap: 8px; }
  .ctrl-btn { width: 34px; height: 34px; font-size: 13px; }
  .ctrl-btn.ctrl-play { width: 44px; height: 44px; font-size: 16px; }
  .container { bottom: 180px; top: 6%; }
  .container li { padding: 0 12px; height: 44px; line-height: 44px; }
  .container li.active { transform: scale(1.55); }
}

@media (max-height: 480px) and (orientation: landscape) {
  /* Stubby landscape (mobile rotated) — keep controls slim. */
  #controls { padding: 8px 12px; gap: 6px; }
  .container { bottom: 110px; }
}
