/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-primary: #121212;
    --bg-secondary: #181818;
    --bg-elevated: #282828;
    --bg-highlight: #333333;
    --text-primary: #ffffff;
    --text-secondary: #b3b3b3;
    --text-muted: #6a6a6a;
    --accent: #1db954;
    --accent-hover: #1ed760;
    --danger: #e74c3c;
    --border: #333333;
    --player-height: 80px;
    --header-height: 64px;
    --tab-height: 44px;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* --- Header --- */
header {
    display: flex;
    align-items: center;
    height: var(--header-height);
    padding: 0 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 16px;
}

.header-left h1 {
    font-size: 20px;
    font-weight: 700;
    white-space: nowrap;
}

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.search-box {
    display: flex;
    max-width: 500px;
    width: 100%;
}

.search-box input {
    flex: 1;
    padding: 8px 16px;
    border: none;
    border-radius: 20px 0 0 20px;
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
}

.search-box input:focus {
    background: var(--bg-highlight);
}

.search-box button {
    padding: 8px 20px;
    border: none;
    border-radius: 0 20px 20px 0;
    background: var(--accent);
    color: #000;
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
}

.search-box button:hover {
    background: var(--accent-hover);
}

.header-right {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover { background: var(--bg-highlight); }

/* --- Tabs --- */
.tabs {
    display: flex;
    height: var(--tab-height);
    background: var(--bg-secondary);
    padding: 0 24px;
    gap: 8px;
    flex-shrink: 0;
}

.tab {
    padding: 8px 24px;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--text-primary); border-bottom-color: var(--accent); }

/* --- Main Content --- */
main {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px;
    padding-bottom: calc(var(--player-height) + 24px);
}

.view { display: none; }
.view.active { display: block; }

.view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

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

.sort-controls label {
    color: var(--text-secondary);
    font-size: 13px;
}

.sort-controls select {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
}

.sort-dir-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-elevated);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 16px;
}

.result-count {
    color: var(--text-secondary);
    font-size: 13px;
}

/* --- Track List --- */
.track-list {
    display: flex;
    flex-direction: column;
}

.track-row {
    display: grid;
    grid-template-columns: 40px 1.5fr 1fr 1fr 80px 40px 40px;
    align-items: center;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    gap: 12px;
    transition: background 0.15s;
}

.track-row:hover { background: var(--bg-elevated); }
.track-row.playing { background: var(--bg-highlight); }

.track-num {
    color: var(--text-muted);
    font-size: 14px;
    text-align: center;
}

.track-row:hover .track-num { display: none; }
.track-play-icon { display: none; }
.track-row:hover .track-play-icon {
    display: block;
    text-align: center;
    font-size: 14px;
    color: var(--accent);
}

.track-title {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.track-title .explicit-badge {
    display: inline-block;
    font-size: 9px;
    background: var(--text-muted);
    color: var(--bg-primary);
    padding: 1px 4px;
    border-radius: 2px;
    margin-left: 6px;
    vertical-align: middle;
    font-weight: 700;
}

.track-artist, .track-album {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.track-artist:hover, .track-album:hover { color: var(--text-primary); text-decoration: underline; }

.track-duration {
    font-size: 13px;
    color: var(--text-secondary);
    text-align: right;
}

.track-info-btn, .track-share-btn {
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 15px;
    padding: 4px;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color .15s, background .15s;
}

.track-info-btn:hover, .track-share-btn:hover { color: var(--text-primary); background: var(--bg-highlight); }

/* Share link button inside the track detail modal */
.share-modal-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: none;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color .15s, color .15s;
    white-space: nowrap;
}

.share-modal-btn:hover {
    border-color: var(--text-primary);
    color: var(--text-primary);
    background: none;
}

.share-modal-btn--copied {
    color: #1DB954 !important;
    border-color: #1DB954 !important;
}

/* --- Artist / Album Lists --- */
.artist-list, .album-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.artist-card, .album-card {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 16px;
    cursor: pointer;
    transition: background 0.2s;
}

.artist-card:hover, .album-card:hover { background: var(--bg-elevated); }

.artist-card .name, .album-card .name {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.artist-card .meta, .album-card .meta {
    font-size: 12px;
    color: var(--text-secondary);
}

/* --- Pagination --- */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 20px 0;
}

.pagination button {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-elevated);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 13px;
}

.pagination button:hover { background: var(--bg-highlight); }
.pagination button:disabled { opacity: 0.4; cursor: default; }
.pagination button.active { background: var(--accent); color: #000; border-color: var(--accent); }
.pagination .page-info { color: var(--text-secondary); font-size: 13px; }

/* --- Player Bar --- */
.player-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--player-height);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    display: grid;
    grid-template-columns: 1fr auto 2fr auto;
    align-items: center;
    padding: 0 16px;
    gap: 16px;
    z-index: 100;
}

.player-bar.hidden { display: none; }

.player-track-info {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.player-album-art {
    width: 56px;
    height: 56px;
    border-radius: 4px;
    background: var(--bg-elevated);
    flex-shrink: 0;
    overflow: hidden;
}

.player-album-art img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.player-text {
    min-width: 0;
}

.player-title {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

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

.ctrl-btn {
    border: none;
    background: none;
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
}

.ctrl-btn:hover { color: var(--accent); }
.play-btn { font-size: 24px; }

.player-progress {
    display: flex;
    align-items: center;
    gap: 8px;
}

.player-progress span {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 40px;
    text-align: center;
}

.player-progress input[type="range"] {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-highlight);
    border-radius: 2px;
    outline: none;
}

.player-progress input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-primary);
    cursor: pointer;
}

