/* Optimized Media Detail Modal */
.media-detail-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(25px) saturate(1.2);
    -webkit-backdrop-filter: blur(25px) saturate(1.2);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-sizing: border-box;
    /* Performance optimizations */
    will-change: opacity;
    transform: translateZ(0);
}

.media-detail-modal {
    background: var(--bg-color-secondary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    width: 500px;
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 40px);
    overflow: hidden;
    box-shadow: 
        0 32px 120px rgba(0, 0, 0, 0.8),
        0 8px 32px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.1),
        0 0 0 1px rgba(255, 255, 255, 0.05);
    animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    color: var(--font-color);
    display: flex;
    flex-direction: column;
    /* Performance optimizations */
    will-change: transform, opacity;
    transform: translateZ(0);
    contain: layout style paint;
}

.modal-header {
    position: absolute;
    top: 0;
    right: 0;
    padding: 16px;
    z-index: 20;
}

.close-button {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    color: var(--font-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.close-button:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}

.modal-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Compact Hero Section */
.hero-section {
    position: relative;
    padding: 50px 24px 24px;
    background: var(--bg-color-tertiary);
    display: flex;
    align-items: flex-start;
    gap: 24px;
    min-height: 200px;
}

.hero-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, 
        rgba(var(--accent-color-rgb, 0, 122, 255), 0.1) 0%, 
        rgba(var(--brand-color-rgb, 138, 43, 226), 0.05) 50%,
        transparent 100%);
    pointer-events: none;
}

.artwork-section {
    position: relative;
    z-index: 2;
    flex-shrink: 0;
}

.artwork-container {
    position: relative;
    margin-bottom: 0;
}

.artwork-container::before {
    content: '';
    position: absolute;
    top: -8px;
    left: -8px;
    right: -8px;
    bottom: -8px;
    background: linear-gradient(135deg, 
        rgba(var(--accent-color-rgb, 0, 122, 255), 0.4) 0%, 
        rgba(var(--brand-color-rgb, 138, 43, 226), 0.3) 50%,
        rgba(255, 107, 107, 0.2) 100%);
    border-radius: 20px;
    opacity: 0;
    transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: -1;
    filter: blur(15px);
}

.artwork-container:hover::before {
    opacity: 0.6;
    transform: scale(1.05);
}

.artwork {
    width: 140px;
    height: 140px;
    border-radius: 12px;
    object-fit: cover;
    box-shadow: 
        0 20px 60px rgba(0, 0, 0, 0.6),
        0 6px 24px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    z-index: 1;
    border: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.artwork:hover {
    transform: scale(1.02);
    box-shadow: 
        0 24px 80px rgba(0, 0, 0, 0.7),
        0 8px 32px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.info-section {
    flex: 1;
    position: relative;
    z-index: 2;
    min-width: 0;
    text-align: left;
}

.info-section * {
    text-align: left !important;
}

.title {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--font-color);
    margin: 0 0 6px 0;
    line-height: 1.1;
    letter-spacing: -0.02em;
    word-wrap: break-word;
    overflow-wrap: break-word;
    text-align: left !important;
}

.artist {
    font-size: 1rem;
    font-weight: 600;
    color: var(--font-color-secondary);
    margin: 0 0 4px 0;
    line-height: 1.2;
    word-wrap: break-word;
    overflow-wrap: break-word;
    text-align: left !important;
}

.album {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--font-color-tertiary);
    margin: 0 0 12px 0;
    line-height: 1.2;
    word-wrap: break-word;
    overflow-wrap: break-word;
    text-align: left !important;
}

/* Clickable artist and album names */
.artist.clickable,
.album.clickable {
    cursor: pointer;
    transition: all 0.15s ease;
    border-radius: 4px;
    padding: 2px 4px;
    margin: -2px -4px;
    display: inline-block;
    position: relative;
}

.artist.clickable:hover,
.album.clickable:hover {
    color: var(--brand-color);
    text-decoration: underline;
    background-color: rgba(255, 255, 255, 0.1);
}

.artist.clickable:active,
.album.clickable:active {
    transform: scale(0.98);
    color: #1db954; /* Spotify green for feedback */
}

.metadata {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 32px;
}

.metadata-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--font-color-secondary);
    font-weight: 500;
}

.metadata-icon {
    font-size: 0.8rem;
    opacity: 0.8;
}

.type-badge {
    background: linear-gradient(135deg, #007AFF 0%, #5856D6 100%);
    color: var(--font-color-inverted);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}

.explicit-badge {
    background: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.8);
    padding: 1px 3px;
    border-radius: 2px;
    font-size: 0.55rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    flex-shrink: 0;
}

.popularity-score {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: #FFD700;
    font-weight: 600;
}

.popularity-bar {
    width: 40px;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    overflow: hidden;
}

