/* === Design Tokens === */

:root {
    /* Colors */
    --color-bg: #fffff8;
    --color-text: #111;
    --color-secondary: #444;
    --color-tertiary: #888;
    --color-muted: #555;
    --color-border: #ddd;
    --color-border-accent: #ccc;
    --color-surface: #f7f7f7;
    --color-surface-alt: #f0f0f0;
    --color-link: #333;
    --color-link-hover: #777;

    /* Spacing */
    --space-xs: 0.3em;
    --space-sm: 0.5em;
    --space-md: 1em;
    --space-lg: 1.5em;
    --space-xl: 2em;
    --space-2xl: 3em;

    /* Typography */
    --font-body:
        et-book, Palatino, "Palatino Linotype", "Palatino LT STD",
        "Book Antiqua", Georgia, serif;
    --font-mono: Consolas, "Liberation Mono", Menlo, Courier, monospace;
    --font-size-base: 15px;
    --font-size-sm: 0.85rem;
    --font-size-md: 0.9rem;
    --font-size-lg: 0.95rem;

    /* Modular type scale (ratio 1.333) */
    --ms-1: 1.333rem; /* h4 */
    --ms-2: 1.777rem; /* h3 */
    --ms-3: 2.369rem; /* h2 */
    --ms-4: 3.157rem; /* h1 */

    /* Modular spacing scale (ratio 1.25) */
    --sp-1: 0.64rem;
    --sp-2: 0.8rem;
    --sp-3: 1rem;
    --sp-4: 1.25rem;
    --sp-5: 1.563rem;
    --sp-6: 1.953rem;

    /* Layout */
    --content-padding: 4rem;
}

/* === Reset & Base === */

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: var(--font-size-base);
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-body);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    padding: 0 var(--content-padding);
    counter-reset: sidenote-counter;
}

/* === Layout === */

article,
.content,
#content {
    width: 100%;
    padding: 0;
    text-align: justify;
}

/* === Typography === */

h1,
h2,
h3,
h4 {
    font-weight: 400;
    line-height: 1.2;
    margin-bottom: var(--space-sm);
    text-align: left;
}

h1 {
    margin-top: var(--sp-6);
}
h2 {
    margin-top: var(--sp-5);
}
h3 {
    margin-top: var(--sp-4);
}
h4 {
    margin-top: var(--sp-3);
}

h1 a,
h2 a,
h3 a,
h4 a {
    text-decoration: none;
    color: inherit;
}

h1 {
    font-size: var(--ms-4);
}
h2 {
    font-size: var(--ms-3);
    font-style: italic;
}
h3 {
    font-size: var(--ms-2);
}
h4 {
    font-size: var(--ms-1);
}

p,
div.list-intro {
    margin-top: var(--sp-1);
    margin-bottom: var(--sp-1);
}

div.list-intro > ul,
div.list-intro > ol {
    margin-top: 0;
    margin-bottom: 0;
}

div.list-intro > p {
    margin-top: 0;
}

dl,
table,
blockquote,
pre {
    margin-bottom: var(--sp-2);
}

ol,
ul {
    padding-left: 1.5em;
    margin-top: 0;
    margin-bottom: var(--sp-1);
    line-height: 1.4;
}

ol ol,
ol ul,
ul ol,
ul ul {
    padding-left: 1.5em;
    margin-bottom: 0;
}

a {
    color: var(--color-link);
}
a:hover {
    color: var(--color-link-hover);
}

blockquote {
    border-left: 3px solid var(--color-border-accent);
    padding-left: 1.2em;
    margin-left: 0;
    font-style: italic;
}

/* === Sidenotes & Margin Notes (Tufte-style) === */

.sidenote-toggle {
    display: none;
}

.sidenote-number {
    counter-increment: sidenote-counter;
}

.sidenote-number::after {
    content: counter(sidenote-counter);
    font-size: 0.7rem;
    vertical-align: super;
    line-height: 0;
}

.sidenote {
    float: right;
    clear: right;
    margin-right: -60%;
    width: 50%;
    font-size: var(--font-size-sm);
    line-height: 1.4;
    margin-top: 0.3rem;
    margin-bottom: var(--space-md);
    vertical-align: baseline;
    position: relative;
}

