:root {
    /* 动态主题变量：随封面取色更新，未取到时用默认值 */
    --theme-bg1: #1a1a2e;
    --theme-bg2: #0f3460;
    --theme-primary: #667eea;
    --theme-secondary: #764ba2;
    --theme-glow: rgba(102, 126, 234, 0.4);
    --cover-bg: none;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* 内联 SVG 图标：尺寸跟随父级 font-size（1em），颜色用 currentColor */
.icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}
.icon svg {
    width: 1em;
    height: 1em;
    fill: currentColor;
    display: block;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, var(--theme-bg1) 0%, #16213e 50%, var(--theme-bg2) 100%);
    transition: background 0.8s ease;
    /* 🚀 修复移动端遮挡：使用 dvh 视口高度，保留 vh 作为兜底 */
    min-height: 100vh;
    min-height: 100dvh; 
    display: flex;
    align-items: center;
    justify-content: center;
    /* 🚀 修复移动端遮挡：适配全面屏刘海和底部手势安全区 */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    overflow: hidden;
    position: relative;
}

/* 动态背景：放大模糊的封面，随切歌平滑淡入淡出（Apple Music 风格） */
body::before {
    content: '';
    position: fixed;
    inset: -10%;
    background-image: var(--cover-bg);
    background-size: cover;
    background-position: center;
    filter: blur(44px) saturate(1.5);
    transform: scale(1.2);
    opacity: 0;
    transition: opacity 0.8s ease;
    z-index: 0;
    pointer-events: none;
}

body.has-backdrop::before {
    opacity: 0.46;
    /* 方案 A：模糊封面缓慢漂浮（平移 + 轻微缩放）；默认暂停，仅播放时运行 */
    animation: bgDrift 42s ease-in-out infinite;
    animation-play-state: paused;
}

body.has-backdrop.playing::before {
    animation-play-state: running;
}

/* 后台（标签页不可见）时暂停背景漂浮，省电（放在 .playing 规则之后以胜出） */
body.bg-paused.has-backdrop::before {
    animation-play-state: paused;
}

@keyframes bgDrift {
    0%   { transform: scale(1.2) translate(0, 0); }
    25%  { transform: scale(1.28) translate(-2%, -1.5%); }
    50%  { transform: scale(1.24) translate(1.8%, 1%); }
    75%  { transform: scale(1.3) translate(-1%, 1.8%); }
    100% { transform: scale(1.2) translate(0, 0); }
}

.player-container {
    position: relative;
    z-index: 1;
}

/* 核心：精确计算容器尺寸，永远不超出屏幕 */
.player-container {
    width: min(92vw, 420px);
    /* 🚀 配合 body，使用 dvh */
    height: calc(100vh - 24px);
    height: calc(100dvh - 24px);
    max-height: 880px;
    min-height: 480px;
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 36px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    padding: 16px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 30px 60px -15px rgba(0, 0, 0, 0.6);
    position: relative;
}

/* 封面：固定尺寸，居中，不参与flex伸缩 */
.cover-container {
    /* 同时受视口宽度、视口高度与上限约束，短屏/横屏不溢出 */
    width: min(70vw, 42dvh, 300px);
    height: min(70vw, 42dvh, 300px);
    max-width: 300px;
    max-height: 300px;
    border-radius: 28px;
    overflow: hidden;
    position: relative;
    background: rgba(0, 0, 0, 0.3);
    margin: 0 auto 12px;
    flex-shrink: 0;
    flex-grow: 0;
    /* 随封面主色的外发光 */
    box-shadow: 0 16px 40px -10px var(--theme-glow);
    transition: box-shadow 0.8s ease;
}

.cover-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transform: scale(1.04);
    transition: opacity 0.5s ease, transform 0.6s ease;
    will-change: opacity, transform;
}

.cover-img.loaded {
    opacity: 1;
    transform: scale(1);
}

/* 缓冲/加载指示：覆盖在封面上的转圈，仅缓冲时显示 */
.loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 44px;
    height: 44px;
    margin: -22px 0 0 -22px;
    border: 3px solid rgba(255, 255, 255, 0.25);
    border-top-color: #fff;
    border-radius: 50%;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease;
    animation: spin 0.8s linear infinite;
    z-index: 2;
}

.loading-spinner.show {
    opacity: 1;
    visibility: visible;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.default-cover {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.3);
    font-size: 68px;
}

/* 歌曲信息：固定高度 */
.song-info {
    text-align: center;
    margin-bottom: 12px;
    flex-shrink: 0;
    flex-grow: 0;
    min-height: 44px;
}

