/* Catppuccin Mocha Color Palette (Dark) */
:root, :root[data-theme="dark"] {
    --ctp-rosewater: #f5e0dc;
    --ctp-flamingo: #f2cdcd;
    --ctp-pink: #f5c2e7;
    --ctp-mauve: #cba6f7;
    --ctp-red: #f38ba8;
    --ctp-maroon: #eba0ac;
    --ctp-peach: #fab387;
    --ctp-yellow: #f9e2af;
    --ctp-green: #a6e3a1;
    --ctp-teal: #94e2d5;
    --ctp-sky: #89dceb;
    --ctp-sapphire: #74c7ec;
    --ctp-blue: #89b4fa;
    --ctp-lavender: #b4befe;
    --ctp-text: #cdd6f4;
    --ctp-subtext1: #bac2de;
    --ctp-subtext0: #a6adc8;
    --ctp-overlay2: #9399b2;
    --ctp-overlay1: #7f849c;
    --ctp-overlay0: #6c7086;
    --ctp-surface2: #585b70;
    --ctp-surface1: #45475a;
    --ctp-surface0: #313244;
    --ctp-base: #1e1e2e;
    --ctp-mantle: #181825;
    --ctp-crust: #11111b;
}

/* Catppuccin Latte Color Palette (Light) */
:root[data-theme="light"] {
    --ctp-rosewater: #dc8a78;
    --ctp-flamingo: #dd7878;
    --ctp-pink: #ea76cb;
    --ctp-mauve: #8839ef;
    --ctp-red: #d20f39;
    --ctp-maroon: #e64553;
    --ctp-peach: #fe640b;
    --ctp-yellow: #df8e1d;
    --ctp-green: #40a02b;
    --ctp-teal: #179299;
    --ctp-sky: #04a5e5;
    --ctp-sapphire: #209fb5;
    --ctp-blue: #1e66f5;
    --ctp-lavender: #7287fd;
    --ctp-text: #4c4f69;
    --ctp-subtext1: #5c5f77;
    --ctp-subtext0: #6c6f85;
    --ctp-overlay2: #7c7f93;
    --ctp-overlay1: #8c8fa1;
    --ctp-overlay0: #9ca0b0;
    --ctp-surface2: #acb0be;
    --ctp-surface1: #bcc0cc;
    --ctp-surface0: #ccd0da;
    --ctp-base: #eff1f5;
    --ctp-mantle: #e6e9ef;
    --ctp-crust: #dce0e8;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    /* background: linear-gradient(135deg, var(--ctp-base) 0%, var(--ctp-mantle) 100%); */
    min-height: 100vh;
    padding: 20px;
    background-color: var(--ctp-base);
    overflow-x: hidden;
}

a {
    color: var(--ctp-mauve);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: var(--ctp-lavender);
    text-decoration: none;
}

/* Hero and Track Link Styling */
.hero-link, .track-link {
    text-decoration: none;
    color: inherit;
    display: block;
}

.hero-link:hover, .track-link:hover {
    text-decoration: none;
    color: inherit;
}

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

header {
    text-align: center;
    color: var(--ctp-text);
    margin-bottom: 40px;
}

header h1 {
    font-size: 3rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.subtitle {
    font-size: 1.2rem;
    color: var(--ctp-subtext0);
}

.controls {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 20px;
}

.toggle-group {
    display: flex;
    background: var(--ctp-surface0);
    border: 1px solid var(--ctp-surface1);
    border-radius: 8px;
    overflow: hidden;
}

.toggle-option {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: transparent;
    border: none;
    border-right: 1px solid var(--ctp-surface1);
    color: var(--ctp-subtext0);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s;
}

.toggle-option:last-child {
    border-right: none;
}

.toggle-option:hover {
    background: var(--ctp-surface1);
}

.toggle-option.active {
    background: var(--ctp-mauve);
    color: var(--ctp-crust);
}

.control-icon {
    font-size: 1.1rem;
}

.control-label {
    font-size: 0.85rem;
}

/* Last Played Hero Section */
.last-played-hero {
    background: var(--ctp-surface0);
    border-radius: 16px;
    padding: 30px;
    margin-bottom: 40px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--ctp-surface1);
    overflow: visible;
    transition: box-shadow 0.2s, border-color 0.2s;
}

.last-played-hero:hover {
    box-shadow: 0 12px 20px rgba(0, 0, 0, 0.4);
    border-color: var(--ctp-mauve);
}

