/* Property order: custom props → display/flex → z-index, position → sizing → spacing → typography → colors/borders → rest */


/* ======= */
/*  Fonts  */
/* ======= */
/* Libre Bodoni, self-hosted (SIL Open Font License, see /fonts/OFL.txt). A browser
   only downloads the latin-ext file when a page uses one of its characters. */
@font-face {
    font-family: 'Libre Bodoni';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url("/fonts/libre-bodoni-latin.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: 'Libre Bodoni';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url("/fonts/libre-bodoni-latin-ext.woff2") format("woff2");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
    font-family: 'Libre Bodoni';
    font-style: italic;
    font-weight: 400 700;
    font-display: swap;
    src: url("/fonts/libre-bodoni-italic-latin.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: 'Libre Bodoni';
    font-style: italic;
    font-weight: 400 700;
    font-display: swap;
    src: url("/fonts/libre-bodoni-italic-latin-ext.woff2") format("woff2");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ========== */
/*  Defaults  */
/* ========== */

@layer defaults {
    * {
        box-sizing: border-box;
    }

    html {
        --hairline: color-mix(in oklab, var(--clr-text) 15%, transparent);

        font-family: var(--font-body);
        background: var(--clr-bg);
        color: var(--clr-text);
        scrollbar-gutter: stable;
    }

    body {
        min-height: 100dvh;
        overflow-x: hidden;
        margin: 0;
        background: var(--clr-bg);
        text-rendering: optimizeLegibility;
    }

    ::selection {
        background-color: var(--clr-selection);
    }

    a {
        text-decoration-color: var(--clr-accent);
        color: var(--clr-text);

        &[href*="://"]::before {
            content: "↗ ";
        }

        &:hover {
            text-decoration: underline;
        }
    }

    h1, h2, h3 {
        margin: 0;
        font-family: var(--font-head);
        font-weight: 500;
        line-height: var(--lh-head);
        color: var(--clr-text-highlight);

        em {
            color: var(--clr-accent);
        }
    }

    h1 {
        font-size: var(--fs-h1);
    }

    h2 {
        font-size: var(--fs-h2);
    }

    h3 {
        font-size: var(--fs-h3);
    }

    em {
        color: var(--clr-text-highlight);
    }

    figure {
        margin: 0;

        img {
            max-width: 100%;
            border-radius: var(--radius-s);
        }
    }

    figcaption {
        display: flex;
        justify-content: space-between;
        margin-top: var(--space-xs);
        font-size: var(--fs-meta);
        color: var(--clr-text-muted);
    }

    img {
        object-fit: cover;
    }

    .link-button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: var(--space-2xs) var(--space);
        border-radius: var(--radius);
        text-decoration: none;
        transition: var(--dur-s) var(--ease-out);

        &.-cta {
            --color: var(--clr-cta);
            color: contrast-color(var(--color));

            border: 2px solid var(--color);
            background: color-mix(in srgb, var(--color), transparent 50%);
            text-decoration: none;

            &:hover {
                background: color-mix(in srgb, var(--color), transparent 30%);
            }

            &:active {
                background: var(--color);
            }
        }
    }

    /* Sits in a bottom-right corner and curves into the content around it. */
    ._notch {
        --r: var(--radius-l);
        --s: var(--radius-xl);
        --notch-padding: calc(var(--r) + var(--s) / (sqrt(2) * 2));

        display: inline-block;
        z-index: 1;
        box-sizing: content-box;
        background: var(--clr-bg);
        border: solid transparent;
        border-width: var(--notch-padding) 0 0 var(--notch-padding);
        border-radius: 0;
        transform: translate(0.5px, 0.5px);
        clip-path: shape(
            from 100% 100%,
            hline to 0,
            arc to var(--r) calc(100% - var(--r)) of var(--r) ccw,
            vline to calc(var(--r) + var(--s)),
            arc to calc(var(--r) + var(--s)) var(--r) of var(--s) cw,
            hline to calc(100% - var(--r)),
            arc to 100% 0 of var(--r) ccw,
            close
        );
    }
}

/* ===== */
/*  Nav  */
/* ===== */
.nav-bar {
    display: flex;
    height: var(--nav-height);
    user-select: none;
    backdrop-filter: blur(15px);

    &.-static {
        background: var(--clr-surface);
        transition: background var(--dur-s) var(--ease);
    }

    &.-fixed {
        z-index: 1;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        background: var(--clr-bg);
        opacity: 0;
        transform: translateY(-100%);
        transition:
            transform var(--dur) var(--ease),
            opacity var(--dur) var(--ease-out),
            background var(--dur-s) var(--ease);
        will-change: transform, opacity;
    }

    &.-fixed.-visible {
        opacity: 1;
        transform: translateY(0);
    }

    > .nav-logo {
        margin-right: auto;
    }

    > .toggle {
        display: none;
        align-items: center;
        justify-content: center;
        height: 100%;
        aspect-ratio: 1;
        font-size: var(--fs-h3);
        text-decoration: none;
        cursor: pointer;
    }
    > .tab {
        --tab-width: 8rem;

        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        min-width: var(--nav-height);
        width: var(--tab-width);
        padding: var(--space-2xs) 0;
        text-decoration: none;

        &.-highlighted {
            width: calc(var(--tab-width) + var(--space));
            background: var(--clr-accent);

            &::after {
                position: absolute;
                right: var(--space-xs);
                content: "➔";
            }
        }

        &.-current {
            box-shadow: inset 0 calc(-1 * var(--border-width)) 0 0 var(--clr-accent);
        }
    }

    /* Mirrors the logo's inset on the other side. */
    > .lang-select {
        margin-right: var(--space);
    }

    @media (width <= 768px) {
        > .toggle {
            display: flex;
        }

        > .tab,
        > .lang-select {
            display: none;
        }
    }
}

/* Scrolling past this marker reveals the fixed nav. */
.nav-sentinel {
    position: absolute;
    top: 60dvh;
    inset-inline: 0;
    height: 1px;
    pointer-events: none;
}

.nav-logo {
    display: inline-block;
    height: 100%;
    aspect-ratio: 4;
    padding: var(--nav-padding) var(--space);
    text-decoration: none;

    &::before {
        display: block;
        width: 100%;
        height: 100%;
        background-color: currentColor;
        content: "";
        mask: var(--url-logo-simple) center / contain no-repeat;
    }
}

.lang-select {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: var(--nav-height);
    padding: 0;
    font: inherit;
    color: var(--clr-text);
    background: transparent;
    border: none;
    cursor: pointer;

    > .label {
        display: inline-flex;
        align-items: center;
        gap: var(--nav-padding);
        padding: var(--nav-padding) var(--space-2xs);
        border: 1px solid rgb(from var(--clr-text) r g b / 50%);
        border-radius: var(--radius-s);
        transition: background var(--dur-s) var(--ease);
    }

    > .label > .caret {
        font-size: 0.5em;
        color: var(--clr-text-disabled);
    }

    &:hover > .label {
        background: rgb(from var(--clr-bg) r g b / 65%);
    }
}

/* Inherits the nav's text size; at least as wide as the button. */
.lang-popover {
    position: fixed;
    inset: auto;
    min-width: var(--nav-height);
    margin: 0;
    padding: var(--nav-padding);
    background: rgb(from var(--clr-bg) r g b / 96%);
    border: 1px solid rgb(from var(--clr-text) r g b / 50%);
    border-radius: var(--radius-s);
    box-shadow: 0 4px 12px rgb(from var(--clr-prm-d) r g b / 8%);
    opacity: 0;
    transform: translateY(-2px);
    transition:
        opacity var(--dur-s) var(--ease),
        transform var(--dur-s) var(--ease),
        display var(--dur-s) var(--ease) allow-discrete,
        overlay var(--dur-s) var(--ease) allow-discrete;

    &:popover-open {
        opacity: 1;
        transform: translateY(0);
    }

    @starting-style {
        &:popover-open {
            opacity: 0;
            transform: translateY(-2px);
        }
    }

    > .option {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: var(--nav-padding) var(--space-2xs);
        text-decoration: none;
        border-radius: var(--radius-s);
        transition: background var(--dur-s) var(--ease);

        &:hover {
            background: rgb(from var(--clr-text) r g b / 10%);
        }
    }
}

/* ========= */
/*  Sidebar  */
/* ========= */
/* Wide enough for the longest item; always leaves a strip of page to tap to close. */
.sidebar-drawer {
    display: flex;
    flex-direction: column;
    z-index: 3;
    position: fixed;
    inset: var(--space-xs) auto var(--space-xs) 0;
    width: min(20ch, 100% - var(--nav-height));
    overflow: hidden;
    font-size: var(--fs-h3);
    color-scheme: dark;
    border-radius: var(--radius);
    user-select: none;
    opacity: 0;
    backdrop-filter: blur(25px) brightness(75%);
    transform: translateX(-100%);
    transition: var(--dur) var(--ease);
    will-change: transform;

    > .close {
        align-self: flex-end;
        margin: var(--space-2xs);
        font: inherit;
        color: var(--clr-text-muted);
        background: none;
        border: none;
        cursor: pointer;
    }

    > .sidebar-menu {
        flex-grow: 1;
    }

    > .languages {
        display: flex;
        align-self: flex-end;
        gap: var(--space-2xs);
        margin: var(--space-2xs);
        font-size: var(--fs-meta);
        color: var(--clr-text-muted);
    }
}

.sidebar-menu {
    display: flex;
    flex-direction: column;
    padding: var(--space-xs);

    > .item {
        display: flex;
        flex-grow: 1;
        align-items: center;
        overflow-x: hidden;
        height: var(--nav-height);
        white-space: nowrap;
        text-decoration: none;
        color: #fff;
        transition: var(--dur-s) var(--ease);
        mask-image: linear-gradient(to left, transparent, #000 1em);

        &:hover {
            font-weight: 600;
            letter-spacing: 0.05em;
            color: var(--clr-accent);
        }
    }
}

.sidebar-backdrop {
    display: none;
    z-index: 2;
    position: fixed;
    inset: 0;
    backdrop-filter: blur(0px);
    will-change: backdrop-filter;
}

/* ======= */
/*  Cards  */
/* ======= */
.news-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-l);
    padding: var(--space) 0;

    > .news-grid {
        width: var(--content-width);
    }
}

.news-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-s);

    @media (width > 480px) {
        grid-template-columns: 1fr 1fr;
    }

    @media (width > 960px) {
        grid-template-columns: repeat(4, 1fr);
    }
}

