/* Self-hosted Figtree (variable weight, latin subset) */
@font-face {
    font-family: "Figtree";
    font-style: normal;
    font-weight: 300 900;
    font-display: swap;
    src: url("/static/fonts/figtree-latin.woff2") format("woff2");
}

@font-face {
    font-family: "Figtree";
    font-style: italic;
    font-weight: 300 900;
    font-display: swap;
    src: url("/static/fonts/figtree-latin-italic.woff2") format("woff2");
}

:root {
    --surface: #171718;
    --background: #202022;
    --border: #303336;
    --text: #e5e7eb;
    --muted: #8892a0;
    --lede: #b7bdc6;
    --accent: #6d2426;
    --accent-text: #f08080;

    --gap: .75rem;
    --radius: .375rem;
    --page-padding: 2rem;
    --prose-size: 1.2rem;
    --prose-width: 70ch;

    color-scheme: dark;
}

/* Global Resets */
* {
    margin: 0;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    background: var(--background);
    color: var(--text);
    -webkit-text-size-adjust: 100%;
}

body {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
    line-height: 1.5;
    text-rendering: optimizeLegibility;
    font-family: "Figtree", system-ui, sans-serif;
    font-optical-sizing: auto;
}

img {
    display: block;
    max-width: 100%;
    height: auto;
}

:focus-visible {
    outline: 3px solid var(--accent-text);
    outline-offset: 2px;
}

.skip-link {
    position: absolute;
    left: var(--gap);
    top: var(--gap);
    z-index: 10;
    padding: var(--gap);
    border-radius: var(--radius);
    background-color: var(--accent);
    color: var(--text);
    transform: translateY(-200%);

    &:focus {
        transform: none;
    }
}

.site-header {
    flex: 0 0 16rem;
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
    background-color: var(--surface);
    border-right: solid 1px var(--border);
    padding: var(--gap);
}

.site-logo {
    color: var(--text);
    text-decoration: none;
    font-size: xx-large;
}

.menu-button,
.menu-close {
    padding: var(--gap) 1rem;
    border: solid 1px var(--border);
    border-radius: var(--radius);
    background-color: transparent;
    color: var(--text);
    font: inherit;
    cursor: pointer;
    line-height: 0;

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

.menu-icon {
    width: 1.5rem;
    height: 1.5rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
}

/* Desktop: the menu is an ordinary part of the sidebar */
@media (min-width: 48.01rem) {
    .menu-button,
    .menu-close {
        display: none;
    }

    .site-menu {
        display: block;
        position: static;
        inset: auto;
        width: auto;
        height: auto;
        margin: 0;
        padding: 0;
        border: 0;
        overflow: visible;
        background: transparent;
        color: inherit;
    }
}

.site-content {
    flex: 1 1 0%;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

main {
    background-color: var(--background);
    flex: 1 1 auto;

    &:focus {
        outline: none;
    }
}

.site-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: var(--page-padding);
    padding: var(--page-padding);
    border-top: solid 1px var(--border);
    background-color: var(--surface);

    .social-links {
        display: flex;
        flex-wrap: wrap;
        gap: var(--gap) 1.5rem;
        list-style: none;
        padding: 0;
    }

    a {
        color: var(--lede);

        &:hover {
            color: var(--text);
        }
    }

    .social-icon {
        display: block;
        width: 1.5rem;
        height: 1.5rem;
        fill: currentColor;
    }
}

h1 {
    font-size: 3rem;
}

h2 {
    font-size: 2rem;
}

h3 {
    font-size: 1.5rem;
}

h2, h3 {
    font-family: 'Times New Roman', Times, serif;
}

h1, h2, h3 {
    font-weight: 500;
    line-height: 1.2;
}

.muted {
    color: var(--muted);
}

.lede {
    color: var(--lede);
}

.avatar {
    flex: none;
    width: 32px;
    height: 48px;
    border-radius: var(--radius);
}

/* Page layout shared by every page */
.page {
    padding: var(--page-padding);
}

.page-heading {
    padding: var(--page-padding);
    border-bottom: solid 1px var(--border);
}

.eyebrow {
    color: var(--accent-text);
    text-transform: uppercase;
    letter-spacing: 0.22em;
    font-size: smaller;
}

.page-section {
    padding: var(--page-padding);

    & + & {
        border-top: solid 1px var(--border);
    }
}

/* Long-form text: about sections, sitemap and rendered Markdown */
.prose {
    font-size: var(--prose-size);
    font-weight: lighter;

    > * {
        max-width: var(--prose-width);
    }

    > * + * {
        margin-top: var(--gap);
    }

    a {
        color: var(--accent-text);
    }

    ul {
        padding-left: 1.25rem;

        li + li {
            margin-top: calc(var(--gap) / 2);
        }
    }

    pre {
        overflow-x: auto;
    }

    img {
        width: min(100%, 36rem);
        border: 1px solid var(--border);
        border-radius: var(--radius);
    }

    table {
        border-collapse: collapse;
        display: block;
        overflow-x: auto;
    }

    th,
    td {
        border: 1px solid var(--border);
        padding: calc(var(--gap) / 2) var(--gap);
    }

    th {
        background-color: var(--surface);
        text-align: left;
    }

    .callout {
        padding: var(--gap) 1rem;
        border-left: 3px solid var(--accent-text);
        border-radius: var(--radius);
        background-color: var(--surface);
        color: var(--lede);
        font-size: 1rem;
    }
}

.site-nav {
    list-style: none;
    padding: 0;

    .site-nav-item + .site-nav-item {
        margin-top: var(--gap);
    }

    .site-nav-link {
        display: block;
        padding: var(--gap);
        border-radius: var(--radius);
        color: var(--lede);
        text-decoration: none;

        &:not([aria-current="page"]):hover {
            color: var(--text);
            background-color: var(--background);
        }

        &[aria-current="page"] {
            color: var(--text);
            background-color: var(--accent);
        }
    }
}

.hero {
    position: relative;
    height: 300px;

    /* Keeps the overlaid profile text legible over any image */
    &::after {
        content: "";
        position: absolute;
        inset: 0;
        background: linear-gradient(to top, rgb(0 0 0 / .7), transparent 60%);
        pointer-events: none;
    }

    .hero-image {
        height: 100%;
        width: 100%;
        object-fit: cover;
        object-position: center 38%;
        transform: scaleX(-1);
    }

    .hero-profile {
        position: absolute;
        z-index: 1;
        bottom: 1.25rem;
        right: 1.25rem;
        display: flex;
        gap: var(--gap);

        .hero-profile-text {
            text-align: right;
        }
    }
}

.post-card {
    position: relative;
    display: flex;
    gap: var(--gap);
    padding: var(--page-padding);

    & + & {
        border-top: solid 1px var(--border);
    }

    .post-card-body {
        display: flex;
        flex-direction: column;

        h2 {
            margin-top: var(--gap);
        }
    }

    /* Stretches the title link over the whole card */
    .post-card-link {
        color: var(--text);
        text-decoration: none;

        &::after {
            content: "";
            position: absolute;
            inset: 0;
        }

        &:hover {
            color: var(--accent-text);
            text-decoration: underline;
        }
    }
}

.post-tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--gap);
    margin-top: var(--gap);

    .post-tag {
        background-color: var(--border);
        border-radius: var(--radius);
        padding: 0 var(--gap);
    }
}

