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

/* CSS Variables - Minimal Set */
:root {
    --bg: #ffffff;
    --bg-alt: #f8fafc;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --accent: #f97316;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
    /* Typography scale */
    --body-size: 16px;
    --body-lh: 1.6;
    --code-size: 13px;
    --code-lh: 1.4; /* denser but >= 1.4 */
    --code-cols: 100; /* desired code width in ch units */
    --container-pad: 2rem; /* pairs with mobile bleed */
}

[data-theme="dark"] {
    --bg: #0f172a;
    --bg-alt: #1e293b;
    --text: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    --accent: #fb923c;
    --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;
}

/* 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 */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--container-pad);
}

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

.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);
}

/* 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);
    border-color: var(--accent);
}

/* Main Content */
main {
    min-height: calc(100vh - 200px);
    padding: 3rem 0;
}

/* Articles */
article {
    background-color: var(--bg);
    margin-bottom: 2rem;
    padding: 2rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

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

article > header {
    padding-top: 1rem;
}

article > header h1 {
    margin-top: 0;
}

article h3 {
    margin-top: 0;
}

article h3 a {
    color: var(--text);
    text-decoration: none;
}

article h3 a:hover {
    color: var(--accent);
}

article p {
    color: var(--text-muted);
    margin-bottom: 14px;
}

/* 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;
    opacity: 0.8;
}

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-decoration: underline;
    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.25rem 0.5rem;
    border-radius: 4px;
    font-size: var(--code-size);
    line-height: var(--code-lh);
}

pre {
    background-color: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem; /* denser */
    overflow-x: auto;
    margin: 1rem 0; /* denser */
    -webkit-overflow-scrolling: touch;
}

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

/* Syntax highlighting wrapper */
.highlight {
    margin: 1.25rem 0; /* denser */
}

.highlight pre {
    margin: 0;
    background-color: var(--bg-alt) !important;
    /* Make code width scale with font-size using ch units, like a page measure */
    width: min(100%, calc(var(--code-cols) * 1ch));
    margin-left: auto;
    margin-right: auto;
}

.highlight table {
    margin: 0;
    border: none;
    background: none;
}

.highlight td {
    padding: 0;
    border: none;
}

.highlight .linenos {
    color: var(--text-muted);
    text-align: right;
    padding-right: 1rem;
    user-select: none;
    font-size: 0.75rem;
}

/* Override syntect theme default text color to keep high contrast */
.highlight .z-code {
    color: var(--text);
}

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

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 {
    background-color: var(--bg-alt);
    border-top: 1px solid var(--border);
    padding: 2rem 0;
    text-align: center;
}

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

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 0 1rem;
    }
    .header-content {
        flex-direction: column;
        gap: 1rem;
    }

    nav {
        gap: 1rem;
    }

    h1 {
        font-size: 2rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    h3 {
        font-size: 1.25rem;
    }

    article {
        padding: 1.5rem;
    }

    .article-meta {
        flex-direction: column;
        align-items: flex-start;
    }

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

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

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

/* Admonitions/Callouts */
.admonition {
    margin: 2rem 0;
    border-radius: 8px;
    overflow: hidden;
}

.admonition-note {
    border: 1px solid #539bf5;
    background-color: rgba(83, 155, 245, 0.1);
}

[data-theme="dark"] .admonition-note {
    border-color: #4493f8;
    background-color: rgba(68, 147, 248, 0.1);
}

.admonition-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    font-weight: 600;
    color: #539bf5;
    border-bottom: 1px solid #539bf5;
}

[data-theme="dark"] .admonition-title {
    color: #4493f8;
    border-bottom-color: #4493f8;
}

.admonition-icon {
    fill: currentColor;
    flex-shrink: 0;
}

.admonition-content {
    padding: 1rem;
}

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

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

/* 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);
    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 block improvements */
@media (max-width: 768px) {
    :root { --container-pad: 1rem; }
    .highlight .linenos { display: none; }
    .highlight table, .highlight tr, .highlight td { display: block; width: 100% !important; padding: 0; border: 0; }
    .highlight pre { width: 100%; }
    
    /* Smoother horizontal scroll and visual hint */
    pre, .highlight pre { position: relative; -webkit-overflow-scrolling: touch; }
    pre, code, .highlight pre code { tab-size: 2; -moz-tab-size: 2; }
    .highlight pre::after {
        content: "";
        position: absolute;
        top: 0; right: 0;
        width: 24px; height: 100%;
        pointer-events: none;
        background: linear-gradient(to left, rgba(248,250,252,0.95), rgba(248,250,252,0));
        border-top-right-radius: 8px; border-bottom-right-radius: 8px;
    }
    [data-theme="dark"] .highlight pre::after {
        background: linear-gradient(to left, rgba(30,41,59,0.95), rgba(30,41,59,0));
    }

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