/**
 * HaloTab 桌面背景音控件
 *   - 右上角常驻：音乐按钮（播放 / 暂停）+ 列表按钮（展开曲目面板）。
 *   - 面板为毛玻璃卡片，跟随桌面主题（data-theme = light / dark）。
 *   - z-index 60：高于左侧程序坞（30），低于弹窗 / 确认框（9000+）。
 * ============================================================ */
.ht-audio {
  position: fixed;
  top: 16px;
  right: 18px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  font-family: inherit;
  color: #334155;
  -webkit-user-select: none;
  user-select: none;
}

.ht-audio-bar { display: flex; align-items: center; gap: 6px; }

.ht-audio-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  box-sizing: border-box;
  width: 38px;
  height: 38px;
  aspect-ratio: 1 / 1;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .62);
  border-radius: 9999px;
  background: rgba(255, 255, 255, .62);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 4px 16px rgba(15, 23, 42, .10);
  color: #475569;
  cursor: pointer;
  transition: transform .15s, background .18s, color .18s, box-shadow .18s;
}
.ht-audio-btn:hover {
  background: rgba(255, 255, 255, .92);
  color: #0f172a;
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(15, 23, 42, .14);
}
.ht-audio-btn:active { transform: scale(.94); }
.ht-audio-btn:focus-visible { outline: 2px solid #38bdf8; outline-offset: 2px; }

.ht-audio-eq { display: none; align-items: flex-end; gap: 2px; height: 16px; }
.ht-audio-eq i {
  display: block;
  width: 3px;
  height: 5px;
  border-radius: 2px;
  background: currentColor;
  animation: ht-audio-eq 900ms ease-in-out infinite alternate;
}
.ht-audio-eq i:nth-child(2) { animation-delay: -620ms; }
.ht-audio-eq i:nth-child(3) { animation-delay: -340ms; }
.ht-audio-eq i:nth-child(4) { animation-delay: -180ms; }
@keyframes ht-audio-eq {
  from { height: 4px; opacity: .65; }
  to   { height: 16px; opacity: 1; }
}

/* 面板标题栏的播放状态指示（小号均衡器） */
.ht-audio-head-right { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.ht-audio-head-eq { height: 12px; }
.ht-audio-head-eq i { width: 2px; animation-name: ht-audio-eq-head; }
.ht-audio.is-playing .ht-audio-head-eq { display: inline-flex; }
@keyframes ht-audio-eq-head {
  from { height: 3px; opacity: .6; }
  to   { height: 12px; opacity: 1; }
}

.ht-audio.is-playing .ht-audio-play {
  background: rgba(255, 255, 255, .92);
  border-color: rgba(14, 165, 233, .55);
  color: #0284c7;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, .14), 0 5px 18px rgba(14, 165, 233, .22);
}
.ht-audio.is-playing .ht-audio-play::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: inherit;
  border: 1px solid rgba(14, 165, 233, .4);
  animation: ht-audio-ring 2.4s ease-out infinite;
  pointer-events: none;
}
@keyframes ht-audio-ring {
  0%   { transform: scale(.9); opacity: .7; }
  70%  { transform: scale(1.18); opacity: 0; }
  100% { transform: scale(1.18); opacity: 0; }
}
.ht-audio.is-playing .ht-audio-play:hover { background: #fff; }

/* 中间音符：暂停时停在当前角度，播放时匀速旋转 */
.ht-audio-note { transform-origin: 50% 50%; animation: ht-audio-spin 3.2s linear infinite; animation-play-state: paused; }
.ht-audio.is-playing .ht-audio-note { animation-play-state: running; }
@keyframes ht-audio-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.ht-audio.is-expanded .ht-audio-list-btn {
  background: rgba(255, 255, 255, .92);
  color: #0ea5e9;
}

/* ---------- 曲目面板 ---------- */
.ht-audio-panel {
  width: 288px;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .72);
  border-radius: 14px;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 16px 44px rgba(15, 23, 42, .18);
  transform-origin: top right;
  animation: ht-audio-in .18s ease;
}
.ht-audio-panel[hidden] { display: none; }
@keyframes ht-audio-in {
  from { opacity: 0; transform: translateY(-6px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.ht-audio-panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 13px 14px 9px;
  border-bottom: 1px solid rgba(15, 23, 42, .08);
}
.ht-audio-panel-title { font-size: 13px; font-weight: 700; color: #0f172a; }
.ht-audio-now { font-size: 11px; color: #64748b; }

.ht-audio-tracks {
  list-style: none;
  margin: 0;
  padding: 6px;
  max-height: 320px;
  overflow: auto;
}
.ht-audio-track {
  --ht-audio-accent: #0ea5e9;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .15s;
}
.ht-audio-track:hover { background: rgba(14, 165, 233, .08); }
.ht-audio-track.is-active { background: rgba(14, 165, 233, .13); }
.ht-audio-track-ico {
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border-radius: 7px;
  background: rgba(15, 23, 42, .05);
  font-size: 14px;
  line-height: 1;
}
.ht-audio-track.is-active .ht-audio-track-ico { background: rgba(14, 165, 233, .16); }
.ht-audio-track-name {
  flex: 0 0 auto;
  min-width: 58px;
  font-size: 12px;
  font-weight: 600;
  color: #1e293b;
}
.ht-audio-track-desc {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 11px;
  color: #94a3b8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ht-audio-track-mark {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1.5px solid #cbd5e1;
}
.ht-audio-track.is-active .ht-audio-track-mark {
  background: var(--ht-audio-accent);
  border-color: var(--ht-audio-accent);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, .15);
}

.ht-audio-volume {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 12px;
  border-top: 1px solid rgba(15, 23, 42, .08);
  color: #64748b;
}
.ht-audio-vol {
  flex: 1 1 auto;
  min-width: 0;
  height: 4px;
  margin: 0;
  border-radius: 999px;
  appearance: none;
  -webkit-appearance: none;
  background: linear-gradient(to right, #38bdf8 0%, #38bdf8 var(--ht-audio-vol, 60%), rgba(15, 23, 42, .12) var(--ht-audio-vol, 60%), rgba(15, 23, 42, .12) 100%);
  outline: none;
  cursor: pointer;
}
.ht-audio-vol::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #0ea5e9;
  box-shadow: 0 1px 4px rgba(15, 23, 42, .22);
}
.ht-audio-vol::-moz-range-thumb {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #0ea5e9;
  box-shadow: 0 1px 4px rgba(15, 23, 42, .22);
}
.ht-audio-vol-val {
  flex: 0 0 auto;
  width: 32px;
  text-align: right;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

/* ---------- 暗色主题 ---------- */
html[data-theme="dark"] .ht-audio { color: #e2e8f0; }
html[data-theme="dark"] .ht-audio-btn {
  border-color: rgba(255, 255, 255, .12);
  background: rgba(30, 41, 59, .66);
  color: #cbd5e1;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .32);
}
html[data-theme="dark"] .ht-audio-btn:hover {
  background: rgba(30, 41, 59, .9);
  color: #fff;
}
html[data-theme="dark"] .ht-audio.is-expanded .ht-audio-list-btn { background: rgba(30, 41, 59, .95); color: #38bdf8; }
html[data-theme="dark"] .ht-audio.is-playing .ht-audio-play {
  background: rgba(30, 41, 59, .92);
  border-color: rgba(56, 189, 248, .6);
  color: #38bdf8;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, .14), 0 5px 18px rgba(0, 0, 0, .34);
}
html[data-theme="dark"] .ht-audio.is-playing .ht-audio-play::after { border-color: rgba(56, 189, 248, .45); }
html[data-theme="dark"] .ht-audio.is-playing .ht-audio-play:hover { background: rgba(30, 41, 59, .98); }
html[data-theme="dark"] .ht-audio-panel {
  border-color: rgba(148, 163, 184, .16);
  background: rgba(17, 24, 39, .88);
  box-shadow: 0 16px 44px rgba(0, 0, 0, .45);
}
html[data-theme="dark"] .ht-audio-panel-head,
html[data-theme="dark"] .ht-audio-volume { border-color: rgba(148, 163, 184, .14); }
html[data-theme="dark"] .ht-audio-panel-title { color: #f1f5f9; }
html[data-theme="dark"] .ht-audio-now { color: #94a3b8; }
html[data-theme="dark"] .ht-audio-track:hover { background: rgba(56, 189, 248, .12); }
html[data-theme="dark"] .ht-audio-track.is-active { background: rgba(56, 189, 248, .18); }
html[data-theme="dark"] .ht-audio-track-ico { background: rgba(255, 255, 255, .06); }
html[data-theme="dark"] .ht-audio-track.is-active .ht-audio-track-ico { background: rgba(56, 189, 248, .18); }
html[data-theme="dark"] .ht-audio-track-name { color: #e2e8f0; }
html[data-theme="dark"] .ht-audio-track-desc { color: #64748b; }
html[data-theme="dark"] .ht-audio-track-mark { border-color: #475569; }
html[data-theme="dark"] .ht-audio-volume { color: #94a3b8; }
html[data-theme="dark"] .ht-audio-vol {
  background: linear-gradient(to right, #38bdf8 0%, #38bdf8 var(--ht-audio-vol, 60%), rgba(148, 163, 184, .22) var(--ht-audio-vol, 60%), rgba(148, 163, 184, .22) 100%);
}

/* ---------- 窄屏 ---------- */
@media (max-width: 640px) {
  .ht-audio { top: 10px; right: 10px; gap: 6px; }
  .ht-audio-btn { width: 34px; height: 34px; }
  .ht-audio-panel { width: min(272px, calc(100vw - 20px)); }
}
