/* ── Variables ── */
:root {
    --bg: #0a0a0a;
    --surface: #111111;
    --surface2: #181818;
    --surface3: #222222;
    --border: rgba(255, 255, 255, 0.07);
    --accent: #e8ff47;
    --text: #f0f0f0;
    --muted: #888;
    --radius: 10px;
    --font-head: 'Bebas Neue', sans-serif;
    --font-body: 'DM Sans', sans-serif;
    --transition: 0.2s cubic-bezier(.4, 0, .2, 1);
}

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

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ── Login page ── */
.login-screen {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 20px;
    background: radial-gradient(circle at top, rgba(232, 255, 71, 0.08), transparent 28%), var(--bg);
}

.login-card {
    width: 100%;
    max-width: 440px;
    padding: 44px 36px;
    border-radius: 24px;
    background: rgba(17, 17, 17, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 26px 100px rgba(0, 0, 0, 0.32);
}

.login-card h1 {
    font-family: var(--font-head);
    font-size: 38px;
    letter-spacing: 4px;
    margin-bottom: 10px;
    color: var(--text);
    text-transform: uppercase;
}

.login-card p {
    color: var(--muted);
    margin-bottom: 28px;
    line-height: 1.7;
}

.login-message {
    color: var(--text);
    margin-bottom: 20px;
    font-size: 14px;
    line-height: 1.6;
    border-radius: 12px;
    padding: 12px 14px;
}

.login-message.error {
    color: #ff6b6b;
    background: rgba(255, 107, 107, 0.1);
    border: 1px solid rgba(255, 107, 107, 0.25);
}

.login-message.info {
    color: var(--text);
    background: rgba(232, 255, 71, 0.1);
    border: 1px solid rgba(232, 255, 71, 0.18);
}

.login-card form {
    display: grid;
    gap: 16px;
}

.login-card input[type="password"] {
    width: 100%;
    padding: 16px 18px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    font-size: 15px;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.login-card input[type="password"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(232, 255, 71, 0.14);
}

.login-card button {
    border: none;
    border-radius: 14px;
    background: var(--accent);
    color: #000;
    font-weight: 700;
    padding: 16px 18px;
    cursor: pointer;
    transition: opacity var(--transition), transform var(--transition);
}

.login-card button:hover {
    opacity: 0.95;
    transform: translateY(-1px);
}

.login-card .login-note {
    color: var(--muted);
    font-size: 13px;
    margin-top: 14px;
    text-align: center;
}

@media (max-width: 640px) {
    .login-screen {
        padding: 22px 14px;
    }

    .login-card {
        padding: 30px 22px;
        border-radius: 18px;
    }

    .login-card h1 {
        font-size: 30px;
        letter-spacing: 3px;
    }

    .login-card p {
        margin-bottom: 22px;
    }

    .login-card input[type="password"] {
        padding: 14px 16px;
        font-size: 15px;
    }

    .login-card button {
        padding: 14px 16px;
        font-size: 15px;
    }
}

/* ── Noise texture overlay ── */
.noise-overlay {
    pointer-events: none;
    position: fixed;
    inset: 0;
    z-index: 999;
    opacity: 0.025;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: 180px 180px;
}

/* ── Header ── */
header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(10, 10, 10, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
}

.header-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px;
    height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    color: var(--accent);
    font-size: 20px;
    line-height: 1;
}

.logo h1 {
    font-family: var(--font-head);
    font-size: 26px;
    letter-spacing: 3px;
    color: var(--text);
}

/* ── Tabs ── */
.tabs {
    display: flex;
    gap: 4px;
    background: var(--surface2);
    padding: 4px;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.auth-controls {
    display: flex;
    align-items: center;
    margin-left: 18px;
}

.logout-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    border-radius: 12px;
    background: var(--accent);
    color: #000;
    text-decoration: none;
    font-weight: 700;
    letter-spacing: 0.2px;
    transition: opacity var(--transition), transform var(--transition);
}

.logout-button:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.refresh-button {
    margin-right: 12px;
    padding: 10px 16px;
    border-radius: 12px;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    font-weight: 600;
    cursor: pointer;
    transition: opacity var(--transition), transform var(--transition);
}

.refresh-button:hover {
    opacity: 0.85;
    transform: translateY(-1px);
}

.tab-button {
    background: transparent;
    color: var(--muted);
    border: none;
    padding: 7px 22px;
    cursor: pointer;
    border-radius: 7px;
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.3px;
    transition: all var(--transition);
}

.tab-button:hover {
    color: var(--text);
    background: var(--surface3);
}

.tab-button.active {
    background: var(--accent);
    color: #000;
    font-weight: 600;
}

/* ── Main layout ── */
main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 32px 24px 64px;
}

/* Bottom nav hidden by default; revealed only inside ≤640px media query */
.bottom-nav {
    display: none;
}

