:root {
    --page-bg: #05070f;
    --bg: #0b0e1c;
    --surface: #141a2e;
    --surface-2: #232b47;
    --input-bg: #131829;
    --text: #f5f5f5;
    --text-soft: #cfcfcf;
    --text-muted: #a0a0a0;
    --text-faint: #666666;
    --accent: #bb86fc;
    --accent-bright: #c77dff;
    --accent-soft: #d8c2ff;
    --selected: #38255c;
    --border: #232b47;
    --duet: #7ee7ff;
    --duet-bg: rgba(77, 219, 255, 0.12);
    --star: #ffd166;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    background: var(--page-bg);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, Helvetica, Arial, sans-serif;
    color: var(--text);
    font-size: 17px;
    line-height: 1.45;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body.sheet-open {
    overflow: hidden;
}

::selection {
    background: var(--selected);
    color: var(--text);
}

a {
    color: var(--accent);
}

button {
    font-family: inherit;
    cursor: pointer;
}

input::placeholder {
    color: #777777;
}

#app {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    min-height: 100dvh;
    background:
        radial-gradient(ellipse 120% 60% at 85% -8%, rgba(255, 94, 196, 0.10), transparent 55%),
        radial-gradient(ellipse 130% 75% at 15% -5%, rgba(124, 77, 255, 0.16), transparent 60%),
        var(--bg);
    position: relative;
    padding-bottom: env(safe-area-inset-bottom);
}

.empty-state {
    padding: 28px 20px;
    text-align: center;
}

.empty-state p {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.empty-state .empty-sub {
    margin-top: 6px;
    font-size: 14px;
    font-weight: 400;
    color: var(--text-muted);
}

/* ===== Home header ===== */
.site-header {
    padding: 32px 20px 8px;
    text-align: center;
    background: radial-gradient(ellipse 130% 100% at 50% -30%, rgba(187, 134, 252, 0.26), transparent 62%);
}

.site-header h1 {
    margin: 4px 0 6px;
    font-size: clamp(28px, 8.5vw, 40px);
    font-weight: 400;
    font-family: 'Tilt Neon', -apple-system, system-ui, sans-serif;
    letter-spacing: 0.04em;
    line-height: 1.1;
    color: #fdf6ff;
    text-shadow:
        0 0 6px rgba(216, 157, 255, 0.95),
        0 0 22px rgba(178, 102, 255, 0.8),
        0 0 52px rgba(155, 64, 255, 0.55);
}

/* ===== Search ===== */
.search-wrap {
    padding: 14px 20px 4px;
}

#searchInput {
    width: 100%;
    height: 54px;
    padding: 0 18px;
    border-radius: 16px;
    border: 1px solid #2b3352;
    background: var(--input-bg);
    color: var(--text);
    font-size: 17px;
    font-family: inherit;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

#searchInput:focus {
    border-color: var(--accent-bright);
    box-shadow: 0 0 0 1px rgba(199, 125, 255, 0.35), 0 0 20px rgba(155, 64, 255, 0.35);
}

.search-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px 6px;
}

.eyebrow {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.clear-btn {
    min-height: 44px;
    padding: 0 12px;
    background: none;
    border: none;
    color: var(--accent);
    font-size: 15px;
    font-weight: 600;
}

/* ===== Song rows (search results) ===== */
.song-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 58px;
    padding: 10px 20px;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    text-align: left;
}

.song-row:active {
    background: var(--selected);
}

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

.song-row-title {
    display: block;
    font-size: 17px;
    font-weight: 600;
    line-height: 1.25;
}

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

.badge-duet {
    flex-shrink: 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--duet);
    background: var(--duet-bg);
    border-radius: 999px;
    padding: 4px 10px;
    white-space: nowrap;
}

.badge-star {
    flex-shrink: 0;
    color: var(--star);
    font-size: 17px;
    text-shadow: 0 0 9px rgba(255, 209, 102, 0.75);
}

/* ===== Home: eyebrow row + category grid ===== */
.home-eyebrow-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px 10px;
}

.surprise-btn {
    min-height: 44px;
    padding: 0 16px;
    border-radius: 999px;
    border: 1px solid rgba(255, 94, 196, 0.55);
    background: none;
    color: #ff8fd4;
    font-size: 14px;
    font-weight: 700;
    box-shadow: 0 0 14px rgba(255, 94, 196, 0.25);
}