.news-card {
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    border-radius: var(--radius) var(--radius-s) var(--radius-s) var(--radius);
    outline-offset: var(--border-width);

    &:focus-visible {
        outline: var(--border-width) solid var(--clr-accent);
    }

    > .thumb {
        aspect-ratio: 4 / 3;
        overflow: hidden;
        background: var(--clr-surface);
        border-radius: var(--radius) var(--radius) var(--radius-s) var(--radius-s);
    }

    &:hover > .thumb > .picture > .img {
        opacity: 0.88;
    }

    > .title {
        margin-top: var(--space-xs);
        font-size: var(--fs-lead);
        text-wrap: balance;
    }

    > .excerpt {
        margin: var(--space-2xs) 0 0;
        line-height: var(--lh-body);
        text-wrap: pretty;
        color: var(--clr-text-muted);
    }

    > .date {
        align-self: flex-end;
        margin-top: var(--space-2xs);
        font-size: var(--fs-meta);
        color: var(--clr-text-placeholder);
    }
}

/* Responsive image from partials/picture.ejs. Fills its parent. */
.picture {
    display: contents;

    > .img {
        display: block;
        width: 100%;
        height: 100%;
        transition: opacity var(--dur) var(--ease);
    }
}

/* ======== */
/*  Footer  */
/* ======== */
.site-footer {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    align-items: start;
    gap: var(--space-xs) var(--space-xl);
    padding: var(--section-pad) var(--gutter) var(--space);
    font-size: var(--fs-meta);
    color-scheme: dark;
    color: var(--clr-prm-l);
    background: var(--clr-bg);

    /* Fades the whole link, buttons included. */
    a:hover {
        opacity: 0.7;
    }

    > :is(.support, nav) {
        display: flex;
        flex-direction: column;
        gap: var(--space-xs);
    }

    > :is(.support, nav) > .col-head {
        margin-bottom: var(--space-xs);
        font-weight: 500;
        letter-spacing: 0.05em;
        text-transform: uppercase;
        color: var(--clr-text-disabled);
    }

    > .support {
        align-items: flex-start;
    }

    > .support > .link-button {
        font-size: var(--fs-body);
    }

    > .brand > .nav-logo {
        height: 1.75rem;
        margin-bottom: var(--space-xs);
        padding: 0;

        &::before {
            mask-position: left;
        }
    }

    > .brand > p {
        margin: 0;
        color: var(--clr-text-disabled);
    }

    > .legal {
        grid-column: 1 / -1;
        margin-top: var(--space);
        padding-top: var(--space-l);
        color: var(--clr-text-placeholder);
        border-top: 1px solid color-mix(in oklab, currentColor 20%, transparent);
    }

    @media (width <= 768px) {
        grid-template-columns: 1fr;
        gap: var(--space);
    }
}
