/* =========================================================================
   DISCOVER SHELVES / SEARCH song rows (densified)
   ========================================================================= */
.region {
    margin-bottom: 10px;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
}

.shelf-header {
    padding: 12px 16px 8px;
    background: var(--surface);
    user-select: none;
}

.shelf-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 28px;
}

.shelf-title-row h2 {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 0;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.shelf-subtitle {
    margin-top: 2px;
    font-size: 0.74rem;
    color: var(--text-3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.shelf-kind-chip {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background: rgba(96,165,250,0.14);
    color: #93c5fd;
    flex-shrink: 0;
}

.shelf-kind-chip.shelf-kind-quickpicks { background: rgba(52,211,153,0.16); color: #6ee7b7; }
.shelf-kind-chip.shelf-kind-personal   { background: rgba(192,132,252,0.16); color: #c4b5fd; }
.shelf-kind-chip.shelf-kind-home       { background: rgba(251,191,36,0.16); color: #fcd34d; }
.shelf-kind-chip.shelf-kind-library    { background: rgba(96,165,250,0.16); color: #93c5fd; }
.shelf-kind-chip.shelf-kind-radio_seed { background: rgba(244,114,182,0.16); color: #f9a8d4; }
.shelf-kind-chip.shelf-kind-charts     { background: rgba(34,197,94,0.16); color: #86efac; }
.shelf-kind-chip.shelf-kind-hero       { background: rgba(250,204,21,0.16); color: #fde047; }
.shelf-kind-chip.shelf-kind-artists    { background: rgba(167,139,250,0.16); color: #c4b5fd; }
.shelf-kind-chip.shelf-kind-albums     { background: rgba(244,114,182,0.16); color: #f9a8d4; }

.shelf-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.shelf-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    min-height: 0;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--text-2);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, transform 0.1s;
}
.shelf-action-btn:hover  { background: var(--surface-3); color: var(--text); }
.shelf-action-btn:active { transform: scale(0.92); }

.region-body.collapsed { display: none; }

.song-row {
    display: grid;
    grid-template-columns: 48px 1fr auto;
    grid-template-rows: auto auto;
    gap: 3px 10px;
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    font-size: 0.88rem;
    align-items: center;
}

.song-row:has(> input[type="checkbox"]) {
    grid-template-columns: 24px 48px 1fr auto;
}

.song-row:active { background: var(--surface-2); }
.song-row:last-child { border-bottom: none; }

.song-row > input[type="checkbox"] {
    grid-row: 1 / 3;
    grid-column: 1;
    align-self: center;
}

.song-thumb {
    grid-row: 1 / 3;
    grid-column: 1;
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}
.song-row:has(> input[type="checkbox"]) > .song-thumb { grid-column: 2; }

.song-info {
    grid-row: 1;
    grid-column: 2;
    min-width: 0;
}
.song-row:has(> input[type="checkbox"]) > .song-info { grid-column: 3; }

.song-title {
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.01em;
}

.song-artist {
    color: var(--text-3);
    font-size: 0.78rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.song-row > .song-artist { display: none; }
.song-duration { display: none; }

.song-badge-col {
    grid-row: 1;
    grid-column: 3;
    text-align: right;
}
.song-row:has(> input[type="checkbox"]) > .song-badge-col { grid-column: 4; }

.song-actions {
    grid-row: 2;
    grid-column: 2 / 4;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-top: 3px;
}
.song-row:has(> input[type="checkbox"]) > .song-actions { grid-column: 3 / 5; }

.song-duration-mobile {
    color: var(--text-3);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
}

.song-actions button.sm {
    padding: 7px 13px;
    min-height: 34px;
    font-size: 0.78rem;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-align: center;
    white-space: nowrap;
}

.badge-new { background: rgba(20,184,166,0.18); color: #5eead4; }
.badge-exists { background: rgba(251,191,36,0.15); color: #fcd34d; }
.badge-queued { background: rgba(96,165,250,0.12); color: #93c5fd; }
.badge-downloading { background: rgba(96,165,250,0.18); color: #93c5fd; animation: badge-pulse 1.4s ease-in-out infinite; }
.badge-done { background: rgba(52,211,153,0.15); color: #86efac; }
.badge-error { background: rgba(248,113,113,0.18); color: #fca5a5; }
.badge-clickable { cursor: pointer; text-decoration: underline; }
.badge-clickable:hover { filter: brightness(1.3); }

@keyframes badge-pulse {
    0%, 100% { background: rgba(96,165,250,0.18); }
    50%      { background: rgba(96,165,250,0.42); }
}

/* Progress bar */
#progress-bar-container {
    margin-bottom: 14px;
    padding: 12px 14px;
    background: var(--surface);
    border-radius: var(--radius);
}

#progress-info { font-size: 0.82rem; color: var(--text-2); margin-bottom: 8px; }

.progress-track {
    height: 6px;
    background: var(--surface-3);
    border-radius: 3px;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 3px;
}

/* Search input group */
.search-input-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.search-input-group .search-field { flex: 1; width: 100%; }

.search-input-group button {
    width: 100%;
    padding: 12px 18px;
}

#csv-selection-count {
    font-size: 0.82rem;
    color: var(--text-3);
    text-align: center;
}

#search-results {
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
}

#yt-search-cta {
    margin-top: 12px;
}

.yt-search-cta-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 16px;
    background: var(--surface);
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}

.yt-search-cta-btn:hover { background: var(--surface-2); }
.yt-search-cta-btn:active { background: var(--surface-3); }
.yt-search-cta-btn:disabled { opacity: 0.6; cursor: default; }
.yt-search-cta-btn .search-icon { color: var(--accent); flex-shrink: 0; }
.yt-search-cta-btn > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

#yt-search-section {
    margin-top: 16px;
}

.section-divider {
    padding: 12px 4px 8px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-3);
    border-top: 1px solid rgba(255,255,255,0.06);
    margin-top: 4px;
}

/* YouTube results header — visible "← Library" control + section label */
.yt-results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 4px 8px;
    border-top: 1px solid rgba(255,255,255,0.06);
    margin-top: 4px;
}

.yt-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px 6px 6px;
    background: transparent;
    color: var(--accent);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
    touch-action: manipulation;
}
.yt-back-btn:hover { color: var(--accent-2); }
.yt-back-btn:active { background: var(--surface-2); }
.yt-back-btn svg { flex-shrink: 0; }

.yt-results-label {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-3);
}

/* Tables (History) */
table { width: 100%; border-collapse: collapse; }

thead { display: none; }

tbody tr {
    display: block;
    padding: 12px 14px;
    margin-bottom: 8px;
    background: var(--surface);
    border-radius: var(--radius);
}

td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 0.88rem;
    border: none;
    gap: 10px;
}

td::before {
    content: attr(data-label);
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    min-width: 82px;
    flex-shrink: 0;
}

td[data-label=""] {
    justify-content: flex-end;
    gap: 8px;
    padding-top: 8px;
    margin-top: 4px;
    border-top: 1px solid rgba(255,255,255,0.04);
}

td[data-label=""]::before { display: none; }


/* =========================================================================
   DISCOVER: filter chips + horizontal card carousels
   ========================================================================= */

.discover-filters {
    display: flex;
    gap: 8px;
    padding: 4px 12px 12px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-snap-type: x proximity;
}

.discover-filters::-webkit-scrollbar { display: none; }

.filter-chip {
    flex-shrink: 0;
    padding: 7px 14px;
    border-radius: 999px;
    border: 1px solid var(--border, rgba(255,255,255,0.08));
    background: var(--surface);
    color: var(--text-2);
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    scroll-snap-align: start;
    white-space: nowrap;
    min-height: 34px;
}

.filter-chip:hover { background: var(--surface-2); }

.filter-chip.active {
    background: var(--text);
    color: var(--bg, #08060c);
    border-color: var(--text);
}

/* Horizontal card carousel inside a shelf. Horizontal gutters are pseudo-
   element spacers rather than container padding because Chromium/WebKit
   clip flex-container padding once the row overflows. */
.shelf-cards {
    display: flex;
    gap: 12px;
    padding: 4px 0 14px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
    scroll-padding-inline: 16px;
    -webkit-overflow-scrolling: touch;
}

.shelf-cards::before,
.shelf-cards::after {
    content: "";
    flex: 0 0 16px;
    align-self: stretch;
}

.shelf-cards::-webkit-scrollbar { height: 6px; }
.shelf-cards::-webkit-scrollbar-track { background: transparent; }
.shelf-cards::-webkit-scrollbar-thumb {
    background: var(--surface-2);
    border-radius: 3px;
}

.song-card {
    flex: 0 0 120px;
    width: 120px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-snap-align: start;
    background: transparent;
}

.card-thumb-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--surface-2);
}

.card-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.card-thumb-empty {
    background: linear-gradient(135deg, var(--surface-2), var(--surface-3, var(--surface-2)));
}

.card-dl-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 30px;
    height: 30px;
    min-height: 0;
    padding: 0;
    border-radius: 50%;
    background: rgba(0,0,0,0.55);
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}

.card-dl-btn:hover { background: rgba(0,0,0,0.75); }
.card-dl-btn:active { transform: scale(0.92); }
.card-dl-btn svg { width: 16px; height: 16px; }

.card-play-btn {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 44px;
    height: 44px;
    min-height: 0;
    padding: 0;
    border-radius: 50%;
    background: rgba(0,0,0,0.55);
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
    pointer-events: none;
}

.discover-card .card-thumb-wrap:hover .card-play-btn,
.discover-card .card-thumb-wrap:focus-within .card-play-btn {
    opacity: 1;
    pointer-events: auto;
}

.card-play-btn:hover { background: rgba(0,0,0,0.75); }
.card-play-btn:active { transform: translate(-50%, -50%) scale(0.92); }

@media (hover: none) {
    .card-play-btn {
        opacity: 1;
        pointer-events: auto;
    }

    /* Touch devices have no hover. The queue's per-row remove (×) and drag
       handle are otherwise hover-gated, so on iPad in landscape (>=900px,
       where the mobile-polish block doesn't apply) neither control is ever
       visible. Reveal them whenever the primary input is touch. */
    .queue-remove-btn { opacity: 0.8; }
    .queue-drag-handle { display: flex; opacity: 0.6; }
}

.card-add-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 30px;
    height: 30px;
    min-height: 0;
    padding: 0;
    border-radius: 50%;
    background: rgba(0,0,0,0.55);
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}

.card-add-btn:hover { background: rgba(0,0,0,0.75); }
.card-add-btn:active { transform: scale(0.92); }
.card-add-btn svg { width: 16px; height: 16px; }

.discover-card .card-thumb-wrap { cursor: pointer; }
.discover-card .card-info { cursor: pointer; }

.card-badge-wrap {
    position: absolute;
    bottom: 6px;
    left: 6px;
    z-index: 1;
}

.card-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    padding: 0 2px;
}

.card-title {
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--text);
    letter-spacing: -0.01em;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-artist {
    font-size: 0.74rem;
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Quick picks: larger cards */
.quickpicks-row .song-card {
    flex-basis: 160px;
    width: 160px;
}

/* Skeleton placeholders for discover */
.skeleton {
    background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3, var(--surface-2)) 40%, var(--surface-2) 80%);
    background-size: 200% 100%;
    animation: shimmer 1.6s infinite linear;
    border-radius: var(--radius-sm);
}

.shelf-skeleton .skeleton-line-title {
    width: 40%;
    height: 16px;
    border-radius: 4px;
}

.shelf-skeleton .skeleton-line-sub {
    width: 25%;
    height: 11px;
    border-radius: 4px;
    margin-top: 8px;
}

.skeleton-card .card-thumb-wrap {
    background: none;
}

.skeleton-card .skeleton-line-card {
    width: 80%;
    height: 11px;
    border-radius: 4px;
}

.skeleton-card .skeleton-line-card-sub {
    width: 55%;
    height: 9px;
    border-radius: 4px;
    margin-top: 6px;
}

/* Desktop / tablet card sizing */
@media (min-width: 600px) {
    .song-card { flex-basis: 140px; width: 140px; }
    .quickpicks-row .song-card { flex-basis: 180px; width: 180px; }
    .card-title { font-size: 0.86rem; }
    .card-artist { font-size: 0.76rem; }
}

@media (min-width: 900px) {
    .song-card { flex-basis: 150px; width: 150px; }
    .quickpicks-row .song-card { flex-basis: 200px; width: 200px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.05ms !important;
    }
    .mesh-bg { animation: none; }
    .eq-icon span { animation: none; height: 50%; }
}

/* =========================================================================
   DISCOVER: hero / artists / albums layouts (Phase 2)
   ========================================================================= */

/* Hero — full-bleed featured card */
.shelf-hero .hero-card {
    display: flex;
    flex-direction: row;
    gap: 14px;
    padding: 12px 16px 18px;
    cursor: pointer;
    align-items: center;
}

.hero-thumb-wrap {
    position: relative;
    flex: 0 0 120px;
    width: 120px;
    aspect-ratio: 1 / 1;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface-2);
}

