/* CSS Reset */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* CSS Variables - Minimal Set */
:root {
    --bg: #ffffff;
    --bg-alt: #f8fafc;
    --text: #0f172a;
    --text-body: #334155; /* 10.4:1 on --bg */
    --text-muted: #64748b;
    --border: #e2e8f0;
    /* Orange for bars and borders; --accent-text is the darker orange that
       reads as text (5.2:1 on --bg, --accent is 2.8:1) */
    --accent: #f97316;
    --accent-text: #c2410c;
    --teal: #0f766e; /* 5.5:1 on --bg */
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
    /* Typography scale */
    --body-size: 16px;
    --body-lh: 1.65;
    --measure: 70ch; /* text column width, about 65-70 characters per line */
    --code-size: 13px;
    --code-lh: 1.5;
    --container-pad: 2rem; /* pairs with mobile bleed */
}

[data-theme="dark"] {
    --bg: #0f172a;
    --bg-alt: #1e293b;
    --text: #f8fafc;
    --text-body: #cbd5e1; /* 12:1 on --bg */
    --text-muted: #94a3b8;
    --border: #334155;
    --accent: #fb923c;
    --accent-text: #fb923c; /* 7.9:1 on --bg */
    --teal: #2dd4bf; /* 9.6:1 on --bg */
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.3);
}

/* Base Typography */
body {
    font-family:
        -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto,
        sans-serif;
    line-height: var(--body-lh);
    background-color: var(--bg);
    color: var(--text);
    font-size: var(--body-size);
    -webkit-font-smoothing: antialiased;
    /* Footer at the bottom of short pages */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

::selection {
    background-color: color-mix(in srgb, var(--teal) 30%, transparent);
}

/* Paragraph spacing */
p {
    margin: 0 0 14px 0;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 600;
    line-height: 1.3;
    color: var(--text);
}

h1 {
    font-size: clamp(2.1rem, 5vw + 1rem, 3.25rem);
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.01em;
    margin: 2.2rem 0 1rem 0;
    text-wrap: balance;
}

h2 {
    font-size: clamp(1.6rem, 2.4vw + 0.8rem, 2.125rem);
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.005em;
    margin: 1.8rem 0 0.75rem 0;
    text-wrap: balance;
}

h3 {
    font-size: 1.5rem;
    margin: 1.5rem 0 0.75rem 0;
}

h4 {
    font-size: 1.25rem;
    margin: 1.25rem 0 0.5rem 0;
}

h5,
h6 {
    font-size: 1rem;
    margin: 1rem 0 0.5rem 0;
}

/* Layout */
/* One narrow column for header, posts, and footer, so the logo lines up with the text */
.container {
    max-width: calc(var(--measure) + 2 * var(--container-pad));
    margin: 0 auto;
    padding: 0 var(--container-pad);
}

/* Header */
.site-header {
    background-color: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 1.5rem 0;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
    font-weight: 400;
    color: var(--text);
    text-decoration: none;
    font-family:
        "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
        "Liberation Mono", "Courier New", monospace;
}

.logo:hover {
    color: var(--accent);
}

.logo-highlight {
    color: var(--accent);
    font-weight: inherit;
}

/* Navigation */
nav {
    display: flex;
    align-items: center;
    gap: 2rem;
}

nav a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

nav a:hover,
nav a.active {
    color: var(--accent-text);
}

/* Icon links */
.icon-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    color: var(--text-muted);
}

.icon-link:hover {
    color: var(--accent);
}

.icon {
    width: 20px;
    height: 20px;
    fill: currentColor;
    display: block;
}

/* Raster/SVG image icons */
.icon-img {
    width: 20px;
    height: auto;
    display: block;
}

[data-theme="dark"] .icon-img.mastodon {
    filter: invert(1);
}

/* Theme Toggle */
.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.2rem;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition:
        border-color 0.2s ease,
        color 0.2s ease;
}

.theme-toggle:hover {
    color: var(--accent-text);
    border-color: var(--accent);
}

.theme-toggle .icon-sun,
[data-theme="dark"] .theme-toggle .icon-moon {
    display: none;
}

