/*
 * The libraries: the site's store at /library, browsed by shelf and by category,
 * and an account's own list at /account/library.
 */


/* --- the store's page ------------------------------------------------------- */

main.store {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.store .notice {
    margin: 0;
}

/* The admin's upload, boxed as the panel under it is. */
.store .add {
    padding: .9rem 1.5rem;
    background: var(--card);
    border: 1px solid var(--edge);
    border-radius: var(--radius);

    summary {
        cursor: pointer;
        font-weight: 600;
    }

    .stack {
        margin-top: 1rem;
    }

    @media (max-width: 640px) {
        padding: .9rem 1rem;
    }
}


/* --- the store's panel ------------------------------------------------------ */

/* While the next contents are on their way, the old ones dim. After a beat, so an
   answer that comes back at once does not flicker. */
.store .panel {
    > :not(.panel-head) {
        transition: opacity .2s ease;
    }

    &.htmx-request > :not(.panel-head) {
        opacity: .5;
        transition-delay: .1s;
    }
}


/* --- tabs and refinements --------------------------------------------------- */

.tabs,
.segments {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;

    a {
        display: inline-flex;
        align-items: center;
        gap: .4rem;
        height: 34px;
        padding: 0 .9rem;
        font-size: .9rem;
        font-weight: 500;
        text-decoration: none;
        color: var(--muted);
        border: 1px solid var(--edge);
        border-radius: var(--radius);

        &[aria-current] {
            font-weight: 600;
            color: #ffffff;
            background: var(--track);
            border-color: var(--track);
        }
    }

    .count {
        font-family: var(--mono);
        font-size: .7rem;
        color: var(--muted);
    }
}

.refine {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;

    .sort {
        margin-left: auto;
    }
}


/* --- shelves ---------------------------------------------------------------- */

.shelf {
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.shelf-head {
    display: flex;
    align-items: baseline;
    gap: .75rem;

    h2 {
        margin: 0;
        font-size: 1.2rem;
    }

    a {
        margin-left: auto;
        font-size: .85rem;
        color: var(--muted);
    }
}

/* Sessions get the largest cards, three to a row; the rest four. */
.cards {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
}

.shelf.session .cards {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}


/* --- a card ----------------------------------------------------------------- */

.card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--card);
    border: 1px solid var(--edge);
    border-radius: var(--radius);
    overflow: hidden;

    .art {
        display: flex;
        background: var(--inset);
        border-bottom: 1px solid var(--edge);
    }

    /* A session's cover stands square beside its strips. */
    .cover {
        flex: none;
        width: 33%;
        aspect-ratio: 1;
        object-fit: cover;
    }

    .strips {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
        justify-content: center;

        img {
            display: block;
            width: 100%;
            aspect-ratio: 5;
        }
    }

    .piece {
        position: relative;
        margin: 0;

        figcaption {
            position: absolute;
            left: 4px;
            bottom: 4px;
            padding: 0 4px;
            font-family: var(--mono);
            font-size: .7rem;
            font-variant-numeric: tabular-nums;
            color: var(--muted);
            background: var(--inset);
            border-radius: 3px;
        }
    }

    /* A long session's pieces side by side, scrolled through freely. Each is a little
       narrower than the box and a thin bar runs under them, so both say there is more.
       A mouse drags the strip (strips.js). */
    .strips.scrolling {
        flex-direction: row;
        justify-content: flex-start;
        align-items: center;
        gap: 4px;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        scrollbar-width: thin;
        scrollbar-color: var(--track) transparent;
        cursor: grab;
        user-select: none;

        &.dragging {
            cursor: grabbing;
        }

        &:focus-visible {
            outline: 2px solid var(--accent);
            outline-offset: -2px;
        }

        .piece {
            flex: 0 0 90%;
        }
    }

    .glyph {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        aspect-ratio: 5 / 2;
        color: var(--track);

        svg {
            width: 40px;
            height: 40px;
            fill: none;
            stroke: currentColor;
            stroke-width: 2;
            stroke-linecap: round;
            stroke-linejoin: round;
        }
    }

    .body {
        display: flex;
        flex-direction: column;
        gap: .5rem;
        padding: .75rem;
    }

    .title {
        display: flex;
        align-items: center;
        gap: .5rem;
        min-width: 0;
    }

    .name {
        flex: 1;
        min-width: 0;
        font-weight: 600;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    input.name {
        height: 30px;
        padding: 0 .35rem;
        font: inherit;
        font-weight: 600;
        color: inherit;
        background: none;
        border: 1px solid transparent;
        border-radius: var(--radius);

        &:hover,
        &:focus {
            border-color: var(--track);
        }
    }

    .scope {
        flex: none;
        height: 20px;
        padding: 0 .45rem;
        font-size: .7rem;
        font-weight: 600;
        line-height: 18px;
        color: var(--muted);
        background: var(--inset);
        border: 1px solid var(--edge);
        border-radius: var(--radius);
    }

    .summary {
        font-size: .8rem;
        color: var(--muted);
    }

    .actions {
        display: flex;
        gap: .5rem;

        > .primary {
            flex: 1;
        }

        form {
            display: contents;
        }
    }
}


/* A download beside an open link: an arrow alone, since the open link carries the
   words and this is the way to take a session to the phone. As specific as the small
   button it also is, so that one's padding does not squeeze the arrow to a sliver. */
a.button.download {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    padding: 0;
    color: var(--muted);

    svg {
        width: 18px;
        height: 18px;
        fill: none;
        stroke: currentColor;
        stroke-width: 1.8;
        stroke-linecap: round;
        stroke-linejoin: round;
    }
}


/* --- a category's rows ------------------------------------------------------ */

.rows {
    display: flex;
    flex-direction: column;
    gap: .5rem;

    .card {
        flex-direction: row;
        align-items: center;

        .art {
            width: 240px;
            flex: none;
            border-bottom: 0;
            border-right: 1px solid var(--edge);
        }

        .body {
            flex: 1;
            flex-direction: row;
            align-items: center;
            flex-wrap: wrap;
        }

        /* The name, then what it is, in a line from the left; the actions keep the
           far end. */
        .title {
            flex: 0 1 auto;
            min-width: 0;
        }

        .summary {
            flex: 1;
            min-width: 0;
        }

        .actions > .primary {
            flex: none;
        }
    }
}


/* --- narrow ----------------------------------------------------------------- */

@media (max-width: 900px) {
    .cards,
    .shelf.session .cards {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .tabs {
        flex-wrap: nowrap;
        overflow-x: auto;

        a {
            flex: none;
        }
    }

    /* A shelf scrolls sideways rather than stacking, so every kind stays in reach. */
    .cards,
    .shelf.session .cards {
        display: flex;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        padding-bottom: .25rem;

        .card {
            flex: none;
            width: 78%;
            scroll-snap-align: start;
        }
    }

    .rows .card {
        flex-direction: column;
        align-items: stretch;

        .art {
            width: auto;
            border-right: 0;
            border-bottom: 1px solid var(--edge);
        }
    }

    .refine .sort {
        margin-left: 0;
    }
}


/* --- an account's own library --------------------------------------------- */

/* The page spaces its parts by a gap already. */
main.mine > .account-head {
    margin-bottom: 0;
}

/* A kind's heading and its rows, inside the panel. */
main.mine .group {
    display: flex;
    flex-direction: column;
    gap: .5rem;

    h3 {
        margin: 0;
    }
}

.drop {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 1rem 1.25rem;
    font-size: .9rem;
    color: var(--muted);
    border: 1px dashed var(--track);
    border-radius: var(--radius);

    &.over {
        border-color: var(--accent);
        background: var(--accent-soft);
    }

    > span {
        flex: 1;
        min-width: 14rem;
    }

    label.button {
        cursor: pointer;
    }
}

ul.library {
    margin: 0;
    padding: 0;
    list-style: none;

    li {
        display: flex;
        align-items: center;
        gap: .6rem;
        flex-wrap: wrap;
        min-height: 52px;
        padding: .35rem 0;
        border-top: 1px solid var(--edge);
    }

    .glyph svg,
    .pin svg {
        width: 18px;
        height: 18px;
        fill: none;
        stroke: currentColor;
        stroke-width: 1.8;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    .glyph {
        display: flex;
        color: var(--muted);
    }

    input.name {
        min-width: 11rem;
        height: 32px;
        padding: 0 .35rem;
        font: inherit;
        font-weight: 600;
        color: inherit;
        background: none;
        border: 1px solid transparent;
        border-radius: var(--radius);

        &:hover,
        &:focus {
            border-color: var(--track);
        }
    }

    .scope,
    .badge {
        height: 20px;
        padding: 0 .45rem;
        font-size: .7rem;
        font-weight: 600;
        line-height: 18px;
        color: var(--muted);
        background: var(--inset);
        border: 1px solid var(--edge);
        border-radius: var(--radius);
    }

    .label {
        font-size: .8rem;
        color: var(--muted);
    }

    .pin {
        width: 32px;
        padding: 0;
        color: var(--muted);

        &[aria-pressed="true"] {
            color: var(--accent);
            border-color: var(--accent);
        }
    }

    .more {
        position: relative;

        summary {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 32px;
            height: 32px;
            list-style: none;
            cursor: pointer;
            color: var(--muted);
            border: 1px solid var(--edge);
            border-radius: var(--radius);

            &::-webkit-details-marker {
                display: none;
            }
        }

        > div {
            position: absolute;
            right: 0;
            top: 36px;
            z-index: 2;
            display: flex;
            flex-direction: column;
            gap: .4rem;
            min-width: 9rem;
            padding: .5rem;
            background: var(--card);
            border: 1px solid var(--edge);
            border-radius: var(--radius);
        }
    }
}