.song-title {
    font-size: 18px;
    font-weight: 600;
    color: #fff;
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.song-artist {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.6);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 进度条：固定高度 */
.progress-container {
    margin-bottom: 16px;
    position: relative;
    flex-shrink: 0;
    flex-grow: 0;
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
    position: relative;
    cursor: pointer;
    touch-action: none;
    overflow: hidden;
}

.buffer-bar {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 3px;
    width: 0%;
    transition: width 0.3s ease;
}

.play-bar {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--theme-primary) 0%, var(--theme-secondary) 100%);
    border-radius: 3px;
    width: 0%;
    /* 🚀 移除 progress-bar 的 CSS transition，交给 JS requestAnimationFrame 丝滑控制 */
    max-width: 100%;
    transition: background 0.6s ease;
}

.progress-thumb {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%) scale(0);
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    left: 0%;
    /* 🚀 优化滑块性能 */
    transition: transform 0.2s ease;
    will-change: transform, left;
}

.progress-bar:focus-visible {
    outline: 2px solid var(--theme-primary);
    outline-offset: 4px;
    border-radius: 4px;
}

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

.time-info {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
}

.time-preview {
    position: absolute;
    top: -32px;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    transform: translateX(-50%);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.time-preview.show {
    opacity: 1;
}

/* 核心：歌词区域 - 自动伸缩填充剩余空间 */
.lyrics-container {
    flex: 1; /* 自动填充剩余空间 */
    min-height: 60px; /* 最小高度 */
    overflow: hidden;
    position: relative;
    margin-bottom: 12px;
    /* 上下渐隐遮罩，让歌词在边缘淡出更有质感 */
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 18%, #000 82%, transparent 100%);
    mask-image: linear-gradient(to bottom, transparent 0, #000 18%, #000 82%, transparent 100%);
}

.lyrics-scroll {
    height: 100%;
    overflow-y: auto;
    padding: 8px 0;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.lyrics-scroll::-webkit-scrollbar {
    display: none;
}

.lyric-line {
    text-align: center;
    padding: 5px 16px;
    color: rgba(255, 255, 255, 0.58);
    font-size: 14px;
    line-height: 1.5;
    /* 淡投影提升在动态背景上的对比度/可读性 */
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
    /* 仅过渡 color/opacity/transform，去掉 transition:all 与 font-size 动画，避免重排掉帧 */
    transition: color 0.3s ease, opacity 0.3s ease, transform 0.3s ease;
    will-change: transform, opacity;
    transform-origin: center;
}

.lyric-line.active {
    color: #fff;
    font-weight: 600;
    /* 用 transform 放大替代 font-size 动画（约等于 14px→16px） */
    transform: scale(1.14);
}

.no-lyrics {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.3);
    font-size: 13px;
}

/* 核心：控制栏 - 永远固定在底部，不参与伸缩 */
.controls {
    /* 用 grid 三列（两侧等宽）保证中间的播放/上一曲/下一曲严格居中，
       不受左右两侧按钮数量/宽度差异影响 */
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    flex-shrink: 0;
    flex-grow: 0;
    padding-bottom: 4px;
    margin-top: auto; /* 推到底部 */
}

.controls > #playlistBtn { justify-self: start; }
.controls > .core-controls { justify-self: center; }
.controls > .right-controls { justify-self: end; }

.control-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.8);
    font-size: 20px;
    cursor: pointer;
    border-radius: 50%;
    transition: color 0.3s ease, transform 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    will-change: transform, color;
    position: relative;
}

.control-btn:hover {
    color: #fff;
    transform: scale(1.1);
}

.control-btn:active {
    transform: scale(0.95);
}

.control-btn.active {
    color: var(--theme-primary);
}

/* 单曲循环按钮的数字标记 */
.control-btn.active.single-mode::after {
    content: '1';
    position: absolute;
    bottom: 4px;
    right: 4px;
    font-size: 10px;
    font-weight: bold;
    color: var(--theme-primary);
    line-height: 1;
}

.core-controls {
    display: flex;
    align-items: center;
    gap: 16px;
}

.play-btn {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--theme-primary) 0%, var(--theme-secondary) 100%);
    font-size: 24px;
    color: #fff;
    border-radius: 50%;
    box-shadow: 0 4px 20px var(--theme-glow);
    transition: transform 0.3s ease, box-shadow 0.3s ease, background 0.6s ease;
}

.play-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 25px var(--theme-glow);
}

.right-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 音量控制 */
.volume-container {
    position: relative;
}

.volume-popup {
    position: absolute;
    bottom: calc(100% + 12px);
    left: 50%;
    transform: translateX(-50%) scale(0.9);
    background: rgba(30, 30, 50, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 16px 12px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    opacity: 0;
    visibility: hidden;
    transition: transform 0.3s ease, opacity 0.3s ease, visibility 0.3s ease;
    will-change: transform, opacity;
}

.volume-popup.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) scale(1);
}

.volume-arrow {
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid rgba(30, 30, 50, 0.95);
}

.volume-bar {
    width: 8px;
    height: 120px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    position: relative;
    cursor: pointer;
    touch-action: none;
    overflow: hidden;
}