[data-theme="dark"] .theme-toggle .icon-sun {
    display: block;
}

/* Main Content */
main {
    flex: 1;
    padding: 3rem 0;
}

/* Post cards on the home page */
.post-preview {
    background-color: var(--bg);
    margin-bottom: 2rem;
    padding: 2rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.post-preview:hover {
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

.post-preview h3 {
    margin-top: 0;
}

.post-preview h3 a {
    color: var(--text);
    text-decoration: none;
}

.post-preview h3 a:hover {
    color: var(--accent-text);
}

.post-preview p {
    color: var(--text-muted);
}

/* Post page: plain text column, no card */
.post-header h1 {
    margin-top: 0;
}

.post .content {
    color: var(--text-body);
}

/* Article Meta */
.article-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    margin: 1rem 0 2rem 0;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    font-weight: 500;
    letter-spacing: 0.02em;
}

time,
.reading-time {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    letter-spacing: 0.02em;
}

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.tag {
    background-color: var(--accent);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

/* Content */
.content > *:first-child {
    margin-top: 0;
}

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

.content h2 {
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}

.content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 2rem 0;
}

.content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 3rem 0;
}

/* Links */
a {
    color: var(--accent-text);
    text-decoration: underline;
    text-decoration-color: var(--accent);
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
}

a:hover {
    text-decoration-thickness: 3px;
}

/* Code */
code {
    font-family:
        "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
        "Liberation Mono", "Courier New", monospace;
    font-variant-ligatures: common-ligatures contextual;
    font-feature-settings:
        "liga" 1,
        "calt" 1;
    background-color: var(--bg-alt);
    color: var(--text);
    padding: 0.15em 0.4em;
    border-radius: 4px;
    font-size: 0.875em;
}

pre {
    background-color: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    overflow-x: auto;
    margin: 1.25rem 0;
    -webkit-overflow-scrolling: touch;
    /* Set on <pre> too: its line box sets the minimum row height of the code inside */
    font-size: var(--code-size);
    line-height: var(--code-lh);
    tab-size: 4;
}

pre code {
    background: none;
    padding: 0;
    font-size: inherit;
    line-height: inherit;
    font-variant-ligatures: common-ligatures contextual;
    font-feature-settings:
        "liga" 1,
        "calt" 1;
}

/* Giallo line markup, required by Zola's highlighter */
.giallo-l {
    display: inline-block;
    min-height: 1lh;
    width: 100%;
    /* An empty line has no text baseline; top alignment keeps it one row tall */
    vertical-align: top;
}

.giallo-ln {
    display: inline-block;
    user-select: none;
    margin-right: 0.4em;
    /* Horizontal only: vertical padding on this inline-block makes every row taller */
    padding: 0 0.4em;
    min-width: 3ch;
    text-align: right;
    opacity: 0.8;
}

/* Label after a highlighted line, added by the script in base.html */
.code-note {
    margin-left: 2ch;
    color: var(--accent-text);
    font-weight: 700;
    user-select: none;
}

/* Source link above an embedded GitHub snippet */
.github-code-source {
    margin: 1rem 0 -0.75rem;
    font-size: 0.8rem;
}

/* Blockquotes */
blockquote {
    border-left: 4px solid var(--accent);
    margin: 2rem 0;
    padding: 1rem 1.5rem;
    background-color: var(--bg-alt);
    font-style: italic;
    color: var(--text-body);
}

blockquote p {
    margin: 0;
}

/* Lists */
ul,
ol {
    margin: 1rem 0;
    padding-left: 2rem;
}

li {
    margin-bottom: 0.5rem;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 2rem 0;
    background-color: var(--bg);
    border-radius: 8px;
    overflow: hidden;
}

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

th {
    background-color: var(--bg-alt);
    font-weight: 600;
}

tr:hover {
    background-color: var(--bg-alt);
}

/* Post Navigation */
.post-navigation {
    display: flex;
    justify-content: space-between;
    margin-top: 3rem;
    gap: 1rem;
}

.prev-post,
.next-post {
    flex: 1;
    padding: 1rem 1.5rem;
    background-color: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
}

