/* fonts */

@font-face {
    font-family: inter;
    src: url("../fonts/inter.var.subset.woff2") format("woff2");
    font-style: oblique 0deg 14deg;
    font-weight: 100 900;
    font-display: swap;
}

@font-face {
    font-family: jetbrainsmono;
    font-display: swap;
    font-weight: 700;
    src: url("../fonts/jetbrainsmono-bold.subset.woff2") format("woff2");
}

@font-face {
    font-family: jetbrainsmono;
    font-display: swap;
    font-weight: 400;
    src: url("../fonts/jetbrainsmono-regular.subset.woff2") format("woff2");
}

@font-face {
    font-family: ampersand;
    src: local("baskerville"), local("georgia"), local("garamond"), local("palatino"), local("Times New Roman");
    unicode-range: u+26;
}

/* tokens */

:root {
    --font: inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif,
        "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    --font-mono: jetbrainsmono, menlo, hack, consolas, "roboto mono", "droid sans mono", monospace;

    --fz: 16px;
    --bg-code: rgb(54 86 107 / 0.04);
    --bg-body: var(--color-paper);
    --c-accent: var(--color-ink);
    --c-accent-dark: #284252;
    --c-gold: #ad956a;

    --c-body: #42545e;
    --c-body_rgb: 66 84 94;
    --p-sides-x: 1.5rem;
    --p-sides-y: 2rem;
    --c-link: var(--c-accent);
    --c-primary: var(--c-accent);

    --stripe-size: 0.5rem;

    --scrollbar-track: #efeee9;
    --scrollbar-thumb: #a7b2b7;
    --scrollbar-size: 4px;
    --c-scrollbar: auto;

    --m-table-side: -1rem;

    /* syntax highlighting (atom one light) */
    --tok-fg: #42545e;
    --tok-comment: #728188;
    --tok-keyword: #a626a4;
    --tok-string: #50a14f;
    --tok-number: #986801;
    --tok-function: var(--c-accent);
    --tok-type: #c18401;
    --tok-builtin: #c18401;
    --tok-tag: #e45649;
    --tok-attr: #986801;
    --tok-variable: #e45649;
    --tok-meta: var(--c-accent);
    --tok-inserted: #50a14f;
    --tok-deleted: #e45649;
}

@media screen and (prefers-color-scheme: dark) {
    html:not(.light) {
        --bg-body: var(--color-dark-paper);
        --c-accent: var(--color-dark-ink);
        --c-body: #e5e9e7;
        --c-body_rgb: 229 233 231;
        --bg-code: rgb(166 191 204 / 0.06);

        --c-accent-dark: #c4d5dd;

        --scrollbar-track: #21333e;
        --scrollbar-thumb: #657c89;
        --c-scrollbar: #657c89 #21333e;

        /* syntax highlighting (night owl) */
        --tok-fg: #e5e9e7;
        --tok-comment: #8a9da6;
        --tok-keyword: #c792ea;
        --tok-string: #ecc48d;
        --tok-number: #f78c6c;
        --tok-function: var(--c-accent);
        --tok-type: #ffcb8b;
        --tok-builtin: #addb67;
        --tok-tag: #7fdbca;
        --tok-attr: #7fdbca;
        --tok-variable: #addb67;
        --tok-meta: var(--c-accent);
        --tok-inserted: #addb67;
        --tok-deleted: #ef5350;
    }
}

@media screen and (min-width: 600px) {
    :root {
        --fz: 18px;
        --p-sides-x: 2rem;
        --scrollbar-size: 6px;
        --m-table-side: 0;
    }
}

@media screen and (min-width: 900px) {
    :root {
        --fz: 20px;
        --p-sides-x: 4rem;
        --p-sides-y: 4rem;
    }
}

@media screen and (min-width: 1300px) {
    :root {
        --fz: 22px;
        --p-sides-x: 6rem;
        --p-sides-y: 4rem;
    }
}

/* base */

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

html {
    scrollbar-width: thin;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font);
    word-break: break-word;
    font-size: var(--fz);
    line-height: 1.6;
    color: var(--c-body);
    background-color: var(--bg-body);
    border-top: var(--stripe-size) solid var(--c-primary);
    border-bottom: var(--stripe-size) solid var(--c-primary);
}

strong,
b {
    font-weight: 580;

    :is(h2, h3, h4, h5, h6):hover & {
        color: var(--c-accent-dark);
    }
}

img,
video {
    max-width: calc(100vw - 2 * var(--p-sides-x) - 1rem);
    height: auto;
}

