/*
 * Styles of the assets index page, built on top of theme.css & frame.css.
 */

/*
 * Cards & buttons
 */

/* Up to 4 cards per row, at least 16rem wide each (or the full width) */

.cards {
    --gap: var(--theme-space);

    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, max(16rem, (100% - 3 * var(--gap)) / 4)), 1fr));
    gap: var(--gap);
    margin-block-start: var(--theme-space);
}

.card {
    display: flex;
    flex-direction: column;
    gap: var(--theme-space);
    padding: var(--theme-space-lg);
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius);

    /* Slightly translucent, with the background blurred behind it */
    background: color-mix(in srgb, var(--theme-surface) 60%, transparent);
    backdrop-filter: blur(8px);
}

.card p {
    flex-grow: 1;
}

.card > code,
.code-block > code {
    display: block;
    padding: var(--theme-space-sm) var(--theme-space);
    overflow-wrap: anywhere;
    white-space: pre-wrap;
    background: var(--theme-background);
}

/* Code snippets with a copy button (added by script.js) */

.code-block {
    position: relative;
}

.code-block > code {
    padding-inline-end: 2.75rem;
}

/* The ASCII icons are small, so all five fit on one line */

.cards.ascii-icons {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, max(10rem, (100% - 4 * var(--gap)) / 5)), 1fr));
}

/*
 * ASCII art: the lines must not wrap & sit tightly on top of each other. Every
 * preview is the same small size, whatever its --columns: the font is sized so
 * the art is --art-width wide (a character is --glyph em wide: about 0.6 in a
 * monospace font, more for braille, which comes from a fallback font), and the
 * art is centred.
 */

.ascii-icon .code-block {
    --art-width: 7rem;
    --glyph: 0.62;

    container-type: inline-size;
}

.ascii-icon.braille .code-block {
    --glyph: 0.71;
}

.ascii-icon .code-block > code {
    overflow-x: auto;
    padding-inline: max(var(--theme-space), calc((100cqi - var(--art-width)) / 2));
    font-size: calc(var(--art-width) / var(--columns) / var(--glyph));
    line-height: 1;
    overflow-wrap: normal;
    white-space: pre;
}

.copy-button {
    position: absolute;
    top: var(--theme-space-xs);
    right: var(--theme-space-xs);
    display: grid;
    place-items: center;
    padding: var(--theme-space-xs);
    border: 0;
    border-radius: var(--theme-radius-sm);
    background: none;
    color: var(--theme-text-muted);
    cursor: pointer;
    transition: background-color var(--theme-transition), color var(--theme-transition);
}

.copy-button:hover {
    background: var(--theme-surface);
    color: var(--theme-text);
}

.copy-button .material-icons {
    font-size: 1.125rem;
}

@media (width >= 40rem) {
    .card.wide {
        grid-column: span 2;
    }
}

.actions,
.card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--theme-space-sm);
}

.actions {
    margin-block-start: var(--theme-space);
}

.button {
    display: inline-flex;
    gap: var(--theme-space-xs);
    align-items: center;
    padding: var(--theme-space-xs) var(--theme-space-sm);
    border-radius: var(--theme-radius-sm);
    background: var(--theme-primary);
    color: var(--theme-primary-contrast);
    font-size: var(--theme-font-size-sm);
    font-weight: var(--theme-font-weight-semibold);
    text-decoration: none;
    transition: background-color var(--theme-transition);
}

.button:hover {
    background: var(--theme-primary-hover);
    color: var(--theme-primary-contrast);
}

button.button {
    border: 0;
    cursor: pointer;
}

.button .material-icons {
    font-size: 1.25em;
}

/*
 * Modals
 */

body:has(.modal[open]) {
    overflow: hidden;
}

.modal {
    width: min(100% - 2rem, 72rem);
    max-width: none;
    max-height: calc(100dvh - 2rem);
    padding: 0;
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius-lg);
    background: var(--theme-surface-raised);
    color: var(--theme-text);
    box-shadow: var(--theme-shadow);
}

.modal::backdrop {
    background: rgb(0 0 0 / 60%);
    backdrop-filter: blur(4px);
}

.modal-header {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    gap: var(--theme-space);
    align-items: center;
    justify-content: space-between;
    padding: var(--theme-space) var(--theme-space-lg);
    border-block-end: 1px solid var(--theme-border);
    background: var(--theme-surface-raised);
}

.modal-header h2 {
    font-size: var(--theme-font-size-xl);
}

/* No flow margins in the header (e.g. the theme's after a heading): the title & the close button align */
.modal-header > * {
    margin: 0;
}