.prev-post:hover,
.next-post:hover {
    background-color: var(--border);
    text-decoration: none;
}

.next-post {
    text-align: right;
}

/* Author Info */
.article-footer {
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
}

.author-info p {
    color: var(--text-muted);
}

/* Footer */
footer {
    border-top: 1px solid var(--border);
    padding: 1.5rem 0;
    text-align: center;
}

footer p {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Responsive */
@media (max-width: 768px) {
    .site-header {
        padding: 0.75rem 0;
    }

    .logo {
        font-size: 1.15rem;
    }

    nav {
        gap: 0.5rem;
    }

    /* The logo already links home */
    .nav-home {
        display: none;
    }

    main {
        padding: 1.5rem 0;
    }

    h1 {
        font-size: 2rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    h3 {
        font-size: 1.25rem;
    }

    .post-preview {
        padding: 1.25rem;
    }

    .post-navigation {
        flex-direction: column;
    }

    .next-post {
        text-align: left;
    }
}

/* Focus styles */
button:focus,
a:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* GitHub-style alerts: > [!NOTE], > [!TIP], > [!IMPORTANT], > [!WARNING], > [!CAUTION] */
blockquote[class^="markdown-alert-"] {
    --alert: var(--teal);
    font-style: normal;
    color: var(--text-body);
    margin: 2rem 0;
    padding: 0.75rem 1rem;
    border: 1px solid var(--alert);
    border-left-width: 4px;
    border-radius: 8px;
    background-color: color-mix(in srgb, var(--alert) 10%, transparent);
}

blockquote[class^="markdown-alert-"]::before {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--alert);
}

blockquote[class^="markdown-alert-"] > :first-child {
    margin-top: 0;
}

blockquote[class^="markdown-alert-"] > :last-child {
    margin-bottom: 0;
}

.markdown-alert-note::before { content: "Note"; }
.markdown-alert-tip { --alert: #3fb950; }
.markdown-alert-tip::before { content: "Tip"; }
.markdown-alert-important { --alert: #a371f7; }
.markdown-alert-important::before { content: "Important"; }
.markdown-alert-warning { --alert: #d29922; }
.markdown-alert-warning::before { content: "Warning"; }
.markdown-alert-caution { --alert: #f85149; }
.markdown-alert-caution::before { content: "Caution"; }

/* "#" link after headings, from templates/anchor-link.html */
.zola-anchor {
    margin-left: 0.4em;
    color: var(--text-muted);
    text-decoration: none;
    opacity: 0;
    transition: opacity 0.15s;
}

:is(h1, h2, h3, h4, h5, h6):hover .zola-anchor,
.zola-anchor:focus {
    opacity: 1;
}

.zola-anchor:hover {
    color: var(--teal);
}

/* No hover on touch screens: keep the link faintly visible */
@media (hover: none) {
    .zola-anchor {
        opacity: 0.4;
    }
}

/* Copy button on code blocks, added by the script in base.html */
.code-block {
    position: relative;
}

.copy-button {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0.2rem 0.6rem;
    font: inherit;
    font-size: 0.75rem;
    color: var(--text-muted);
    background-color: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
}

.code-block:hover .copy-button,
.copy-button:focus {
    opacity: 1;
}

@media (hover: none) {
    .copy-button {
        opacity: 1;
    }
}

/* TL;DR minimal callout: just an accent bar + label */
.tldr {
    border-left: 4px solid var(--accent);
    padding-left: 0.75rem;
    margin: 1.25rem 0 1.5rem;
}

.tldr-label {
    color: var(--accent-text);
    font-weight: 700;
    margin-right: 0.25rem;
}

.tldr p {
    /* if body renders a <p>, keep it inline */
    display: inline;
    margin: 0;
}

/* Themed images */
.themed-image {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 2rem auto;
}

/* Mobile code blocks */
@media (max-width: 768px) {
    :root { --container-pad: 1rem; }

    pre { tab-size: 2; }

    /* Bleed code blocks edge-to-edge on mobile */
    pre {
        margin-left: calc(-1 * var(--container-pad));
        margin-right: calc(-1 * var(--container-pad));
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
}
