/*
 * Based on: https://github.com/owickstrom/the-monospace-web/
 *
 * Sections:
 * 1. Font Faces
 * 2. CSS Variables
 * 3. Base Styles
 * 4. Layout
 * 5. Typography
 * 6. Navigation
 * 7. Tables
 * 8. Content (Posts, Images, Code)
 * 9. Tree View
 * 10. Footnotes
 * 11. Journal Table
 * 12. Forms & Buttons
 * 13. Utilities
 * 14. Responsive
 */

/* ==========================================================================
   1. Font Faces
   ========================================================================== */

@font-face {
    font-family: "Jetbrains Mono";
    src: url("../fonts/jetbrains_mono/JetBrainsMono-Regular.woff2") format("woff2");
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: "Jetbrains Mono";
    src: url("../fonts/jetbrains_mono/JetBrainsMono-Bold.woff2") format("woff2");
    font-weight: bold;
    font-style: normal;
}

@font-face {
    font-family: "Jetbrains Mono";
    src: url("../fonts/jetbrains_mono/JetBrainsMono-Italic.woff2") format("woff2");
    font-weight: normal;
    font-style: italic;
}

@font-face {
    font-family: "Jetbrains Mono";
    src: url("../fonts/jetbrains_mono/JetBrainsMono-BoldItalic.woff2") format("woff2");
    font-weight: bold;
    font-style: italic;
}

@font-face {
    font-family: "Atkinson Hyperlegible Mono";
    src: url("../fonts/atkinson_hyperlegible/AtkinsonHyperlegibleMono-Regular.ttf") format("truetype");
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: "Atkinson Hyperlegible Mono";
    src: url("../fonts/atkinson_hyperlegible/AtkinsonHyperlegibleMono-Bold.ttf") format("truetype");
    font-weight: bold;
    font-style: normal;
}

@font-face {
    font-family: "Atkinson Hyperlegible Mono";
    src: url("../fonts/atkinson_hyperlegible/AtkinsonHyperlegibleMono-Italic.ttf") format("truetype");
    font-weight: normal;
    font-style: italic;
}

@font-face {
    font-family: "Atkinson Hyperlegible Mono";
    src: url("../fonts/atkinson_hyperlegible/AtkinsonHyperlegibleMono-BoldItalic.ttf") format("truetype");
    font-weight: bold;
    font-style: italic;
}

/* ==========================================================================
   2. CSS Variables
   ========================================================================== */

:root {
    /* Colors */
    --light: #f0f6f0;
    --dark: #222323;
    --text-color: var(--dark);
    --text-color-flip: var(--light);
    --text-color-alt: #666;
    --background-color: var(--light);
    --background-color-flip: var(--dark);
    --background-color-alt: #eee;

    /* Typography */
    --font-family: "Jetbrains Mono", monospace;
    --font-size: 16px;
    --line-height: 1.4rem;
    --font-weight-normal: 500;
    --font-weight-medium: 600;
    --font-weight-bold: 800;

    /* Spacing & Borders */
    --border-thickness: 1px;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
    :root {
        --text-color: var(--light);
        --text-color-flip: var(--dark);
        --text-color-alt: #aaa;
        --background-color: var(--dark);
        --background-color-flip: var(--light);
        --background-color-alt: #111;
    }
}

/* ==========================================================================
   3. Base Styles
   ========================================================================== */

* {
    box-sizing: border-box;
}

* + * {
    margin-top: var(--line-height);
}

/* ==========================================================================
   4. Layout
   ========================================================================== */

html {
    display: flex;
    width: 100%;
    margin: 0;
    padding: 0;
    padding-bottom: calc(var(--line-height) * 2);
    flex-direction: column;
    align-items: center;
    background: var(--background-color);
    color: var(--text-color);

    /* Typography base */
    font-family: var(--font-family);
    font-optical-sizing: auto;
    font-weight: var(--font-weight-normal);
    font-style: normal;
    font-variant-numeric: tabular-nums lining-nums;
    font-size: var(--font-size);
}

body {
    position: relative;
    width: 100%;
    margin: 0;
    padding: 2px;
    max-width: calc(min(80ch, round(down, 100%, 1ch)));
    line-height: var(--line-height);
    overflow-x: hidden;
}

/* ==========================================================================
   5. Typography
   ========================================================================== */

h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: var(--font-weight-bold);
    margin: calc(var(--line-height) * 2) 0 var(--line-height);
    line-height: var(--line-height);
}

h1 {
    font-size: 2rem;
    line-height: calc(2 * var(--line-height));
    margin-bottom: calc(var(--line-height) * 2);
    text-transform: uppercase;
}

h2 {
    font-size: 1.3rem;
    text-transform: uppercase;
}

p {
    margin-bottom: var(--line-height);
    word-break: break-word;
    word-wrap: break-word;
    hyphens: auto;
}

