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

:root {
    --primary-color: #fa243c;
    --secondary-color: #d71f35;
    --bg-main: #ffffff;
    --bg-secondary: #f5f5f7;
    --bg-hover: #f9f9f9;
    --text-primary: #1d1d1f;
    --text-secondary: #6e6e73;
    --border-color: #d2d2d7;
    --border-radius: 8px;
    --transition: all 0.2s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.5;
    overflow-x: hidden;
    margin: 0;
    padding: 40px 20px;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    background: var(--bg-main);
    border-radius: 12px;
    overflow: hidden;
}

/* Header */
.header {
    background: var(--bg-main);
    border-bottom: 1px solid var(--border-color);
    padding: 20px;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center; /* vertical align logo and badge */
    gap: 20px;
    padding-top: 0; /* remove offset */
}

.header-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.logo {
    display: flex;
    align-items: center; /* center logo vertically */
}

.logo-image {
    display: block; /* avoid baseline gaps */
}


.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.country-badge {
    background: var(--bg-secondary);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0; /* no vertical offset */
    display: inline-flex;
    align-items: center; /* center text inside pill */
    line-height: 1; /* tighter vertical rhythm */
}

/* Hidden elements */
.filters,
.refresh-btn,
.filter-note,
.filter-group {
    display: none;
}

/* Loading State */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    gap: 20px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Error State */
.error {
    background: #fff3f3;
    border: 1px solid #ffcccc;
    border-radius: var(--border-radius);
    padding: 20px;
    margin: 20px;
    text-align: center;
    color: var(--primary-color);
}

/* Chart List */
.chart-grid {
    display: block;
    padding: 0;
    animation: fadeIn 0.4s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Track Row */
.track-card {
    display: grid;
    grid-template-columns: 32px 48px 1fr 60px 40px; /* rank, art, info, duration, button */
    gap: 12px;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
}

.track-card:first-child {
    border-top: 1px solid var(--border-color);
}

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

/* Track Row Elements */
.track-rank {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-secondary);
    text-align: center;
}

.track-artwork {
    width: 48px;
    height: 48px;
    border-radius: 4px;
    object-fit: cover;
}

.track-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.track-name {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

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

.track-duration { display: none; }

.track-itunes-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-color);
    border: none;
    width: 36px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
}
.track-itunes-btn:hover { background: var(--secondary-color); }

.apple-music-logo-small {
    height: 14px;
    width: auto;
    filter: brightness(0) invert(1); /* white logo */
}

.track-itunes-btn:hover .apple-music-logo-small {
    filter: brightness(0) saturate(100%) invert(18%) sepia(96%) saturate(6765%) hue-rotate(349deg) brightness(88%) contrast(91%);
    /* Darker red on hover (#d71f35) */
}

.open-apple-music {
    display: none;
}

.play-overlay {
    display: none;
}

.track-meta {
    display: none;
}

.track-price {
    display: none;
}

/* Footer */
.footer {
    background: var(--bg-main);
    border-top: 1px solid var(--border-color);
    padding: 40px 20px 30px;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
}

.footer-disclaimer {
    margin-bottom: 30px;
    padding-bottom: 25px;
    border-bottom: 1px solid var(--border-color);
}

.footer-disclaimer p {
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-secondary);
    margin: 0;
    text-align: center;
    max-width: 900px;
    margin: 0 auto;
}

.footer-disclaimer strong {
    color: var(--text-primary);
    font-weight: 600;
}

.footer-disclaimer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.footer-disclaimer a:hover {
    text-decoration: underline;
}

.footer-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

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

.footer-links {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 12px;
    flex-wrap: wrap;
}

.footer-links a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: var(--transition);
}

.footer-links a:hover {
    color: var(--primary-color);
}

.footer-divider {
    color: var(--border-color);
    user-select: none;
}

.footer-affiliate {
    color: var(--text-secondary);
    font-size: 11px;
    font-family: 'Courier New', monospace;
    background: var(--bg-main);
    padding: 2px 8px;
    border-radius: 4px;
}

/* Audio Player */
.audio-player {
    position: fixed;
    bottom: -100%;
    left: 0;
    right: 0;
    background: var(--bg-main);
    border-top: 1px solid var(--border-color);
    padding: 16px 20px;
    transition: var(--transition);
    z-index: 1000;
    backdrop-filter: blur(20px);
    background: rgba(255, 255, 255, 0.95);
}