.surprise-btn:active {
    background: rgba(255, 94, 196, 0.15);
}

.category-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 0 20px calc(28px + env(safe-area-inset-bottom));
}

.category-card {
    position: relative;
    display: block;
    width: 100%;
    min-height: 136px;
    padding: 0;
    border-radius: 16px;
    border: none;
    background: var(--surface-2);
    color: var(--text);
    text-align: left;
    overflow: hidden;
}

.category-card:active {
    outline: 2px solid var(--accent-bright);
    outline-offset: -2px;
}

.category-card-inner {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 12px 14px;
}

.category-name {
    display: block;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.2;
    text-wrap: pretty;
    text-shadow: 0 1px 10px rgba(0, 0, 0, 0.55);
}

/* Card backgrounds (gradient from the category's hue, or its image) are set
   inline by browse.js from /api/categories data */

.full-list-btn {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 60px;
    padding: 16px 18px;
    border-radius: 16px;
    border: 1px solid rgba(199, 125, 255, 0.55);
    background: rgba(124, 77, 255, 0.10);
    color: var(--text);
    text-align: left;
    box-shadow: 0 0 18px rgba(155, 64, 255, 0.22);
}

.full-list-btn:active {
    background: var(--selected);
}

.full-list-text {
    flex: 1;
    min-width: 0;
}

.full-list-title {
    display: block;
    font-size: 17px;
    font-weight: 700;
    color: var(--accent-soft);
}

.full-list-sub {
    display: block;
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 3px;
}

.full-list-count {
    flex-shrink: 0;
    font-size: 13px;
    color: var(--text-muted);
}

.full-list-chevron {
    flex-shrink: 0;
    color: var(--accent);
    font-size: 20px;
    line-height: 1;
}

/* ===== Sticky top bar (list view) ===== */
.top-bar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 4px;
    height: 56px;
    padding: 0 8px;
    background: rgba(8, 10, 22, 0.9);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

.back-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 0 10px;
    background: none;
    border: none;
    color: var(--accent);
    font-size: 16px;
    font-weight: 600;
}

.back-btn:active {
    background: var(--selected);
    border-radius: 12px;
}

.top-bar-title {
    flex: 1;
    font-size: 16px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 12px;
}

.list-head {
    padding: 18px 20px 8px;
}

.list-head h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 800;
    line-height: 1.15;
}

/* ===== Category rows (card style) ===== */
.cat-rows {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 4px 20px 30px;
}

.cat-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 62px;
    padding: 12px 16px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    text-align: left;
}

.cat-row:active {
    background: var(--selected);
}

/* ===== Full list ===== */
.list-toggle {
    display: flex;
    gap: 8px;
    padding: 0 20px 12px;
}

.list-toggle-btn {
    padding: 8px 16px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: none;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
}

.list-toggle-btn.active {
    background: var(--selected);
    border-color: var(--accent);
    color: var(--text);
}

.full-body {
    padding-bottom: 30px;
}

.letter-rail-anchor {
    position: sticky;
    top: 64px;
    height: 0;
    z-index: 8;
}

.letter-rail {
    position: absolute;
    right: 2px;
    top: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(19, 24, 43, 0.92);
    border-radius: 12px;
    padding: 5px 1px;
}

.letter-rail button {
    width: 26px;
    height: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    padding: 0;
    color: var(--accent);
    font-size: 10px;
    font-weight: 700;
}

.letter-band {
    position: sticky;
    top: 56px;
    z-index: 5;
    background: #151233;
    color: var(--accent-bright);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.15em;
    padding: 6px 20px;
}

.artist-header {
    padding: 14px 44px 2px 20px;
    font-size: 15px;
    font-weight: 700;
}

.full-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 48px;
    padding: 8px 44px 8px 20px;
    background: none;
    border: none;
    color: var(--text);
    text-align: left;
}

.full-row:active {
    background: var(--selected);
}

.full-row-title {
    flex: 1;
    min-width: 0;
    font-size: 16px;
    color: #d9d9d9;
    line-height: 1.3;
}

/* ===== Song bottom sheet ===== */
.sheet-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
}

.sheet-scrim {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
}

