/*
 * Dear Friends — library collection explorer.
 *
 * Collections on the homepage become openable, and opening one expands a panel
 * directly beneath its row holding the pieces inside it.
 *
 * Scoped to .iw-path / .rest-path / .lib-* so it cannot affect anything else,
 * and deliberately reuses the existing gold-on-deep-navy palette, Prata
 * headings and Outfit body text rather than introducing a new look.
 */

/* ---------------------------------------------------------------- *
 * Openable collections
 * ---------------------------------------------------------------- */

/* The openable variants are <button> elements so they are keyboard and screen
   reader accessible, which means undoing the user-agent button styling before
   the existing .iw-path / .rest-path rules can show through. */
button.iw-path,
button.rest-path {
    appearance: none;
    -webkit-appearance: none;
    -webkit-tap-highlight-color: transparent;
    width: 100%;
    margin: 0;
    font: inherit;
    color: inherit;
    text-align: left;
    cursor: pointer;
}

button.rest-path.is-tile {
    flex-direction: column;
    text-align: center;
}

.iw-path.is-openable,
.rest-path.is-openable {
    position: relative;
}

/* Affordance that this one can be opened. It turns downward once open, which
   is also the only cue the tile variant gets. */
.iw-path.is-openable::after,
.rest-path.is-openable:not(.is-tile)::after {
    content: '\2193';
    position: absolute;
    top: 15px;
    right: 15px;
    font-size: 15px;
    line-height: 1;
    color: rgba(239, 189, 114, .55);
    opacity: 0;
    transform: translateY(-3px);
    transition: opacity .24s ease, transform .24s ease, color .24s ease;
    pointer-events: none;
}

.iw-path.is-openable:hover::after,
.iw-path.is-openable:focus-visible::after,
.rest-path.is-openable:not(.is-tile):hover::after,
.rest-path.is-openable:not(.is-tile):focus-visible::after {
    opacity: 1;
    transform: translateY(0);
}

.iw-path.is-open::after,
.rest-path.is-open:not(.is-tile)::after {
    opacity: 1;
    transform: rotate(180deg);
    color: rgba(245, 212, 160, .95);
}

.iw-path.is-openable:focus-visible,
.rest-path.is-openable:focus-visible {
    outline: 2px solid rgba(239, 189, 114, .6);
    outline-offset: 3px;
}

/* The collection currently open. */
.iw-path.is-open,
.rest-path.is-open {
    border-color: rgba(239, 189, 114, .5);
    background: rgba(239, 189, 114, .09);
}

.iw-path.is-open .lib-path-meta,
.rest-path.is-open .lib-path-meta {
    color: rgba(245, 212, 160, .95);
}

/* How many pieces are inside — the part that visibly grows as the library
   is filled in. */
.lib-path-meta {
    display: block;
    margin-top: 10px;
    font-family: 'Outfit', sans-serif;
    font-size: 12px;
    font-weight: 400;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: rgba(239, 189, 114, .72);
}

.rest-path.is-tile .lib-path-meta {
    margin-top: 6px;
    font-size: 11px;
}

/* ---------------------------------------------------------------- *
 * The panel that opens beneath the row
 * ---------------------------------------------------------------- */

.lib-drawer {
    grid-column: 1 / -1;
    height: 0;
    overflow: hidden;
    transition: height .34s cubic-bezier(.4, 0, .2, 1);
}

.lib-drawer-inner {
    position: relative;
    margin-top: 8px;
    padding: 22px 20px 20px;
    border-radius: 18px;
    border: 1px solid rgba(239, 189, 114, .24);
    background: linear-gradient(165deg, rgba(20, 26, 50, .92), rgba(7, 10, 26, .96));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05);
}

/* Pointer back to the collection that was opened. */
.lib-drawer-inner::before {
    content: '';
    position: absolute;
    top: -7px;
    left: var(--notch-x, 44px);
    width: 12px;
    height: 12px;
    transform: rotate(45deg);
    background: rgb(19, 25, 48);
    border-left: 1px solid rgba(239, 189, 114, .24);
    border-top: 1px solid rgba(239, 189, 114, .24);
}

.lib-drawer-head {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 18px;
}

.lib-drawer-headings {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 680px;
}

.lib-drawer-title {
    margin: 0 0 6px;
    font-family: 'Prata', serif;
    font-size: clamp(19px, 2.2vw, 23px);
    font-weight: 400;
    line-height: 1.3;
    color: #fff;
}

.lib-drawer-title:focus {
    outline: none;
}

.lib-drawer-info {
    margin: 0 0 8px;
    color: rgba(210, 218, 236, .84);
    font-size: 14px;
    font-weight: 300;
    line-height: 1.65;
}

.lib-drawer-count {
    display: block;
    font-family: 'Outfit', sans-serif;
    font-size: 11.5px;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: rgba(239, 189, 114, .75);
}

.lib-close {
    appearance: none;
    -webkit-appearance: none;
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    border: 1px solid rgba(210, 222, 255, .18);
    background: rgba(255, 255, 255, .04);
    color: rgba(220, 228, 246, .85);
    font-size: 17px;
    line-height: 1;
    transition: border-color .22s, background .22s, color .22s;
}

.lib-close:hover {
    border-color: rgba(239, 189, 114, .5);
    background: rgba(239, 189, 114, .1);
    color: #fff;
}

.lib-close:focus-visible {
    outline: 2px solid rgba(239, 189, 114, .6);
    outline-offset: 3px;
}

/* ---------------------------------------------------------------- *
 * The pieces themselves
 * ---------------------------------------------------------------- */

/* A single column, capped so the description keeps a comfortable line length
   even when the panel spans a wide screen. */
.lib-tracks {
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-width: 920px;
}