.tab-content {
    display: none;
    animation: fadeIn 0.25s ease;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Section header ── */
.section-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 28px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.section-header h2 {
    font-family: var(--font-head);
    font-size: 42px;
    letter-spacing: 3px;
    color: var(--text);
    line-height: 1;
}

/* ── Stats pills ── */
.home-stats {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.stat-pill {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 5px 14px;
    font-size: 13px;
    color: var(--muted);
}

.stat-pill strong {
    color: var(--accent);
    font-weight: 600;
}

/* ── Controls row ── */
.tab-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-input {
    flex: 1;
    min-width: 200px;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 16px;
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-size: 14px;
    outline: none;
    transition: border-color var(--transition);
}

.search-input::placeholder {
    color: var(--muted);
}

.search-input:focus {
    border-color: var(--accent);
}

.sort-group {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 5px 8px;
    flex-wrap: wrap;
}

.sort-label {
    font-size: 12px;
    color: var(--muted);
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding: 0 4px;
    white-space: nowrap;
}

.sort-btn {
    background: transparent;
    border: none;
    color: var(--muted);
    padding: 5px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    transition: all var(--transition);
    white-space: nowrap;
}

.sort-btn:hover {
    color: var(--text);
    background: var(--surface3);
}

.sort-btn.active {
    background: var(--surface3);
    color: var(--accent);
    font-weight: 600;
}

/* ── Artist list ── */
#artistList {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.artist-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition);
    overflow: hidden;
}

.artist-card:hover {
    background: var(--surface2);
    border-color: rgba(255, 255, 255, 0.12);
}

.artist-card.is-active {
    border-color: rgba(232, 255, 71, 0.35);
    background: var(--surface2);
}

.artist-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
}

.artist-header img {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--surface3);
    flex-shrink: 0;
}

.artist-meta {
    flex: 1;
    min-width: 0;
}

.artist-meta h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.artist-song-count {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
    display: block;
}

.artist-chevron {
    font-size: 11px;
    color: var(--muted);
    flex-shrink: 0;
    transition: color var(--transition);
}

.artist-card.is-active .artist-chevron {
    color: var(--accent);
}

/* ── Inline song expansion ── */
.inline-songs {
    border-top: 1px solid var(--border);
    animation: expandIn 0.2s ease;
}

@keyframes expandIn {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.song-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 16px 10px 82px;
    /* indent to align with artist name */
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
}

.song-item:last-child {
    border-bottom: none;
}

.song-item:hover {
    background: var(--surface3);
}

.song-item img {
    width: 38px;
    height: 38px;
    border-radius: 5px;
    object-fit: cover;
    background: var(--surface3);
    flex-shrink: 0;
}

.song-item-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Duration badge ── */
.song-duration {
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    color: transparent;
    /* invisible until loaded */
    background: var(--surface3);
    border-radius: 4px;
    padding: 2px 7px;
    flex-shrink: 0;
    min-width: 38px;
    text-align: center;
    transition: color 0.3s ease;
}

.song-duration.loaded {
    color: var(--muted);
}

/* ── Songs tab ── */
#songList {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.song-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    transition: background var(--transition), border-color var(--transition);
}

.song-card:hover {
    background: var(--surface2);
    border-color: rgba(255, 255, 255, 0.13);
}

.song-header {
    display: flex;
    align-items: center;
    gap: 14px;
}

.song-header img {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    object-fit: cover;
    background: var(--surface3);
    flex-shrink: 0;
}

.song-info {
    flex: 1;
    min-width: 0;
}

.song-info strong {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.song-info span {
    font-size: 13px;
    color: var(--muted);
}

/* ── Stats Tab ───────────────────────────────────────────── */

.stats-grid {
    display: grid;
    gap: 24px;
    align-content: start;
}

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

.stats-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
}

.stats-block h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 14px;
    color: var(--text);
}

/* List container */
.stats-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Each row */
.stats-row {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
}

/* Artist / song image */
.stats-row img {
    width: 42px;
    height: 42px;
    border-radius: 6px;
    object-fit: cover;
    background: var(--surface3);
    flex-shrink: 0;
}

/* Name + artist */
.stats-info {
    flex: 1;
    min-width: 0;
}