.volume-level {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: linear-gradient(to top, var(--theme-primary) 0%, var(--theme-secondary) 100%);
    border-radius: 4px;
    height: 70%;
    transition: height 0.1s ease;
    max-height: 100%;
}

.volume-thumb {
    position: absolute;
    left: 50%;
    transform: translate(-50%, 50%) scale(0);
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    bottom: 70%;
    transition: transform 0.2s ease;
    will-change: transform, bottom;
}

.volume-bar:hover .volume-thumb,
.volume-bar.dragging .volume-thumb {
    transform: translate(-50%, 50%) scale(1);
}

/* 歌单 */
.playlist-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 998;
}

.playlist-overlay.show {
    opacity: 1;
    visibility: visible;
}

.playlist-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 70vh;
    /* 与主体统一的磨砂玻璃质感（白色半透明 + 模糊 + 饱和），替代原先近不透明深色板 */
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(28px) saturate(1.4);
    -webkit-backdrop-filter: blur(28px) saturate(1.4);
    border-top: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 28px 28px 0 0;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 999;
    display: flex;
    flex-direction: column;
}

.playlist-panel.show {
    transform: translateY(0);
}

.playlist-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.playlist-header h3 {
    color: #fff;
    font-size: 18px;
    font-weight: 600;
}

.close-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    transition: background 0.3s ease;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.playlist-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.playlist-item {
    display: flex;
    align-items: center;
    padding: 12px 24px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.playlist-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.playlist-item.active {
    background: rgba(102, 126, 234, 0.2);
}

.playlist-item-cover {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    object-fit: cover;
    background: rgba(255, 255, 255, 0.1);
    margin-right: 12px;
    flex-shrink: 0;
}

.playlist-item-info {
    flex: 1;
    min-width: 0;
}

.playlist-item-title {
    color: #fff;
    font-size: 15px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.playlist-item-artist {
    color: rgba(255, 255, 255, 0.5);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.playlist-item-playing {
    color: var(--theme-primary);
    font-size: 14px;
    margin-left: 12px;
    opacity: 0;
}

.playlist-item.active .playlist-item-playing {
    opacity: 1;
}

/* 模式提示 */
.mode-toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    padding: 12px 24px;
    border-radius: 16px;
    font-size: 14px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
    z-index: 1000;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.mode-toast.show {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

/* 响应式优化 */
@media (max-width: 480px) {
    .player-container {
        width: 94vw;
        border-radius: 32px;
        padding: 14px;
    }
    
    .cover-container {
        width: 72vw;
        height: 72vw;
        max-width: 280px;
        max-height: 280px;
        border-radius: 24px;
        margin-bottom: 10px;
    }
    
    .default-cover {
        font-size: 60px;
    }
    
    /* 窄屏：略缩按钮与间距，保证两侧不挤压居中的播放群组 */
    .core-controls {
        gap: 12px;
    }
    
    .right-controls {
        gap: 4px;
    }
    
    .control-btn {
        width: 42px;
        height: 42px;
        font-size: 19px;
    }
    
    .play-btn {
        width: 58px;
        height: 58px;
        font-size: 22px;
    }
}

/* 矮屏优化 */
@media (max-height: 700px) {
    .player-container {
        height: calc(100vh - 16px);
        height: calc(100dvh - 16px);
        padding: 12px;
        border-radius: 28px;
    }
    
    .cover-container {
        width: 60vw;
        height: 60vw;
        max-width: 240px;
        max-height: 240px;
        border-radius: 20px;
        margin-bottom: 8px;
    }
    
    .default-cover {
        font-size: 52px;
    }
    
    .song-info {
        margin-bottom: 8px;
        min-height: 40px;
    }
    
    .song-title {
        font-size: 16px;
    }
    
    .progress-container {
        margin-bottom: 12px;
    }
    
    .lyric-line {
        padding: 4px 12px;
        font-size: 13px;
    }
    
    .lyric-line.active {
        transform: scale(1.15);
    }
}

/* 极限矮屏 */
@media (max-height: 560px) {
    .player-container {
        padding: 10px;
        border-radius: 24px;
    }
    
    .cover-container {
        width: 48vw;
        height: 48vw;
        max-width: 200px;
        max-height: 200px;
        border-radius: 18px;
        margin-bottom: 6px;
    }
    
    .default-cover {
        font-size: 44px;
    }
    
    .song-info {
        margin-bottom: 6px;
        min-height: 36px;
    }
    
    .song-title {
        font-size: 15px;
        margin-bottom: 2px;
    }
    
    .song-artist {
        font-size: 12px;
    }
    
    .progress-container {
        margin-bottom: 10px;
    }
    
    .lyrics-container {
        min-height: 40px;
        margin-bottom: 8px;
    }
    
    .lyric-line {
        padding: 3px 10px;
        font-size: 12px;
    }
    
    .lyric-line.active {
        transform: scale(1.17);
    }
}
/* 尊重系统"减少动态效果"设置 */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}
