/*
 * The frame of the pages of the site (the index, the theme page & the asset studio), built on top of
 * theme.css: the fonts, the layout, the circuit background (see background.js) & the header with its menu
 * (see frame.js).
 */

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

/* Behind a modal dialog (the arcade & its games) it isn't seen, so it isn't painted either: 50 glowing pulses cost a lot of frames */
html:has(dialog:modal) .background-circuit {
    visibility: hidden;
}

@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);
    scroll-margin-block-start: 4rem;  /* Below the sticky header, when linked (e.g. #icon-variants) */
}

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

/* A submenu of the header: a dropdown on hover (or focus), indented in the mobile menu */

header nav li {
    position: relative;
}

.submenu-arrow {
    font-size: 1.1em;
    vertical-align: -0.2em;
}

header .submenu {
    position: absolute;
    top: 100%;
    left: calc(-1 * var(--theme-space));
    display: none;
    flex-direction: column;
    gap: 0;
    min-width: 12rem;
    margin-block-start: var(--theme-space-sm);
    padding: var(--theme-space-sm) var(--theme-space);
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius);
    background: var(--theme-surface-raised);
    box-shadow: var(--theme-shadow);

    /* A bridge over the gap, so the dropdown stays open on the way down to it */
    &::before {
        position: absolute;
        inset: calc(-1 * var(--theme-space-sm)) 0 auto;
        height: var(--theme-space-sm);
        content: "";
    }

    a {
        display: block;
        padding-block: var(--theme-space-xs);
    }
}

/* The parent: a button which looks like the links (a tap opens it, for touch screens without hover) */
.submenu-toggle {
    padding: 0;
    border: 0;
    background: none;
    color: var(--theme-text);
    font: inherit;
    font-weight: var(--theme-font-weight-medium);
    cursor: pointer;

    &:hover {
        color: var(--theme-link-hover);
    }
}

header .has-submenu:hover > .submenu,
header .has-submenu:focus-within > .submenu,
header .has-submenu.open > .submenu {
    display: flex;
}

@media (width < 48rem) {
    .submenu-arrow {
        display: none;
    }

    header .submenu {
        position: static;
        display: flex;
        min-width: 0;
        margin: 0;
        padding: 0 0 0 var(--theme-space);
        border: 0;
        background: none;
        box-shadow: none;

        &::before {
            content: none;
        }
    }
}