.popularity-fill {
    height: 100%;
    background: linear-gradient(90deg, #FFD700 0%, #FFA500 100%);
    border-radius: 2px;
    transition: width 0.5s ease;
}

/* Album Description */
.album-description {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.album-description p {
    font-size: 0.8rem;
    line-height: 1.4;
    color: rgba(255, 255, 255, 0.7);
    margin: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Mobile hint */
.mobile-hint {
    display: none;
    font-size: 11px;
    line-height: 1.3;
    max-width: 280px;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 8px;
    text-align: center;
    font-style: italic;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 24px;
    background: rgba(0, 0, 0, 0.2);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.download-button, .spotify-button {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
}

.download-button {
    background: linear-gradient(135deg, #007AFF 0%, #5856D6 100%);
    color: var(--font-color-inverted);
    box-shadow: 0 4px 16px rgba(0, 122, 255, 0.3);
}

.download-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 122, 255, 0.4);
}

.download-button.downloading {
    background: linear-gradient(135deg, #FF9500 0%, #FF6B35 100%);
    cursor: not-allowed;
}

.download-button.downloaded {
    background: linear-gradient(135deg, #34C759 0%, #30D158 100%);
    cursor: default;
}

.spotify-button {
    background: linear-gradient(135deg, #1DB954 0%, #1ed760 100%);
    color: var(--font-color-inverted);
    box-shadow: 0 4px 16px rgba(29, 185, 84, 0.3);
}

.spotify-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(29, 185, 84, 0.4);
}

/* Tracks Section */
.tracks-section {
    background: rgba(0, 0, 0, 0.1);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.tracks-header {
    padding: 16px 24px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(0, 0, 0, 0.2);
    text-align: left;
}

.tracks-header * {
    text-align: left;
}

.tracks-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--font-color);
    margin: 0 0 3px 0;
    letter-spacing: -0.02em;
}

.tracks-subtitle {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.6);
    margin: 0;
    font-weight: 500;
}

.tracks-list {
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    max-height: 400px;
    overflow-y: auto;
    /* Performance optimizations */
    -webkit-overflow-scrolling: touch;
    will-change: scroll-position;
    contain: layout style paint;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

/* Track Items */
.track-item {
    display: flex;
    align-items: center;
    padding: 10px 24px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 0;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    cursor: pointer;
    border: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    gap: 12px;
    min-height: 56px;
    position: relative;
    overflow: hidden;
    margin: 0;
    justify-content: flex-start;
}

.track-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, 
        transparent 0%, 
        rgba(255, 255, 255, 0.05) 50%, 
        transparent 100%);
    transition: left 0.5s ease;
}

.track-item:hover {
    background: rgba(255, 255, 255, 0.08);
    border-bottom-color: rgba(255, 255, 255, 0.15);
}

.track-item:hover::before {
    left: 100%;
}

.track-number {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--font-color-tertiary, rgba(255, 255, 255, 0.7));
    width: 35px;
    text-align: center;
    opacity: 0.7;
    font-variant-numeric: tabular-nums;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.track-info {
    flex: 1;
    min-width: 0;
    margin-left: 0;
    text-align: left !important;
    justify-self: flex-start !important;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.track-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--font-color, white);
    margin: 0 0 2px 0;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block !important;
    text-align: left !important;
}

.track-artist {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--font-color-secondary, rgba(255, 255, 255, 0.8));
    margin: 0;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    opacity: 0.8;
    text-align: left !important;
    display: block !important;
}

.track-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    transform: translateX(6px);
}

.track-item:hover .track-actions {
    opacity: 1;
    transform: translateX(0);
}

.track-download-button {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    width: 28px;
    height: 28px;
}

.track-download-button:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    transform: scale(1.1);
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3);
}

.track-download-button.downloading {
    background: rgba(255, 149, 0, 0.2);
    color: #FF9500;
    cursor: not-allowed;
    border-color: rgba(255, 149, 0, 0.3);
}

.track-download-button.downloaded {
    background: rgba(52, 199, 89, 0.2);
    color: #34C759;
    cursor: default;
    border-color: rgba(52, 199, 89, 0.3);
}

.track-duration {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--font-color-tertiary, rgba(255, 255, 255, 0.7));
    opacity: 0.7;
    min-width: 40px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    margin-left: auto;
}

/* No Tracks State */
.no-tracks {
    text-align: center;
    padding: 40px 20px;
    color: rgba(255, 255, 255, 0.6);
}

.no-tracks-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

.no-tracks-text {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: rgba(255, 255, 255, 0.8);
}

.no-tracks-subtext {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.5);
    line-height: 1.4;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        backdrop-filter: blur(0px);
        -webkit-backdrop-filter: blur(0px);
    }
    to {
        opacity: 1;
        backdrop-filter: blur(25px);
        -webkit-backdrop-filter: blur(25px);
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(40px) scale(0.95);
        filter: blur(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0px);
    }
}

/* Double tap animation */
@keyframes doubleTapPulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
        color: #1db954;
    }
    100% {
        transform: scale(1);
    }
}