.sidenote::before {
    content: counter(sidenote-counter) ". ";
    font-size: 0.7rem;
    vertical-align: super;
}

/* === Standard Footnotes (fallback and mobile) === */

.footref {
    font-size: 0.75rem;
    vertical-align: super;
    line-height: 0;
    text-decoration: none;
}

.footnotes {
    margin-top: var(--space-2xl);
    border-top: 1px solid var(--color-border);
    padding-top: var(--space-md);
    font-size: var(--font-size-md);
}

.footnotes h2 {
    font-size: 1.2rem;
    margin-bottom: var(--space-sm);
}

.footnotes ol {
    padding-left: var(--space-lg);
}

.footnotes li {
    margin-bottom: var(--space-sm);
}

/* === Code === */

code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    background: var(--color-surface-alt);
    padding: 0.15em 0.3em;
    border-radius: 3px;
}

pre {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: var(--space-md);
    overflow-x: auto;
    font-size: var(--font-size-sm);
    line-height: 1.5;
    text-align: left;
}

pre code {
    background: none;
    padding: 0;
    border-radius: 0;
}

/* === Tables === */

table {
    border-collapse: collapse;
    width: auto;
    margin-bottom: var(--sp-3);
}

th,
td {
    border-bottom: 1px solid var(--color-border);
    padding: 0.4em 0.8em;
    text-align: left;
}

th {
    font-weight: 600;
}

/* === Citations / References === */

.csl-bib-body {
    font-size: var(--font-size-md);
    line-height: 1.5;
}

.csl-entry {
    margin-bottom: 0.8em;
    overflow: hidden;
}

.csl-left-margin {
    float: left;
    min-width: 2.5em;
    padding-right: 0.5em !important;
}

.csl-right-inline {
    margin-left: 3em !important;
}

/* === Header & Nav === */

header {
    padding: var(--space-lg) 0 var(--space-md);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-xl);
}

header .site-title {
    font-size: 1.6rem;
    font-weight: 400;
    text-decoration: none;
    color: var(--color-text);
}

nav {
    margin-top: var(--space-sm);
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
}

nav a {
    display: inline-flex;
    align-items: center;
    gap: 0.3em;
    margin-right: 1.2em;
    text-decoration: none;
    color: var(--color-muted);
    font-size: var(--font-size-lg);
}

nav a:hover {
    color: var(--color-text);
}

.nav-icon {
    display: none;
}

/* === Footer === */

footer {
    margin-top: var(--space-2xl);
    padding: var(--space-lg) 0;
    border-top: 1px solid var(--color-border);
    font-size: var(--font-size-sm);
    color: var(--color-tertiary);
}

/* === Sitemap (blog/til index) === */

.sitemap-date {
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    color: var(--color-tertiary);
    margin-right: var(--space-sm);
}

/* === Post metadata === */

.post-date {
    color: var(--color-tertiary);
    font-size: var(--font-size-md);
    margin-bottom: var(--space-lg);
}

.subtitle {
    font-style: italic;
    font-size: 1.1rem;
    color: var(--color-muted);
    margin-top: -0.5em;
    margin-bottom: var(--space-lg);
}

/* === Table of Contents === */

#table-of-contents {
    font-size: var(--font-size-md);
    margin-bottom: var(--space-xl);
    display: block;
}

#table-of-contents h2 {
    font-size: 1.1rem;
    display: block;
    margin-bottom: var(--space-sm);
}

.toc-select {
    display: block;
    width: auto;
    margin-bottom: var(--space-sm);
    font-size: var(--font-size-sm);
    font-family: var(--font-body);
    color: var(--color-secondary);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 3px;
    padding: 0.3em 0.5em;
}

.toc-toggle {
    display: inline-block;
    width: 2.2em;
    line-height: 1.4;
    text-align: center;
    cursor: pointer;
    color: var(--color-tertiary);
    user-select: none;
    font-size: 0.75em;
    vertical-align: 0.15em;
    border-radius: 3px;
    background: var(--color-surface-alt);
    margin-right: 0.3em;
}

