/* ===========================================================================
   Algorithm-set cards

   Shared by:
     • /algs                       (cards generated in app/static/js/algs.js)
     • /profile/<user>/algs        (same renderer)
     • /profile/<user>             (algorithm carousel)

   The artwork sits directly on the card — no thumbnail tile behind it — with
   the set name, known/total + percentage and a thin progress bar underneath.
   Loaded after surface-cards.css so it can refine the shared .algset-card
   surface treatment for these pages.
   =========================================================================== */

.algset-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 156px;
    flex: 0 0 156px;
    padding: 0.8rem 0.75rem 0.7rem;
    border-radius: 14px !important;
    border: 1px solid var(--card-item-border, var(--border-color)) !important;
    background: var(--card-item-bg, var(--card-bg)) !important;
    box-shadow: var(--card-item-shadow, 0 2px 12px var(--shadow-sm)) !important;
    color: var(--text-color);
    text-decoration: none;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.algset-card:hover {
    transform: translateY(-2px);
    border-color: color-mix(in srgb, var(--accent-color) 45%, var(--border-color)) !important;
    background: var(--card-item-bg, var(--card-bg)) !important;
    box-shadow: 0 10px 24px -14px var(--shadow) !important;
}

.algset-card:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* Artwork: transparent, no tile/box behind it. */
.algset-card__figure {
    display: grid;
    place-items: center;
    width: 60px;
    height: 60px;
    flex: 0 0 60px;
    margin: 0.08rem 0 0.4rem;
}

.algset-card__figure img,
.algset-card__figure canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.algset-card__name {
    width: 100%;
    font-size: 0.8rem;
    font-weight: 700;
    line-height: 1.25;
    text-align: center;
    color: var(--text-color);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.algset-card__meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    margin-top: 0.38rem;
    font-size: 0.66rem;
    font-weight: 600;
    line-height: 1.2;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.algset-card__meta span {
    white-space: nowrap;
}

.algset-card__progress {
    display: flex;
    width: 100%;
    height: 4px;
    margin-top: 0.25rem;
    border-radius: 999px;
    background: var(--bg-tertiary);
    overflow: hidden;
}

.algset-card__progress .progress-bar {
    display: block;
    height: 100%;
    border-radius: 999px;
    background-color: var(--accent-color) !important;
}

/* A card without a generated image should still line up with its neighbours. */
.algset-card__figure:empty {
    min-height: 60px;
}

/* The description "?" trigger stays in the top-right corner of the card. */
.algset-card .algset-creds-trigger,
.algset-card .algset-desc-trigger {
    top: 0.4rem;
    right: 0.4rem;
}

/* ---------------------------------------------------------------------------
   Subset pickers (ZBLL / ZBLS / COLL etc.)

   The modal used Bootstrap columns, which could squeeze cards narrow enough
   for the count and percentage to collide. Use a real responsive grid and cap
   the cards slightly below the main card width instead.
   --------------------------------------------------------------------------- */
/* Two IDs so these rules also win over the older #subsetModal layout rules in
   subset-modal.css, which is loaded before this file on /algs. */
#subsetModal #subsetGrid {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.8rem;
    margin: 0 !important;
}

/* Neutralise the per-entry Bootstrap column classes; the grid owns the layout. */
#subsetModal #subsetGrid > div {
    width: auto !important;
    max-width: none !important;
    flex: none !important;
    padding: 0 !important;
    margin: 0 !important;
}

#subsetModal #subsetGrid .algset-card {
    width: 100%;
    max-width: 150px;
    margin-inline: auto;
}

/* Keep the artwork inside the smaller figure box instead of subset-modal.css's
   fixed 64px image size. */
#subsetModal #subsetGrid .algset-card__figure img,
#subsetModal #subsetGrid .algset-card__figure canvas,
#subsetModal #subsetGrid .algset-card__figure [data-zbll-image-src] {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain;
}

/* ---------------------------------------------------------------------------
   Keep tall subset pickers (ZBLS especially) inside the viewport: the header
   stays put and only the card area scrolls.
   --------------------------------------------------------------------------- */
#subsetModal .modal-dialog {
    margin: 1rem auto !important;
    max-height: calc(100vh - 2rem);
    max-height: calc(100dvh - 2rem);
}

#subsetModal .modal-content {
    display: flex !important;
    flex-direction: column;
    max-height: calc(100vh - 2rem);
    max-height: calc(100dvh - 2rem);
    padding-left: 0 !important;
    padding-right: 0 !important;
    overflow: hidden;
}

#subsetModal .modal-header {
    flex: 0 0 auto;
}

#subsetModal .modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}

@media (max-width: 767.98px) {
    .algset-card {
        width: 148px;
        flex: 0 0 148px;
    }

    .algset-card__figure {
        width: 56px;
        height: 56px;
        flex-basis: 56px;
    }

    #subsetModal #subsetGrid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 0.6rem;
    }

    #subsetModal #subsetGrid .algset-card {
        max-width: 140px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .algset-card {
        transition-duration: 0.01ms;
    }
}
