/*!
 * hexo-music-player v2.0.0
 * Inline lyrics music player card for Hexo
 */

/* ========== CSS Variables (Light Mode) ========== */
.hmp-wrapper {
  --hmp-accent: #43a047;
  --hmp-accent-hover: #388e3c;
  --hmp-text: #333;
  --hmp-text-secondary: #888;
  --hmp-lyric-normal: rgba(0, 0, 0, 0.35);
  --hmp-lyric-active: #43a047;
  --hmp-bg-mask: rgba(255, 255, 255, 0.72);
  --hmp-bar-bg: rgba(255, 255, 255, 0.95);
  --hmp-bar-border: rgba(0, 0, 0, 0.06);
  --hmp-btn-bg: rgba(0, 0, 0, 0.04);
  --hmp-btn-hover: rgba(0, 0, 0, 0.08);
  --hmp-height: 420px;
  --hmp-bar-height: 64px;
}

/* ========== Dark Mode ========== */
@media (prefers-color-scheme: dark) {
  .hmp-wrapper {
    --hmp-accent: #66bb6a;
    --hmp-accent-hover: #81c784;
    --hmp-text: #e0e0e0;
    --hmp-text-secondary: #888;
    --hmp-lyric-normal: rgba(255, 255, 255, 0.3);
    --hmp-lyric-active: #66bb6a;
    --hmp-bg-mask: rgba(20, 20, 20, 0.78);
    --hmp-bar-bg: rgba(35, 35, 35, 0.96);
    --hmp-bar-border: rgba(255, 255, 255, 0.06);
    --hmp-btn-bg: rgba(255, 255, 255, 0.06);
    --hmp-btn-hover: rgba(255, 255, 255, 0.12);
  }
}

body.dark .hmp-wrapper,
html.dark .hmp-wrapper,
.hmp-wrapper.dark {
  --hmp-accent: #66bb6a;
  --hmp-accent-hover: #81c784;
  --hmp-text: #e0e0e0;
  --hmp-text-secondary: #888;
  --hmp-lyric-normal: rgba(255, 255, 255, 0.3);
  --hmp-lyric-active: #66bb6a;
  --hmp-bg-mask: rgba(20, 20, 20, 0.78);
  --hmp-bar-bg: rgba(35, 35, 35, 0.96);
  --hmp-bar-border: rgba(255, 255, 255, 0.06);
  --hmp-btn-bg: rgba(255, 255, 255, 0.06);
  --hmp-btn-hover: rgba(255, 255, 255, 0.12);
}

/* ========== Wrapper (Inline Card) ========== */
.hmp-wrapper {
  position: relative;
  display: block;
  width: 100%;
  max-width: 680px;
  height: var(--hmp-height);
  margin: 20px auto;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
  transition: height 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.3s ease;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

.hmp-wrapper:hover {
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
}

/* Collapsed state: only bar visible */
.hmp-wrapper.collapsed {
  height: var(--hmp-bar-height);
}

.hmp-wrapper.collapsed .hmp-bg,
.hmp-wrapper.collapsed .hmp-bg-mask,
.hmp-wrapper.collapsed .hmp-lyrics-viewport {
  opacity: 0;
  pointer-events: none;
}

.hmp-wrapper.collapsed .hmp-icon-collapse {
  display: none;
}
.hmp-wrapper.collapsed .hmp-icon-expand {
  display: block;
}

/* In collapsed state, controls are always visible (no hover needed) */
.hmp-wrapper.collapsed .hmp-controls {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* ========== Background ========== */
.hmp-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  filter: blur(1px);
  transform: scale(1.03);
  transition: opacity 0.3s ease, background-image 0.5s ease;
  z-index: 0;
}

.hmp-bg-mask {
  position: absolute;
  inset: 0;
  background: var(--hmp-bg-mask);
  transition: opacity 0.3s ease;
  z-index: 1;
}

/* ========== Lyrics ========== */
.hmp-lyrics-viewport {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: var(--hmp-bar-height);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 24px 20px;
  z-index: 2;
  mask-image: linear-gradient(to bottom, transparent 0%, black 12%, black 88%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 12%, black 88%, transparent 100%);
  transition: opacity 0.3s ease;
}

.hmp-lyrics-track {
  width: 100%;
  max-width: 520px;
  text-align: center;
  transition: transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  will-change: transform;
}

.hmp-lyric-line {
  padding: 7px 8px;
  font-size: 17px;
  line-height: 1.7;
  color: var(--hmp-lyric-normal);
  transition: color 0.3s ease, font-size 0.3s ease, font-weight 0.3s ease;
  cursor: pointer;
  user-select: none;
}

.hmp-lyric-line:hover {
  color: var(--hmp-text-secondary);
}

.hmp-wrapper .hmp-lyric-line.active {
  color: var(--hmp-lyric-active) !important;
  font-size: 20px;
  font-weight: 600;
}

.hmp-lyrics-loading,
.hmp-lyrics-empty {
  color: var(--hmp-text-secondary);
  font-size: 14px;
  text-align: center;
  padding: 30px;
}

.hmp-lyrics-empty {
  font-style: italic;
}

/* ========== Bottom Bar ========== */
.hmp-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--hmp-bar-height);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: var(--hmp-bar-bg);
  border-top: 1px solid var(--hmp-bar-border);
  z-index: 3;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.hmp-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: var(--hmp-btn-bg);
  color: var(--hmp-text);
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
  padding: 0;
}

