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

/*
 * Theme overrides
 */

:root {
    --theme-font-size: 1.1rem;

    /* Background (see below) */
    --background-trace: color-mix(in srgb, var(--theme-primary) 10%, transparent);
    --background-pulse: color-mix(in srgb, var(--theme-primary) 70%, transparent);
}

/*
 * Material Icons: self-hosted (Apache License 2.0, see fonts/LICENSE-Material-Icons.txt), fetched from
 * Fontsource by "make fonts". The icons are ligatures, so the text stays hidden until the font is there
 * (font-display: block) instead of showing the names of the icons. The font is preloaded by index.html.
 */

@font-face {
    font-family: "Material Icons";
    font-style: normal;
    font-weight: 400;
    font-display: block;
    src: url("../fonts/material-icons-latin-400-normal.woff2") format("woff2");
}

.material-icons {
    display: inline-block;
    font-family: "Material Icons", fantasy;  /* The generic family is never used, the icons need the font */
    font-size: 24px;
    font-style: normal;
    font-weight: normal;
    font-feature-settings: "liga";
    line-height: 1;
    text-transform: none;
    letter-spacing: normal;
    overflow-wrap: normal;
    white-space: nowrap;
    direction: ltr;
    -webkit-font-smoothing: antialiased;
}

/*
 * Layout
 */

body {
    display: grid;
    grid-template-rows: auto 1fr;
}

/*
 * Background: circuit board traces with pulses of light travelling along them, generated by background.js.
 *
 * Every pulse is a short dash (6 % of its trace), moved along the trace by animating its offset to --end.
 */

.background-circuit {
    position: fixed;
    animation: background-circuit-appear 1.2s ease-out both;
    inset: 0;
    z-index: -1;
    width: 100%;
    height: 100%;
    mask-image: radial-gradient(ellipse at center, #000000 35%, transparent 90%);
    pointer-events: none;

    .trace,
    .via {
        stroke: var(--background-trace);
        stroke-width: 1.5;
    }

    .trace {
        fill: none;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    .via {
        fill: var(--theme-background);
    }

    .pulse {
        fill: none;
        stroke: var(--background-pulse);
        stroke-width: 2.5;
        stroke-linecap: round;
        stroke-dasharray: 6 100000;
        filter: drop-shadow(0 0 3px var(--background-pulse));
        animation: background-circuit-pulse linear infinite;
    }
}

@keyframes background-circuit-appear {
    from {
        opacity: 0;
    }
}

@keyframes background-circuit-pulse {
    from {
        stroke-dashoffset: 6;
    }

    to {
        stroke-dashoffset: var(--end);
    }
}

main {
    width: 100%;
    max-width: 90rem;
    margin-inline: auto;
    padding: var(--theme-space-xl) var(--theme-space-lg) var(--theme-space-2xl);
}

main > section {
    padding-block-start: var(--theme-space-2xl);
    scroll-margin-block-start: 4rem;
}

main h3 {
    margin-block: var(--theme-space-xl) var(--theme-space);
}

/*
 * Header
 */

header {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    flex-wrap: wrap;
    gap: var(--theme-space-sm) var(--theme-space-lg);
    align-items: center;
    justify-content: space-between;
    padding: var(--theme-space) var(--theme-space-lg);
    border-block-end: 1px solid var(--theme-border);
    background: color-mix(in srgb, var(--theme-background) 85%, transparent);
    backdrop-filter: blur(12px);
}

:where(header) .logo img {
    width: auto;
    height: 28px;
}

header .version {
    color: var(--theme-text-muted);
    font-family: var(--theme-font-mono);
    font-size: var(--theme-font-size-sm);
}

header nav {
    margin-inline-start: auto;
}

/* Mobile: the navigation collapses into a menu, toggled by a button */

.menu-toggle {
    display: none;
    place-items: center;
    margin-inline-start: auto;
    padding: var(--theme-space-xs);
    border: 0;
    border-radius: var(--theme-radius-sm);
    background: none;
    color: var(--theme-text);
    cursor: pointer;
}

.menu-toggle:hover {
    background: var(--theme-surface);
}

@media (width < 48rem) {
    .menu-toggle {
        display: grid;
    }

    header nav {
        display: none;
        flex-basis: 100%;
        max-height: calc(100dvh - 5rem);
        margin: 0;
        overflow-y: auto;
    }

    header.open nav {
        display: block;
    }

    header ul {
        flex-direction: column;
        gap: 0;
    }

    :where(header nav) a {
        display: block;
        padding: var(--theme-space-sm) 0;
    }
}

@media (width < 30rem) {
    header .version {
        display: none;
    }
}

header ul {
    display: flex;
    flex-wrap: wrap;
    gap: var(--theme-space-xs) var(--theme-space-lg);
    padding: 0;
    list-style: none;
}

:where(header nav) a {
    color: var(--theme-text);
    font-weight: var(--theme-font-weight-medium);
    text-decoration: none;
}

:where(header nav) a:hover {
    color: var(--theme-link-hover);
}

/*
 * 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);
}

.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);
}

/*
 * Colour swatches
 */

.colour-swatch {
    font-size: 0.75rem;
}

.colour-swatch.opaque {
    opacity: 0.5;
}

.colour-swatch.colour-10,
.colour-swatch.colour-20,
.colour-swatch.colour-30,
.colour-swatch.colour-40,
.colour-swatch.colour-50,
.colour-swatch.colour-black {
    color: var(--cd-white);
}

.colour-swatch.colour-60,
.colour-swatch.colour-70,
.colour-swatch.colour-80,
.colour-swatch.colour-90,
.colour-swatch.colour-100,
.colour-swatch.colour-white {
    color: var(--cd-black);
}

.colour-swatch:not(.colour-black, .colour-white) {
    cursor: pointer;
}

/* Size the palette so all families (10 swatches each) fit the screen height */

#colour-palette {
    width: min(100% - 2rem, (100dvh - 14.5rem) * 10 / var(--families) + 2 * var(--theme-space-lg) + 2px);
}

/* The specifications use most of the viewport width, to show more families per row */

#colour-specifications {
    width: calc(100% - 4rem);
}

#colour-palette-display {
    margin-block-start: var(--theme-space);

    .colour-family {
        display: grid;
        grid-template-columns: repeat(10, 1fr);
    }

    .colour-swatch {
        aspect-ratio: 1;
    }
}

#colour-specifications-display {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 11rem), 1fr));
    gap: var(--theme-space);
    margin-block-start: var(--theme-space);

    .colour-family {
        overflow: hidden;
        border-radius: var(--theme-radius-sm);
    }

    .colour-swatch {
        display: grid;
        grid-template-columns: 1fr auto;
        padding: var(--theme-space-sm);
    }
}

/*
 * Wallpapers
 */

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