.sheet {
    position: absolute;
    inset: 0;
    margin: 0 auto;
    width: 100%;
    max-width: 480px;
    background: var(--surface);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
    scrollbar-width: thin;
    scrollbar-color: rgba(187, 134, 252, 0.35) transparent;
}

.sheet::-webkit-scrollbar {
    width: 6px;
}

.sheet::-webkit-scrollbar-track {
    background: transparent;
}

.sheet::-webkit-scrollbar-thumb {
    background: rgba(187, 134, 252, 0.35);
    border-radius: 3px;
}

.sheet::-webkit-scrollbar-thumb:active {
    background: rgba(187, 134, 252, 0.6);
}

.sheet-top {
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    padding: calc(10px + env(safe-area-inset-top)) 12px 0 22px;
}

.sheet-close {
    min-width: 44px;
    min-height: 44px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 22px;
}

.sheet-close:active {
    color: var(--text);
}

.sheet-body {
    padding: 0 22px calc(28px + env(safe-area-inset-bottom));
}

.sheet-body h2 {
    margin: 0;
    font-size: 26px;
    font-weight: 800;
    line-height: 1.15;
    text-wrap: pretty;
}

.sheet-artist {
    margin: 6px 0 0;
    font-size: 16px;
    color: var(--text-muted);
}

.sheet-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

.sheet-surprise {
    margin-top: 16px;
}

/* Surprise spin: title/artist flicker while "rolling", chips hold their space */
.spinning {
    opacity: 0.7;
}

.spin-hidden {
    visibility: hidden;
}

.chip {
    font-size: 13px;
    font-weight: 600;
    border-radius: 999px;
    padding: 6px 12px;
}

.chip-duet {
    color: var(--duet);
    background: var(--duet-bg);
}

.chip-star {
    color: #1a1206;
    background: var(--star);
    box-shadow: 0 0 12px rgba(255, 209, 102, 0.4);
}

.chip-cat {
    color: var(--text-soft);
    background: var(--surface-2);
}

.sheet-lyrics {
    margin-top: 22px;
    white-space: pre-wrap;
    font-size: 16px;
    line-height: 1.6;
    color: #e8e8e8;
}

.lyrics-marker {
    color: var(--text-muted);
    font-size: 13px;
}

.skeleton-bar {
    height: 13px;
    border-radius: 7px;
    background: var(--surface-2);
    margin-bottom: 11px;
}

/* ===== Desktop (wider than the app column; mobile is untouched) ===== */
@media (min-width: 520px) {
    html {
        scrollbar-width: thin;
        scrollbar-color: #2b3352 transparent;
    }

    body {
        background:
            radial-gradient(ellipse 60% 45% at 82% -5%, rgba(255, 94, 196, 0.06), transparent 60%),
            radial-gradient(ellipse 70% 55% at 18% -5%, rgba(124, 77, 255, 0.09), transparent 60%),
            var(--page-bg);
        background-attachment: fixed;
    }

    #app {
        border-left: 1px solid var(--border);
        border-right: 1px solid var(--border);
        box-shadow: 0 0 80px rgba(124, 77, 255, 0.12);
    }

    /* Lyric sheet becomes a floating dialog instead of edge-to-edge */
    .sheet {
        top: 24px;
        bottom: 24px;
        border-radius: 20px;
    }
}

/* Hover feedback for mouse/trackpad users only — touch devices never see these */
@media (hover: hover) and (pointer: fine) {
    .song-row:hover,
    .cat-row:hover,
    .full-row:hover {
        background: rgba(56, 37, 92, 0.5);
    }

    .cat-row:hover {
        border-color: rgba(187, 134, 252, 0.5);
    }

    .category-card:hover {
        filter: brightness(1.12);
    }

    .full-list-btn:hover {
        background: rgba(124, 77, 255, 0.16);
    }

    .surprise-btn:hover {
        background: rgba(255, 94, 196, 0.15);
    }

    .back-btn:hover {
        background: var(--selected);
        border-radius: 12px;
    }

    .clear-btn:hover,
    .letter-rail button:hover {
        color: var(--accent-soft);
    }

    .list-toggle-btn:not(.active):hover {
        color: var(--text);
        border-color: var(--accent);
    }

    .sheet-close:hover {
        color: var(--text);
    }
}