.hmp-btn:hover {
  background: var(--hmp-btn-hover);
  color: var(--hmp-accent);
}

.hmp-btn svg {
  display: block;
}

.hmp-icon-expand {
  display: none;
}

/* Cover */
.hmp-cover-wrap {
  width: 42px;
  height: 42px;
  min-width: 42px;
  min-height: 42px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  background: var(--hmp-btn-bg);
}

.hmp-wrapper .hmp-cover {
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  object-fit: cover !important;
  object-position: center !important;
  display: block;
  margin: 0;
  padding: 0;
}

.hmp-cover:not([src]),
.hmp-cover[src=""] {
  display: none !important;
}

/* Info */
.hmp-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.hmp-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--hmp-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.hmp-artist {
  font-size: 11px;
  color: var(--hmp-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

/* Collapsed-state lyric display (shown only when player is collapsed) */
.hmp-collapsed-lyric {
  display: none;
}

.hmp-wrapper.collapsed .hmp-collapsed-lyric {
  display: block;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  color: var(--hmp-text-secondary);
  padding: 0 10px;
  text-align: center;
  line-height: 1.4;
}

/* In collapsed state, limit info width to leave room for the lyric */
.hmp-wrapper.collapsed .hmp-info {
  flex: 0 1 auto;
  max-width: 32%;
}

/* On narrow screens, hide artist to make room for the lyric (never hide the lyric) */
@media (max-width: 520px) {
  .hmp-wrapper.collapsed .hmp-artist {
    display: none;
  }
  .hmp-wrapper.collapsed .hmp-info {
    max-width: 38%;
  }
  .hmp-wrapper.collapsed .hmp-collapsed-lyric {
    padding: 0 6px;
    font-size: 14px;
  }
}

@media (max-width: 380px) {
  .hmp-wrapper.collapsed .hmp-collapsed-lyric {
    font-size: 13px;
    padding: 0 4px;
  }
  .hmp-wrapper.collapsed .hmp-info {
    max-width: 35%;
  }
}

/* ========== Control Buttons (hover reveal) ========== */
.hmp-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0;
  transform: translateX(8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  flex-shrink: 0;
}

.hmp-bar:hover .hmp-controls,
.hmp-bar:focus-within .hmp-controls {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

/* Single-song mode: only play/pause visible */
.hmp-wrapper.single .hmp-prev,
.hmp-wrapper.single .hmp-next {
  display: none !important;
}

.hmp-wrapper.single .hmp-playlist-toggle {
  display: none !important;
}

/* Touch devices: controls always visible */
@media (hover: none) {
  .hmp-controls {
    opacity: 1;
    transform: none;
    pointer-events: auto;
  }
}

.hmp-controls .hmp-btn {
  width: 40px;
  height: 40px;
  background: var(--hmp-accent);
  color: #fff;
}

.hmp-controls .hmp-btn:hover {
  background: var(--hmp-accent-hover);
  color: #fff;
  transform: scale(1.08);
}

.hmp-controls .hmp-play {
  width: 48px;
  height: 48px;
}

.hmp-icon-pause {
  display: none;
}

.hmp-wrapper.playing .hmp-icon-play {
  display: none;
}

.hmp-wrapper.playing .hmp-icon-pause {
  display: block;
}

/* ========== Progress Bar ========== */
.hmp-progress {
  position: absolute;
  bottom: var(--hmp-bar-height);
  left: 0;
  right: 0;
  height: 3px;
  background: var(--hmp-bar-border);
  cursor: pointer;
  z-index: 4;
  touch-action: none;
}

.hmp-progress-buffer {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  background: var(--hmp-btn-hover);
  width: 0%;
  transition: width 0.3s ease;
}

.hmp-progress-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  background: var(--hmp-accent);
  width: 0%;
  transition: width 0.1s linear;
}

.hmp-progress-thumb {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--hmp-accent);
  transform: translate(-50%, -50%) scale(0);
  transition: transform 0.2s ease;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.hmp-progress:hover .hmp-progress-thumb {
  transform: translate(-50%, -50%) scale(1);
}

/* ========== Playlist Panel ========== */
.hmp-playlist-panel {
  position: absolute;
  right: 12px;
  bottom: calc(var(--hmp-bar-height) + 8px);
  width: 240px;
  max-height: 260px;
  background: var(--hmp-bar-bg);
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18);
  overflow: hidden;
  display: none;
  flex-direction: column;
  z-index: 5;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  animation: hmp-slideUp 0.2s ease;
}

.hmp-playlist-panel.open {
  display: flex;
}

@keyframes hmp-slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.hmp-playlist-header {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--hmp-text);
  border-bottom: 1px solid var(--hmp-bar-border);
}