.hero-content {
    display: flex;
    align-items: center;
    gap: 30px;
    transition: transform 0.2s;
}

.last-played-hero:hover .hero-content {
    transform: translateY(-2px);
}

.hero-album-art {
    width: 200px;
    height: 200px;
    border-radius: 12px;
    object-fit: cover;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

.hero-info {
    flex: 1;
}

.now-playing-badge {
    display: inline-block;
    background: var(--ctp-green);
    color: var(--ctp-crust);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 12px;
    animation: pulse 2s infinite;
}

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

.last-played-time {
    display: inline-block;
    color: var(--ctp-overlay0);
    font-size: 0.9rem;
    margin-bottom: 12px;
}

.hero-track-name {
    font-size: 2rem;
    font-weight: 700;
    color: var(--ctp-text);
    margin-bottom: 8px;
}

.hero-artist-name {
    font-size: 1.3rem;
    color: var(--ctp-mauve);
    font-weight: 600;
    margin-bottom: 4px;
}

.hero-album-name {
    font-size: 1.1rem;
    color: var(--ctp-subtext0);
}

.hero-genre {
    font-size: 0.95rem;
    color: var(--ctp-lavender);
    font-weight: 500;
    margin-top: 8px;
}

.hero-hipster-badge {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 8px;
    color: var(--ctp-crust);
    font-size: 0.9rem;
    font-weight: 600;
    margin-top: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.tracks-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
    margin-bottom: 60px;
    overflow: visible;
}

.track-card {
    background: var(--ctp-surface0);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--ctp-surface1);
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    position: relative;
}

.track-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 12px rgba(0, 0, 0, 0.4);
    border-color: var(--ctp-mauve);
}

.album-art {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}

.track-info {
    padding: 16px;
}

