/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Dark Theme Colors */
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #2a2a2a;
    --bg-hover: #333333;
    --text-primary: #ffffff;
    --text-secondary: #b3b3b3;
    --text-muted: #666666;
    --accent-primary: #1db954;
    --accent-secondary: #1ed760;
    --accent-danger: #e22134;
    --border-color: #333333;
    --shadow: rgba(0, 0, 0, 0.3);
    --gradient-primary: linear-gradient(135deg, #1db954, #1ed760);
    --gradient-secondary: linear-gradient(135deg, #333333, #1a1a1a);
}

[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --bg-hover: #dee2e6;
    --text-primary: #212529;
    --text-secondary: #495057;
    --text-muted: #6c757d;
    --accent-primary: #1db954;
    --accent-secondary: #1ed760;
    --accent-danger: #dc3545;
    --border-color: #dee2e6;
    --shadow: rgba(0, 0, 0, 0.1);
    --gradient-primary: linear-gradient(135deg, #1db954, #1ed760);
    --gradient-secondary: linear-gradient(135deg, #f8f9fa, #e9ecef);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    margin-top: 25px;
    margin-bottom: 15px;
    /* Full screen support for iOS */
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

/* iOS Safe Area Support */
@supports (padding: max(0px)) {
    .app-container {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    
    .header {
        padding-top: max(1rem, env(safe-area-inset-top));
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
    
    .player {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
}

/* Prevent iOS bounce scrolling */
html, body {
    position: fixed;
    overflow: hidden;
    width: 100%;
    height: 100%;
}

.app-container {
    position: relative;
    overflow: hidden;
    width: 100%;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for better mobile support */
}

/* Enable scrolling only where needed */
.content-area, .sidebar {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
}

/* Header */
.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

.app-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-controls {
    display: flex;
    gap: 0.5rem;
}

.search-bar {
    margin-top: 1rem;
    display: none;
    position: relative;
}

.search-bar.active {
    display: block;
}

.search-bar input {
    width: 100%;
    padding: 0.75rem 3rem 0.75rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 25px;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.search-bar input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.search-bar #clearSearch {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
}

/* Main Content */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 250px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 1rem 0;
    overflow-y: auto;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0 1rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    width: 100%;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-primary);
    color: white;
}

.nav-item i {
    width: 20px;
    text-align: center;
}

/* Content Area */
.content-area {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    background: var(--bg-primary);
}

.view-container {
    display: none;
    max-width: 1200px;
    margin: 0 auto;
}

.view-container.active {
    display: block;
}

.view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.view-header h2 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.view-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}

/* Buttons */
.btn-primary, .btn-secondary {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 25px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(29, 185, 84, 0.3);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-hover);
}

.btn-icon {
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    color: var(--text-secondary);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-back {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 1rem;
}

.btn-back:hover {
    background: var(--bg-hover);
}

/* Sort Select */
.sort-select {
    padding: 0.5rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.9rem;
}

/* Playlists Grid */
.playlists-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
}

.playlist-card {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid var(--border-color);
}

.playlist-card:hover {
    background: var(--bg-tertiary);
    transform: translateY(-4px);
    box-shadow: 0 8px 25px var(--shadow);
}

.playlist-card-thumbnail {
    width: 100%;
    height: 150px;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 1rem;
    position: relative;
    background: var(--bg-tertiary);
}

.playlist-card-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.playlist-card-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.playlist-card:hover .playlist-card-overlay {
    opacity: 1;
}

.playlist-card-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.playlist-card-stats {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* Songs List */
.songs-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.song-item {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.song-item:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-color);
}

.song-item.playing {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
}

.song-item-thumbnail {
    width: 50px;
    height: 50px;
    border-radius: 6px;
    overflow: hidden;
    margin-right: 1rem;
    background: var(--bg-tertiary);
    flex-shrink: 0;
}

.song-item-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.song-item-info {
    flex: 1;
    min-width: 0;
}

.song-item-title {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.song-item-artist {
    color: var(--text-secondary);
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.song-item-duration {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-left: 1rem;
    flex-shrink: 0;
}

.song-item-actions {
    display: flex;
    gap: 0.5rem;
    margin-left: 1rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.song-item:hover .song-item-actions {
    opacity: 1;
}

/* Playlist Detail */
.playlist-header {
    display: flex;
    align-items: center;
    margin-bottom: 2rem;
}

.playlist-info {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.playlist-thumbnail {
    width: 200px;
    height: 200px;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    background: var(--bg-tertiary);
}

.playlist-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.playlist-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.playlist-thumbnail:hover .playlist-overlay {
    opacity: 1;
}

.btn-play-large {
    width: 60px;
    height: 60px;
    border: none;
    background: var(--accent-primary);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.btn-play-large:hover {
    background: var(--accent-secondary);
    transform: scale(1.1);
}

.playlist-details h2 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.playlist-stats {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Player */
.player {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 1rem;
    position: sticky;
    bottom: 30px;
    z-index: 100;
}

.player-content {
    display: flex;
    align-items: center;
    gap: 1rem;
    max-width: 1200px;
    margin: 0 auto;
}

.song-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-width: 0;
    flex: 1;
}

.song-thumbnail {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-tertiary);
    flex-shrink: 0;
}

.song-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.song-details {
    min-width: 0;
    flex: 1;
}

.song-title {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.song-artist {
    color: var(--text-secondary);
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.favorite-btn {
    margin-left: 1rem;
}

.favorite-btn.active {
    color: var(--accent-primary);
}

.favorite-btn.active i {
    font-weight: 900;
}

/* Progress Container */
.progress-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 2;
    max-width: 600px;
}

.time-display {
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    min-width: 40px;
    text-align: center;
}

.progress-bar {
    flex: 1;
    height: 0.6px;
    background: var(--bg-tertiary);
    border-radius: 0.3px;
    position: relative;
    cursor: pointer;
}

.progress-fill {
    height: 100%;
    background: var(--accent-primary);
    border-radius: 3px;
    width: 0%;
    transition: width 0.1s ease;
}

.progress-handle {
    width: 4.2px;
    height: 4.2px;
    background: var(--accent-primary);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    left: 0%;
    opacity: 0;
    transition: opacity 0.2s ease;
    cursor: pointer;
    z-index: 10;
}

.progress-handle::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 13.2px;
    height: 13.2px;
    background: transparent;
    border-radius: 50%;
    z-index: -1;
}

.progress-bar:hover .progress-handle,
.progress-handle:active {
    opacity: 1;
}

/* Mobile-specific improvements */
@media (max-width: 768px) {
    .progress-handle {
        width: 4.2px;
        height: 4.2px;
        opacity: 0.8; /* Always slightly visible on mobile */
    }
    
    .progress-handle::before {
        width: 13.2px;
        height: 13.2px;
    }
    
    .progress-bar {
        height: 0.6px; /* Keep consistent with desktop */
        cursor: pointer;
        /* Increase touch target */
        padding: 20px 0;
        margin: -20px 0;
    }
    
    .progress-bar::before {
        content: '';
        position: absolute;
        top: -20px;
        left: 0;
        right: 0;
        bottom: -20px;
        background: transparent;
    }
}

/* Player Controls */
.player-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    justify-content: center;
}

.btn-control {
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    color: var(--text-secondary);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.btn-control:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-control.active {
    color: var(--accent-primary);
}

.btn-play-pause {
    width: 50px;
    height: 50px;
    background: var(--accent-primary);
    color: white;
    font-size: 1.2rem;
}

.btn-play-pause:hover {
    background: var(--accent-secondary);
    transform: scale(1.05);
}

/* Volume Control */
.volume-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    justify-content: flex-end;
    max-width: 150px;
}

.volume-slider {
    width: 24px;
    height: 0.36px;
    background: var(--bg-tertiary);
    border-radius: 0.3px;
    position: relative;
    cursor: pointer;
}

.volume-fill {
    height: 100%;
    background: var(--accent-primary);
    border-radius: 2px;
    width: 70%;
    transition: width 0.1s ease;
}

.volume-handle {
    width: 3.6px;
    height: 3.6px;
    background: var(--accent-primary);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    left: 70%;
    opacity: 0;
    transition: opacity 0.2s ease;
    cursor: pointer;
    z-index: 10;
}

.volume-handle::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 13.2px;
    height: 13.2px;
    background: transparent;
    border-radius: 50%;
    z-index: -1;
}

.volume-slider:hover .volume-handle,
.volume-handle:active {
    opacity: 1;
}

/* Mobile volume control improvements */
@media (max-width: 768px) {
    .volume-handle {
        width: 3.6px;
        height: 3.6px;
        opacity: 0.8; /* Always slightly visible on mobile */
    }
    
    .volume-handle::before {
        width: 13.2px;
        height: 13.2px;
    }
    
    .volume-slider {
        height: 0.36px; /* Keep consistent with desktop */
        cursor: pointer;
        /* Increase touch target */
        padding: 20px 0;
        margin: -20px 0;
        width: 24px; /* Keep consistent with desktop */
    }
    
    .volume-slider::before {
        content: '';
        position: absolute;
        top: -20px;
        left: 0;
        right: 0;
        bottom: -20px;
        background: transparent;
    }
    
    .volume-control {
        gap: 1rem; /* More space between elements on mobile */
    }
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    color: var(--text-primary);
}

.loading-overlay.hidden {
    display: none;
}

.loading-spinner {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: var(--accent-primary);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-secondary);
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    border: 1px solid var(--border-color);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-content {
    padding: 1.5rem;
}

.setting-group {
    margin-bottom: 1.5rem;
}

.setting-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.setting-group select,
.setting-group input[type="range"] {
    width: 100%;
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
}

.setting-group input[type="checkbox"] {
    width: auto;
    margin-right: 0.5rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -250px;
        top: 0;
        height: 100vh;
        z-index: 200;
        transition: left 0.3s ease;
    }
    
    .sidebar.active {
        left: 0;
    }
    
    .main-content {
        flex-direction: column;
    }
    
    .content-area {
        padding: 1rem;
    }
    
    .view-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .view-header h2 {
        font-size: 1.5rem;
    }
    
    .playlists-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 1rem;
    }
    
    .playlist-thumbnail {
        width: 150px;
        height: 150px;
    }
    
    .playlist-info {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .player-content {
        flex-direction: column;
        gap: 1rem;
    }
    
    .song-info {
        width: 100%;
        justify-content: space-between;
    }
    
    .progress-container {
        width: 100%;
        max-width: none;
    }
    
    .player-controls {
        width: 100%;
        justify-content: center;
    }
    
    .volume-control {
        width: 100%;
        justify-content: center;
        max-width: none;
    }
    
    .volume-slider {
        width: 36px;
    }
}

@media (max-width: 480px) {
    .header {
        padding: 0.75rem;
    }
    
    .app-title {
        font-size: 1.25rem;
    }
    
    .content-area {
        padding: 0.75rem;
    }
    
    .playlists-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
    
    .playlist-card-thumbnail {
        height: 120px;
    }
    
    .song-item {
        padding: 0.5rem;
    }
    
    .song-item-thumbnail {
        width: 40px;
        height: 40px;
    }
    
    .player {
        padding: 0.75rem;
    }
    
    .song-thumbnail {
        width: 50px;
        height: 50px;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        transform: translateX(-100%);
    }
    to {
        transform: translateX(0);
    }
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.fade-in {
    animation: fadeIn 0.3s ease;
}

.slide-in {
    animation: slideIn 0.3s ease;
}

.pulse {
    animation: pulse 2s infinite;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Focus Styles */
button:focus,
input:focus,
select:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.text-center {
    text-align: center;
}

.text-truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