.hmp-playlist-list {
  list-style: none;
  margin: 0;
  padding: 4px 0;
  overflow-y: auto;
  flex: 1;
}

.hmp-playlist-list li {
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.hmp-playlist-list li:hover {
  background: var(--hmp-btn-bg);
}

.hmp-playlist-list li.current .hmp-pl-title {
  color: var(--hmp-accent);
  font-weight: 600;
}

.hmp-pl-title {
  font-size: 12px;
  color: var(--hmp-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hmp-pl-artist {
  font-size: 10px;
  color: var(--hmp-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ========== Error ========== */
.hmp-error {
  padding: 12px 16px;
  color: #e53935;
  font-size: 14px;
  border: 1px solid #ffcdd2;
  border-radius: 8px;
  background: #ffebee;
  margin: 16px 0;
}

/* ========== Screen Reader Only ========== */
.hmp-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ========== Responsive ========== */
@media (max-width: 600px) {
  .hmp-wrapper {
    --hmp-height: 360px;
    --hmp-bar-height: 58px;
    border-radius: 10px;
    margin: 16px auto;
  }

  .hmp-lyric-line {
    font-size: 15px;
    padding: 5px 6px;
  }

  .hmp-lyric-line.active {
    font-size: 18px;
  }

  .hmp-bar {
    padding: 0 10px;
    gap: 8px;
  }

  .hmp-cover-wrap {
    width: 38px;
    height: 38px;
  }

  .hmp-title {
    font-size: 13px;
  }

  .hmp-artist {
    font-size: 10px;
  }

  .hmp-controls .hmp-btn {
    width: 36px;
    height: 36px;
  }

  .hmp-controls .hmp-play {
    width: 42px;
    height: 42px;
  }

  .hmp-info {
    max-width: 100px;
  }

  .hmp-playlist-panel {
    width: 200px;
    right: 8px;
  }
}

@media (max-width: 400px) {
  .hmp-wrapper {
    --hmp-height: 320px;
  }

  .hmp-btn {
    width: 30px;
    height: 30px;
  }

  .hmp-controls {
    gap: 4px;
  }

  .hmp-controls .hmp-btn {
    width: 32px;
    height: 32px;
  }

  .hmp-controls .hmp-play {
    width: 38px;
    height: 38px;
  }
}
