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

:root {
    --bg: #0f0f0f;
    --surface: #1a1a1a;
    --card: #242424;
    --card-hover: #2a2a2a;
    --border: #333;
    --accent: #ff4e45;
    --accent-hover: #ff6b63;
    --text: #f1f1f1;
    --text-2: #aaa;
    --text-3: #666;
    --radius: 12px;
    --radius-sm: 8px;
    --player-h: 140px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

/* === Utilities === */
.hidden { display: none !important; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    padding: 10px 20px;
    transition: background 0.15s, opacity 0.15s;
}
.btn:active { opacity: 0.8; }
.btn-accent {
    background: var(--accent);
    color: #fff;
}
.btn-accent:hover { background: var(--accent-hover); }

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.btn-icon:hover { background: rgba(255,255,255,0.08); }
.btn-icon:active { background: rgba(255,255,255,0.14); }

.badge {
    font-size: 0.75rem;
    color: var(--text-2);
    background: var(--border);
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

/* === Setup banner === */
.banner {
    background: #2c1810;
    border-bottom: 1px solid #5c3a20;
    padding: 16px;
    text-align: center;
    font-size: 0.9rem;
    color: #ffbb99;
}
.banner .btn { margin: 10px 0 6px; }
.banner .hint {
    font-size: 0.78rem;
    color: #aa8866;
}
.banner code {
    background: rgba(0,0,0,0.3);
    padding: 2px 6px;
    border-radius: 4px;
}

/* === Header === */
.header {
    padding: 16px 16px 8px;
}
.logo {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.5px;
}

/* === Search === */
.search-section {
    padding: 8px 16px 16px;
}
.input-group {
    display: flex;
    gap: 8px;
}
.input-group input {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.15s;
}
.input-group input::placeholder { color: var(--text-3); }
.input-group input:focus { border-color: var(--accent); }
.input-group .btn {
    padding: 12px 16px;
    flex-shrink: 0;
}

.status {
    margin-top: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    animation: fadeIn 0.2s;
}
.status.loading {
    background: #1a2332;
    color: #7eb8f7;
}
.status.error {
    background: #2c1a1a;
    color: #f77e7e;
}
.status.success {
    background: #1a2c1a;
    color: #7ef77e;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* === Channels === */
.channels-section {
    padding: 0 16px 16px;
}
.section-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-2);
    margin-bottom: 12px;
}
.channels-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.channel-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--card);
    border-radius: var(--radius);
    padding: 12px 14px;
    cursor: pointer;
    transition: background 0.15s;
}
.channel-card:hover { background: var(--card-hover); }
.channel-card:active { background: var(--border); }
.channel-thumb {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--border);
    overflow: hidden;
    flex-shrink: 0;
}
.channel-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.channel-info {
    flex: 1;
    min-width: 0;
}
.channel-name {
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.channel-count {
    font-size: 0.8rem;
    color: var(--text-2);
    margin-top: 2px;
}
.channel-delete {
    flex-shrink: 0;
    color: var(--text-3);
    padding: 6px;
}
.channel-delete:hover { color: var(--accent); }

/* === Tracks === */
.tracks-section {
    padding: 0 16px;
    padding-bottom: calc(var(--player-h) + 16px + var(--safe-bottom));
}
.tracks-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    position: sticky;
    top: 0;
    background: var(--bg);
    padding: 8px 0;
    z-index: 10;
}
.tracks-header .section-title {
    flex: 1;
    margin-bottom: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tracks-list {
    list-style: none;
    display: flex;
    flex-direction: column;
}
.track-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.12s;
}
.track-item:hover { background: var(--card); }
.track-item:active { background: var(--card-hover); }
.track-item.active {
    background: var(--card);
}
.track-item.active .track-num {
    color: var(--accent);
}
.track-item.playing .track-num {
    animation: pulse 1.2s ease-in-out infinite;
}
.track-num {
    width: 28px;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-3);
    flex-shrink: 0;
}
.track-info {
    flex: 1;
    min-width: 0;
}
.track-title {
    font-size: 0.9rem;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.track-date {
    font-size: 0.75rem;
    color: var(--text-3);
    margin-top: 2px;
}
.track-dur {
    font-size: 0.78rem;
    color: var(--text-3);
    flex-shrink: 0;
    margin-left: auto;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* === Download button & menu === */
.btn-dl {
    color: var(--text-3);
    flex-shrink: 0;
    padding: 6px;
}
.btn-dl:hover { color: var(--accent); }
.track-item {
    position: relative;
}
.dl-menu {
    position: absolute;
    right: 8px;
    top: 100%;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    z-index: 20;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    animation: fadeIn 0.15s;
}
.dl-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.12s;
}
.dl-option:hover { background: var(--card-hover); }
.dl-option span {
    font-weight: 400;
    font-size: 0.75rem;
    color: var(--text-3);
}

.load-more-row {
    justify-content: center;
    padding: 16px 8px;
}
.btn-load-more {
    width: 100%;
}

/* === Banner (removed yt-dlp, kept for CSS cleanup) === */

/* === Hidden YouTube player === */
#yt-player-wrap {
    position: fixed;
    bottom: 0;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
    pointer-events: none;
}

/* === Player Bar === */
.player-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #181818;
    border-top: 1px solid var(--border);
    padding-bottom: var(--safe-bottom);
    z-index: 100;
    animation: slideUp 0.3s ease-out;
}
@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: none; }
}

.player-progress-wrap {
    padding: 0 12px;
    height: 20px;
    display: flex;
    align-items: center;
}

/* Range input styling */
#progress {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}
#progress::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
}
#progress::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
}
#progress::-webkit-slider-runnable-track {
    height: 3px;
    border-radius: 2px;
}

.player-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px;
}
.player-thumb {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    background: var(--card) center/cover no-repeat;
    flex-shrink: 0;
}
.player-meta {
    flex: 1;
    min-width: 0;
}
.player-title {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.player-time {
    font-size: 0.72rem;
    color: var(--text-3);
    margin-top: 2px;
}

.player-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 6px 16px 10px;
}
.btn-play {
    width: 52px;
    height: 52px;
}

/* === Spinner === */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.2);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Desktop (>600px) === */
@media (min-width: 600px) {
    #app {
        max-width: 520px;
        margin: 0 auto;
    }
    .player-bar {
        max-width: 520px;
        left: 50%;
        transform: translateX(-50%);
        border-radius: var(--radius) var(--radius) 0 0;
    }
    @keyframes slideUp {
        from { transform: translateX(-50%) translateY(100%); }
        to { transform: translateX(-50%); }
    }
}