strong {
    font-weight: var(--font-weight-bold);
}

em {
    font-style: italic;
}

a {
    text-decoration-thickness: var(--border-thickness);
}

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

sub {
    position: relative;
    display: inline-block;
    margin: 0;
    vertical-align: sub;
    line-height: 0;
    width: calc(1ch / 0.75);
    font-size: 0.75rem;
}

hr {
    position: relative;
    display: block;
    height: var(--line-height);
    border: none;
    color: var(--text-color);
}

hr:after {
    display: block;
    content: "";
    position: absolute;
    top: calc(var(--line-height) / 2 - var(--border-thickness));
    left: 0;
    width: 100%;
    border-top: var(--border-thickness) solid var(--text-color);
    height: 0;
}

mark {
    background-color: var(--background-color-flip);
    color: var(--text-color-flip);
}

/* Lists */
ul,
ol {
    padding: 0;
    margin: 0 0 var(--line-height);
}

ul {
    list-style-type: square;
    padding-left: 2ch;
}

ol {
    list-style-type: none;
    counter-reset: item;
    padding: 0;
}

ol ul,
ol ol,
ul ol,
ul ul {
    padding: 0 0 0 3ch;
    margin: 0;
}

ol li:before {
    content: counters(item, ".") ". ";
    counter-increment: item;
    font-weight: var(--font-weight-medium);
}

li {
    margin: 0;
    padding: 0;
}

li::marker {
    line-height: 0;
}

/* Details/Summary */
details {
    border: var(--border-thickness) solid var(--text-color);
    padding: calc(var(--line-height) - var(--border-thickness)) 1ch;
    margin-bottom: var(--line-height);
}

summary {
    font-weight: var(--font-weight-medium);
    cursor: pointer;
}

summary ::marker {
    display: inline-block;
    content: "▶";
    margin: 0;
}

summary[open] ::marker {
    content: "▼";
}

details :last-child {
    margin-bottom: 0;
}

/* ==========================================================================
   6. Navigation
   ========================================================================== */

.titlebar {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    flex-wrap: wrap;
}

.titlebar h1 {
    margin-bottom: initial;
}

.logo {
    line-height: var(--line-height);
    text-align: left;
}

nav {
    margin-bottom: var(--line-height);
    text-transform: uppercase;
    text-align: left;
    font-weight: var(--font-weight-normal);
    display: flex;
    gap: var(--line-height);
}

nav a {
    margin-top: var(--line-height);
}

header a {
    text-decoration: none;
}

header a.active {
    font-weight: var(--font-weight-bold);
}

/* ==========================================================================
   7. Tables
   ========================================================================== */

table {
    position: relative;
    top: calc(var(--line-height) / 2);
    width: calc(round(down, 100%, 1ch));
    border-collapse: collapse;
    margin: 0 0 calc(var(--line-height) * 2);
}

th,
td {
    border: var(--border-thickness) solid var(--text-color);
    padding: calc((var(--line-height) / 2)) calc(1ch - var(--border-thickness) / 2)
        calc((var(--line-height) / 2) - (var(--border-thickness)));
    line-height: var(--line-height);
    vertical-align: top;
    text-align: left;
}

table tbody tr:first-child > * {
    padding-top: calc((var(--line-height) / 2) - var(--border-thickness));
}

th {
    font-weight: 700;
}

/* Table utilities */
.width-min {
    width: 0%;
}

.width-auto {
    width: 100%;
}

/* Header table (used in post banners) */
.header {
    margin-bottom: calc(var(--line-height) * 2);
}

.header h1 {
    margin: 0;
}

.header tr td:last-child {
    text-align: right;
}

.header a {
    text-decoration: none;
}

.header a:hover {
    text-decoration: underline;
    text-decoration-thickness: var(--border-thickness);
}

/* ==========================================================================
   8. Content (Posts, Images, Code)
   ========================================================================== */

/* Post list */
.posts ul {
    padding: 0;
}

