html {
    scroll-behavior: smooth;
}

::selection {
    background-color: var(--text-color);
    color: var(--background-color);
}

@font-face {
    font-family: "Berkeley Mono";
    src: url("./fonts/BerkeleyMonoVariable-Regular.woff2")
        format("woff2-variations");
    font-weight: 100 300;
    font-style: normal;
}

/* Light theme (default) */
:root {
    --background-color: #ffffff;
    --text-color: #000000;
    --link-hover-color: #505050;
    --code-background: #f7f7f7;
    --code-border: #e5e5e5;
    --blockquote-border: #d4d4d4;
    --date-color: #8a8a8a;
    --border-color: #c7c7c7;
    --accent-color: #252525;
    --step-0: clamp(1rem, 0.9rem + 0.7vw, 1.25rem);
    --step-1: clamp(1.7rem, 1.5rem + 1.2vw, 2.4rem);
    --foot-and-header-line-width: 15rem;
    --progress-bar-background: var(--border-color);
}

/* Dark theme using system preference */
@media (prefers-color-scheme: dark) {
    :root {
        --background-color: #1e1e1e;
        --text-color: #d0d0d0;
        --link-hover-color: #a0a0a0;
        --code-background: #2d2d2d;
        --code-border: #404040;
        --blockquote-border: #404040;
        --date-color: #707070;
        --border-color: #404040;
        --progress-bar-background: var(--border-color);
    }
}

/* Global Styles */
body {
    background-color: var(--background-color);
    color: var(--text-color);
    font-family:
        IBM Plex Sans,
        sans-serif;
    line-height: 1.75;
    letter-spacing: 0.01em;
    margin: 0;
    padding: 0;
    font-size: var(--step-0);
    font-weight: 100;
    font-feature-settings: "ss01" 1;
    padding-bottom: 50px;
    transition:
        background-color 0.3s,
        color 0.3s;
}

hr {
    border-top: 1px solid var(--border-color);
    margin: 25px 0 25px 0;
    width: 100%;
}

code {
    font-family: "Berkeley Mono", monospace;
    font-size: 14px;
    background-color: var(--code-background);
    border: 1px solid var(--code-border);
    border-radius: 3px;
    padding: 1em 1.25em;
    overflow-x: auto;
    display: block;
    max-width: 100%;
    white-space: pre-wrap;
    word-wrap: break-word;
    box-sizing: border-box;
    margin-bottom: 1.5em;
    margin-top: 1.5em;
}

pre {
    margin: 0;
    overflow-x: auto;
    max-width: 100%;
}

b {
    font-weight: 150;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-color);
    margin-bottom: 0;
    margin-top: 30px;
    font-family: "Berkeley Mono";
    line-height: 1.2;
}

h2 {
    font-weight: 110;
    /* font-size: var(--step-1); */
    letter-spacing: -0.01em;
    margin-left: -0.03em;
}

h3 {
    font-weight: 110;
}

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

a {
    color: var(--text-color);
    text-decoration: underline;
    text-decoration-color: var(--border-color);
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
    display: inline-block;
    transform: translateY(0);
    transition:
        color 0.15s ease-in-out,
        transform 0.15s ease-in-out;
}

a:hover {
    color: var(--link-hover-color);
    transform: translateY(1px);
}

p {
    margin-bottom: 0;
    hanging-punctuation: first;
}

blockquote {
    border-left: 3px solid var(--blockquote-border);
    margin: 10px 0;
    padding: 0 2rem;
    font-variation-settings: "wght" 360;
}

blockquote p {
    font-style: italic;
    font-weight: 300;
}

/* Layout Containers */
.index-container,
.post-container,
.container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    max-width: 750px;
    margin: 0 auto;
}

/* Navigation */
header {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    background-color: var(--background-color);
    width: 100%;
    box-sizing: border-box;
    margin: 0 auto;
}

nav {
    width: 100%;
}

.nav-bar {
    display: flex;
    max-width: 750px;
    width: 100%;
    margin: 0 auto;
    justify-content: flex-end;
}