.track-timestamp {
    position: absolute;
    top: 12px;
    right: 12px;
    background: var(--ctp-crust);
    color: var(--ctp-text);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.track-name {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--ctp-text);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.artist-name {
    font-size: 1rem;
    color: var(--ctp-mauve);
    font-weight: 500;
    margin-bottom: 4px;
}

.album-name {
    font-size: 0.9rem;
    color: var(--ctp-subtext0);
}

.genre-tag {
    font-size: 0.85rem;
    color: var(--ctp-teal);
    font-weight: 500;
    margin-top: 6px;
}

.track-hipster-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
    color: var(--ctp-crust);
    font-size: 0.75rem;
    font-weight: 600;
    margin-top: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.loading, .error {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px;
    color: var(--ctp-text);
    font-size: 1.2rem;
}

.error {
    background: var(--ctp-surface0);
    border: 1px solid var(--ctp-red);
    border-radius: 8px;
}

/* Top Artists Section */
.top-artists-section {
    margin-top: 60px;
}

/* Chart Section */
.chart-section {
    margin-top: 60px;
}

.chart-loading {
    text-align: center;
    padding: 12px;
    margin-bottom: 16px;
    background: var(--ctp-surface0);
    border-radius: 8px;
    color: var(--ctp-mauve);
    font-size: 0.95rem;
    font-weight: 500;
    animation: pulse 1.5s infinite;
}

.chart-container {
    background: var(--ctp-surface0);
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--ctp-surface1);
    height: 450px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.chart-container canvas {
    max-height: 100%;
    max-width: 100%;
}

.genre-charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.genre-chart-column {
    display: flex;
    flex-direction: column;
}

@media (max-width: 1024px) {
    .genre-charts-grid {
        grid-template-columns: 1fr;
    }
}

/* Music Stats Section */
.music-stats-section {
    margin-top: 60px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.stat-card {
    background: var(--ctp-surface0);
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--ctp-surface1);
    text-align: center;
}

.stat-title {
    color: var(--ctp-subtext0);
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.big-stat {
    font-size: 3.5rem;
    font-weight: 700;
    color: var(--ctp-text);
    margin-bottom: 10px;
    line-height: 1;
}

.stat-label {
    font-size: 1rem;
    color: var(--ctp-subtext0);
    font-weight: 600;
}

.stat-sublabel {
    font-size: 0.9rem;
    color: var(--ctp-overlay0);
    margin-top: 8px;
}

.score-cutoffs {
    margin-top: 16px;
    font-size: 0.75rem;
    color: var(--ctp-overlay0);
    line-height: 1.4;
}

.chart-container-small {
    height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.chart-container-small canvas {
    max-height: 100%;
    max-width: 100%;
}

@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* Explanation Section */
.explanation-section {
    margin-top: 60px;
    background: var(--ctp-surface0);
    border-radius: 16px;
    padding: 30px;
    border: 1px solid var(--ctp-surface1);
}

.explanation-content {
    color: var(--ctp-text);
    line-height: 1.8;
}

.explanation-intro {
    font-size: 1.1rem;
    margin-bottom: 30px;
    color: var(--ctp-subtext0);
}

.explanation-formula,
.explanation-visualization,
.explanation-distribution,
.explanation-categories,
.explanation-examples {
    margin-top: 30px;
}

.explanation-formula h3,
.explanation-visualization h3,
.explanation-distribution h3,
.explanation-categories h3,
.explanation-examples h3 {
    color: var(--ctp-mauve);
    font-size: 1.2rem;
    margin-bottom: 15px;
}

.explanation-formula code {
    background: var(--ctp-mantle);
    padding: 10px 15px;
    border-radius: 8px;
    display: inline-block;
    font-size: 1.1rem;
    color: var(--ctp-text);
    border: 1px solid var(--ctp-surface2);
}

.formula-note {
    margin-top: 10px;
    font-size: 0.95rem;
    color: var(--ctp-subtext1);
    font-style: italic;
}

.chart-container-formula {
    height: 300px;
    margin: 20px 0;
}

.chart-note {
    margin-top: 10px;
    font-size: 0.9rem;
    color: var(--ctp-subtext1);
    font-style: italic;
    text-align: center;
}

.distribution-note {
    margin-bottom: 20px;
    font-size: 0.95rem;
    color: var(--ctp-subtext0);
}

.distribution-bars {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.distribution-bar-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.distribution-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.distribution-emoji {
    font-size: 1.2rem;
}

.distribution-category {
    color: var(--ctp-text);
}

.distribution-bar-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

.distribution-bar {
    height: 24px;
    border-radius: 4px;
    transition: width 0.3s ease;
    min-width: 2%;
}

.distribution-percentage {
    font-size: 0.9rem;
    color: var(--ctp-subtext0);
    min-width: 35px;
}

.category-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.category-item {
    background: var(--ctp-mantle);
    padding: 12px 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--ctp-surface2);
}

.category-emoji {
    font-size: 1.5rem;
}

.category-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.category-name {
    font-weight: 600;
    color: var(--ctp-text);
    font-size: 1rem;
}

.category-range {
    font-size: 0.85rem;
    color: var(--ctp-subtext0);
}

.category-listeners {
    font-size: 0.85rem;
    color: var(--ctp-subtext1);
    font-style: italic;
}

.explanation-examples ul {
    list-style: none;
    padding: 0;
    margin: 15px 0;
}

.explanation-examples li {
    padding: 8px 0;
    border-bottom: 1px solid var(--ctp-surface1);
    color: var(--ctp-subtext0);
}

.explanation-examples li:last-child {
    border-bottom: none;
}

.explanation-examples strong {
    color: var(--ctp-text);
}

@media (max-width: 768px) {
    .explanation-section {
        padding: 20px;
    }

    .category-list {
        grid-template-columns: 1fr;
    }
}

/* Collapsible Section */
.collapsible {
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: color 0.2s;
}

.collapsible:hover {
    color: var(--ctp-mauve);
}

.collapse-icon {
    font-size: 0.8em;
    transition: transform 0.3s ease;
}

.collapse-icon.collapsed {
    transform: rotate(-90deg);
}

.tracks-grid {
    transition: max-height 0.3s ease, opacity 0.3s ease;
    overflow: hidden;
}

.tracks-grid.collapsed {
    max-height: 0 !important;
    opacity: 0;
    margin: 0;
    pointer-events: none;
}

.section-header {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.section-title {
    color: var(--ctp-text);
    font-size: 2rem;
    text-align: center;
    margin: 0;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.period-selector {
    background: var(--ctp-surface0);
    color: var(--ctp-text);
    border: 1px solid var(--ctp-surface1);
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 0.95rem;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.period-selector:hover {
    border-color: var(--ctp-mauve);
    background: var(--ctp-surface1);
}

.period-selector:focus {
    outline: none;
    border-color: var(--ctp-mauve);
}

.period-checkboxes {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.period-checkboxes label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--ctp-text);
    font-size: 0.9rem;
    cursor: pointer;
}

.period-checkboxes input[type="checkbox"] {
    cursor: pointer;
}

.top-artists-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

.artist-item {
    background: var(--ctp-surface0);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--ctp-surface1);
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    cursor: pointer;
}

.artist-item:hover {
    transform: translateX(4px);
    box-shadow: 0 6px 10px rgba(0, 0, 0, 0.4);
    border-color: var(--ctp-mauve);
}

a.artist-item {
    text-decoration: none;
    color: inherit;
    display: flex;
}

.artist-rank {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--ctp-mauve);
    min-width: 50px;
    text-align: center;
}

.artist-details {
    flex: 1;
}

.artist-details .artist-name {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--ctp-text);
    margin-bottom: 4px;
}

.artist-playcount {
    font-size: 0.9rem;
    color: var(--ctp-subtext0);
}

.artist-genre {
    font-size: 0.85rem;
    color: var(--ctp-sky);
    font-weight: 500;
    margin-top: 4px;
}

/* Hipster Score Badge */
.hipster-badge {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 16px;
    border-radius: 8px;
    color: var(--ctp-crust);
    font-size: 0.85rem;
    font-weight: 600;
    min-width: 120px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.hipster-score {
    font-size: 1.5rem;
    font-weight: 700;
    margin-top: 4px;
}

@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
    }

    .control-label {
        display: none;
    }

    .hero-content {
        flex-direction: column;
        text-align: center;
    }

    .hero-album-art {
        width: 150px;
        height: 150px;
    }

    .hero-track-name {
        font-size: 1.5rem;
    }

    .hero-artist-name {
        font-size: 1.1rem;
    }

    .tracks-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 16px;
    }

    .section-title {
        font-size: 1.5rem;
    }

    .top-artists-list {
        grid-template-columns: 1fr;
    }

    .artist-item {
        flex-wrap: wrap;
    }

    .hipster-badge {
        width: 100%;
        margin-top: 8px;
    }
}

