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

/* ── Tokens ──────────────────────────────────── */
:root {
    --bg:           #f5f3ee;
    --bg2:          #edeae3;
    --surface:      #ffffff;
    --surface2:     #f9f8f5;
    --text:         #18180f;
    --text2:        #5a5849;
    --text3:        #9a9486;
    --border:       rgba(0,0,0,0.08);
    --border2:      rgba(0,0,0,0.14);
    --accent:       #1d3a6e;
    --accent2:      #e8edf7;
    --accent3:      #c5d0ea;
    --red:          #b83030;
    --red2:         #fdf0ee;
    --shadow-sm:    0 1px 3px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
    --shadow-md:    0 2px 8px rgba(0,0,0,.08), 0 8px 24px rgba(0,0,0,.08);
    --shadow-lg:    0 8px 32px rgba(0,0,0,.14), 0 2px 8px rgba(0,0,0,.06);
    --radius:       14px;
    --radius-sm:    8px;
    --ff-display:   'Playfair Display', Georgia, serif;
    --ff-body:      'Outfit', system-ui, sans-serif;
    --transition:   0.2s ease;
}

[data-theme="dark"] {
    --bg:      #111210;
    --bg2:     #1a1917;
    --surface: #201f1d;
    --surface2:#272523;
    --text:    #f0ede6;
    --text2:   #a09a8e;
    --text3:   #6b6459;
    --border:  rgba(255,255,255,0.07);
    --border2: rgba(255,255,255,0.12);
    --accent:  #8fabd4;
    --accent2: #1a2540;
    --accent3: #2a3a5e;
    --red:     #e07070;
    --red2:    #2a1818;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
    --shadow-md: 0 2px 8px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
    --shadow-lg: 0 8px 32px rgba(0,0,0,.5);
}

/* ── Body ────────────────────────────────────── */
body {
    font-family: var(--ff-body);
    font-weight: 400;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.6;
    transition: background var(--transition), color var(--transition);
}

/* ── Header ──────────────────────────────────── */
header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}
.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}
.header-inner:first-child {
    height: 56px;
    border-bottom: 1px solid var(--border);
}
.header-title-row {
    padding-top: .75rem;
    padding-bottom: .75rem;
    flex-wrap: wrap;
    gap: .75rem;
    align-items: flex-start;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text);
    flex-shrink: 0;
}
.brand-icon { width: 24px; height: 24px; color: var(--accent); }
.brand-name {
    font-family: var(--ff-display);
    font-size: .95rem;
    font-weight: 500;
    letter-spacing: .02em;
}

.header-controls { display: flex; align-items: center; gap: .75rem; margin-left: auto; }

.search-wrap {
    position: relative;
    display: flex;
    align-items: center;
}
.search-icon {
    position: absolute;
    left: 10px;
    width: 14px; height: 14px;
    color: var(--text3);
    pointer-events: none;
}
#search {
    background: var(--bg2);
    border: 1px solid var(--border2);
    border-radius: 99px;
    padding: 6px 14px 6px 32px;
    font-family: var(--ff-body);
    font-size: .85rem;
    color: var(--text);
    width: 200px;
    outline: none;
    transition: border-color var(--transition), width var(--transition), background var(--transition);
}
#search:focus { border-color: var(--accent); width: 260px; background: var(--surface); }
#search::placeholder { color: var(--text3); }

.theme-toggle {
    background: var(--bg2);
    border: 1px solid var(--border2);
    border-radius: 99px;
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    color: var(--text2);
    flex-shrink: 0;
    transition: background var(--transition), color var(--transition);
}
.theme-toggle:hover { background: var(--accent2); color: var(--accent); }
.theme-toggle svg { width: 15px; height: 15px; }
[data-theme="light"] .icon-moon { display: none; }
[data-theme="dark"]  .icon-sun  { display: none; }

header h1 {
    font-family: var(--ff-display);
    font-size: clamp(1.3rem, 3vw, 1.75rem);
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    flex-shrink: 0;
}
header h1 em { font-style: italic; color: var(--accent); }

/* ── Filter bar ──────────────────────────────── */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.filter-chip {
    font-family: var(--ff-body);
    font-size: .75rem;
    font-weight: 500;
    padding: 4px 12px;
    border-radius: 99px;
    border: 1px solid var(--border2);
    background: transparent;
    color: var(--text2);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}