.nav-item {
    padding: 1.5rem;
    justify-content: initial;
    text-align: left;
    font-family: "Berkeley Mono", monospace;
    display: flex;
    align-items: center;
}

.nav-item a {
    transition: color 0.1s ease-in-out;
}

.nav-item:first-child {
    margin-right: auto;
    padding-left: 0;
}

.nav-item h3 {
    margin-top: 0;
    line-height: inherit;
    letter-spacing: -0.02em;
}

/* Post Specific Styles */
.post {
    display: flex;
    margin-bottom: 0.1em;
    font-family: "Berkeley Mono";
    width: 100%;
    transition: background-color 0.15s ease-in-out;
}

.post:hover {
    background-color: rgba(0, 0, 0, 0.02);
}

@media (prefers-color-scheme: dark) {
    .post:hover {
        background-color: rgba(255, 255, 255, 0.03);
    }
}

.index-post-title {
    flex: 1;
}

.post-container {
    padding-top: 2rem;
}

.post-container h1 {
    margin-bottom: 10px;
}

.post-date {
    display: block;
    margin-bottom: 20px;
    color: var(--date-color);
    font-family: "Berkeley Mono";
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.8;
    font-size: 0.85em;
    font-variant-numeric: tabular-nums;
}

.index-date {
    color: var(--date-color);
    flex: 0 0 150px;
    text-align: left;
    font-variant-numeric: tabular-nums;
}

.post-content {
    margin-top: 20px;
}

/* Add subtle spacing between paragraphs */
.post-content p + p {
    margin-top: 1.5em;
}

/* Sharper, more refined borders */
.post-title-separator {
    border-top: 1px solid var(--border-color);
    margin: 1rem 0 1.5rem;
    width: min(var(--foot-and-header-line-width), 100%);
}

.cover-image {
    max-width: 100%;
    margin: 0.05rem 0;
    filter: contrast(1.03) brightness(1.02);
}

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

.post-content img {
    margin: 2rem 0;
}

/* Utility/Component Styles */
.about,
.newsletter {
    color: var(--link-hover-color);
}

/* Animations/Effects */
/* Reading progress bar: draws a line based on viewport scroll */
body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    height: 1px;
    width: 100%; /* we'll animate scale instead */
    background: var(--progress-bar-background);
    transform-origin: 0 0; /* anchor left */

    /* Animate its X-scale from 0â†’1 along the scroll timeline */
    animation: grow-x linear forwards;
    animation-timeline: scroll(
        root block
    ); /* Uses the root (viewport) scroller, block (vertical) axis */
}

/* Hide progress bar if body has 'no-progress-bar' class (e.g., for index.html) */
body.no-progress-bar::before {
    display: none;
}

@keyframes grow-x {
    from {
        transform: scaleX(0);
    }
    to {
        transform: scaleX(1);
    }
}

/* Subtle page transition */
.container,
.index-container {
    animation: fade-in 0.4s ease-out;
}

@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

ul {
    padding-left: 1em;
}

li {
    margin: 0.7em 0;
    list-style-type: none;
    position: relative;
}

li::before {
    content: "—";
    position: absolute;
    left: -1em;
}

footer {
    margin-top: 6rem;
    padding-top: 2rem;
    padding-bottom: 3rem;
}

.footer-content {
    max-width: 750px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.footer-line {
    width: var(--foot-and-header-line-width);
    height: 1px;
    background-color: var(--border-color);
    margin-bottom: 1rem;
}

.footer-text {
    font-family: "Berkeley Mono", monospace;
    font-size: 0.9rem;
    opacity: 0.7;
}

/* Print styles */
@media print {
    header,
    footer,
    nav {
        display: none;
    }

    body::before {
        display: none;
    }

    * {
        animation: none !important;
        transition: none !important;
    }

    body {
        font-size: 12pt;
        line-height: 1.5;
        color: #000;
        background: #fff;
    }

    a {
        color: #000;
        text-decoration: underline;
    }

    a[href^="http"]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }

    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
    }

    p, blockquote {
        orphans: 3;
        widows: 3;
    }

    img {
        max-width: 100% !important;
        page-break-inside: avoid;
    }
}