.audio-player.active {
    bottom: 0;
}

.player-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 20px;
}

.player-artwork {
    width: 56px;
    height: 56px;
    border-radius: 6px;
    object-fit: cover;
}

.player-info {
    flex: 0 0 200px;
}

.player-track {
    font-weight: 500;
    font-size: 14px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

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

.player-btn {
    width: 36px;
    height: 36px;
    background: var(--primary-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}

.player-btn:hover {
    background: var(--secondary-color);
}

.player-btn svg {
    width: 20px;
    height: 20px;
    color: white;
}

.player-progress {
    flex: 1;
}

.progress-bar {
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    overflow: hidden;
    cursor: pointer;
    margin-bottom: 6px;
}

.progress-fill {
    height: 100%;
    background: var(--primary-color);
    width: 0%;
    transition: width 0.1s linear;
}

.progress-time {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

/* Removed right-side controls - now handled by red button */

/* Make Apple Music button full-width */
.track-itunes-btn { width: 100%; }
.track-itunes-btn .apple-music-logo-small { display: block; margin: 0 auto; }

.player-close {
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

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

.player-close svg {
    width: 24px;
    height: 24px;
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 20px 10px;
    }
    
    .container {
        border-radius: 8px;
    }
    
    .header {
        padding: 15px;
    }
    
    .header-content {
        flex-direction: row;      /* keep in one line on mobile */
        align-items: center;
        flex-wrap: nowrap;
    }
    .header-right {
        width: auto;
        justify-content: flex-end;
        margin-left: auto;        /* push badge to the right */
    }
    .country-badge {
        font-size: 14px;
        padding: 6px 12px;
        margin: 0;
        align-self: center;
    }
    .logo-image {
        height: 70px;             /* a bit smaller to fit */
    }
    
    .footer {
        padding: 30px 15px 20px;
    }
    
    .footer-disclaimer p {
        font-size: 11px;
        text-align: left;
    }
    
    .footer-bottom {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .footer-links {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .footer-divider {
        display: none;
    }

    .header-content {
        flex-direction: column;
        align-items: flex-start;
        padding: 0 20px;
        gap: 12px;
    }

    .logo {
        font-size: 20px;
    }
    
    .header-info {
        width: 100%;
        flex-wrap: wrap;
    }
    
    .open-playlist-btn {
        flex: 1;
        min-width: 200px;
        justify-content: center;
    }
    
    .refresh-btn {
        flex: 0;
    }

    .track-card {
        grid-template-columns: 30px 48px 1fr 80px;
        gap: 12px;
        padding: 10px 15px;
    }
    
    .track-album {
        display: none;
    }
    
    .apple-music-logo-small {
        height: 14px;
    }

    .player-content {
        flex-wrap: wrap;
    }

    .player-info {
        flex: 0 0 150px;
    }

    .player-controls {
        flex: 1 1 100%;
    }
}

@media (min-width: 769px) {
    .header-content {
        align-items: flex-start;   /* desktop: badge slightly lower */
        padding-top: 10px;         /* as it was before */
    }
    .country-badge {
        margin-top: 40px;          /* desktop offset restored */
    }
    .logo-image {
        height: 72px !important;   /* cap logo height on desktop */
        max-width: 220px;          /* avoid overflow if wide */
        width: auto;
    }
}

@media (max-width: 480px) {
    .filters {
        flex-direction: column;
        gap: 10px;
        padding: 15px;
    }

    .filter-group {
        width: 100%;
        justify-content: space-between;
    }
    
    .track-duration {
        display: none;
    }
    
    .apple-music-logo-small {
        height: 12px;
    }
    
    .footer {
        padding: 25px 15px 80px;
    }
    
    .footer-copyright {
        font-size: 12px;
    }
    
    .footer-affiliate {
        font-size: 10px;
    }

    .header-content {
        flex-direction: row;      /* ensure row on very small screens */
        align-items: center;
    }
    .header-right {
        margin-left: auto;
    }
    .logo-image {
        height: 60px;
    }
}

.load-more { display: flex; justify-content: center; padding: 16px; }
.load-more-btn {
    background: var(--primary-color);
    color: #fff;
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
}
.load-more-btn:hover { background: var(--secondary-color); }