.stats-info strong {
    font-size: 14px;
    color: var(--text);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stats-info span {
    font-size: 12px;
    color: var(--muted);
}

/* Playtime sub-label shown under artist name */
.stats-playtime {
    font-size: 11px;
    color: var(--muted);
    opacity: 0.75;
    display: block;
    margin-top: 1px;
}

/* Empty state */
.stats-empty {
    color: var(--muted);
    font-size: 13px;
    padding: 16px 0;
    text-align: center;
}

/* Play count badge */
.stats-count {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

::-webkit-scrollbar-thumb {
    background: var(--surface3);
    border-radius: 3px;
}

/* ── Loading Overlay ── */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 10, 0.85);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.loading-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ════════════════════════════════
   MOBILE  (≤ 640px)
════════════════════════════════ */
@media (max-width: 640px) {

    /* Header: tighter, no wasted height */
    .header-inner {
        padding: 0 16px;
        height: 54px;
        gap: 10px;
    }

    .auth-controls {
        margin-left: 0;
    }

    .logout-button {
        padding: 9px 12px;
        font-size: 13px;
    }

    .logo h1 {
        font-size: 20px;
        letter-spacing: 2px;
    }

    .logo-icon {
        font-size: 16px;
    }

    /* Hide desktop tab nav — we use a bottom bar instead */
    header .tabs {
        display: none;
    }

    /* Bottom navigation bar */
    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 200;
        background: rgba(10, 10, 10, 0.95);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border-top: 1px solid var(--border);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .bottom-nav .tab-button {
        flex: 1;
        padding: 14px 8px 12px;
        border-radius: 0;
        font-size: 12px;
        font-weight: 600;
        letter-spacing: 0.5px;
        text-transform: uppercase;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
        color: var(--muted);
        background: transparent;
        position: relative;
    }

    .bottom-nav .tab-button::before {
        font-size: 18px;
        line-height: 1;
    }

    .bottom-nav .tab-button[data-tab="artists"]::before {
        content: "♪";
    }

    .bottom-nav .tab-button[data-tab="songs"]::before {
        content: "♫";
    }

    .bottom-nav .tab-button[data-tab="stats"]::before {
        content: "★";
    }

    .bottom-nav .tab-button.active {
        color: var(--accent);
        background: transparent;
    }

    .bottom-nav .tab-button.active::after {
        content: "";
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 32px;
        height: 2px;
        background: var(--accent);
        border-radius: 0 0 2px 2px;
    }

    /* Extra padding so content clears the bottom nav */
    main {
        padding: 20px 14px 90px;
    }

    /* Section heading smaller */
    .section-header {
        margin-bottom: 16px;
        padding-bottom: 12px;
        gap: 10px;
    }

    .section-header h2 {
        font-size: 30px;
    }

    /* Controls: search full width, sort scrolls horizontally */
    .tab-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        margin-bottom: 16px;
    }

    .search-input {
        min-width: 0;
        width: 100%;
        font-size: 16px;
        /* prevents iOS zoom on focus */
        padding: 12px 16px;
    }

    .sort-group {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        scrollbar-width: none;
        padding: 6px 10px;
    }

    .sort-group::-webkit-scrollbar {
        display: none;
    }

    .sort-btn {
        padding: 7px 14px;
        font-size: 13px;
        flex-shrink: 0;
        /* Larger tap targets */
        min-height: 36px;
    }

    /* Artist cards: bigger tap targets */
    .artist-header {
        padding: 14px 14px;
        gap: 12px;
    }

    .artist-header img {
        width: 46px;
        height: 46px;
    }

    .artist-meta h3 {
        font-size: 14px;
    }

    /* Inline songs: remove deep indent on mobile */
    .song-item {
        padding: 10px 14px;
        gap: 12px;
    }

    .song-item img {
        width: 36px;
        height: 36px;
    }

    /* Song cards */
    .song-card {
        padding: 11px 14px;
    }

    .song-header img {
        width: 44px;
        height: 44px;
    }

    .song-info strong {
        font-size: 13px;
    }

    .song-info span {
        font-size: 12px;
    }

    /* Duration badge smaller on mobile */
    .song-duration {
        font-size: 11px;
        min-width: 34px;
        padding: 2px 5px;
    }

    /* ── Stats Tab (Mobile) ── */
    #stats .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 16px;
    }

    #stats .stats-block {
        padding: 14px 16px;
    }

    #stats .stats-row {
        padding: 10px 12px;
        gap: 12px;
    }

    #stats .stats-row img {
        width: 36px;
        height: 36px;
        border-radius: 5px;
    }

    #stats .stats-info strong {
        font-size: 13px;
    }

    #stats .stats-info span {
        font-size: 11px;
    }

    #stats .stats-count {
        font-size: 12px;
    }


    /* Prevent Stats grid from breaking mobile layout */
    #stats .stats-grid {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    /* Prevent blocks from expanding wider than viewport */
    #stats .stats-block,
    #stats .stats-row {
        max-width: 100%;
        overflow: hidden;
    }

    /* Ensure images never cause horizontal overflow */
    #stats .stats-row img {
        max-width: 36px;
        max-height: 36px;
    }


}

/* ════════════════════════════════
   TABLET  (641px – 900px)
════════════════════════════════ */
@media (min-width: 641px) and (max-width: 900px) {
    main {
        padding: 24px 20px 56px;
    }

    .section-header h2 {
        font-size: 34px;
    }

    .tab-controls {
        flex-wrap: wrap;
    }

    .sort-group {
        overflow-x: auto;
        flex-wrap: nowrap;
        scrollbar-width: none;
    }

    .sort-group::-webkit-scrollbar {
        display: none;
    }
}

/* Bottom nav: hidden by default, shown only on mobile via the ≤640px block above */
@media (min-width: 641px) {
    .bottom-nav {
        display: none;
    }
}