/**
 * Song Library — v6.0.0
 * Changes from v5:
 *   - Card FRONT footer: popularity indicator (iconic/core/common/rare) replaces difficulty stars
 *   - Card BACK: streamlined to rhythm + tempo info only (description/chords/key → info modal)
 *   - Card BACK: two CTA buttons — "Open Leadsheet" + "More Information"
 *   - New "Info Modal" mirroring chord library modal pattern
 *   - Tempo label system: ballad / slow bossa / medium swing / etc.
 */

/* ==============================================
   PAGE WRAPPER
   ============================================== */

.sbn-song-library-main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 40px 20px;
}

/* ==============================================
   HEADER
   ============================================== */

.sbn-library-header {
    text-align: center;
    margin-bottom: 40px;
}

.sbn-library-title {
    font-size: 42px;
    font-weight: 700;
    color: #1a202c;
    margin: 0 0 10px 0;
    letter-spacing: -0.02em;
}

.sbn-library-subtitle {
    font-size: 18px;
    color: #718096;
    margin: 0 0 30px 0;
    font-weight: 400;
}

/* ==============================================
   SEARCH BOX
   ============================================== */

.sbn-search-container {
    max-width: 700px;
    margin: 0 auto;
}

.sbn-search-box {
    display: flex;
    align-items: center;
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 16px;
    padding: 6px 6px 6px 20px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}
