:root {
    /* colors */
    color-scheme: light dark;
    --primary-color: light-dark(hsl(204, 19%, 21%), hsl(204, 19%, 21%));
    --bg-color: light-dark(hsl(120, 7%, 97%), hsl(207, 13%, 17%));
    --text-color: light-dark(hsl(0, 0%, 13%), hsl(0, 0%, 82%));
    --header-text-color: light-dark(hsl(0, 0%, 100%), hsl(0, 0%, 85%));
    --code-text-color: light-dark(black, #ddd);
    --deemphasize-text-color: light-dark(hsl(0, 0%, 40%), hsl(0, 0%, 60%));
    --fat-underline-color: light-dark(#ccc, #4c545b);
    --link-color: light-dark(#06509f, #a4c7ed);
    --link-visited-color: light-dark(#8c3576, #c3a4c3);
    --border-color: light-dark(#ccc, #666);
    --subtle-border-color: light-dark(#c5ced5, #464d53);

    /* fonts */
    --heading-font: "Inter", sans-serif;
    --body-font: "Inter", sans-serif;
    --nav-font: "Open Sans", sans-serif;
    --code-font: "Ubuntu Mono", monospace;
}

/* reset */
html, body { margin: 0; padding: 0; }
h1, h2, h3, h4, h5, h6 { margin: 0; }

* {
    box-sizing: border-box;
}

html {
    font-size: 62.5%;
    background-color: var(--primary-color); /* For rubber band scrolling */
    min-height: 100%;
    display: flex;
    flex-direction: column;
}

body {
    color: var(--text-color);
    background-color: var(--bg-color);
    font-family: var(--body-font);
    font-size: 1.7rem;
    flex: 1;
    display: grid;
    grid-template-rows: auto 1fr auto;
    grid-template-columns: minmax(180px, 1fr);
}

/* --- header -------------------------------------------------------------- */
header {
    position: relative;
    padding: 1.2rem 12px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 24px;

    color: var(--header-text-color);
    background-color: var(--primary-color);

    h2 {
        font-size: 2rem;
        font-weight: 300;
        text-transform: lowercase;
    }
    
    a {
        color: inherit !important; /* Undo global anchor tag color */
        text-decoration: none;
        &:hover { text-decoration: underline; }
    }

    ul {
        list-style: none;
        margin: 0;
        padding: 0;
        display: flex;
    }

    nav {
        flex: 1 0 auto;
        font-family: var(--nav-font);
        font-size: 1.5rem;
        text-transform: lowercase;

        ul { 
            align-items: center; 
            gap: 12px;
        }

        li { flex: 0 0 auto; }
    }
    
    li.rss-icon {
        a { display: block; }

        img {
            width: 24px;
            height: 24px;
            display: block;
        }
    }
}

header.splash {
    position: relative;
    display: block;
    padding-top: 6rem;
    padding-bottom: 2rem;

    .title {
        flex: 0 0 auto;
        width: 100%;
        font-family: var(--heading-font);
        font-size: 2rem;
        font-weight: 300;
        line-height: 1;
        color: var(--header-text-color);
        text-align: center;
        font-size: 3rem;
        margin-bottom: 1.4rem;
    }

    nav {
        position: absolute;
        top: 14px;
        left: 12px;
    }

    .icon {
        width: 28px;
        height: 28px;
    }

    .social {
        justify-content: center;
    }

    .social li {
        padding: 0 4px;
    }
}

@media (min-width: 512px) {
    header {
        padding-left: 20px;
        padding-right: 20px;
        flex-wrap: nowrap;

        h2 { display: block; }
        nav ul { justify-content: end; }
    }

    header.splash {
        nav { right: 20px; }

        .title {
            font-size: 4rem;
            margin-bottom: 2rem;
            width: auto;
        }
    }
}

@media (min-width: 1024px) {
    header.splash {
        padding-top: 4rem;
    }
}

/* --- main ---------------------------------------------------------------- */
main { padding: 30px 12px ; }

section {
    .section-title {
        font-size: 3rem;
        font-family: var(--body-font);
        margin-bottom: 2.2rem;
        border-bottom: 6px solid var(--fat-underline-color);
        display: inline-block;
        position: relative;
        left: 50%;
        transform: translateX(-50%);
    }

    &:not(:last-of-type) { margin-bottom: 3rem; }
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--heading-font);
    font-weight: 700;
}

h1 { font-size: 3rem; }
h4 { font-size: 1.7rem; }

@media (min-width: 512px) {
    main { padding: 40px 12px; }
    h1 { font-size: 3.4rem; }

    section {
        max-width: 64rem;
        margin-left: auto;
        margin-right: auto;

        &:not(:last-of-type) {
            margin-bottom: 5rem;
        }
    }
}

article p, section p {
    margin: 0;
    line-height: 1.7;

    &:not(:last-child) { margin-bottom: 3rem; }
}

a {
    color: var(--link-color);
    &:visited { color: var(--link-visited-color); }
}

code {
    font-family: var(--code-font);
    font-size: 1.6rem;

    /* Fixes iOS font sizing anomaly */
    text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
}

p code {
    color: var(--code-text-color);
    margin: 0px 2px;
    font-weight: 400;
    padding: 2px 4px;
    border: 1px solid light-dark(#aaa, #777);
    border-radius: 5px;
}

/* code blocks */
pre:has(code) {
    margin-bottom: 3rem;
    box-shadow: 2px 2px 8px #161616;
    padding: 20px 12px;
    color: hsl(0, 0%, 90%);
    background-color: light-dark(#272822, #272822);

    code {
        line-height: 1.4;
    }

    overflow-x: auto;
}

table.matrix {
    table-layout: fixed;
    width: 100%;
    border-collapse: collapse;
    border: 1px solid var(--subtle-border-color);
    margin-bottom: 3rem;

    thead {
        border-bottom: 1px solid var(--subtle-border-color);
    }

    th, td {
        padding: 6px 12px;
    }

    th:first-child {
        width: 10rem;
    }

    th:first-child, td:first-child {
        font-weight: bold;
        border-right: 1px solid var(--subtle-border-color);
    }
}

footer {
    margin-top: 24px;
    padding: 24px 0;
    text-align: center;
    font-weight: 300;
    font-size: 1.2rem;

    color: var(--deemphasize-text-color);
}

/* --- index --------------------------------------------------------------- */
.gallery {
    .project:not(:last-of-type) {
        margin-bottom: 5rem;
    }

    .project-title {
        font-family: var(--heading-font);
        font-size: 2.6rem;
        font-weight: 700;

        a {
            text-decoration: none;
            color: inherit !important;
        }
    }

    a.screenshot {
        position: relative;
        display: block;
        margin: 1.5rem 0;

        img {
            width: 100%;
            max-height: 360px;
            border: 1px solid var(--border-color);
        }

        img.external {
            position: absolute;
            width: 24px;
            height: 24px;
            bottom: 12px;
            right: 8px;
            border: none;
            background-color: #77777799;
            padding: 4px;
        }
    }
}

@media (min-width: 1024px) {
    section.has-gallery {
        max-width: 1600px;
    }

    .gallery {
        display: flex;
        flex-wrap: wrap;
        gap: 48px 42px;
        justify-content: center;

        .project {
            flex: 1 0 auto;
            max-width: 35%;
            margin-bottom: 0;
        }

        .project:not(:last-of-type) {
            margin-bottom: 0rem;
        }
    }
}

table.talks {
    border-collapse: collapse;
    margin: 0.5em 0;
    line-height: 1.5;

    td {
        padding: 0.5em 0px;
    }

    td:not(:last-child) {
        padding-right: 20px;
    }
}

/* --- blog index ---------------------------------------------------------- */
table.posts {
    border-collapse: collapse;
    margin: 0.5em 0;

    td { padding: 0.5em 0px; }
    td:not(:last-child) { padding-right: 20px; }

    td.date {
        font-size: 1.4rem;
        white-space: nowrap;
        color: var(--deemphasize-text-color);
    }
}

@media (min-width: 512px) {
    table.posts td.date {
        font-size: inherit;
    }
}

/* --- article ------------------------------------------------------------- */
article {
    max-width: 860px;
    margin: auto;

    h1, h2, h3, .meta, p, aside.admonition, blockquote {
        max-width: 64rem;
        margin: auto;
    }

    h1 {
        margin-bottom: 2rem;
    }

    /* article metadata */
    .meta {
        margin-bottom: 5rem;
        color: var(--deemphasize-text-color);

    }

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

    figure {
        margin: 0;
        margin-bottom: 6px;
        padding: 12px 0;
    }

    figcaption {
        text-align: center;
        font-style: italic;
        font-size: 1.5rem;
        padding: 14px;
        color: var(--deemphasize-text-color);

        em {
            font-style: normal;
        }

        p {
            max-width: 360px;
            display: inline-block;
            position: relative;
            padding: 0 20px;
        }
    }

    h2 {
        margin-top: 5rem;
        margin-bottom: 3rem;
    }

    h2, h2 code {
        font-size: 2.5rem;
    }

    h3 {
        margin-top: 3rem;
        margin-bottom: 3rem;
    }

    h3, h3 code {
        font-size: 2rem;
    }

    p code {
        text-wrap: nowrap;
    }

    aside.admonition {
        p.admonition-title {
            font-weight: 700;
            margin-bottom: 0.5rem;
        }

        border: 1px solid #ccc;
        border-radius: 0px 5px 5px 0px;
        border-left: 4px solid #ccc;
        background-color: light-dark(#f2f2f2, #333);
        padding: 8px;
        padding-left: 20px;
        margin-bottom: 3rem;
    }

    aside.admonition.warning {
        border-left: 4px solid light-dark(#d0d005, yellow);
    }

    blockquote {
        padding-left: 20px;
        border-left: 4px solid var(--border-color);
        margin-bottom: 3rem;
    }

    blockquote.output {
      border-left: none;
    }

    table:not(.lntable) {
        table-layout: fixed;
        width: 100%;
        border-collapse: collapse;
        border: 1px solid var(--subtle-border-color);

        thead {
            border-bottom: 1px solid var(--subtle-border-color);
        }

        th, td {
            padding: 6px 12px;
        }

        margin-bottom: 3rem;
    }

    table.matrix {
        th:first-child {
            width: 10rem;
        }

        th:first-child, td:first-child {
            font-weight: bold;
            border-right: 1px solid var(--subtle-border-color);
        }
    }

    hr {
        margin-top: 5rem;
        margin-bottom: 5rem;
        max-width: 300px;
        color: var(--subtle-border-color);
    }
}

@media (min-width: 512px) {
    article {
        figcaption {
            p::before, p::after {
                content: '';
                width: 40px;
                height: 1.5rem;
                position: absolute;
                top: 0px;
                border-bottom: 1px solid var(--subtle-border-color);
            }

            p::before {
                left: -46px;
                border-left: 1px solid var(--subtle-border-color);
                border-radius: 0 0 0 10px;
            }

            p::after {
                right: -46px;
                border-right: 1px solid var(--subtle-border-color);
                border-radius: 0 0 10px 0;
            }
        }

        table.matrix {
            th:first-child {
                width: 20%;
            }
        }
    }
}