img {
    max-width: 100%;
    cursor: zoom-in;

    @media screen and (min-width: 1200px) {
        &.zoom {
            width: initial;
            max-width: none;
            max-height: calc(100vh - var(--p-sides-y));
            object-fit: contain;
            cursor: zoom-out;
        }
    }
}

video {
    width: 100%;

    @media screen and (min-width: 1200px) {
        &:hover,
        &:active,
        &:focus-within {
            width: initial;
            max-height: calc(100vh - var(--p-sides-y));
            object-fit: contain;
        }
    }
}

:is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6) {
    font-family: var(--font);
    line-height: 1.33;
    font-weight: 600;
    margin: 1em 0;
    scroll-margin-top: 1em;
}

:is(h1, .h1) {
    font-weight: 700;
    font-size: calc(1.5em + 0.5vw);

    &:first-child {
        margin-bottom: 1.5em;
    }

    &.title {
        color: var(--c-primary);
    }
}

:is(h2, .h2) {
    font-size: 1.5em;
}

:is(h3, .h3) {
    font-size: 1.333em;
}

:is(h4, .h4) {
    font-size: 1.25em;
}

:is(h5, .h5) {
    font-size: 1.125em;
}

:is(h6, .h6) {
    font-weight: 500;
    font-size: 1em;
}