.modal-close {
    display: grid;
    place-items: center;
    padding: var(--theme-space-xs);
    border: 0;
    border-radius: var(--theme-radius-round);
    background: none;
    color: inherit;
    cursor: pointer;
    transition: background-color var(--theme-transition);
}

.modal-close:hover {
    background: var(--theme-border);
}

.modal-body {
    padding: var(--theme-space-lg);
}

.modal-hint {
    color: var(--theme-text-muted);
    font-size: var(--theme-font-size-sm);
}

/*
 * Logos
 */

/* A light & a dark variant per logo: side by side, or stacked on small screens */

.logo-usage {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
    margin-block-start: var(--theme-space-lg);
    overflow: hidden;
    border-radius: var(--theme-radius);
}

.logo-variant {
    display: flex;
    flex-direction: column;
    gap: var(--theme-space);
    align-items: center;
    padding: var(--theme-space-lg);

    &.light {
        background: var(--cd-grey-90);
        color: var(--cd-grey-20);
    }

    &.dark {
        background: var(--cd-grey-20);
        color: var(--cd-grey-90);
    }

    img {
        width: auto;
        height: 30px;
    }
}

.logo-versions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--theme-space-sm);
    justify-content: center;
    margin: 0;
}

/* Icon variants: the icon on a light & a dark background, its usage and downloads */

.icon-variant {
    align-items: center;
    text-align: center;
}

.icon-variant-preview {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
    overflow: hidden;
    border-radius: var(--theme-radius-sm);

    > span {
        display: grid;
        place-items: center;
        padding: var(--theme-space-lg);
    }

    .light {
        background: var(--cd-grey-90);
    }

    .dark {
        background: var(--cd-grey-20);
    }

    img {
        width: auto;
        height: 48px;
    }
}

/* A segmented chip per file type: the type, followed by one link per size */

/* Long chips (e.g. many wallpaper sizes) wrap on small screens. The radius matches the line height, so a
   single-line chip is still a pill, while a wrapped one becomes a rounded box. */

.download {
    display: inline-flex;
    flex-wrap: wrap;
    max-width: 100%;
    overflow: hidden;
    border-radius: 0.9em;
    background: color-mix(in srgb, currentcolor 12%, transparent);
    color: inherit;
    font-size: var(--theme-font-size-sm);
    line-height: 1.8;
    text-decoration: none;
    transition: background-color var(--theme-transition), color var(--theme-transition);
}

.download .filetype {
    padding-inline: 0.75em 0.5em;
    font-weight: var(--theme-font-weight-semibold);
}

a.download .filetype {
    padding-inline: 0.75em;
}

.download a {
    padding-inline: 0.5em;
    border-inline-start: 1px solid color-mix(in srgb, currentcolor 20%, transparent);
    color: inherit;
    text-decoration: none;
    transition: background-color var(--theme-transition), color var(--theme-transition);
}

.download a:last-child {
    padding-inline-end: 0.75em;
}

a.download:hover,
.download a:hover {
    background: var(--theme-primary);
    color: var(--theme-primary-contrast);
}

/*
 * Wallpapers
 */

.wallpaper img {
    width: 100%;
    border-radius: var(--theme-radius-sm);
}

/* The card of the asset studio, among the icon variants: its icon */
.studio-card-preview {
    display: grid;
    place-items: center;
    width: 100%;
    padding: var(--theme-space-lg);
}

/* Laid out as high as the icons of the other variants (.icon-variant-preview img), but drawn bigger: the scale
   takes no room, so the text & the card stay put */
.studio-card-icon {
    width: 48px;
    height: 48px;
    transform: scale(1.75);
}

.studio-card-hint {
    color: var(--theme-text-muted);
    font-size: var(--theme-font-size-sm);
}

.studio-card-link {
    display: inline-flex;
    gap: var(--theme-space-xs);
    align-items: center;
    color: var(--cd-orange-70);
    font-weight: var(--theme-font-weight-semibold);
    text-decoration: none;
    transition: color var(--theme-transition);

    &:hover {
        color: var(--cd-orange-80);
    }

    .material-icons {
        font-size: 1.2em;
    }
}

/* The controller icon, which opens the arcade for those who have signed in (see launcher.js) */
.arcade-launcher {
    position: fixed;
    right: var(--theme-space);
    bottom: var(--theme-space);
    z-index: 5;
    padding: var(--theme-space-sm);
    line-height: 0;
    color: var(--theme-text-muted);
    cursor: pointer;
    background: var(--theme-background);
    border: 1px solid var(--theme-border, currentcolor);
    border-radius: 50%;
    opacity: 0.6;
    transition: opacity 150ms, color 150ms;

    &:hover,
    &:focus-visible {
        color: var(--theme-primary);
        opacity: 1;
    }
}
