/*
 * Default layout for the awesome_list hook's cards. It's loaded before any other extra_css,
 * so the theme can override the custom properties or any rule.
 */

.awesome-list {
    --awesome-list-border: rgba(128, 128, 128, 0.3);
    --awesome-list-tint: rgba(128, 128, 128, 0.1);
    --awesome-list-radius: 12px;
    --awesome-list-media-width: 200px;
    list-style: none;
    margin: 0 0 1.5rem;
    padding: 0;
}

/* Items that don't start with a link aren't entries, and keep a plain bullet */
.awesome-list > li:not(.awesome-entry, .awesome-subs) {
    list-style: disc;
    margin-left: 1.5em;
}

.awesome-entry {
    position: relative;
    display: grid;
    column-gap: 16px;
    /* Long names and domains would otherwise overflow narrow screens */
    overflow-wrap: anywhere;
}

.awesome-entry__header {
    grid-area: header;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0 10px;
}

.awesome-entry__title,
.awesome-subs .awesome-entry__sub > a {
    font-weight: 600;
}

/* Stretched over the entry or sub-entry, so the whole card is one click target */
.awesome-entry__title::after,
.awesome-subs .awesome-entry__sub > a::after {
    content: "";
    position: absolute;
    inset: 0;
}

/* Links in the description and sub-entries stay clickable above it */
.awesome-entry__desc a,
.awesome-entry__subs a {
    position: relative;
    z-index: 1;
}

.awesome-entry__favicon {
    width: 1em;
    height: 1em;
    margin-right: 0.35em;
    vertical-align: -0.125em;
}

.awesome-entry__domain {
    font-size: 0.8em;
    opacity: 0.75;
}

.awesome-entry__desc {
    grid-area: desc;
}

.awesome-entry__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: var(--awesome-list-tint);
    font-weight: 600;
}

.awesome-entry__subs {
    grid-area: subs;
    display: flex;
    flex-wrap: wrap;
    gap: 4px 8px;
    list-style: none;
    margin: 6px 0 0;
    padding: 0;
}

/* Shown as the link's tooltip instead */
.awesome-entry__sub-desc {
    display: none;
}

/*****************************************************************************/
/* "media" style: a card per entry, with the preview image on the left        */
/*****************************************************************************/
/* Gallery lists also have this class, so these rules style their cards too */
.awesome-list--media {
    display: flex;
    flex-direction: column;
    gap: 12px;
    container-type: inline-size;
}

.awesome-list--media .awesome-entry {
    grid-template-columns: var(--awesome-list-media-width) minmax(0, 1fr);
    /* The last row soaks up the image's extra height, so the text rows stay together */
    grid-template-rows: auto auto auto 1fr;
    grid-template-areas:
        "media header"
        "media desc"
        "media subs"
        "media .";
    padding: 12px;
    border: 1px solid var(--awesome-list-border);
    border-radius: var(--awesome-list-radius);
}

.awesome-list--media .awesome-entry__media,
.awesome-list--media .awesome-entry[data-image="none"] .awesome-entry__icon {
    grid-area: media;
    display: flex;
    align-items: center;
    justify-content: center;
    /* OpenGraph's recommended 1200x630 */
    aspect-ratio: 1.91 / 1;
    overflow: hidden;
    border-radius: calc(var(--awesome-list-radius) - 4px);
    background: var(--awesome-list-tint);
}

.awesome-list--media .awesome-entry__media img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Small images, kept at their own size so they aren't blurred by scaling up */
.awesome-list--media .awesome-entry[data-image="logo"] .awesome-entry__media img {
    width: auto;
    height: auto;
    max-width: 80%;
    /* 60% of the frame's height; WebKit ignores a percentage max-height in this frame */
    max-height: calc(var(--awesome-list-media-width) / 1.91 * 0.6);
}

.awesome-list--media .awesome-entry__icon {
    display: none;
}

/* A theme script can switch to "none" when an image fails to load in the browser */
.awesome-list--media .awesome-entry[data-image="none"] .awesome-entry__media {
    display: none;
}

.awesome-list--media .awesome-entry[data-image="none"] .awesome-entry__icon {
    font-size: 1.75em;
}

.awesome-list--media .awesome-entry[data-image="none"] .awesome-entry__icon img {
    width: 32px;
    height: 32px;
}

/* Galleries keep sub-entries in the card; media lists put them in smaller cards under it */
.awesome-list--gallery .awesome-entry__sub a {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    background: var(--awesome-list-tint);
    font-size: 0.85em;
}

.awesome-subs {
    padding-left: 24px;
}