.filter-chip:hover { background: var(--accent2); color: var(--accent); border-color: var(--accent3); }
.filter-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
[data-theme="dark"] .filter-chip.active { color: var(--bg); }

/* ── Main / Grid ─────────────────────────────── */
main { flex: 1; padding: 2rem 1.5rem; }
.music-grid {
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1.25rem;
}

/* ── Card ────────────────────────────────────── */
.music-card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    animation: fadeUp .4s ease both;
    transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.music-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    border-color: var(--border2);
}
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

.card-cover {
    aspect-ratio: 3/2;
    overflow: hidden;
    position: relative;
    background: var(--bg2);
}
.card-cover img {
    width: 100%; height: 100%;
    object-fit: cover;
    display: block;
    transition: transform .35s ease;
}
.music-card:hover .card-cover img { transform: scale(1.05); }

.cover-placeholder {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    background: var(--accent2);
}
.cover-placeholder span {
    font-family: var(--ff-display);
    font-size: 3.5rem;
    font-style: italic;
    color: var(--accent);
    opacity: .5;
}

.card-overlay {
    position: absolute; inset: 0;
    background: rgba(0,0,0,0);
    display: flex; align-items: flex-end; justify-content: center;
    padding-bottom: 1rem;
    transition: background var(--transition);
    pointer-events: none;
}
.overlay-hint {
    font-size: .75rem;
    font-weight: 500;
    color: #fff;
    background: rgba(0,0,0,.55);
    padding: 4px 12px;
    border-radius: 99px;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity var(--transition), transform var(--transition);
    backdrop-filter: blur(4px);
}
.music-card:hover .card-overlay { background: rgba(0,0,0,.12); }
.music-card:hover .overlay-hint { opacity: 1; transform: translateY(0); }

.card-body { padding: 1rem 1.1rem 1.1rem; display: flex; flex-direction: column; gap: .5rem; flex: 1; }
.card-title {
    font-family: var(--ff-display);
    font-size: 1rem;
    font-weight: 500;
    line-height: 1.3;
    color: var(--text);
}
.card-meta { display: flex; align-items: center; gap: 8px; }
.instrument-count { font-size: .75rem; color: var(--text3); }
.has-audio { font-size: .72rem; color: var(--red); background: var(--red2); padding: 2px 7px; border-radius: 99px; }

.card-instruments { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.chip {
    font-size: .7rem;
    padding: 2px 8px;
    border-radius: 99px;
    background: var(--bg2);
    color: var(--text2);
    border: 1px solid var(--border);
}
.chip-more { background: var(--accent2); color: var(--accent); border-color: var(--accent3); }

/* ── No results ──────────────────────────────── */
.no-results {
    text-align: center;
    color: var(--text3);
    padding: 3rem;
    font-size: .95rem;
    max-width: 1200px;
    margin: 0 auto;
}

/* ── Loading / Error ─────────────────────────── */
.loading {
    grid-column: 1/-1;
    display: flex; flex-direction: column;
    align-items: center; gap: 1rem;
    padding: 5rem 0;
    color: var(--text3);
    font-size: .9rem;
}
.spinner {
    width: 28px; height: 28px;
    border: 2px solid var(--border2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-box {
    grid-column: 1/-1;
    background: var(--red2);
    border: 1px solid rgba(184,48,48,.2);
    border-radius: var(--radius);
    padding: 1.5rem 2rem;
    max-width: 520px;
}
.error-box strong { color: var(--red); display: block; margin-bottom: 6px; }
.error-box p { font-size: .85rem; color: var(--text2); margin-top: 4px; }
.error-hint { font-family: monospace; font-size: .78rem !important; opacity: .7; }

/* ── Modal ───────────────────────────────────── */
.modal {
    position: fixed; inset: 0;
    z-index: 200;
    display: flex; align-items: center; justify-content: center;
    padding: 1rem;
}
.modal[hidden] { display: none; }

.modal-backdrop {
    position: absolute; inset: 0;
    background: rgba(0,0,0,.45);
    backdrop-filter: blur(3px);
    opacity: 0;
    transition: opacity .25s ease;
}
.modal.open .modal-backdrop { opacity: 1; }

.modal-box {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 640px;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px) scale(.97);
    transition: opacity .25s ease, transform .25s ease;
}
.modal.open .modal-box { opacity: 1; transform: none; }

.modal-close {
    position: absolute; top: 12px; right: 12px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 99px;
    width: 30px; height: 30px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    color: var(--text2);
    z-index: 1;
    transition: background var(--transition);
}
.modal-close:hover { background: var(--border2); }
.modal-close svg { width: 12px; height: 12px; }

.modal-cover-wrap {
    width: 100%;
    aspect-ratio: 16/7;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--bg2);
}
.modal-cover { width: 100%; height: 100%; object-fit: cover; display: block; }
.modal-cover[hidden] { display: none; }
.modal-cover-placeholder {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    font-family: var(--ff-display);
    font-size: 5rem;
    font-style: italic;
    color: var(--accent);
    opacity: .3;
    background: var(--accent2);
}
.modal-cover-placeholder[hidden] { display: none; }

.modal-content { padding: 1.5rem; display: flex; flex-direction: column; gap: 1.25rem; }

.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
#modal-title {
    font-family: var(--ff-display);
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
    flex: 1;
}

