:root {
    --bg-base: #0a0a0a;
    --bg-highlight: #1a1a1a;
    --bg-elevated: rgba(30, 30, 30, 0.6);
    --text-base: #ffffff;
    --text-subdued: #a7a7a7;
    --accent: #1db954;
    --accent-hover: #1ed760;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --glass-bg: rgba(18, 18, 18, 0.7);
    --glass-border: rgba(255, 255, 255, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
body {
    font-family: var(--font-family);
    background-color: var(--bg-base);
    color: var(--text-base);
    height: 100vh; height: 100dvh;
    display: flex; flex-direction: column; overflow: hidden;
}
#app { display: flex; flex-direction: column; height: 100%; }

.main-view {
    flex-grow: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
    position: relative; background: linear-gradient(to bottom, #1f1f1f 0%, var(--bg-base) 100%);
}

.glass-panel { background: var(--glass-bg); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
.top-nav {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px; position: sticky; top: 0; z-index: 50; border-bottom: 1px solid var(--glass-border);
}
.top-nav h2 { font-size: 1.2rem; font-weight: 700; flex-grow: 1; margin-left: 12px; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.hidden { display: none !important; }

/* Search Bar (Animated) */
.search-bar-container {
    max-height: 0; overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0.16, 1, 0.3, 1), padding 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s;
    background: var(--bg-base); position: sticky; top: 65px; z-index: 49;
    padding: 0 16px; opacity: 0;
}
.search-bar-container.open { max-height: 70px; padding: 12px 16px; opacity: 1; }
#search-input {
    width: 100%; padding: 12px 16px; border-radius: 20px;
    border: 1px solid var(--glass-border); background: var(--bg-elevated);
    color: var(--text-base); font-size: 1rem; outline: none; transition: all 0.3s ease;
}
#search-input:focus { border-color: var(--accent); background: rgba(40, 40, 40, 0.8); }

/* Buttons */
button { background: none; border: none; cursor: pointer; outline: none; transition: all 0.2s ease; color: currentColor; }
.icon-btn { display: flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 50%; }
.icon-btn:hover, .icon-btn:active { background: rgba(255, 255, 255, 0.1); }
.text-btn { color: var(--text-base); font-weight: 700; font-size: 0.9rem; width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.text-btn:hover { background: rgba(255,255,255,0.1); }

/* Skeleton Loading */
.skeleton { background: linear-gradient(90deg, #222 25%, #333 50%, #222 75%); background-size: 400% 100%; animation: skeleton-loading 1.5s infinite ease-in-out; }
@keyframes skeleton-loading { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Animations */
.fade-in { animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Grid Sections */
.section-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 16px; margin-top: 8px; }
.history-scroll { display: flex; gap: 16px; overflow-x: auto; padding-bottom: 16px; scrollbar-width: none; }
.history-scroll::-webkit-scrollbar { display: none; }
.history-card { flex: 0 0 120px; cursor: pointer; transition: transform 0.2s; }
.history-card:active { transform: scale(0.95); }
.history-cover { width: 120px; height: 120px; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.4); margin-bottom: 8px; overflow: hidden; }
.history-title { font-size: 0.85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Views */
.view { display: none; padding: 16px; padding-bottom: 140px; }
.view.active { display: block; }

/* Album Grid */
.albums-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 20px; }
.album-card { background-color: transparent; border-radius: 12px; cursor: pointer; transition: transform 0.2s ease, background-color 0.2s; padding: 12px; margin: -12px; }
.album-card:hover, .album-card:active { background-color: rgba(255,255,255,0.05); transform: translateY(-2px); }
.cover-container { width: 100%; aspect-ratio: 1; margin-bottom: 12px; box-shadow: 0 8px 24px rgba(0,0,0,0.5); border-radius: 12px; overflow: hidden; }
.cover-placeholder { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 4rem; font-weight: 900; color: rgba(255,255,255,0.3); }
.cover-image { width: 100%; height: 100%; object-fit: cover; transition: transform 0.3s ease; }
.album-card:hover .cover-image { transform: scale(1.05); }
.album-card-title { font-size: 0.95rem; font-weight: 700; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.album-card-subtitle { font-size: 0.8rem; color: var(--text-subdued); }

/* Album Detail View */
.album-header { display: flex; align-items: flex-end; gap: 24px; margin-bottom: 20px; margin-top: 10px; animation: fadeIn 0.4s ease; }
.album-cover-large { width: 160px; height: 160px; border-radius: 12px; box-shadow: 0 12px 32px rgba(0,0,0,0.6); flex-shrink: 0; overflow: hidden; }
.album-info { display: flex; flex-direction: column; }
.album-type { font-size: 0.8rem; text-transform: uppercase; font-weight: 700; margin-bottom: 6px; letter-spacing: 1px; }
#detail-title { font-size: 2rem; font-weight: 900; line-height: 1.1; margin-bottom: 8px; }
.album-meta { font-size: 0.95rem; color: var(--text-subdued); font-weight: 500; }
.album-description-container { margin-bottom: 20px; font-size: 0.9rem; color: var(--text-subdued); line-height: 1.5; }
.album-duration { margin-top: 8px; font-weight: 600; color: var(--text-base); }

/* Download Controls */
.album-actions { display: flex; align-items: center; gap: 16px; margin-bottom: 32px; flex-wrap: wrap; }
.btn-play-large { background-color: var(--accent); width: 56px; height: 56px; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: transform 0.1s, background-color 0.2s, box-shadow 0.2s; box-shadow: 0 8px 16px rgba(0,0,0,0.3); }
.btn-play-large:active { transform: scale(0.95); background-color: var(--accent-hover); }
.download-controls { display: flex; align-items: center; gap: 8px; }
.format-select { background: rgba(255,255,255,0.1); color: white; border: none; padding: 8px 12px; border-radius: 8px; font-weight: 600; outline: none; }
.btn-secondary { display: flex; align-items: center; gap: 6px; background: rgba(255,255,255,0.1); padding: 8px 16px; border-radius: 8px; font-weight: bold; }
.btn-secondary:active { background: rgba(255,255,255,0.2); transform: scale(0.95); }
.btn-cancel-download { display: flex; align-items: center; justify-content: center; background: #e91e63; color: white; padding: 8px; border-radius: 8px; font-weight: bold; }
.btn-cancel-download:active { background: #c2185b; transform: scale(0.95); }
.download-status { font-size: 0.8rem; color: var(--accent); }

/* Track List */
.track-list { list-style: none; }
.track-item { display: flex; align-items: center; padding: 12px 16px; border-radius: 8px; cursor: pointer; transition: background-color 0.2s; margin-bottom: 2px; }
.track-item:hover, .track-item:active { background-color: rgba(255,255,255,0.08); }
.track-item.playing .track-title { color: var(--accent); }
.track-number { width: 32px; text-align: right; margin-right: 16px; color: var(--text-subdued); font-size: 0.95rem; font-variant-numeric: tabular-nums; }
.track-item.playing .track-number { color: var(--accent); }
.track-title { font-size: 1.05rem; font-weight: 500; }

/* Bottom Player & Progress Bar */
#bottom-player { position: fixed; bottom: 0; left: 0; right: 0; border-top: 1px solid var(--glass-border); padding: 8px 20px 12px 20px; padding-bottom: max(12px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; z-index: 100; cursor: pointer; transition: transform 0.3s; }
.progress-bar-container { display: flex; align-items: center; gap: 12px; width: 100%; margin-bottom: 8px; pointer-events: none; }
.time-label { font-size: 0.75rem; color: var(--text-subdued); font-variant-numeric: tabular-nums; width: 35px; text-align: center; }
#progress-slider, #fs-progress-slider { flex-grow: 1; -webkit-appearance: none; height: 4px; background: rgba(255,255,255,0.2); border-radius: 2px; outline: none; transition: background 0.2s; pointer-events: auto; }
#progress-slider::-webkit-slider-thumb, #fs-progress-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; border-radius: 50%; background: var(--text-base); cursor: pointer; opacity: 0; transition: opacity 0.2s, transform 0.2s; }
.progress-bar-container:hover input[type="range"]::-webkit-slider-thumb, .fs-progress-container:hover input[type="range"]::-webkit-slider-thumb { opacity: 1; }
input[type="range"]:active::-webkit-slider-thumb { opacity: 1; transform: scale(1.3); }

.player-main-row { display: flex; align-items: center; justify-content: space-between; width: 100%; pointer-events: none; }
.player-now-playing { display: flex; align-items: center; gap: 16px; width: 30%; min-width: 140px; }
.player-cover { width: 48px; height: 48px; border-radius: 8px; background-color: #333; flex-shrink: 0; overflow: hidden; box-shadow: 0 4px 12px rgba(0,0,0,0.3); pointer-events: auto; }
.player-cover img { width: 100%; height: 100%; object-fit: cover; }
.player-info { overflow: hidden; pointer-events: auto; }
.player-title { font-size: 0.95rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 2px; }
.player-artist { font-size: 0.8rem; color: var(--text-subdued); }

.player-controls-container { display: flex; flex-direction: column; align-items: center; flex-grow: 1; pointer-events: auto; }
.player-controls { display: flex; align-items: center; gap: 16px; position: relative; }
.player-controls button { color: var(--text-subdued); }
.player-controls button:active, .player-controls button:hover { color: var(--text-base); }
.btn-play-circle { background-color: var(--text-base) !important; color: #000 !important; border-radius: 50%; width: 44px !important; height: 44px !important; display:flex; align-items:center; justify-content:center; }
.btn-play-circle:active { transform: scale(0.92); }
.badge { position: absolute; top: -4px; right: -4px; background: var(--accent); color: #000; font-size: 0.65rem; font-weight: bold; padding: 2px 5px; border-radius: 8px; pointer-events: none; }

/* Fullscreen Player (Apple Music Style) */
.fullscreen-panel {
    position: fixed; inset: 0; z-index: 500;
    transform: translateY(100%); transition: transform 0.25s cubic-bezier(0.25, 1, 0.3, 1);
    display: flex; flex-direction: column; overflow: hidden; background-color: var(--bg-base);
}
.fullscreen-panel.open { transform: translateY(0); }
.fs-bg {
    position: absolute; inset: -10%; background-size: cover; background-position: center;
    filter: blur(60px) brightness(0.6); z-index: 0; transition: background-image 0.5s ease;
}
.fs-content {
    position: relative; z-index: 1; display: flex; flex-direction: column; height: 100%;
    padding: 24px; padding-top: max(32px, env(safe-area-inset-top)); padding-bottom: max(32px, env(safe-area-inset-bottom));
}
.fs-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4vh; }
.fs-header-text { font-size: 0.9rem; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: rgba(255,255,255,0.7); }
.fs-cover-container { flex-grow: 1; display: flex; align-items: center; justify-content: center; margin-bottom: 4vh; }
.fs-cover {
    width: 100%; max-width: 380px; aspect-ratio: 1; border-radius: 16px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.6); overflow: hidden; background-color: #222;
    transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}
.fs-cover img { width: 100%; height: 100%; object-fit: cover; }
.paused .fs-cover { transform: scale(0.85); box-shadow: 0 8px 24px rgba(0,0,0,0.4); }

.fs-info-controls { display: flex; flex-direction: column; gap: 32px; padding-bottom: 24px; }
.fs-info { text-align: left; }
#fs-title { font-size: 1.8rem; font-weight: 800; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#fs-artist { font-size: 1.2rem; color: rgba(255,255,255,0.7); font-weight: 500; }
.fs-progress-container { display: flex; flex-direction: column; gap: 8px; }
#fs-progress-slider::-webkit-slider-thumb { width: 16px; height: 16px; background: #fff; opacity: 1; }
.fs-time-labels { display: flex; justify-content: space-between; font-size: 0.8rem; color: rgba(255,255,255,0.6); font-variant-numeric: tabular-nums; }

.fs-controls { display: flex; align-items: center; justify-content: space-between; margin: 0 16px; }
.large-btn { width: 56px; height: 56px; }
.btn-play-circle.huge { width: 72px !important; height: 72px !important; }

/* Modals */
.modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6); z-index: 600; display: flex; align-items: center; justify-content: center; opacity: 0; pointer-events: none; transition: opacity 0.2s ease; }
.modal:not(.hidden) { opacity: 1; pointer-events: auto; }
.modal-content { background: var(--bg-elevated); border: 1px solid var(--glass-border); border-radius: 16px; padding: 24px; width: 80%; max-width: 320px; text-align: center; transform: translateY(20px) scale(0.95); transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1); }
.modal:not(.hidden) .modal-content { transform: translateY(0) scale(1); }
.modal-content h3 { margin-bottom: 20px; }
.timer-options { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.timer-options button { background: rgba(255,255,255,0.05); color: white; padding: 12px; border-radius: 8px; font-size: 1rem; }
.timer-options button:active { background: rgba(255,255,255,0.15); }
.custom-timer-row { display: flex; gap: 8px; margin-top: 4px; }
.custom-timer-row input { flex-grow: 1; padding: 12px; border-radius: 8px; border: none; background: rgba(255,255,255,0.1); color: white; outline: none; font-size: 1rem; }
.custom-timer-row button { background: var(--accent); color: #000; font-weight: bold; padding: 12px 16px; flex-shrink: 0; }
.custom-timer-row button:active { background: var(--accent-hover); transform: scale(0.95); }

/* Settings Modal */
.settings-section { margin-bottom: 24px; text-align: left; }
.settings-section label { display: block; margin-bottom: 12px; font-size: 0.9rem; color: var(--text-subdued); }
.color-picker-container { display: flex; gap: 12px; justify-content: center; }
.color-btn { width: 36px; height: 36px; border-radius: 50%; border: 2px solid transparent; transition: transform 0.2s; }
.color-btn:active { transform: scale(0.9); }
.color-btn.active { border-color: white; transform: scale(1.1); }
.btn-cancel { color: var(--text-subdued); font-weight: bold; padding: 12px; width: 100%; border-radius: 8px; }
.btn-cancel:active { background: rgba(255,255,255,0.1); }

.loading { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 50vh; color: var(--text-subdued); }
@media (max-width: 600px) {
    .album-header { flex-direction: column; align-items: center; text-align: center; }
    .album-cover-large { width: 200px; height: 200px; margin-bottom: 16px; }
    .player-now-playing { width: auto; max-width: 40%; }
    .player-controls { gap: 8px; }
}