.toc-toggle:hover {
    background: var(--color-border);
}

/* placeholder keeps alignment for leaf items */
.toc-toggle-placeholder {
    display: inline-block;
    width: 2.2em;
    margin-right: 0.3em;
    font-size: 0.75em;
}

#text-table-of-contents ul {
    list-style: none;
    padding-left: 1em;
    margin-bottom: 0;
}

#text-table-of-contents > ul {
    padding-left: 0;
}

/* === Images === */

img {
    max-width: 100%;
    height: auto;
}

figure {
    margin: var(--space-lg) 0;
}

figcaption {
    font-size: var(--font-size-sm);
    color: var(--color-secondary);
    margin-top: var(--space-xs);
}

/* === Mobile === */

@media (max-width: 900px) {
    body {
        padding: 0 1.5rem;
    }

    .sidenote {
        display: none;
    }

    .sidenote-toggle:checked + .sidenote {
        display: block;
        float: none;
        width: 95%;
        margin: var(--space-sm) 0 var(--space-sm) var(--space-md);
        padding: var(--space-sm);
        background: #f9f9f5;
        border-left: 2px solid var(--color-border-accent);
    }

    label.sidenote-toggle {
        display: inline;
        cursor: pointer;
    }
}

@media (max-width: 600px) {
    html {
        font-size: 14px;
    }
    h1 {
        font-size: 1.8rem;
    }
    h2 {
        font-size: 1.4rem;
    }
    .nav-label {
        display: none;
    }
    .nav-icon {
        display: block;
        width: 28px;
        height: 28px;
    }
    nav {
        justify-content: center;
    }
    nav a {
        margin-right: 0.8em;
    }
    header {
        text-align: center;
    }
}

/* === Debug mode (toggle by clicking year in footer) === */

body.debug * {
    outline: 1px solid #00cc44;
}

body.debug *:hover {
    outline: 2px solid #ff4400;
    background: rgba(0, 204, 68, 0.04);
}

#debug-toggle {
    cursor: pointer;
    user-select: none;
}

/* === Bib header (reading pages) === */

.bib-header {
    width: 100%;
    padding: var(--space-sm) 0;
    margin-bottom: var(--space-lg);
    color: var(--color-secondary);
    font-size: var(--font-size-md);
}

.bib-author {
    font-weight: bold;
    margin-bottom: 0.2em;
}

.bib-journal {
    margin-bottom: 0.2em;
}

.bib-doi a {
    color: var(--color-tertiary);
    font-size: var(--font-size-sm);
}

.bib-abstract {
    font-size: var(--font-size-sm);
}

.bib-abstract-label {
    display: block;
    font-variant: small-caps;
    color: var(--color-tertiary);
}

/* === Inline citation quotes (transclusion) === */

.cite-group {
    display: inline;
}

.cite-group-body {
    display: none;
}

.cite-group.open .cite-group-body {
    display: block;
    background: var(--color-surface);
    border-left: 3px solid var(--color-border);
    padding: 0.5em 1em 0.4em 1em;
    margin: 0.4em 0 0.4em 0;
}

.cite-group-body ol {
    padding-left: 1.5em;
    margin: 0;
}

.cite-group-body li {
    margin-bottom: 0.5em;
}

.cite-group-body li:last-child {
    margin-bottom: 0;
}

.cite-quote-text {
    display: none;
    font-style: italic;
    margin-bottom: 0.2em;
}

li.quote-open .cite-quote-text {
    display: block;
}

.cite-heading {
    display: block;
    font-size: var(--font-size-sm);
    color: var(--color-tertiary);
    font-weight: bold;
}

.cite-heading-arrow {
    display: inline-block;
    margin-left: 0.4em;
    transition: transform 0.15s ease;
}

li.quote-open .cite-heading-arrow {
    transform: rotate(90deg);
}

.cite-attribution {
    display: block;
    font-size: var(--font-size-sm);
    color: var(--color-tertiary);
    opacity: 0.6;
    margin-top: 0.2em;
    text-decoration: underline;
}

