/* ========================================
   課本音檔播放器 - 樣式表
   設計系統: 深色模式 + Glassmorphism
======================================== */

/* CSS 變數 */
:root {
    /* 配色 */
    --bg-primary: #0D1117;
    --bg-secondary: #161B22;
    --bg-tertiary: #21262D;
    --accent-primary: #6366F1;
    --accent-secondary: #8B5CF6;
    --accent-gradient: linear-gradient(135deg, #6366F1 0%, #8B5CF6 100%);
    --text-primary: #F0F6FC;
    --text-secondary: #8B949E;
    --text-tertiary: #6E7681;
    --border-color: #30363D;
    --success: #3FB950;
    --warning: #D29922;

    /* 字型 */
    --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', monospace;

    /* 圓角 */
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    /* 陰影 */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.3);

    /* 過渡 */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;

    /* 間距 */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;
}

/* 重置 */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-primary);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* 應用容器 */
.app {
    position: relative;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 背景裝飾 */
.bg-decoration {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.gradient-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
    animation: float 20s ease-in-out infinite;
}

.orb-1 {
    width: 400px;
    height: 400px;
    background: var(--accent-primary);
    top: -100px;
    right: -100px;
    animation-delay: 0s;
}

.orb-2 {
    width: 300px;
    height: 300px;
    background: var(--accent-secondary);
    bottom: 20%;
    left: -50px;
    animation-delay: -7s;
}

.orb-3 {
    width: 250px;
    height: 250px;
    background: #22D3EE;
    bottom: -50px;
    right: 20%;
    animation-delay: -14s;
}

@keyframes float {

    0%,
    100% {
        transform: translate(0, 0) scale(1);
    }

    25% {
        transform: translate(20px, -30px) scale(1.05);
    }

    50% {
        transform: translate(-10px, 20px) scale(0.95);
    }

    75% {
        transform: translate(-30px, -10px) scale(1.02);
    }
}

/* 主容器 */
.container {
    position: relative;
    z-index: 1;
    max-width: 480px;
    width: 100%;
    margin: 0 auto;
    padding: var(--space-lg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 標題區 */
.header {
    text-align: center;
    margin-bottom: var(--space-xl);
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.logo-icon {
    width: 32px;
    height: 32px;
    color: var(--accent-primary);
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* URL 輸入區域 */
.url-input-section {
    margin-bottom: var(--space-lg);
}

.url-input-container {
    display: flex;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.url-input {
    flex: 1;
    padding: var(--space-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: 0.875rem;
    outline: none;
    transition: all var(--transition-fast);
}

.url-input::placeholder {
    color: var(--text-tertiary);
}

.url-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.load-url-btn {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-md) var(--space-lg);
    background: var(--accent-gradient);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-family: var(--font-primary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.load-url-btn svg {
    width: 18px;
    height: 18px;
}

.load-url-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow);
}

.load-url-btn:active {
    transform: translateY(0);
}

.load-url-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.load-url-btn.loading svg {
    animation: spin 1s linear infinite;
}

.url-hint {
    color: var(--text-tertiary);
    font-size: 0.75rem;
    text-align: center;
}

/* 播放器卡片 */
.player-card {
    background: rgba(22, 27, 34, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: var(--space-xl);
    box-shadow: var(--shadow-lg);
}

/* 封面區域 */
.cover-section {
    text-align: center;
    margin-bottom: var(--space-xl);
}

.cover-art {
    position: relative;
    width: 180px;
    height: 180px;
    margin: 0 auto var(--space-lg);
    background: var(--accent-gradient);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-glow);
    overflow: hidden;
}

.music-icon {
    width: 80px;
    height: 80px;
    color: white;
    opacity: 0.9;
}

.cover-glow {
    position: absolute;
    inset: -50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.2) 0%, transparent 70%);
    animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 0.5;
        transform: scale(1);
    }

    50% {
        opacity: 0.8;
        transform: scale(1.1);
    }
}

.track-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: var(--space-xs);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.track-artist {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* 進度條 */
.progress-section {
    margin-bottom: var(--space-xl);
}

.progress-bar {
    position: relative;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    cursor: pointer;
    overflow: visible;
}

.progress-fill {
    height: 100%;
    background: var(--accent-gradient);
    border-radius: var(--radius-full);
    width: 0%;
    transition: width 100ms linear;
}

.progress-handle {
    position: absolute;
    top: 50%;
    left: 0%;
    width: 14px;
    height: 14px;
    background: white;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: var(--shadow-md);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.progress-bar:hover .progress-handle {
    opacity: 1;
}

.time-display {
    display: flex;
    justify-content: space-between;
    margin-top: var(--space-sm);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* 主控制區 */
.controls-main {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.control-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    border-radius: var(--radius-full);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.control-btn svg {
    width: 22px;
    height: 22px;
}

.control-btn:hover {
    background: var(--bg-tertiary);
    color: var(--accent-primary);
}

.control-btn:active {
    transform: scale(0.95);
}

.control-btn.active {
    color: var(--accent-primary);
}

.play-btn {
    width: 64px;
    height: 64px;
    background: var(--accent-gradient);
    color: white;
    box-shadow: var(--shadow-glow);
}

.play-btn svg {
    width: 28px;
    height: 28px;
}

.play-btn:hover {
    background: var(--accent-gradient);
    transform: scale(1.05);
    box-shadow: 0 0 50px rgba(99, 102, 241, 0.5);
}

/* 次要控制區 */
.controls-secondary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: var(--space-md);
    border-top: 1px solid var(--border-color);
}

.volume-control {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.control-btn-sm {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-full);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.control-btn-sm svg {
    width: 20px;
    height: 20px;
}

.control-btn-sm:hover {
    color: var(--text-primary);
}

.volume-slider-container {
    width: 80px;
}

.volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    outline: none;
    cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.volume-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background: var(--accent-primary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

.speed-btn {
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.speed-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

/* 播放清單區域 */
.playlist-section {
    margin-top: var(--space-xl);
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* 播放清單分頁標籤 */
.playlist-tabs {
    display: flex;
    gap: 12px;
    padding: 0 30px 16px 0;
    /* 右側留白以便遮罩過渡 */
    overflow-x: auto;
    scrollbar-width: none;
    /* Firefox */
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    mask-image: linear-gradient(to right, #000 70%, transparent 100%);
    -webkit-mask-image: linear-gradient(to right, #000 70%, transparent 100%);
}

.playlist-tabs::-webkit-scrollbar {
    display: none;
    /* Chrome, Safari, Opera */
}

.playlist-tab {
    padding: 8px 18px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
}

.playlist-tab:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.playlist-tab.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
}

/* 搜尋框 */
.playlist-search {
    position: relative;
    margin: 0 0 15px;
    padding: 0 0;
}

.playlist-search .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--text-tertiary);
    pointer-events: none;
}

.playlist-search input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 10px 10px 10px 38px;
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
    transition: all 0.3s ease;
}

.playlist-search input:focus {
    border-color: var(--accent-primary);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.playlist-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
}

.playlist-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.track-count {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.playlist-container {
    background: rgba(22, 27, 34, 0.6);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    max-height: 320px;
    overflow-y: auto;
    flex: 1;
}

.playlist-container::-webkit-scrollbar {
    width: 6px;
}

.playlist-container::-webkit-scrollbar-track {
    background: transparent;
}

.playlist-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: var(--radius-full);
}

.playlist-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

.playlist {
    list-style: none;
}

/* 單元小標題 */
.playlist-unit-header {
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.03);
    color: var(--accent-primary);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(5px);
}

.playlist-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    cursor: pointer;
    transition: background var(--transition-fast);
    border-bottom: 1px solid var(--border-color);
}

.playlist-item:last-child {
    border-bottom: none;
}

.playlist-item:hover {
    background: rgba(99, 102, 241, 0.1);
}

.playlist-item.active {
    background: rgba(99, 102, 241, 0.15);
}

.playlist-item-number {
    width: 24px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-tertiary);
    text-align: center;
}

.playlist-item.active .playlist-item-number {
    color: var(--accent-primary);
}

.playlist-item-icon {
    width: 20px;
    height: 20px;
    color: var(--accent-primary);
    display: none;
}

.playlist-item.active .playlist-item-icon {
    display: block;
}

.playlist-item.active .playlist-item-number-text {
    display: none;
}

.playlist-item-info {
    flex: 1;
    min-width: 0;
}

.playlist-item-title {
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.playlist-item.active .playlist-item-title {
    color: var(--accent-primary);
}

.playlist-item-duration {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

/* 載入狀態 */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-2xl);
    color: var(--text-secondary);
}

.loading-state.hidden {
    display: none;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: var(--space-md);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* 頁腳 */
.footer {
    text-align: center;
    padding: var(--space-xl) 0 var(--space-md);
    color: var(--text-tertiary);
    font-size: 0.75rem;
}

/* 響應式設計 */
@media (max-width: 480px) {
    .container {
        padding: var(--space-md);
    }

    .player-card {
        padding: var(--space-lg);
    }

    .cover-art {
        width: 140px;
        height: 140px;
    }

    .music-icon {
        width: 60px;
        height: 60px;
    }

    .track-title {
        font-size: 1.1rem;
    }

    .play-btn {
        width: 56px;
        height: 56px;
    }

    .volume-slider-container {
        width: 60px;
    }
}

@media (min-width: 768px) {
    .container {
        max-width: 520px;
        padding: var(--space-2xl);
    }

    .cover-art {
        width: 200px;
        height: 200px;
    }

    .music-icon {
        width: 90px;
        height: 90px;
    }
}

/* 動畫 - 減少動畫偏好 */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}