.player-volume {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 120px;
}

.volume-icon { font-size: 14px; }

.player-volume input[type="range"] {
    width: 80px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-highlight);
    border-radius: 2px;
    outline: none;
}

.player-volume input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-primary);
    cursor: pointer;
}

/* --- Modal --- */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.modal.hidden { display: none; }

.modal-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 32px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
}

.modal-close:hover { color: var(--text-primary); }

/* Detail modal content */
.detail-header {
    display: flex;
    gap: 20px;
    margin-bottom: 24px;
}

.detail-art {
    width: 160px;
    height: 160px;
    border-radius: 8px;
    background: var(--bg-elevated);
    flex-shrink: 0;
    overflow: hidden;
}

.detail-art img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.detail-info h2 {
    font-size: 22px;
    margin-bottom: 4px;
}

.detail-info .artist {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.detail-info .album-label {
    font-size: 13px;
    color: var(--text-muted);
}

.detail-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 16px 0;
}

.tag {
    padding: 4px 10px;
    border-radius: 12px;
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font-size: 12px;
}

.detail-meta {
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.detail-meta-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 13px;
}

.detail-meta-row .label {
    color: var(--text-muted);
}

.detail-meta-row .value {
    color: var(--text-secondary);
}

/* Scan modal */
.scan-section {
    margin-bottom: 24px;
}

.scan-section h3 {
    font-size: 16px;
    margin-bottom: 12px;
}

.scan-dir-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: var(--bg-elevated);
    border-radius: 6px;
    margin-bottom: 6px;
    font-size: 13px;
}

.scan-dir-item .dir-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    margin-right: 12px;
}

.scan-dir-item .dir-meta {
    color: var(--text-secondary);
    white-space: nowrap;
}

.scan-dir-item button {
    padding: 4px 14px;
    border: 1px solid var(--accent);
    border-radius: 4px;
    background: transparent;
    color: var(--accent);
    cursor: pointer;
    font-size: 12px;
    margin-left: 8px;
}

.scan-dir-item button:hover { background: var(--accent); color: #000; }
.scan-dir-item button:disabled { opacity: 0.5; cursor: default; }

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-elevated);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent);
}

.stat-card .stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Loading indicator */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--bg-highlight);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.scan-bar-shimmer {
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent 0%, var(--accent) 40%, transparent 100%);
    animation: scan-shimmer 1.4s ease-in-out infinite;
}
@keyframes scan-shimmer {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(200%); }
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state h3 {
    font-size: 20px;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 14px;
    margin-bottom: 20px;
}

.empty-state button {
    padding: 10px 28px;
    border: none;
    border-radius: 20px;
    background: var(--accent);
    color: #000;
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
}

.empty-state button:hover { background: var(--accent-hover); }

/* Scrollbar */
main::-webkit-scrollbar { width: 8px; }
main::-webkit-scrollbar-track { background: transparent; }
main::-webkit-scrollbar-thumb { background: var(--bg-highlight); border-radius: 4px; }
main::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
.modal-content::-webkit-scrollbar { width: 6px; }
.modal-content::-webkit-scrollbar-track { background: transparent; }
.modal-content::-webkit-scrollbar-thumb { background: var(--bg-highlight); border-radius: 3px; }

/* --- Discover / Recommendations --- */
.discover-empty {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-muted);
}

.discover-empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.discover-empty h3 {
    font-size: 20px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.discover-empty p {
    font-size: 14px;
    margin-bottom: 20px;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

.discover-empty button {
    padding: 10px 28px;
    border: none;
    border-radius: 20px;
    background: var(--accent);
    color: #000;
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
}

.discover-empty button:hover { background: var(--accent-hover); }

.discover-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.discover-header h2 {
    font-size: 24px;
    font-weight: 700;
}

.discover-session-count {
    font-size: 13px;
    color: var(--text-muted);
}

.discover-refresh {
    margin-left: auto;
    padding: 6px 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.discover-refresh:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.discover-section {
    margin-bottom: 32px;
}

.discover-section-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.discover-play-all {
    margin-left: auto;
    padding: 4px 12px;
    border: 1px solid var(--accent);
    border-radius: 12px;
    background: transparent;
    color: var(--accent);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}
.discover-play-all:hover {
    background: var(--accent);
    color: #000;
}

.discover-section-icon {
    font-size: 20px;
}

.discover-section-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.discover-genres {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.discover-tracks {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 8px;
}

.discover-track-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
}

.discover-track-card:hover {
    background: var(--bg-elevated);
}

.discover-card-play {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.15s;
}

.discover-track-card:hover .discover-card-play {
    opacity: 1;
}

.discover-card-info {
    flex: 1;
    min-width: 0;
}

.discover-card-title {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.discover-card-artist {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.discover-card-album {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.discover-card-duration {
    font-size: 12px;
    color: var(--text-muted);
    flex-shrink: 0;
}
