/**
 * Masterpieces (score 11): the showcase of a user's five per module (components/masterpiece/showcase, with
 * the arrange mode of js/components/masterpiece-order.js) and the swap dialog
 * (components/dialogs/masterpiece-swap, over the shared site dialogs). The gold tokens and the small marks
 * used on cards everywhere live in components/media-kit.css.
 */

/* ================== SHOWCASE ================== */
.masterpiece-showcase {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 196px));
    gap: 18px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.masterpiece-tile {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
}

.masterpiece-tile-link {
    display: flex;
    flex-direction: column;
    gap: 10px;
    text-decoration: none;
    color: inherit;
}

.masterpiece-tile-cover {
    border-radius: 10px;
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--masterpiece) 55%, transparent),
        0 18px 38px -18px color-mix(in srgb, var(--masterpiece) 60%, transparent);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.masterpiece-tile-cover img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.masterpiece-tile-link:hover .masterpiece-tile-cover,
.masterpiece-tile-link:focus-visible .masterpiece-tile-cover {
    transform: translateY(-3px);
    box-shadow: 0 0 0 2px var(--masterpiece), 0 22px 44px -18px color-mix(in srgb, var(--masterpiece) 75%, transparent);
}

/* Place in the showcase, in the corner of the cover */
.masterpiece-tile .masterpiece-rank {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 1;
}

.masterpiece-tile-name {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    font-size: 14px;
    font-weight: 600;
    line-height: 19px;
    color: var(--text-1);
}

.masterpiece-tile-link:hover .masterpiece-tile-name {
    color: var(--masterpiece);
}

/* A place the user has not filled yet */
.masterpiece-tile.is-open .masterpiece-tile-cover {
    aspect-ratio: 2 / 3;
    display: grid;
    place-content: center;
    gap: 8px;
    border: 1px dashed color-mix(in srgb, var(--masterpiece) 40%, var(--line-strong));
    background: color-mix(in srgb, var(--masterpiece) 5%, var(--surface-1));
    box-shadow: none;
    text-align: center;
    color: var(--text-2);
}

.masterpiece-tile.is-open .masterpiece-tile-cover i {
    font-size: 20px;
    color: color-mix(in srgb, var(--masterpiece) 60%, var(--text-2));
}

.masterpiece-tile.is-open .masterpiece-tile-cover span {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* Arrange mode (profile): the tiles drag, and the arrows under each cover move it one place */
.masterpiece-tile-moves {
    display: none;
    justify-content: center;
    gap: 8px;
    /* Level on every tile, whatever the length of the name above */
    margin-top: auto;
}

.masterpiece-showcase.is-arranging .masterpiece-tile-moves {
    display: flex;
}

.masterpiece-showcase.is-arranging .masterpiece-tile:not(.is-open) {
    cursor: grab;
}

.masterpiece-showcase.is-arranging .masterpiece-tile-link {
    cursor: inherit;
}

.masterpiece-showcase.is-arranging .masterpiece-tile-cover {
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--masterpiece) 70%, transparent);
}

.masterpiece-tile.is-dragging {
    opacity: 0.45;
}

.masterpiece-tile-move {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid var(--line-strong);
    border-radius: 50%;
    background: var(--surface-1);
    color: var(--text-1);
    font-size: 12px;
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease;
}

.masterpiece-tile-move:hover:not(:disabled),
.masterpiece-tile-move:focus-visible {
    border-color: var(--masterpiece);
    color: var(--masterpiece);
}

.masterpiece-tile-move:focus-visible {
    outline: 2px solid var(--masterpiece);
    outline-offset: 2px;
}

.masterpiece-tile-move:disabled {
    opacity: 0.35;
    cursor: default;
}

/* ================== SECTION (components/masterpiece/section) ================== */
.masterpiece-tab-count {
    margin-left: 7px;
    font-size: 12px;
    font-weight: 700;
    color: var(--masterpiece);
}

/* The intro (or how to get a first one) and the owner's "Arrange" switch, on one row */
.masterpiece-panel-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 20px;
    min-height: 34px;
    margin: -4px 0 20px;
}

.masterpiece-section-intro {
    flex: 1 1 320px;
    margin: 0;
    font-size: 14px;
    line-height: 21px;
    color: var(--text-2);
}

/* The switch and, beside it, where the saved order is announced */
.masterpiece-section-tools {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-left: auto;
}

.masterpiece-order-status {
    margin: 0;
    font-size: 13px;
    color: var(--masterpiece);
}


/* ================== SWAP DIALOG ================== */
.site-dialog.masterpiece-swap {
    --tone: var(--masterpiece);
    /* Over the add-to-library modal, which opens it */
    z-index: 10050;
}

.masterpiece-swap .site-dialog-panel {
    width: min(520px, 100%);
}

.masterpiece-swap .site-dialog-icon {
    background: var(--masterpiece-gradient);
    color: var(--on-masterpiece);
}

.masterpiece-swap-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 20px 0 4px;
    padding: 0;
    list-style: none;
}

.masterpiece-swap-row {
    display: grid;
    grid-template-columns: auto 40px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 8px 10px 8px 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: color-mix(in srgb, var(--surface-2) 60%, transparent);
}

.masterpiece-swap-cover {
    width: 40px;
    border-radius: 5px;
}

.masterpiece-swap-cover img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.masterpiece-swap-cover .poster-fallback-title {
    font-size: 7px;
}

.masterpiece-swap-name {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 14px;
    font-weight: 600;
    color: var(--dialog-text, var(--text-1));
}

/* ================== RESPONSIVE ================== */
@media (max-width: 991.98px) {
    .masterpiece-showcase {
        grid-template-columns: none;
        grid-auto-flow: column;
        grid-auto-columns: 132px;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        scroll-snap-type: x proximity;
        padding-bottom: 6px;
    }

    .masterpiece-tile {
        scroll-snap-align: start;
    }
}

@media (max-width: 575.98px) {
    .masterpiece-swap-row {
        grid-template-columns: 40px minmax(0, 1fr) auto;
    }

    .masterpiece-swap-row .masterpiece-rank {
        display: none;
    }
}