.sbn-search-box:hover { border-color: #cbd5e0; box-shadow: 0 8px 12px -2px rgba(0,0,0,0.08); }
.sbn-search-box:focus-within { border-color: #e85d3b; box-shadow: 0 0 0 4px rgba(232,93,59,0.1), 0 8px 16px -2px rgba(0,0,0,0.1); }

.sbn-search-icon { color: #a0aec0; flex-shrink: 0; margin-right: 12px; transition: color 0.2s; }
.sbn-search-box:focus-within .sbn-search-icon { color: #e85d3b; }

.sbn-search-input {
    flex: 1; border: none; outline: none; font-size: 18px;
    color: #2d3748; background: transparent; padding: 14px 0; font-weight: 500;
}
.sbn-search-input::placeholder { color: #a0aec0; font-weight: 400; }

.sbn-clear-btn {
    width: 36px; height: 36px; border-radius: 10px; border: none;
    background: #f7fafc; color: #718096; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.sbn-clear-btn:hover { background: #e85d3b; color: white; }

.sbn-search-examples { margin-top: 14px; font-size: 14px; color: #718096; text-align: center; }
.sbn-search-try { color: #4a5568; margin-right: 6px; }
.sbn-example-btn {
    display: inline-block; padding: 5px 12px; margin: 3px;
    border: 1px solid #e2e8f0; border-radius: 8px;
    background: white; color: #4a5568; font-size: 13px; cursor: pointer; transition: all 0.2s;
}
.sbn-example-btn:hover { border-color: #e85d3b; color: #e85d3b; background: #fff5f2; }

/* ==============================================
   SEARCH STATUS
   ============================================== */

.sbn-search-status {
    margin-bottom: 24px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 8px 20px;
    font-size: 14px;
    color: #718096;
    text-align: center;
    display: none;
}
.sbn-search-status.active { display: block; }
.sbn-search-status strong { color: #1a202c; }

/* ==============================================
   CONTENT WRAPPER
   ============================================== */

.sbn-content-wrapper {
    display: flex;
    gap: 24px;
    position: relative;
}

.sbn-filter-sidebar {
    position: sticky;
    top: 20px;
    align-self: flex-start;
    width: 240px;
    min-width: 240px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    order: 1;
}

.sbn-results-container {
    flex: 1;
    min-width: 0;
    order: 0;
}

.sbn-sidebar-header { margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid #f0f4f8; }
.sbn-sidebar-header h3 { font-size: 16px; font-weight: 700; color: #1a202c; margin: 0; }

.sbn-sidebar-section { margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid #f0f4f8; }
.sbn-sidebar-section:last-of-type { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.sbn-sidebar-label { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: #a0aec0; margin-bottom: 8px; }

.sbn-sidebar-options { display: flex; flex-wrap: wrap; gap: 6px; }
.sbn-sidebar-option {
    padding: 5px 11px; border: 1px solid #e2e8f0; border-radius: 8px;
    background: white; color: #4a5568; font-size: 12px; cursor: pointer;
    transition: all 0.2s; white-space: nowrap; line-height: 1.4;
}
.sbn-sidebar-option:hover { border-color: #cbd5e0; background: #f7fafc; }
.sbn-sidebar-option.active { border-color: #e85d3b; background: #fff5f2; color: #e85d3b; font-weight: 600; }

.sbn-tempo-filter { display: flex; flex-direction: column; gap: 6px; }
.sbn-tempo-option  { width: 100%; text-align: left; }

.sbn-clear-filters-btn {
    width: 100%; padding: 10px; margin-top: 6px;
    border: 1px solid #e2e8f0; border-radius: 8px;
    background: white; color: #718096; font-size: 13px;
    font-weight: 600; cursor: pointer; transition: all 0.2s;
}
.sbn-clear-filters-btn:hover { border-color: #e85d3b; color: #e85d3b; background: #fff5f2; }

/* ==============================================
   LOADING / EMPTY
   ============================================== */

.sbn-loading { text-align: center; padding: 60px 20px; color: #718096; }
.sbn-loading-spinner {
    width: 40px; height: 40px; margin: 0 auto 16px;
    border: 3px solid #e2e8f0; border-top-color: #e85d3b;
    border-radius: 50%; animation: sbn-spin 0.8s linear infinite;
}
@keyframes sbn-spin { to { transform: rotate(360deg); } }

.sbn-no-results { text-align: center; padding: 60px 20px; color: #718096; }
.sbn-no-results h3 { font-size: 20px; color: #1a202c; margin: 16px 0 8px; }
.sbn-no-results p  { margin: 0; font-size: 15px; }

/* ==============================================
   SONGS GRID
   ============================================== */

.sbn-songs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 20px;
}

/* ==============================================
   SLIDE-UP REVEAL CARD
   ============================================== */

.sbn-song-card {
    height: 220px;
    cursor: pointer;
    border-radius: 12px;
    position: relative;
    overflow: hidden;
    /* Gradient background always present — revealed as front slides away */
    background: linear-gradient(135deg, #78909c 0%, #263238 100%);
    transition: box-shadow 0.35s ease;
}
.sbn-song-card:hover {
    box-shadow: 0 12px 32px rgba(0,0,0,0.18);
}

/* Genre gradients on the wrapper — no 3D, no bleed */
.sbn-song-card.sbn-genre--bossa-nova { background: linear-gradient(135deg, #ff8c42 0%, #e65100 100%); }
.sbn-song-card.sbn-genre--jazz       { background: linear-gradient(135deg, #42a5f5 0%, #1565c0 100%); }
.sbn-song-card.sbn-genre--classical  { background: linear-gradient(135deg, #66bb6a 0%, #2e7d32 100%); }
.sbn-song-card.sbn-genre--samba      { background: linear-gradient(135deg, #ef5350 0%, #c62828 100%); }
.sbn-song-card.sbn-genre--choro      { background: linear-gradient(135deg, #26a69a 0%, #00695c 100%); }
.sbn-song-card.sbn-genre--latin-jazz { background: linear-gradient(135deg, #7e57c2 0%, #4527a0 100%); }

.sbn-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 12px;
}

.sbn-card-front,
.sbn-card-back {
    position: absolute;
    inset: 0;
    border-radius: 12px;
    overflow: hidden;
    padding: 18px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* ==============================================
   CARD FRONT — slides up and fades out on hover
   ============================================== */

.sbn-card-front {
    background: white;
    border: 1px solid #e8ecf0;
    transform: translateY(0);
    opacity: 1;
    transition: transform 0.38s cubic-bezier(0.4, 0, 0.2, 1),
                opacity    0.28s ease,
                border-color 0.28s ease;
    z-index: 2;
}
.sbn-song-card:hover .sbn-card-front {
    transform: translateY(-100%);
    opacity: 0;
    border-color: transparent;
}

/* Top row: genre badge + difficulty stars */
.sbn-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

/* Genre badges */
.sbn-genre-badge {
    display: inline-block; padding: 3px 9px; border-radius: 20px;
    font-size: 10px; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.05em; white-space: nowrap;
}
.sbn-genre--bossa-nova  { background: linear-gradient(135deg, #ff8c42 0%, #e65100 100%); color: white; }
.sbn-genre--jazz        { background: #e3f2fd; color: #1565c0; }
.sbn-genre--classical   { background: #e8f5e9; color: #2e7d32; }
.sbn-genre--samba       { background: #fce4ec; color: #c62828; }
.sbn-genre--choro       { background: #e0f2f1; color: #00695c; }
.sbn-genre--latin-jazz  { background: #ede7f6; color: #4527a0; }
.sbn-genre-badge:not([class*="sbn-genre--"]) { background: #f1f5f9; color: #475569; }

/* Difficulty stars — kept top-right */
.sbn-difficulty { display: inline-flex; align-items: center; gap: 1px; }
.sbn-star         { font-size: 13px; line-height: 1; }
.sbn-star--filled { color: #fb8c00; }
.sbn-star--empty  { color: #dde1e7; }

/* Title block */
.sbn-card-titles { flex: 1; padding-top: 10px; }
.sbn-song-title {
    font-size: 16px; font-weight: 700; color: #1a202c;
    margin: 0 0 3px 0; line-height: 1.3;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.sbn-song-composer { font-size: 12px; color: #8898a8; font-style: italic; margin: 0; }

/* ---- FRONT FOOTER: popularity (if set) + key pill ---- */
.sbn-card-front-footer {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Popularity — Apple-style pill badge on card front footer */
.sbn-pop-indicator {
    display: inline-flex;
    align-items: center;
}

.sbn-pop-label {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
    /* neutral base — tier classes override */
    background: #f1f5f9;
    color: #475569;
}

/* Tier pill styles — all neutral tones, iconic slightly warmer */
.sbn-pop-rare   .sbn-pop-label { background: #f1f5f9; color: #718096; }
.sbn-pop-common .sbn-pop-label { background: #f1f5f9; color: #4a5568; }
.sbn-pop-core   .sbn-pop-label { background: #edf2f7; color: #2d3748; }
.sbn-pop-iconic .sbn-pop-label { background: #fefce8; color: #854d0e; border: 1px solid #fde68a; }

/* ==============================================
   CARD BACK — slides up into view on hover
   ============================================== */

.sbn-card-back {
    background: transparent; /* gradient is on .sbn-song-card wrapper */
    color: white;
    gap: 10px;
    transform: translateY(100%);
    opacity: 0;
    transition: transform 0.38s cubic-bezier(0.4, 0, 0.2, 1),
                opacity    0.28s ease 0.08s;
    z-index: 1;
}
.sbn-song-card:hover .sbn-card-back {
    transform: translateY(0);
    opacity: 1;
}

/* Primary CTA button text colour matches genre */
.sbn-song-card.sbn-genre--bossa-nova .sbn-back-cta:not(.sbn-back-cta-secondary) { color: #e65100; }
.sbn-song-card.sbn-genre--jazz       .sbn-back-cta:not(.sbn-back-cta-secondary) { color: #1565c0; }
.sbn-song-card.sbn-genre--classical  .sbn-back-cta:not(.sbn-back-cta-secondary) { color: #2e7d32; }
.sbn-song-card.sbn-genre--samba      .sbn-back-cta:not(.sbn-back-cta-secondary) { color: #c62828; }
.sbn-song-card.sbn-genre--choro      .sbn-back-cta:not(.sbn-back-cta-secondary) { color: #00695c; }
.sbn-song-card.sbn-genre--latin-jazz .sbn-back-cta:not(.sbn-back-cta-secondary) { color: #4527a0; }

/* Song name at top of back */
.sbn-back-song-name {
    font-size: 15px;
    font-weight: 700;
    opacity: 1.0;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Apple-style pill container */
.sbn-back-pills {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 10px;
}

/* Group: heading text + pill below it */
.sbn-back-pill-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Plain heading above the pill */
.sbn-back-pill-heading {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    opacity: 0.65;
    color: white;
    padding-left: 2px;
}

/* The pill itself — frosted glass */
.sbn-back-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 12px;
    background: rgba(255,255,255,0.18);
    border: 1px solid rgba(255,255,255,0.30);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 700;
    color: white;
    line-height: 1.2;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    width: fit-content;
}

/* Linked rhythm pill */
.sbn-back-pill--link {
    text-decoration: none;
    color: white;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.sbn-back-pill--link:hover {
    color: white;    
    background: rgba(255,255,255,0.28);
    border-color: rgba(255,255,255,0.55);
}

/* BPM sub-label inside tempo pill */
.sbn-back-pill-bpm {
    font-size: 10px;
    font-weight: 500;
    opacity: 0.70;
    margin-left: 2px;
}

/* Two-button row */
.sbn-back-actions {
    display: flex;
    gap: 7px;
    flex-shrink: 0;
}

.sbn-back-cta {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 9px 6px;
    background: white;
    border: none;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.15s;
    white-space: nowrap;
    line-height: 1;
}
.sbn-back-cta:hover { opacity: 0.88; transform: translateY(-1px); }

/* Secondary button — ghost style */
.sbn-back-cta-secondary {
    background: rgba(255,255,255,0.18);
    border: 1.5px solid rgba(255,255,255,0.5);
    color: white !important;
}
.sbn-back-cta-secondary:hover { background: rgba(255,255,255,0.28); }

/* CTA genre colours defined with .sbn-card-back above */

/* ==============================================
   SONG INFO MODAL
   Mirrors chord library .sbn-modal-overlay pattern.
   ============================================== */

body.sbn-modal-open { overflow: hidden; }

.sbn-song-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: none;
}
.sbn-song-modal-overlay.sbn-modal-visible {
    opacity: 1;
    pointer-events: all;
}

.sbn-song-modal {
    background: #fff;
    border-radius: 16px;
    width: 100%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    transform: translateY(20px) scale(0.97);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.18);
}
.sbn-modal-visible .sbn-song-modal {
    transform: translateY(0) scale(1);
}

/* Modal header */
.sbn-song-modal-header {
    position: relative;
    padding: 28px 28px 0;
    text-align: center;
}

.sbn-song-modal-close {
    position: absolute;
    top: 20px; right: 20px;
    width: 32px; height: 32px;
    border: none; background: #f7fafc; color: #718096;
    border-radius: 8px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.15s ease;
}
.sbn-song-modal-close:hover { background: #e85d3b; color: white; }

.sbn-song-modal-title {
    font-size: 28px;
    font-weight: 800;
    color: #1a202c;
    margin: 0 0 4px 0;
    line-height: 1.1;
}

.sbn-song-modal-composer {
    font-size: 14px;
    color: #718096;
    font-style: italic;
    margin: 0 0 16px 0;
}

/* Meta tag row */
.sbn-song-modal-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    padding: 0 0 20px 0;
    border-bottom: 1px solid #f1f5f9;
}

.sbn-song-modal-tag {
    display: inline-flex;
    align-items: center;
    padding: 5px 13px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    gap: 4px;
}

/* Neutral base for all non-genre tags */
.sbn-song-modal-tag--neutral {
    background: #f1f5f9;
    color: #4a5568;
}

/* BPM sub-label inside tempo tag */
.sbn-modal-tag-bpm {
    font-size: 10px;
    font-weight: 500;
    opacity: 0.65;
    margin-left: 3px;
}

/* Genre tag — uses same gradient class as card badge (.sbn-genre--*) */
.sbn-song-modal-tag--genre {
    color: white;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 10px;
}
/* Neutral fallback if no genre class matches */
.sbn-song-modal-tag--genre:not([class*="sbn-genre--"]) {
    background: #f1f5f9;
    color: #475569;
}

/* Popularity tag — wraps .sbn-pop-indicator, inherits its pill style */
.sbn-song-modal-tag--pop {
    background: transparent;
    padding: 0;
}

/* Body */
.sbn-song-modal-body {
    padding: 0 28px 28px;
}

.sbn-song-modal-section {
    padding: 20px 0;
}
.sbn-song-modal-section + .sbn-song-modal-section {
    border-top: 1px solid #f1f5f9;
}

.sbn-song-modal-section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: #a0aec0;
    margin: 0 0 12px 0;
}

.sbn-song-modal-desc {
    font-size: 14px;
    line-height: 1.65;
    color: #4a5568;
    margin: 0;
}

/* Chord pills */
.sbn-song-modal-chords {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.sbn-song-modal-chord {
    display: inline-block;
    padding: 5px 12px;
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 700;
    color: #1a202c;
    text-decoration: none;
    font-family: 'Crimson Text', Georgia, serif;
    transition: all 0.15s;
    cursor: pointer;
}
.sbn-song-modal-chord:hover {
    border-color: #e85d3b;
    background: #fff5f2;
    color: #e85d3b;
}

/* Open leadsheet CTA inside modal */
.sbn-song-modal-cta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 13px 20px;
    background: #e85d3b;
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
}
.sbn-song-modal-cta:hover { background: #d14f2e; transform: translateY(-1px); }

/* ==============================================
   LEADSHEET MODAL (existing — unchanged)
   ============================================== */

.sbn-leadsheet-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.sbn-leadsheet-modal-box {
    position: relative;
    background: white;
    border-radius: 12px;
    width: 100%;
    max-width: 900px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 24px 60px rgba(0,0,0,0.35);
}

.sbn-leadsheet-close {
    position: sticky;
    top: 12px; float: right;
    margin: 12px 12px 0 0;
    width: 36px; height: 36px;
    border: none; background: #f1f5f9;
    border-radius: 8px; color: #64748b; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    z-index: 10; transition: background 0.15s, color 0.15s; flex-shrink: 0;
}
.sbn-leadsheet-close:hover { background: #e85d3b; color: white; }

.sbn-leadsheet-modal-inner {
    padding: 0 20px 20px;
    clear: both;
}

/* ==============================================
   RESPONSIVE
   ============================================== */

@media (max-width: 1024px) {
    .sbn-content-wrapper { flex-direction: column; }
    .sbn-filter-sidebar  { position: static; width: 100%; min-width: 0; max-height: none; order: 0; }
    .sbn-results-container { order: 1; }
}

@media (max-width: 768px) {
    .sbn-song-library-main      { padding: 24px 16px; }
    .sbn-library-title          { font-size: 30px; }
    .sbn-songs-grid             { grid-template-columns: repeat(2, 1fr); gap: 12px; }
    .sbn-song-card              { height: 210px; }
    .sbn-leadsheet-modal        { padding: 10px; }
    .sbn-leadsheet-modal-inner  { padding: 0 12px 16px; }
    .sbn-song-modal-overlay     { align-items: flex-end; padding: 0; }
    .sbn-song-modal             { max-height: 90vh; border-radius: 12px 12px 0 0; margin-top: auto; }
    .sbn-song-modal-header      { padding: 20px 20px 0; }
    .sbn-song-modal-body        { padding: 0 20px 20px; }
}

@media (max-width: 480px) {
    .sbn-songs-grid { grid-template-columns: 1fr; }
}