/* Apply animation on double tap (can be triggered via JS) */
.double-tap-feedback {
    animation: doubleTapPulse 0.3s ease;
}

/* Optimized Mobile Design */
@media (max-width: 768px) {
    .media-detail-modal-overlay {
        padding: 8px;
        align-items: flex-start;
        padding-top: 20px;
    }
    
    .media-detail-modal {
        width: calc(100vw - 16px);
        max-height: calc(100vh - 40px);
        border-radius: 12px;
        margin: 0;
    }
    
    .hero-section {
        flex-direction: row;
        text-align: left;
        padding: 35px 16px 16px;
        gap: 16px;
        min-height: auto;
        align-items: flex-start;
    }
    
    .artwork-container {
        align-self: flex-start;
        flex-shrink: 0;
    }
    
    .artwork {
        width: 120px;
        height: 120px;
        border-radius: 12px;
    }
    
    .info-section {
        text-align: left;
        padding: 0;
        flex: 1;
        min-width: 0;
    }
    
    .info-section * {
        text-align: left !important;
    }
    
    .title {
        font-size: 1.4rem;
        line-height: 1.3;
        margin-bottom: 4px;
    }
    
    .artist {
        font-size: 0.95rem;
        margin-bottom: 8px;
    }
    
    .album {
        font-size: 0.85rem;
        margin-bottom: 12px;
    }
    
    .metadata {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px 12px;
        margin-bottom: 12px;
    }
    
    .metadata-item {
        font-size: 0.8rem;
    }
    
    .mobile-hint {
        display: block;
    }
    
    .action-buttons {
        padding: 16px;
        flex-direction: column;
        gap: 10px;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .download-button, .spotify-button {
        width: 100%;
        min-width: auto;
        padding: 12px 16px;
        font-size: 0.9rem;
        border-radius: 10px;
    }
    
    .tracks-section {
        flex: 1;
        min-height: 0;
    }
    
    .tracks-header {
        padding: 16px 16px 8px;
        text-align: left;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .tracks-title {
        font-size: 1.1rem;
        margin-bottom: 4px;
    }
    
    .tracks-subtitle {
        font-size: 0.8rem;
    }
    
    .tracks-list {
        padding: 0;
        max-height: 40vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .track-item {
        padding: 12px 16px;
        gap: 12px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        align-items: center;
        justify-content: flex-start;
    }
    
    .track-item:last-child {
        border-bottom: none;
    }
    
    .track-number {
        font-size: 0.8rem;
        min-width: 24px;
    }
    
    .track-info {
        flex: 1;
        min-width: 0;
    }
    
    .track-name {
        font-size: 0.9rem;
        line-height: 1.3;
        margin-bottom: 2px;
    }
    
    .track-artist {
        font-size: 0.75rem;
    }
    
    .track-duration {
        font-size: 0.75rem;
        min-width: 35px;
    }
    
    .track-download-button {
        padding: 6px 8px;
        font-size: 0.7rem;
        min-width: 60px;
        border-radius: 6px;
    }
}

@media (max-width: 480px) {
    .media-detail-modal-overlay {
        padding: 4px;
        padding-top: 10px;
    }
    
    .media-detail-modal {
        width: calc(100vw - 8px);
        max-height: calc(100vh - 20px);
        border-radius: 10px;
    }
    
    .hero-section {
        padding: 30px 12px 12px;
        gap: 10px;
    }
    
    .artwork {
        width: 120px;
        height: 120px;
        border-radius: 10px;
    }
    
    .title {
        font-size: 1.3rem;
        line-height: 1.2;
    }
    
    .artist {
        font-size: 0.9rem;
    }
    
    .album {
        font-size: 0.8rem;
    }
    
    .metadata {
        gap: 6px 10px;
    }
    
    .metadata-item {
        font-size: 0.75rem;
    }
    
    .action-buttons {
        padding: 12px;
        gap: 8px;
    }
    
    .download-button, .spotify-button {
        padding: 10px 12px;
        font-size: 0.85rem;
    }
    
    .tracks-header {
        padding: 12px 12px 6px;
    }
    
    .tracks-title {
        font-size: 1rem;
    }
    
    .tracks-subtitle {
        font-size: 0.75rem;
    }
    
    .tracks-list {
        max-height: 35vh;
    }
    
    .track-item {
        padding: 10px 12px;
        gap: 10px;
    }
    
    .track-number {
        font-size: 0.75rem;
        min-width: 20px;
    }
    
    .track-name {
        font-size: 0.85rem;
    }
    
    .track-artist {
        font-size: 0.7rem;
    }
    
    .track-duration {
        font-size: 0.7rem;
        min-width: 30px;
    }
    
    .track-download-button {
        padding: 4px 6px;
        font-size: 0.65rem;
        min-width: 50px;
    }
    
    .close-button {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }
}