.awesome-subs .awesome-entry__subs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr));
    gap: 6px;
    margin: 0;
}

.awesome-subs .awesome-entry__sub {
    position: relative;
    padding: 8px 10px;
    border: 1px solid var(--awesome-list-border);
    border-radius: calc(var(--awesome-list-radius) - 4px);
}

/* Not positioned, so its stretched link covers the card; description links stay above it */
.awesome-subs .awesome-entry__sub > a {
    position: static;
    display: block;
}

.awesome-subs .awesome-entry__sub-desc {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Narrow lists (phones, or tablets beside a sidebar) put the description under the image */
@container (max-width: 599px) {
    .awesome-list--media .awesome-entry {
        --awesome-list-media-width: 112px;
        grid-template-rows: auto;
        grid-template-areas:
            "media header"
            "desc desc"
            "subs subs";
        row-gap: 8px;
    }
}

/*****************************************************************************/
/* "gallery" style: media cards with the preview image on top, in columns     */
/*****************************************************************************/
/* Columns of at least 220px, and never more than four */
.awesome-list--gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, max(220px, (100% - 36px) / 4)), 1fr));
}

/* From two columns (2 x 220px and the gap), narrower lists keep the media layout */
@container (min-width: 452px) {
    .awesome-list--gallery .awesome-entry {
        --awesome-list-media-width: 200px;
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto auto auto 1fr;
        grid-template-areas:
            "media"
            "header"
            "desc"
            "subs";
        align-content: start;
        row-gap: 8px;
    }
}

/*****************************************************************************/
/* "index" style: compact rows with the site's favicon and no preview image   */
/*****************************************************************************/
.awesome-list--index .awesome-entry {
    grid-template-columns: 36px minmax(0, 1fr);
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
        "icon header"
        "icon desc"
        "icon subs";
    column-gap: 14px;
    padding: 12px 0;
    border-bottom: 1px solid var(--awesome-list-border);
}

.awesome-list--index .awesome-entry__media,
.awesome-list--index .awesome-entry__favicon {
    display: none;
}

.awesome-list--index .awesome-entry__icon {
    grid-area: icon;
    width: 36px;
    height: 36px;
}

.awesome-list--index .awesome-entry__icon img {
    width: 20px;
    height: 20px;
}

.awesome-list--index .awesome-entry__subs {
    gap: 2px 16px;
}

.awesome-list--index .awesome-entry__sub::before {
    content: "↳ ";
    opacity: 0.6;
}

/*****************************************************************************/
/* "shelf" style: covers side by side, with the details over the cover        */
/*****************************************************************************/
.awesome-list--shelf {
    --awesome-list-cover-height: 180px;
    --awesome-list-details-gap: 8px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-end;
    gap: 24px;
}

.awesome-list--shelf .awesome-entry,
.awesome-list--shelf .awesome-entry__media {
    display: block;
}

.awesome-list--shelf .awesome-entry__media img {
    display: block;
    width: auto;
    height: var(--awesome-list-cover-height);
}

.awesome-list--shelf .awesome-entry__icon {
    display: none;
}

/* Without an image, a plain cover with the favicon */
.awesome-list--shelf .awesome-entry[data-image="none"] .awesome-entry__icon {
    display: flex;
    width: calc(var(--awesome-list-cover-height) * 0.7);
    height: var(--awesome-list-cover-height);
}

.awesome-list--shelf .awesome-entry[data-image="none"] .awesome-entry__media {
    display: none;
}

.awesome-list--shelf .awesome-entry__details {
    position: absolute;
    z-index: 2;
    bottom: calc(100% + var(--awesome-list-details-gap));
    left: 50%;
    width: 260px;
    padding: 12px 14px;
    border: 1px solid var(--awesome-list-border);
    border-radius: var(--awesome-list-radius);
    background: Canvas;
    transform: translateX(-50%);
}

/* Keeps the pointer on the entry while it moves from the cover to the details */
.awesome-list--shelf .awesome-entry__details::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    height: var(--awesome-list-details-gap);
}

/* Out of sight, but still read out and focusable, until the entry is hovered, focused with the
   keyboard, or opened (a theme script can add awesome-entry--open, e.g. on a tap) */
@media (hover: hover) {
    .awesome-list--shelf .awesome-entry:not(:hover, .awesome-entry--open, :has(.awesome-entry__title:focus-visible)) .awesome-entry__details {
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
    }
}

/* Touch screens get no hover, which would stick to the last cover tapped */
@media (hover: none) {
    .awesome-list--shelf .awesome-entry:not(.awesome-entry--open, :has(.awesome-entry__title:focus-visible)) .awesome-entry__details {
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
    }
}