.hero-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.hero-thumb-empty {
    background: linear-gradient(135deg, #4338ca, #ec4899);
}

.hero-play-btn {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 56px;
    height: 56px;
    min-height: 0;
    padding: 0;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}

.hero-play-btn:hover { background: rgba(0,0,0,0.8); }
.hero-play-btn:active { transform: translate(-50%, -50%) scale(0.92); }

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

.hero-blurb {
    font-size: 0.72rem;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hero-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.hero-artist {
    font-size: 0.84rem;
    color: var(--text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (min-width: 600px) {
    .hero-thumb-wrap { flex-basis: 160px; width: 160px; }
    .hero-title { font-size: 1.4rem; }
}

/* Artists row — circular avatars */
.shelf-artists .artists-row {
    align-items: flex-start;
}

.artist-card {
    flex: 0 0 100px;
    width: 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    scroll-snap-align: start;
}

.artist-thumb-wrap {
    width: 88px;
    height: 88px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--surface-2);
}

.artist-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.artist-thumb-empty {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--surface-2), var(--surface-3, var(--surface-2)));
}

.artist-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

@media (min-width: 600px) {
    .artist-card { flex-basis: 120px; width: 120px; }
    .artist-thumb-wrap { width: 104px; height: 104px; }
}

/* Albums row — square tiles, slightly bigger than song cards */
.shelf-albums .albums-row {
    align-items: flex-start;
}

.album-card {
    flex: 0 0 140px;
    width: 140px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-snap-align: start;
    cursor: pointer;
}

.album-thumb-wrap {
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--surface-2);
}

.album-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.album-thumb-empty {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--surface-2), var(--surface-3, var(--surface-2)));
}

.album-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    padding: 0 2px;
}

.album-title {
    font-weight: 600;
    font-size: 0.84rem;
    color: var(--text);
    letter-spacing: -0.01em;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.album-artist {
    font-size: 0.74rem;
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.album-year {
    font-size: 0.7rem;
    color: var(--text-3);
}

@media (min-width: 600px) {
    .album-card { flex-basis: 160px; width: 160px; }
}

/* Chart rank badge over song card thumb */
.card-rank-badge {
    position: absolute;
    top: 6px;
    left: 6px;
    padding: 3px 7px;
    border-radius: 6px;
    background: rgba(0,0,0,0.65);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    z-index: 1;
}
