/* Reset */

body, div, header, main, h1, h2, h3, h4, figure, img, ul, ol, dl, li, p, blockquote, pre, math {
    margin: 0;
    padding: 0;
}

/* Colors */

:root {
    color-scheme: light dark;
    --bg: #fff;
    --backdrop: #eef3fc;
    --block: #f6f6f6;
    --border: #ccc;
    --subtle: #888;
    --detail: #6c6c6c;
    --fg: #2f2f2f;
    --intense: #000;
    --active: #0054c9;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #222222;
        --backdrop: #252a3c;
        --block: #333;
        --border: #666;
        --subtle: #999;
        --detail: #ccc;
        --fg: #f3f3f3;
        --intense: #fff;
        --active: #88a8ff;
    }
}

/* Fonts */

:root {
    font: 20px/1.4 Charter, "Bitstream Charter", Cambria, serif;
    -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4, .button, .nav, .page-nav, .post-header, .screen-on {
    font-family: Seravek, Calibri, source-sans-pro, sans-serif;
}

code, .listing__date {
    font: 0.85em monospace, monospace;
}

/* Layout */

body {
    background: var(--backdrop);
    color: var(--fg);
    padding: 0 10px;
    max-width: 720px;
    margin: 20px auto;
}

.skip-link { position: absolute; top: 10px; left: -999px; width: 1px; height: 1px; }
.skip-link:focus { left: 10px; width: auto; height: auto; background: var(--bg); }

.header {
    line-height: 1.2;
    margin: 0 10px 11px; /* 11px so that 3px underline is centered between baseline and .wrapper */
    display: flex;
    gap: 30px;
}

.logo { border: none; align-self: center; }
.logo:hover { border: none; opacity: 0.5; }
.logo__image { image-rendering: pixelated; }
@media (prefers-color-scheme: dark) { .logo__image { filter: invert(); } }

.nav {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: end;
}

.nav ul, .nav li { display: contents; }

.nav__item {
    margin-bottom: -4px;
    padding: 0 0 1px;
    border-bottom: 3px solid transparent;
    text-align: center;
    color: var(--intense);
}

.nav__item--active { border-bottom: 3px solid var(--border); }
.nav__item:hover { border-bottom: 3px solid var(--active); }

.wrapper {
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 20px;
    border-radius: 10px;
}

footer {
    font-size: 0.9em;
    text-align: center;
    margin-top: 0.5rem;
}

.grid {
    display: flex;
    flex-flow: row wrap;
    gap: 30px;
    justify-content: center;
    margin: 1.2rem 0;
    text-align: center;
}

.grid__link { gap: 8px; border: none; }
.grid--200 .grid__link { width: 200px; }
.grid--146 .grid__link { width: 146px; }
.grid__name { border-bottom: 1px dotted var(--subtle); }
.grid__link:hover { border: none; }
.grid__link:hover .grid__name { border-bottom-color: var(--active); }

.grid__image {
    border-radius: 10px;
    display: block;
    margin: 0 auto 4px;
}

.listing {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 0.8rem;
    row-gap: 0.3rem;
    align-items: baseline;
    justify-items: left;
}

.listing__date {
    color: var(--detail);
    white-space: nowrap;
}

.alpha-listing li {
    margin-bottom: 0.3rem;
}

.view-compact { display: none; }
.show-compact .view-default { display: none; }
.show-compact .view-compact { display: block; }

.blogroll > ul { display: contents; }
.blogroll li { list-style: none; margin: 0; display: inline; }
.blogroll li::after { content: " • "; }
.blogroll li:last-child::after { content: none; }

.toc-grid ul { display: contents; }
.toc-grid li { list-style: none; margin: 0; padding: 0; }
.toc-grid { columns: 5em; }

/* General */

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

h1 {
    font-size: 1.4em;
    font-weight: bold;
    margin: 0 0 0.6rem;
}

h2 {
    font-size: 1.1em;
    font-weight: bold;
    margin: 1rem 0 0.5rem;
}

h3 {
    font-size: 1em;
    font-weight: bold;
    color: var(--detail);
}

h4 {
    font-size: 1em;
    font-weight: normal;
    font-style: italic;
    color: var(--detail);
}

h3, h4 { margin: 0.5rem 0 0.2rem; }
h3 + blockquote, h4 + blockquote { margin-top: 0.5rem; }

a {
    text-decoration: none;
    color: currentColor;
    border-bottom: 1px dotted var(--subtle);
}

a:hover {
    color: var(--active);
    border-bottom: 1px solid currentColor;
}

.disabled {
    color: var(--subtle);
}

p, ul, ol { margin-bottom: 1em; }
p:last-child, ul:last-child, ol:last-child { margin-bottom: 0; }

.math-block {
    /* Use some padding so scrollbar doesn't occlude math. */
    padding-bottom: 0.3rem;
    margin-bottom: 0.7rem;
    overflow-x: auto;
}

blockquote, pre, .toc {
    background-color: var(--block);
    margin-bottom: 1rem;
}

blockquote {
    padding: 0.6rem;
    font-size: 0.9em;
}

blockquote p:last-child {
    margin-bottom: 0;
}

blockquote + blockquote, blockquote + ul, ul + blockquote {
    margin-top: -0.3rem;
}

small {
    display: block;
    margin: 0.5rem 0 0;
    font-size: 0.8em;
    text-align: right;
    color: var(--detail);
}

.toc { font-size: 0.9em; }
.toc h2 { margin-top: 0; }

figure {
    margin: 1.7rem 0 1.2rem;
}

figure img, figure svg {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}

figure img {
    border-radius: 10px;
}

figcaption {
    text-align: center;
    margin: 0.7rem 0;
    font-size: 0.9em;
    font-style: italic;
}

.right { float: right; margin: 0 0 15px 15px; }

@media screen and (max-width: 500px) {
    .right--200 { float: none; display: block; margin: 0 0 15px; }
    .right--200 img { margin: 1rem 0; }
}

li, dt { margin-left: 1rem; }
ul { list-style: disc outside; }
ol { list-style: decimal outside;}
ul > li { margin-left: 1.1rem; }
ol > li { margin-left: 1.6rem; }

table {
    margin: 1rem auto 1.5rem;
    border-collapse: collapse;
    border-spacing: 0;
}

tr { border-bottom: 1px solid var(--border); }
td, th { padding: 5px 20px; text-align: left; }

code {
    white-space: pre;
    word-break: normal;
    word-wrap: normal;
    background: var(--block);
    padding: 1px 3px;
    border-radius: 5px;
}

.fnref-content code {
    padding: 0;
}

pre, .toc {
    margin-left: -20px; /* -20px matches .wrapper padding */
    margin-right: -20px;
    padding: 15px 20px;
}

pre {
    overflow-x: auto;
    font-size: 15px;
}

pre code {
    font-size: inherit;
    padding: 0;
    background: transparent;
    border-radius: 0;
}

.verse {
    font-style: italic;
    margin-left: 2rem;
}

hr {
    border: 0;
    border-bottom: 1px solid var(--border);
    margin: 1.5rem 0;
}

.recently-rule {
    margin-bottom: 1rem;
}

.last-updated {
    font-size: 0.9em;
    font-style: italic;
    margin-top: 1.5rem;
    color: var(--detail);
}

.button {
    background: var(--block);
    border: 1px solid var(--border);
    padding: 8px 6px;
    border-radius: 5px;
    font-size: 0.9em;
    line-height: 1;
}

.button:hover {
    border: 1px solid var(--active);
}

.control {
    float: right;
    margin: -2px -2px 0 15px;
    box-sizing: border-box;
    height: 36px;
}

.control--home {
    margin: -2px 0 0 0;
}

.segmented {
    /* `display: flex;` set in JS */
    align-items: stretch;
}

.segmented input {
    border: 0;
    clip: rect(0, 0, 0, 0);
    height: 1px;
    overflow: hidden;
    padding: 0;
    position: absolute !important;
    white-space: nowrap;
    width: 1px;
}

.segmented__item {
    border: 1px solid var(--border);
    margin-left: -1px;
    display: flex;
    align-items: center;
    padding: 0 6px;
    cursor: pointer;
    background: var(--block);
}

.segmented__item:first-of-type {
    margin-left: 0;
    border-radius: 5px 0 0 5px;
}

.segmented__item:last-of-type {
    border-radius: 0 5px 5px 0;
}

:checked + .segmented__item {
    background: var(--border);
    color: var(--detail);
    cursor: default;
    pointer-events: none;
}

:not(:checked) + .segmented__item:hover {
    color: var(--active);
    border-color: var(--active);
    z-index: 1;
}

.page-nav {
    font-size: 0.9em;
    display: flex;
    border-bottom: 1px solid var(--border);
    margin: -20px -20px 20px; /* -20px matches .wrapper padding */
}

.page-nav__item {
    flex: 1;
    text-align: center;
    padding: 5px;
    white-space: nowrap;
    overflow-x: hidden;
    text-overflow: ellipsis;
    border-bottom: none;
}

.page-nav__item:first-child { border-top-left-radius: 10px; }
.page-nav__item:last-child { border-top-right-radius: 10px; }

.page-nav__item:nth-child(2) {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
}

a.page-nav__item:hover {
    color: currentColor;
    background: var(--block);
    border-bottom: none;
}

span.page-nav__item {
    color: var(--subtle);
}

/* Blog */

.post-header {
    margin: 0 0 1.2rem;
    line-height: 1.2;
}

.post-header__subtitle {
    font-style: italic;
    margin-bottom: 0.6em;
}

.post-header__date {
    color: var(--detail);
}

/* Footnotes */

.fnref {
    vertical-align: baseline;
    position: static;
    font-size: inherit;
    margin: 0 2px;
}

.fnref > a {
    font: 16px system-ui, sans-serif;
    background: var(--block);
    padding: 2px 4px;
    border: 1px solid var(--subtle);
    border-radius: 4px;
    color: currentColor;
    text-decoration: none;
}

.fnref--shown > a {
    background: var(--border);
}

.fnref--active > a {
    background: var(--subtle);
    color: var(--bg);
}

.fnref-wrapper {
    box-sizing: border-box;
    position: absolute;
    font-size: 20px;
}

.fnref-notch {
    position: absolute;
    width: 40px;
    height: 20px;
}

.fnref-notch-a, .fnref-notch-b, .fnref-notch-c {
    pointer-events: none;
    position: relative;
}

.fnref-notch-a, .fnref-notch-b {
    border: 20px solid transparent;
    border-bottom: 20px solid var(--subtle);
    width: 0;
    height: 0;
}

.fnref-notch-a {
    pointer-events: none;
    position: absolute;
    top: -18px;
    border-bottom: 20px solid var(--subtle);
}

.fnref-notch-b {
    top: -16px;
    border-bottom-color: var(--block);
}

.fnref-notch-c {
    top: -19px;
    width: 40px;
    height: 2px;
    background: var(--block);
}

.footnotes, .fnref-content { font-size: 0.85em; }
.footnotes-rule { margin: 1.5rem 0 0.6rem; }

.fnref-content {
    position: absolute;
    top: 20px;
    padding: 10px;
}

.fnref-content, .screen-on {
    background: var(--block);
    border: 1px solid var(--subtle);
    border-radius: 5px;
    box-shadow: 0 0 12px var(--block);
}

.screen-on {
    position: fixed;
    top: 7px; right: 7px;
    font-size: 0.8em;
    padding: 4px;
    touch-action: none;
}

/* Media queries */

@media screen and (max-width: 650px) {
    body { padding: 0; }
    .header { flex-flow: column nowrap; gap: 10px; }
    .nav { justify-content: space-around; }
    .control { margin-right: 0; }
    .page-nav__item:first-child, .page-nav__item:last-child { flex: 100px; }
    .page-nav__item:nth-child(2) { flex: auto; }

    .wrapper {
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
}

@media screen and (max-width: 500px) {
    .header { gap: 15px; margin-bottom: 15px; }

    .nav {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        grid-auto-flow: row;
        row-gap: 10px;
        justify-items: center;
    }

    .page-nav__item {
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .wrapper { padding: 20px 12px; }
    .page-nav { margin-left: -12px; margin-right: -12px; }
    pre, .toc {
        margin-left: -12px;
        margin-right: -12px;
        padding-left: 12px;
        padding-right: 12px;
    }

    .listing { display: block; }
    .listing .listing__title { margin: 0 0 0.75rem; }
    .listing .listing__title:last-child { margin-bottom: 0.2rem; }
    /* Undo those rules for narrow */
    .listing--narrow { display: grid; }
    .listing--narrow .listing__title { margin: 0; }
    .listing--narrow .listing__title:last-child { margin: 0; }
}

@media screen and (max-width: 455px) {
    .grid--200 .grid__link, .grid--200 .grid__image {
        width: auto;
        max-width: clamp(150px, 42vw, 200px);
    }
    .grid--200 .grid__image { height: auto; }
}

/* Code highlighting */

.kw { color: #a626a4; }
.cn { color: #307a06; }
.co { color: #c0392b; }
.ca { color: #0060d5; }
.cb { color: #986801; }

@media (prefers-color-scheme: dark) {
    .kw { color: #c678dd; }
    .cn { color: #98c379; }
    .co { color: #e7727b; }
    .ca { color: #61afef; }
    .cb { color: #e5c07b; }
}
