@import url("/asset?u=https%3A%2F%2Ffonts.googleapis.com%2Fcss2%3Ffamily%3DDM%2BMono%26display%3Dswap");
@import url("/asset?u=https%3A%2F%2Ftwey.io%2Fassets%2Ffonts%2Furw-palladio%2Ffont.css");
@import url("/asset?u=https%3A%2F%2Ftwey.io%2Fassets%2Ffonts%2Feb-garamond%2Ffont.css");

:root {
    --font-text: "URW Palladio", "Liberation Serif", "Times New Roman", serif;
    --font-header: "EB Garamond", "Times New Roman", serif;
    --font-around: var(--font-header);
    --font-code: "DM Mono", monospace;
    --font-footer: var(--font-code);

    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
:root {
    --colour-highlight-fg: #907040;
    --colour-bright-highlight: #c0a000;
    --colour-highlight-bg: #ccc;
    --colour-slight-highlight-bg: #e5e5e5;
    --colour-bg: #eee;
    --colour-bg-transparent: #eeeeee00;
    --colour-fg: black;
    --colour-slightly-faded: #666;
    --colour-faded: #888;
    --colour-very-faded: #bbb;
}
@media (prefers-color-scheme: dark) {
    :root {
        --colour-highlight-bg: #333;
        --colour-slight-highlight-bg: #191919;
        --colour-bg: #111;
        --colour-bg-transparent: #11111100;
        --colour-fg: #eee;
        --colour-slightly-faded: #aaa;
        --colour-faded: #666;
        --colour-very-faded: #444;
    }

    .imageblock.mono .content > *,
    img.mono,
    hr {
        filter: invert(50%);
    }

    .logo img {
        filter: invert(100%);
    }
}

/* layout */

body {
    display: grid;
    gap: 1rem 2rem;
    margin: 0 auto;
    min-height: 100dvh;
    max-width: 80rem;
    justify-content: center;
    padding: 2rem;
    padding-bottom: 0;
}

.logo {
    grid-area: logo;
}
header {
    grid-area: header;
}
nav {
    grid-area: nav;
}
main {
    grid-area: main;
}
footer {
    grid-area: footer;
}
body > hr {
    grid-area: rule;
}

body {
    grid-template-rows: auto auto auto auto 1fr auto;
    grid-template-areas:
        "logo"
        "header"
        "rule"
        "nav"
        "main"
        "footer";
}

@media (width < 67rem) {
    article h2 {
        background-image: linear-gradient(
            to top,
            var(--colour-bg-transparent) 0%,
            var(--colour-bg) .25em,
            var(--colour-bg) 100%
        );
        position: sticky;
        top: 0;
        z-index: 1;
    }

    .index nav {
        display: none;
    }
}

@media (width >= 67rem) {
    body {
        grid-template-rows: auto auto auto 1fr;
        grid-template-columns: 20rem 35rem;
        grid-template-areas:
            "logo  header"
            ".     rule  "
            "title main  "
            "nav   main  "
            ".     footer";

        justify-content: start;

        &.post,
        &.archive {
            header {
                grid-area: title;
            }

            main {
                grid-row-start: header;
            }
        }

        section:first-child > h2:first-child {
            padding-top: 0;
        }
    }

    nav {
        position: relative;

        ul {
            position: sticky;
            top: 1rem;
        }

        a:link.active, a:visited.active {
            color: var(--colour-fg);
        }
    }

    .index .logo {
        align-items: end;
        margin-right: -2rem;
    }
}

.sidenote-id {
    display: none;
}

.sidenote {
    display: block;
    margin: 0 auto 1rem;
    width: 15rem;

    font-size: 0.9em;
    padding-top: 0.1em; /* compensate text-top alignment for font-size */
    line-height: 1.2;
    color: var(--colour-slightly-faded);
    border-bottom: dashed 1px var(--colour-very-faded);
}

@media (width < 84rem) {
    label.sidenote-toggle {
        display: inline-block;
        cursor: pointer;
        font-family: "EB Garamond 12";
        color: var(--colour-highlight-fg);
        height: 1em;
        vertical-align: top;
        margin-left: 0.2em;
        margin-right: 0.2em;
    }
    input.sidenote-toggle:not(:checked) + label.sidenote-toggle::before {
        content: "❦";
    }
    input.sidenote-toggle:checked + label.sidenote-toggle::before {
        content: "❧";
        position: relative;
        top: -3px;
    }
    input.sidenote-toggle {
        display: none;
    }
    input.sidenote-toggle:not(:checked) + label.sidenote-toggle + .sidenote {
        display: none;
    }
}

@media (width >= 84rem) {
    aside {
        float: right;
        margin-right: -20rem;
        max-width: 20rem;

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

    .sidenote-id {
        font-family: var(--font-header);
        font-variant-numeric: oldstyle-nums;
    }

    .sidenote-id {
        display: initial;
    }

    .sidenote {
        float: right;
        clear: right;
        margin: 0 -17rem 1.5rem 1rem;
        padding-bottom: 0.5em;

        .sidenote-id {
            width: 2em;
            display: block;
            float: left;
            text-align: right;
            margin-left: -2.2em;

            a:link, a:visited {
                text-decoration: none;
            }
        }
    }

    .sidenote-toggle {
        display: none;
    }
}

body {
    color: var(--colour-fg);
    background-color: var(--colour-bg);
    font-family: var(--font-text);
}

h2,
h3 {
    font-family: var(--font-header);
    text-wrap: balance;
}

h1 {
    margin: 0;
}

h2 {
    padding-top: 0.5em;
}

h2, h3, h4 {
    line-height: 1.2em;
}

article h3 {
    font-size: 1.4rem;
    margin: 0;
    margin-top: 0.5em;
}

article > section {
    margin-bottom: 1.5em;
}

code {
    background-color: var(--colour-slight-highlight-bg);
    font-family: var(--font-code);
    padding: 0 0.3em;

    /* even when in the first line */
    font-variant: none;
    letter-spacing: normal;
}

kbd {
    color: var(--colour-fg);
    background-color: var(--colour-highlight-bg);
    border: 1px var(--colour-fg) outset;
    white-space: nowrap;
    word-spacing: -0.2em;
    display: inline-block;
    padding: 0.1rem 0.4rem;
}

.listingblock {
    margin-bottom: 0.5em;
}

.highlight code {
    padding: 0;
}

.index {
    grid-template-rows: auto auto auto 1fr;

    .logo {
        display: flex;
        flex-direction: column;
        justify-content: center;

        img {
            height: 15rem;
        }
    }

    header {
        font-family: var(--font-text);
        font-weight: normal;

        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;

        p {
            padding: 2rem 0;
            font-size: 1.3em;
            line-height: 1.5em;
            text-align: center;
            max-width: 30rem;
        }

        a {
            white-space: nowrap;
        }
    }

    hr {
        margin-top: 0;
    }

    nav {
        grid-row-start: title;
    }
}

.logo img {
    height: 5rem;
}

.archive {
    time {
        font-style: italic;
        float: right;
        text-align: right;
        width: 11em;
        font-size: 0.9em;
        margin-bottom: 0.5rem;
    }

    section > a:link:first-of-type {
        text-decoration: none;
    }

    h3 {
        font-size: 1.3em;
        margin: 0;
    }

    h4 {
        font-family: var(--font-header);
        margin-top: 0;
        margin-bottom: 0.5em;
    }
}

.teaser {
    .sidenote,
    h2,
    h3,
    h4 {
        display: none;
    }
}

:not(:hover) > .section-heading {
    visibility: hidden;
}

main {
    line-height: 1.5;

    sup {
        line-height: 1;
    }

    p {
        margin-top: 0.25em 0;
    }

    .underline {
        text-decoration: underline;
    }

    pre {
        margin: 0;
        font-family: var(--font-code);
        color: var(--colour-fg);
        font-size: 100%; /* undo a Bootstrap directive that shrinks <pre> */
    }

    abbr {
        font-variant: all-small-caps;
    }

    h2 {
        font-size: 2rem;
        margin: 0;
        padding-bottom: 0.25em;
    }

    ul,
    ol {
        margin-left: 1.5em;
        padding-left: 0;
        list-style-position: outside;
    }

    li {
        padding-left: 0.5em;
    }

    ul li::marker {
        content: "❧";
        font-family: "EB Garamond 12";
        font-feature-settings: "cv90"; /* ornate ❧ */
    }

    ol li::marker {
        font-size: 0.8em;
        font-style: italic;
    }

    li::marker {
        color: var(--colour-faded);
        font-weight: bold;
        font-family: var(--font-header);
    }

    ol {
        list-style-type: lower-roman;
    }

    .imageblock {
        text-align: center;
        margin: 2rem 0;

        .title {
            font-style: italic;
            margin: 0 2rem;
            text-align: justify;
        }

        .content {
            border: 3px double var(--colour-highlight-bg);
            padding: 1rem;
            & > *,
            a > * {
                max-width: 100%;
                height: auto;
                display: block;
            }
        }
    }

    a {
        &:link {
            text-decoration: underline;
        }

        &:visited {
            color: var(--colour-slightly-faded);
        }
    }

    h2 a, h3 a, h4 a {
        &:link, &:visited, &:hover, &:visited:hover {
            color: var(--colour-fg);
            text-decoration: none;
        }

        &:hover:after {
            color: var(--colour-highlight-fg);
            content: ' §';
        }
    }
}

hr {
    border: 0;
    height: 4rem;
    margin-bottom: 2em;
    margin-top: 2em;
    width: 100%;
    background: center/contain url(/asset?u=https%3A%2F%2Ftwey.io%2Fassets%2Fdivider.svg) transparent no-repeat;
}

/* .mono is for black-on-transparent images that should change in dark
   mode */

.imageblock.mono .content > *,
img.mono,
hr {
    filter: opacity(50%);
}

@media (prefers-color-scheme: dark) {
    .imageblock.mono .content > *,
    img.mono,
    hr {
        filter: invert(50%);
    }

    .logo img {
        filter: invert(100%);
    }
}

ul.posts time {
    display: block;
    margin-left: 2em;
}

a {
    &:link {
        text-decoration: none;
        color: var(--colour-highlight-fg);
    }

    &:visited {
        color: var(--colour-slightly-faded);
    }

    &:hover,
    &:visited:hover {
        color: var(--colour-bright-highlight);
    }
}

header {
    text-align: right;
    font-family: var(--font-header);
    font-weight: bold;
    margin-bottom: 1rem;

    h1 {
        font-size: 1.5rem;
    }

    p {
        margin: 0.5rem 0;
        text-wrap: balance;
    }

    time {
        font-weight: normal;
        font-size: 0.9em;
        font-style: italic;

        &:before {
            content: "― ";
        }

        &:after {
            content: " ―";
        }
    }
}

nav {
    text-align: right;

    font-family: var(--font-around);
    margin-bottom: 2rem;
    .section-heading {
        display: none;
    }

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

        li {
            padding: 0.5rem 0;
            font-size: 1.1em;
        }
    }

    a {
        &:link,
        &:visited {
            color: var(--colour-faded);
            text-decoration: none;
        }

        &:hover,
        &:active {
            color: var(--colour-fg);
        }
    }
}

nav,
header,
.logo {
    text-align: right;
}

main h2 + p:first-of-type {
    margin-top: 0;
    min-height: 4rem;
}

article {
    h2 + p:first-of-type:first-line {
        font-variant: small-caps;
        letter-spacing: 0.1em;
    }

    p:first-of-type {
        padding-top: 0;
    }
}

article p,
.teaser p {
    text-align: justify;
}

.quoteblock {
    font-style: italic;
}

.quoteblock blockquote {
    padding-left: 1em;
    margin-left: 0;
    margin-bottom: 0.3em;
    border-left: 2px solid var(--colour-highlight-bg);
    font-size: 1.3em;
}

footer {
    font-size: 0.7em;
    font-family: var(--font-footer);
    padding-bottom: 0.5em;

    img {
        max-height: 1em;
        width: auto;
        vertical-align: -0.1em;
    }

    ul {
        margin: 0;
        padding-left: 0;

        li {
            display: inline-block;

            &:not(:first-child):before {
                content: "/ ";
            }
        }
    }
}

.admonitionblock {
    margin: 1em 0;
    padding: 0.5em 0.75em;
    padding-top: 0.5em;
    border: 3px double var(--colour-slight-highlight-bg);
}

.admonitionblock :last-child {
    margin-bottom: 0;
}

.admonitionblock .title {
    font-family: var(--font-header);
    font-size: 1.2em;
}

.admonitionblock .title::before {
    font-variant: small-caps;
}

.admonitionblock.warning .title::before {
    color: #8e0a00;
    content: "Cavē: ";
}

.admonitionblock.note .title::before {
    color: #505aae;
    content: "Notā: ";
}

.admonitionblock.tip .title::before {
    color: #0a8e00;
    content: "Moneō: ";
}

.ordinal-suffix {
    text-decoration: underline;
}