a {
    color: var(--c-link);
    text-underline-offset: 0.166em;
    text-decoration-skip-ink: auto;

    :is(h1, h2, h3, h4, h5, h6) & {
        color: currentColor;
        text-decoration: none;
    }

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

p {
    margin: 0 0 1em;

    &:only-child {
        margin: 0;
    }
}

p:has(+ :not(p)) {
    margin-bottom: 0;
}

thead th {
    text-align: left;
}

th {
    font-weight: 600;
}

input,
button {
    font-family: inherit;
    font-size: inherit;
}

input,
textarea {
    padding: 0.75rem 0.5rem;
    display: block;
    width: 100%;
    background-color: transparent;
    border: 1px solid rgb(102 102 102 / 0.5);
    color: currentColor;

    &:not(:placeholder-shown) {
        border-color: var(--c-link);
    }

    &:hover,
    &:focus {
        border-color: var(--c-link);
        outline: 0;
    }
}

label {
    display: block;
    width: 100%;
    margin-bottom: 0.5rem;
}

ul,
ol {
    padding: 0;
    margin: 1rem 0;
}

:is(ul, ol) :is(ul, ol) {
    padding-left: 1rem;
}

hr {
    margin: 2rem 0;
    border: 0;
    height: 1px;
    background-color: rgb(0 0 0 / 0.2);
    width: 33%;
}

cite {
    font-size: 0.8em;
    font-style: normal;
}

code,
pre {
    font-family: var(--font-mono);
}

code {
    background-color: var(--bg-code);
    padding: 0.2em;
    border-radius: 0.25em;

    pre & {
        --bg-code: transparent;
        padding: 0;
    }
}

kbd {
    font-weight: 550;
    padding: 0.2em 0.5em;
    border-radius: 0.5em;
    min-width: 2rem;
    background-color: rgb(var(--c-body_rgb) / 0.1);
}

table {
    margin: 1rem 0;
    border-spacing: 0.75rem 0.25rem;

    .table & {
        margin: 0;
        white-space: nowrap;
    }
}

blockquote {
    padding: 0 1rem 0;
    margin: 2rem 0;
    border-left: 2px solid var(--c-primary);
}

td {
    vertical-align: top;
}

details {
    margin: 2rem 0;
}

summary {
    font-weight: 600;
    margin-bottom: 1rem;
    cursor: pointer;
}

/* utilities */

.d--i {
    display: inline;
}

.d--ib {
    display: inline-block;
}

.flex-and-center {
    display: flex;
    align-items: center;
}

.mb--1 {
    margin-bottom: 0.5rem;
}

.mb--2 {
    margin-bottom: 1rem;
}

.mr--1 {
    margin-right: 0.5rem;
}

.c--primary {
    color: var(--c-primary);
}

.c--error {
    color: var(--c-accent);
}

.text--dim {
    opacity: 0.5;
}

.text--bold {
    font-weight: 600;
}

.text--lowercase {
    text-transform: lowercase;
}

.text--narrow {
    letter-spacing: -1px;
}

small,
.text--small {
    font-size: 0.75em;
}

.link {
    text-decoration: none;
    color: currentColor;
}

.button {
    display: inline-block;
    padding: 1rem 1.5rem;
    background-color: var(--c-primary);
    color: white;
    border-radius: 10rem;
    font-size: 0.75em;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 2px;
    border: 0;
    appearance: none;
    cursor: pointer;
}

/* layout */

.page-wrapper {
    display: grid;
    grid-template-columns:
        [content-start] minmax(0, calc(60rem - 2 * var(--p-sides-x)))
        [content-end] minmax(0, 1fr) [full-end];
    grid-template-rows: auto 1fr auto;
    min-height: 100vh;
    padding: var(--p-sides-y) var(--p-sides-x);

    & > * {
        grid-column: content-start / content-end;
        min-width: 0;
    }
}

.page-wrapper > .content,
.content > .single,
.post > .post__content {
    display: grid;
    grid-template-columns: subgrid;
    align-content: start;

    & > * {
        grid-column: content-start / content-end;
        min-width: 0;
    }
}

.post-list .post__description {
    font-size: 0.75em;
    opacity: 0.75;
    margin-bottom: 0;
}

.post-list .post__link {
    display: inline-block;
    min-width: 8rem;
}

.page-wrapper > .content,
.content > .single,
.post > .post__content,
.single > :is(.image-gallery, pre),
.post__content > :is(.image-gallery, pre) {
    grid-column: content-start / full-end;
}

.single > h1:first-child {
    margin-top: 0;
}

.page-title {
    text-transform: lowercase;

    &::before {
        content: "/";
        color: var(--c-primary);
        margin-right: 0.25rem;
    }
}

.nav {
    margin-bottom: 2rem;
    color: var(--c-primary);
}

.nav__link {
    display: inline-block;
    padding: 0.25rem 0;
    margin-right: 1rem;
    font-size: 1em;
    font-weight: 700;
    color: var(--c-body);
}

.nav__link--home {
    color: var(--c-link);
}

.nav__link--darkmode {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    align-items: center;

    svg {
        width: auto;
        height: 1em;
    }
}

/* horizontal overflow: expands on hover */

.overflow,
.table,
pre {
    scrollbar-width: thin;
    scrollbar-color: var(--c-scrollbar);

    &.has-overflow:not(pre):is(:hover, :active, :focus-within) {
        overflow-x: scroll;

        @media screen and (min-width: 1200px) {
            --width: calc(var(--scrollWidth) + 1rem);
            width: var(--width, var(--maxWidth));
            max-width: calc(100vw - 2 * var(--p-sides-x) - 1rem);
            --scrollbar-track: transparent;
            --scrollbar-thumb: transparent;
        }
    }

    &::-webkit-scrollbar {
        height: var(--scrollbar-size);
    }

    &::-webkit-scrollbar-track {
        background: var(--scrollbar-track);
    }

    &::-webkit-scrollbar-thumb {
        background-color: var(--scrollbar-thumb);
    }
}

.table {
    margin: 1rem var(--m-table-side);
    overflow-x: auto;
}

/* home */

.intro h1 {
    letter-spacing: -1px;
}

.field {
    position: fixed;
    top: 0;
    left: 0;
    z-index: -1;
    width: 100%;
    height: min(90vh, 60rem);
    pointer-events: none;
    /* fade into the page below the hero */
    mask-image: linear-gradient(to bottom, #000 55%, transparent);
}

/* posts */

.single img {
    display: block;
    margin: 1rem 0;
}

.post {
    & > h1 {
        order: -2;
    }

    & > .page__meta {
        order: -1;
    }

    & > * {
        order: 0;
    }
}

.post__content > * {
    position: relative;
}

.page__updated-at {
    margin: 1rem 0;
    font-size: 14px;
    opacity: 0.5;

    &:hover {
        opacity: 1;
    }

    .page--recently-updated &::before {
        content: "🌱";
    }
}

.tip {
    margin: 2rem -1rem;
    padding: 1rem;
    border: 1px solid limegreen;

    &::before {
        content: "tip";
        text-transform: uppercase;
        letter-spacing: 1px;
        display: block;
        font-weight: bold;
        font-size: 0.8em;
        color: limegreen;
        margin-bottom: 0.5rem;
    }
}

.download {
    padding: 1rem 1.25rem;
    margin: 2rem 0;
    border: 1px solid rgb(var(--c-body_rgb) / 0.18);
    border-radius: 0.6rem;
    color: var(--c-body);

    a {
        color: var(--c-accent);
        text-decoration: none;
        overflow-wrap: anywhere;

        &:hover {
            text-decoration: underline;
        }

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

    ul {
        display: grid;
        gap: 0.6rem;
        margin: 0;
        padding: 0;
        list-style: none;
        font-size: 0.8em;
        line-height: 1.45;
    }

    & > *:last-child {
        margin-bottom: 0;
    }
}

.tag {
    font-size: 0.75em;
    margin-right: 0.5rem;
    font-weight: 600;
    text-decoration: none;
}

.table-of-contents {
    padding: 1rem;
    margin: 2rem -1rem;
    font-weight: 600;
    background-color: var(--bg-code);

    &::before {
        content: "Table Of Contents";
        color: var(--c-primary);
        text-transform: uppercase;
        letter-spacing: 1px;
        font-weight: bold;
        margin-bottom: 1rem;
        display: block;
    }

    ul {
        list-style: none;
        margin: 0;
    }

    ul ul {
        list-style: inside;
    }

    a {
        text-decoration: none;
    }
}

.footnote-backref {
    font-family: var(--font-mono);
    text-decoration: none;
}

[id*="fnref"] {
    text-decoration: none;
}

.anchor {
    opacity: 0.25;
    width: 0;
    margin-left: 0.5rem;
    text-decoration: none;

    &::after {
        font-weight: normal;
        content: " ⚓\FE0E";
    }

    :is(h2, h3, h4, h5, h6):is(:hover, :focus-within) & {
        opacity: 1;
        color: var(--c-primary);
    }
}

.has-recommend {
    position: relative;
}

.recommend {
    margin: 1rem 0;
    font-weight: 600;
    border-left: 3px solid var(--c-primary);
    padding-left: 1rem;

    &::before {
        content: "Recommended";
        font-weight: 400;
        opacity: 0.5;
        margin-bottom: 1rem;
    }

    a {
        text-decoration: none;
        color: currentColor;
    }

    & > :first-child {
        margin-top: 0;
    }

    @media (min-width: 1300px) {
        margin: 0 0 0 1rem;
        top: 0;
        left: 100%;
        position: absolute;
        width: 50%;
    }
}

/* code blocks */

pre {
    position: relative;
    z-index: 0;

    overflow-x: auto;
    white-space: pre;
    word-break: keep-all;

    margin-left: 0;
    margin-right: 0;
    padding: 1rem !important;
    background-color: var(--bg-code);
    color: var(--tok-fg);

    &::before {
        content: attr(data-lang);
        display: inline-block;
        line-height: 1;
        text-transform: uppercase;
        letter-spacing: 1px;
        font-size: 0.6em;
        font-weight: 600;
        position: absolute;
        top: 0.5rem;
        right: 0.5rem;
        z-index: 1;
        opacity: 0;
    }

    &:hover::before {
        opacity: 0.5;
    }
}

/* chroma token classes (prefix z-)
   kopkop injects code-github.css after this stylesheet, hence the extra
   specificity from `pre.z-chroma` */

pre.z-chroma {
    background-color: var(--bg-code);
    color: var(--tok-fg);

    .z-err {
        color: inherit;
        background-color: transparent;
    }

    .z-n,
    .z-nx,
    .z-o,
    .z-go,
    .z-ow,
    .z-p {
        color: var(--tok-fg);
    }

    /* keywords */
    .z-k,
    .z-kc,
    .z-kd,
    .z-kn,
    .z-kp,
    .z-kr {
        color: var(--tok-keyword);
    }

    .z-kt,
    .z-nc,
    .z-no,
    .z-ne,
    .z-nn {
        color: var(--tok-type);
    }

    /* names */
    .z-nb,
    .z-bp {
        color: var(--tok-builtin);
    }

    .z-nf,
    .z-fm {
        color: var(--tok-function);
    }

    .z-nt {
        color: var(--tok-tag);
    }

    .z-na,
    .z-py {
        color: var(--tok-attr);
    }

    .z-nv,
    .z-vc,
    .z-vg,
    .z-vi,
    .z-vm {
        color: var(--tok-variable);
    }

    .z-nd,
    .z-nl,
    .z-ni {
        color: var(--tok-meta);
    }

    /* literals */
    .z-s,
    .z-sa,
    .z-sb,
    .z-sc,
    .z-dl,
    .z-sd,
    .z-s2,
    .z-se,
    .z-sh,
    .z-si,
    .z-sx,
    .z-sr,
    .z-s1,
    .z-ss {
        color: var(--tok-string);
    }

    .z-m,
    .z-mb,
    .z-mf,
    .z-mh,
    .z-mi,
    .z-il,
    .z-mo,
    .z-l,
    .z-ld {
        color: var(--tok-number);
    }

    /* comments */
    .z-c,
    .z-ch,
    .z-cm,
    .z-c1,
    .z-cs,
    .z-cp,
    .z-cpf {
        color: var(--tok-comment);
        font-style: italic;
    }

    /* generic */
    .z-gi {
        color: var(--tok-inserted);
    }

    .z-gd,
    .z-gr {
        color: var(--tok-deleted);
    }

    .z-ge {
        font-style: italic;
    }

    .z-gs {
        font-weight: bold;
    }

    .z-gh,
    .z-gu {
        color: var(--tok-function);
        font-weight: bold;
    }
}

/* Image galleries */

.image-gallery {
    --gallery-height: min(22rem, 55svh);
    display: block;
    min-width: 0;
    margin: 2rem 0;
}

.image-gallery__track {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    scrollbar-width: thin;
    scrollbar-color: var(--c-scrollbar);
    padding: 0.25rem 0.25rem 0.75rem;
}

.image-gallery__track > img,
.image-gallery__trigger {
    flex: none;
    scroll-snap-align: start;
}

.image-gallery__trigger {
    display: block;
    padding: 0;
    border: 0;
    border-radius: 0.5rem;
    background: transparent;
    cursor: zoom-in;
}

.image-gallery__track img {
    display: block;
    width: auto;
    height: var(--gallery-height);
    max-width: none;
    margin: 0;
    border-radius: 0.5rem;
}

.image-gallery__track:focus-visible,
.image-gallery__trigger:focus-visible,
.image-gallery__close:focus-visible {
    outline: 2px solid var(--c-accent);
    outline-offset: 2px;
}

.image-gallery__lightbox {
    position: fixed;
    inset: 0;
    width: fit-content;
    height: fit-content;
    max-width: calc(100vw - 2rem);
    max-height: calc(100svh - 2rem);
    margin: auto;
    padding: 0;
    border: 0;
    border-radius: 0.5rem;
    overflow: visible;
    anchor-scope: --gallery-preview;
    background: var(--bg-body);
    color: var(--c-body);

    &::backdrop {
        background: rgb(0 0 0 / 0.8);
    }

    img {
        anchor-name: --gallery-preview;
        display: block;
        width: auto;
        height: auto;
        max-width: calc(100vw - 2rem);
        max-height: calc(100svh - 2rem);
        margin: 0;
        object-fit: contain;
        cursor: default;
    }
}

.image-gallery__close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    display: grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: 1px solid rgb(255 255 255 / 0.5);
    border-radius: 50%;
    background: rgb(0 0 0 / 0.8);
    color: white;
    cursor: pointer;

    &::before,
    &::after {
        content: "";
        position: absolute;
        top: 50%;
        left: 50%;
        width: 1rem;
        height: 0.125rem;
        background: currentColor;
        transform: translate(-50%, -50%) rotate(45deg);
    }

    &::after {
        transform: translate(-50%, -50%) rotate(-45deg);
    }
}

@supports (position-anchor: --gallery-preview) and (position-try-fallbacks: --gallery-close-above) {
    .image-gallery__close {
        position: fixed;
        position-anchor: --gallery-preview;
        inset: auto;
        top: calc(anchor(top) + 0.5rem);
        left: calc(anchor(right) + 0.5rem);
        position-try-fallbacks: --gallery-close-above, --gallery-close-inside;
    }
}

@position-try --gallery-close-above {
    inset: auto;
    bottom: calc(anchor(top) + 0.5rem);
    right: calc(anchor(right) + 0.5rem);
}

@position-try --gallery-close-inside {
    inset: auto;
    top: calc(anchor(top) + 0.5rem);
    right: calc(anchor(right) + 0.5rem);
}

/* GitHub repository cards */

.repo-card {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin: 2rem 0;
    padding: 1rem 1.25rem;
    border: 1px solid rgb(var(--c-body_rgb) / 0.18);
    border-radius: 0.6rem;
    color: var(--c-body);
    text-decoration: none;
    transition: border-color 150ms ease, transform 150ms ease;

    &:hover {
        border-color: var(--c-accent);
        transform: translateY(-2px);
    }

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

.repo-card__name {
    display: flex;
    gap: 0.35em;
    align-items: baseline;
    color: var(--c-accent);
    font-size: 0.95em;
}

.repo-card__owner {
    opacity: 0.75;
}

.repo-card__description {
    font-size: 0.8em;
    line-height: 1.45;
}

.repo-card__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    font-size: 0.7em;
    opacity: 0.75;

    svg {
        width: 1.2em;
        height: 1.2em;
        vertical-align: -0.2em;
    }
}