.modal-yt-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px;
    background: var(--red2);
    color: var(--red);
    border-radius: var(--radius-sm);
    font-size: .82rem;
    font-weight: 500;
    text-decoration: none;
    transition: opacity var(--transition);
    flex-shrink: 0;
}
.modal-yt-btn:hover { opacity: .8; }
.modal-yt-btn svg { width: 16px; height: 16px; }

/* ── Modal file list ─────────────────────────── */
.modal-file-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.modal-file-row {
    display: flex; align-items: center;
    justify-content: space-between; gap: .75rem;
    padding: 9px 12px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color var(--transition);
}
.modal-file-row:hover { border-color: var(--border2); }
.modal-file-name {
    font-size: .875rem;
    color: var(--text);
    font-weight: 500;
    flex: 1;
}
.modal-file-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Buttons ─────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 5px 12px;
    border-radius: var(--radius-sm);
    font-family: var(--ff-body);
    font-size: .78rem;
    font-weight: 500;
    text-decoration: none;
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity var(--transition), background var(--transition);
}
.btn svg { width: 12px; height: 12px; flex-shrink: 0; }
.btn:hover { opacity: .85; }

.btn-preview {
    background: var(--accent2);
    color: var(--accent);
    border-color: var(--accent3);
}
.btn-download {
    background: var(--bg2);
    color: var(--text2);
    border-color: var(--border2);
}

/* ── PDF Preview ─────────────────────────────── */
.pdf-preview-wrap {
    border: 1px solid var(--border2);
    border-radius: var(--radius-sm);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.pdf-preview-wrap[hidden] { display: none; }

.pdf-preview-header {
    display: flex; align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    font-size: .82rem;
    font-weight: 500;
    color: var(--text2);
}
.pdf-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text3);
    display: flex; align-items: center;
    padding: 2px;
    border-radius: 4px;
    transition: color var(--transition);
}
.pdf-close-btn:hover { color: var(--text); }
.pdf-close-btn svg { width: 12px; height: 12px; }

#pdf-preview {
    width: 100%;
    height: 520px;
    border: none;
    display: block;
    background: var(--bg);
}

/* ── Footer ──────────────────────────────────── */
footer {
    border-top: 1px solid var(--border);
    padding: .75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: .75rem;
    color: var(--text3);
    background: var(--surface);
}

/* ── Responsive ──────────────────────────────── */
@media (max-width: 640px) {
    main { padding: 1.25rem 1rem; }
    .music-grid { gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
    #search { width: 150px; }
    #search:focus { width: 180px; }
    header h1 { font-size: 1.15rem; }
    .header-title-row { flex-direction: column; align-items: flex-start; gap: .5rem; }

    .modal-box { max-height: 95vh; border-radius: var(--radius) var(--radius) 0 0; }
    .modal { align-items: flex-end; padding: 0; }
    #pdf-preview { height: 340px; }
    .modal-file-row { flex-direction: column; align-items: flex-start; gap: 8px; }
    .modal-file-actions { width: 100%; }
    .btn { flex: 1; justify-content: center; }
}

@media (max-width: 400px) {
    .music-grid { grid-template-columns: 1fr 1fr; }
    .card-instruments { display: none; }
}

/* ── Scrollbar ───────────────────────────────── */
.modal-box::-webkit-scrollbar { width: 6px; }
.modal-box::-webkit-scrollbar-track { background: transparent; }
.modal-box::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 99px; }