.post-header {
    border-bottom: solid 1px var(--border);

    .page-heading {
        border-bottom: 0;
        padding-bottom: 1rem;
    }
}

.back-link {
    display: inline-block;
    padding: var(--page-padding) var(--page-padding) 0;
    color: var(--lede);
    text-decoration: none;

    &:hover {
        color: var(--text);
        text-decoration: underline;
    }
}

.post-meta {
    padding: 0 var(--page-padding) var(--page-padding);
}

.post-body {
    padding: var(--page-padding);
    border-bottom: solid 1px var(--border);
}

.post-nav {
    display: flex;
    flex-wrap: wrap;
    gap: var(--gap);
    padding: 0 var(--page-padding) var(--page-padding);

    .post-nav-link {
        display: flex;
        flex-direction: column;
        flex: 1 1 14rem;
        padding: var(--gap) 1rem;
        border: solid 1px var(--border);
        border-radius: var(--radius);
        color: var(--text);
        text-decoration: none;

        &:hover {
            background-color: var(--surface);
            text-decoration: underline;
        }
    }

    .post-nav-link-older {
        text-align: right;
    }
}

.sitemap-links {
    display: flex;
    flex-direction: column;
    gap: calc(var(--gap) / 2);
}

.intro-section {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 1.5rem;

    .intro-portrait {
        flex: none;
        width: auto;
        height: 8rem;
        border-radius: var(--radius);
    }

    .prose {
        flex: 1 1 20rem;
    }
}

@media (max-width: 48rem) {
    :root {
        --page-padding: 1rem;
    }

    body {
        flex-direction: column;
    }

    /* Lock page scroll while the drawer is open */
    body:has(:popover-open) {
        overflow: hidden;
    }

    .site-header {
        position: sticky;
        z-index: 5;
        align-self: stretch;
        flex-basis: auto;
        height: auto;
        display: flex;
        align-items: center;
        justify-content: space-between;
        border-right: 0;
        border-bottom: solid 1px var(--border);
    }

    .site-menu {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(20rem, 85vw);
        height: 100dvh;
        margin: 0;
        padding: var(--gap);
        border: 0;
        border-right: solid 1px var(--border);
        background-color: var(--surface);
        color: var(--text);
        overflow-y: auto;
        overscroll-behavior: contain;
        transform: translateX(-100%);
        transition: transform .25s ease-out, overlay .25s allow-discrete, display .25s allow-discrete;

        &:popover-open {
            transform: none;

            @starting-style {
                transform: translateX(-100%);
            }
        }

        &::backdrop {
            background-color: rgb(0 0 0 / .6);
        }

        .menu-close {
            margin-bottom: var(--gap);
        }
    }

    h1 {
        font-size: 2.25rem;
    }

    .hero {
        height: 220px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition: none !important;
        scroll-behavior: auto !important;
    }
}