.lib-track {
    display: flex;
    gap: 18px;
    padding: 16px;
    border-radius: 16px;
    border: 1px solid rgba(210, 222, 255, .12);
    background: rgba(255, 255, 255, .03);
    transition: border-color .25s, background .25s;
}

.lib-track:hover {
    border-color: rgba(239, 189, 114, .3);
    background: rgba(239, 189, 114, .05);
}

.lib-track-art {
    position: relative;
    flex: 0 0 104px;
    width: 104px;
    height: 104px;
    border-radius: 12px;
    overflow: hidden;
    background: radial-gradient(ellipse at 30% 0%, rgba(239, 189, 114, .2), transparent 58%),
                linear-gradient(165deg, rgba(38, 30, 66, .9), rgba(10, 13, 30, .95));
    border: 1px solid rgba(239, 189, 114, .18);
}

.lib-track-art img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Tracks without artwork keep the same footprint so the column stays even. */
.lib-track-art.is-empty::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 24px;
    height: 1px;
    transform: translate(-50%, -50%);
    background: linear-gradient(90deg, transparent, rgba(239, 189, 114, .7), transparent);
}

.lib-track-body {
    flex: 1 1 auto;
    min-width: 0;
}

.lib-track-title {
    margin: 0 0 8px;
    font-family: 'Outfit', sans-serif;
    font-size: 16px;
    font-weight: 500;
    line-height: 1.35;
    color: #fff;
}

.lib-track-about {
    margin: 0;
    max-width: 66ch;
    color: rgba(200, 210, 235, .8);
    font-size: 13.5px;
    font-weight: 300;
    line-height: 1.62;
}

.lib-track-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.lib-tag {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    border: 1px solid rgba(210, 222, 255, .16);
    background: rgba(255, 255, 255, .04);
    font-family: 'Outfit', sans-serif;
    font-size: 11px;
    font-weight: 400;
    letter-spacing: .04em;
    color: rgba(210, 220, 242, .82);
}

.lib-tag.is-premium {
    border-color: rgba(239, 189, 114, .42);
    background: rgba(239, 189, 114, .1);
    color: rgba(245, 212, 160, .96);
}

/* Alternate which side the artwork sits on so a long collection does not read
   as one uniform column of thumbnails down the left edge. */
@media (min-width: 620px) {
    .lib-track:nth-child(even) {
        flex-direction: row-reverse;
    }

    .lib-track:nth-child(even) .lib-track-about {
        margin-left: auto;
    }
}

/* ---------------------------------------------------------------- *
 * Loading, empty and error states
 * ---------------------------------------------------------------- */

.lib-state {
    margin: 0;
    padding: 14px 2px;
    color: rgba(200, 210, 235, .72);
    font-size: 14px;
    font-weight: 300;
}

.lib-skeleton-card {
    height: 136px;
    border-radius: 16px;
    border: 1px solid rgba(210, 222, 255, .1);
    background: linear-gradient(100deg, rgba(255, 255, 255, .03) 30%, rgba(255, 255, 255, .07) 50%, rgba(255, 255, 255, .03) 70%);
    background-size: 220% 100%;
    animation: libShimmer 1.3s linear infinite;
}

@keyframes libShimmer {
    from { background-position: 180% 0; }
    to   { background-position: -40% 0; }
}

/* ---------------------------------------------------------------- *
 * Responsive
 * ---------------------------------------------------------------- */

@media (max-width: 760px) {
    .lib-drawer-inner {
        padding: 17px 14px 15px;
        border-radius: 15px;
    }

    .lib-drawer-head {
        margin-bottom: 14px;
    }

    .lib-drawer-info {
        font-size: 13.5px;
        line-height: 1.6;
    }

    .lib-track {
        gap: 13px;
        padding: 13px;
        border-radius: 14px;
    }

    .lib-track-art {
        flex-basis: 76px;
        width: 76px;
        height: 76px;
        border-radius: 10px;
    }

    .lib-track-title {
        font-size: 15px;
    }

    .lib-track-about {
        font-size: 13px;
        line-height: 1.58;
    }

    .lib-path-meta {
        margin-top: 8px;
        font-size: 11px;
    }

    /* The arrow affordance is hover-driven, so it earns nothing on touch
       until the collection is actually open. */
    .iw-path.is-openable:not(.is-open)::after,
    .rest-path.is-openable:not(.is-tile):not(.is-open)::after {
        display: none;
    }
}

/* On a phone, artwork beside a full paragraph leaves a column too narrow to
   read — roughly two words per line. Keep the thumbnail next to the title,
   which is short, and give the paragraph the full width underneath.
   .lib-track-body becomes display:contents so its children can be placed on
   the card's own grid; grid placement handles the ordering, so a track with
   no tags or no description still lays out correctly. */
@media (max-width: 560px) {
    .lib-track {
        display: grid;
        grid-template-columns: 56px minmax(0, 1fr);
        column-gap: 12px;
        row-gap: 9px;
        align-items: center;
    }

    .lib-track-body {
        display: contents;
    }

    .lib-track-art {
        grid-column: 1;
        grid-row: 1;
        flex: none;
        width: 56px;
        height: 56px;
    }

    .lib-track-title {
        grid-column: 2;
        grid-row: 1;
        margin: 0;
    }

    .lib-track-tags {
        grid-column: 1 / -1;
        grid-row: 2;
        margin-bottom: 0;
    }

    .lib-track-about {
        grid-column: 1 / -1;
        max-width: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .lib-drawer {
        transition: none;
    }

    .lib-track,
    .lib-close,
    .iw-path.is-openable::after,
    .rest-path.is-openable:not(.is-tile)::after {
        transition: none;
    }

    .lib-skeleton-card {
        animation: none;
    }
}