.posts li {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.posts li a {
    text-decoration: none;
}

.posts li a:hover {
    text-decoration: underline;
    text-decoration-thickness: var(--border-thickness);
}

.posts li time {
    font-variant-numeric: tabular-nums;
}

/* Single post */
.post .meta {
    color: var(--text-color-alt);
    font-size: 0.9rem;
}

/* Images */
img,
video {
    display: block;
    width: 100%;
    object-fit: contain;
    overflow: hidden;
}

img {
    width: initial;
    max-width: 100%;
    margin: var(--line-height) auto;
    height: auto;
    font-style: italic;
    color: var(--text-color-alt);
}

/* Code */
pre,
code {
    font-family: var(--font-family);
}

pre {
    white-space: pre;
    overflow-x: auto;
    overflow-y: hidden;
    margin: var(--line-height) 0;
    padding: var(--line-height);
}

code {
    font-weight: var(--font-weight-medium);
    color: #01a0e4;
}

figure {
    margin: var(--line-height) 0;
    overflow-x: auto;
    overflow-y: hidden;
}

figure pre {
    margin: 0;
}

figcaption {
    display: block;
    font-style: italic;
    margin-top: var(--line-height);
}

/* ==========================================================================
   9. Tree View
   ========================================================================== */

.tree,
.tree ul {
    position: relative;
    padding-left: 0;
    list-style-type: none;
    line-height: var(--line-height);
}

.tree ul {
    margin: 0;
}

.tree ul li {
    position: relative;
    padding-left: 1.5ch;
    margin-left: 1.5ch;
    border-left: var(--border-thickness) solid var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree ul li:before {
    position: absolute;
    display: block;
    top: calc(var(--line-height) / 2);
    left: 0;
    content: "";
    width: 1ch;
    border-bottom: var(--border-thickness) solid var(--text-color);
}

.tree ul li:last-child {
    border-left: none;
}

.tree ul li:last-child:after {
    position: absolute;
    display: block;
    top: 0;
    left: 0;
    content: "";
    height: calc(var(--line-height) / 2);
    border-left: var(--border-thickness) solid var(--text-color);
}

/* Reset ordered list counters in tree */
.tree ol li:before {
    content: none;
    counter-increment: none;
}

/* ==========================================================================
   10. Footnotes
   ========================================================================== */

.footnotes > ol {
    counter-reset: footnote-counter;
    list-style: none;
}

.footnotes > ol > li {
    counter-increment: footnote-counter;
    margin-bottom: var(--line-height);
}

.footnotes > ol > li::before {
    content: counter(footnote-counter) ". ";
    font-weight: var(--font-weight-bold);
}

.footnotes p {
    display: inline;
}

/* ==========================================================================
   11. Journal Table
   ========================================================================== */

.latest-journal.header {
    text-transform: uppercase;
}

.latest-journal.header td.width-auto {
    white-space: nowrap;
}

.latest-journal.header th.width-min {
    white-space: nowrap;
}

.latest-journal.header td[colspan="2"] {
    text-align: left;
}

.latest-journal .journal-label {
    background-color: var(--background-color-alt);
    text-align: left;
}

.latest-journal .journal-cell:hover {
    cursor: pointer;
}

.latest-journal .journal-cell:hover .journal-link {
    text-decoration: underline;
}

/* ==========================================================================
   12. Forms & Buttons
   ========================================================================== */

input,
button,
.button,
textarea {
    border: var(--border-thickness) solid var(--text-color);
    padding: calc(var(--line-height) / 2 - var(--border-thickness)) calc(1ch - var(--border-thickness));
    margin: 0;
    font: inherit;
    font-weight: inherit;
    height: calc(var(--line-height) * 2);
    width: auto;
    overflow: visible;
    background: var(--background-color);
    color: var(--text-color);
    line-height: normal;
    -webkit-font-smoothing: inherit;
    -moz-osx-font-smoothing: inherit;
    -webkit-appearance: none;
    appearance: none;
}

button:focus,
.button:active,
input:focus {
    --border-thickness: 3px;
    outline: none;
}

input {
    width: calc(round(down, 100%, 1ch));
}

::placeholder {
    color: var(--text-color-alt);
    opacity: 1;
}

::-ms-input-placeholder {
    color: var(--text-color-alt);
}

button::-moz-focus-inner,
.button::-moz-focus-inner {
    padding: 0;
    border: 0;
}

button,
.button {
    text-transform: uppercase;
    font-weight: var(--font-weight-medium);
    cursor: pointer;
}

button:hover,
.button:hover {
    background: var(--background-color-alt);
}

button:active,
.button:active {
    transform: translate(2px, 2px);
}

label {
    display: block;
    width: calc(round(down, 100%, 1ch));
    height: auto;
    line-height: var(--line-height);
    font-weight: var(--font-weight-medium);
    margin: 0;
}

label input {
    width: 100%;
}

/* ==========================================================================
   13. Utilities
   ========================================================================== */

/* Grid layout */
.grid {
    display: flex;
    gap: 1ch;
    margin-bottom: var(--line-height);
}

.grid > * {
    flex: 1;
}

/* Text sizes */
.text-sm,
.text-small {
    font-size: calc(var(--font-size) * 0.8);
}

/* Read more link */
.read-more {
    margin: 0;
    display: block;
    text-decoration: none;
    text-transform: uppercase;
    font-weight: var(--font-weight-bold);
}

.read-more:hover {
    text-decoration: underline;
}

/* ==========================================================================
   14. Responsive
   ========================================================================== */

@media screen and (max-width: 480px) {
    :root {
        font-size: 14px;
    }

    table:not(.header) {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        margin: var(--line-height) 0;
        -webkit-overflow-scrolling: touch;
    }
}