/* Footer */
.footer {
    text-align: center;
    padding: 40px 20px;
    margin-top: 60px;
    color: var(--ctp-subtext0);
    font-size: 0.9rem;
    border-top: 1px solid var(--ctp-surface1);
}

.footer a {
    color: var(--ctp-mauve);
    font-weight: 600;
}

.footer a:hover {
    color: var(--ctp-lavender);
}

/* Light mode adjustments */
:root[data-theme="light"] .last-played-hero {
    box-shadow: 0 2px 8px rgba(76, 79, 105, 0.15);
}

:root[data-theme="light"] .last-played-hero:hover {
    box-shadow: 0 4px 12px rgba(76, 79, 105, 0.2);
}

:root[data-theme="light"] .hero-album-art {
    box-shadow: 0 2px 4px rgba(76, 79, 105, 0.15);
}

:root[data-theme="light"] .hero-hipster-badge {
    box-shadow: 0 1px 3px rgba(76, 79, 105, 0.2);
}

:root[data-theme="light"] .track-card {
    box-shadow: 0 2px 4px rgba(76, 79, 105, 0.12);
}

:root[data-theme="light"] .track-card:hover {
    box-shadow: 0 4px 8px rgba(76, 79, 105, 0.18);
}

:root[data-theme="light"] .track-timestamp {
    box-shadow: 0 1px 3px rgba(76, 79, 105, 0.15);
}

:root[data-theme="light"] .track-hipster-badge {
    box-shadow: 0 1px 3px rgba(76, 79, 105, 0.2);
}

:root[data-theme="light"] .chart-container {
    box-shadow: 0 2px 4px rgba(76, 79, 105, 0.12);
}

:root[data-theme="light"] .artist-item {
    box-shadow: 0 2px 4px rgba(76, 79, 105, 0.12);
}

:root[data-theme="light"] .artist-item:hover {
    box-shadow: 0 3px 8px rgba(76, 79, 105, 0.18);
}

:root[data-theme="light"] .hipster-badge {
    box-shadow: 0 1px 3px rgba(76, 79, 105, 0.2);
}

:root[data-theme="light"] header h1 {
    text-shadow: 0 1px 2px rgba(76, 79, 105, 0.1);
}

:root[data-theme="light"] .section-title {
    text-shadow: 0 1px 2px rgba(76, 79, 105, 0.1);
}

:root[data-theme="light"] .stat-card {
    box-shadow: 0 2px 4px rgba(76, 79, 105, 0.12);
}
