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

html {
    font-size: 16px;
    line-height: 1.6;
    height: 100%; /* Ensure html takes full height */
}

body {
    font-family: 'JetBrains Mono', 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    font-feature-settings: "liga" 1, "calt" 1, "ss01" 1;
    font-variant-ligatures: common-ligatures contextual;
    background-color: #FEFEFE; /* Keep a fallback background color */
    color: #1A1A1A;
    min-height: 100vh; /* Ensure body takes full viewport height */
    padding: 0; /* Remove padding from body, it will be on site-container */
}

@media (max-width: 768px) {
    body {
        padding: 16px; /* This media query will still apply padding to body on small screens */
    }
}

/* Site Container for main content */
.site-container {
    max-width: 832px;
    margin: 0 auto;
    padding: 32px;
}

/* Typography */
h1 {
    font-size: 2rem;
    font-weight: 500;
    letter-spacing: -0.02em;
    line-height: 1.2;
    margin-bottom: 2.5rem; /* Refined */
    max-width: 65ch;
}

h2 {
    font-size: 1.5rem;
    font-weight: 500;
    line-height: 1.2;
    margin-top: 3rem; /* Refined */
    margin-bottom: 1.5rem; /* Refined */
    max-width: 65ch;
}

h3 {
    font-size: 1.25rem;
    font-weight: 500;
    line-height: 1.2;
    margin-top: 2rem; /* Refined */
    margin-bottom: 1rem; /* Refined */
    max-width: 65ch;
}

p {
    margin-bottom: 1.5rem; /* Refined */
    max-width: 65ch;
}

.meta {
    font-size: 0.875rem;
    color: #666666;
    margin-bottom: 32px;
}

/* Links */
a {
    color: #1A1A1A;
    text-decoration: underline;
    text-underline-offset: 0.2em; /* Subtle */
}

a:hover {
    text-decoration: none; /* Subtle */
    font-weight: 500;
}

a.external::after {
    content: " →";
}

/* Code */
code {
    font-size: 1rem;
    background-color: #F8F8F8;
    padding: 2px 4px;
    border: 1px solid #E5E5E5;
}

pre {
    background-color: #F8F8F8;
    border: 1px solid #E5E5E5;
    padding: 24px;
    margin: 24px 0;
    overflow-x: auto;
    line-height: 1.4;
    max-width: 65ch;
}

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

/* ASCII Elements */
.divider {
    color: #666666;
    margin: 48px 0;
    font-family: monospace;
    user-select: none;
}

.ascii-box {
    color: #666666;
    font-family: monospace;
    white-space: pre;
    margin: 24px 0;
    user-select: none;
}

/* Navigation */
nav {
    margin-bottom: 64px;
    max-width: 65ch;
}

nav ul {
    list-style: none;
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    padding-left: 0;
}

nav a {
    text-decoration: none;
    color: #1A1A1A;
    padding: 8px 16px;
}

nav a:hover {
    background-color: #F8F8F8;
}

nav a.current {
    background-color: #0A0A0A;
    color: #FEFEFE;
}

/* Article Layout */
article {
    margin-bottom: 64px;
}

.article-navigation {
    padding-top: 32px;
    margin-top: 64px;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
}

.nav-button {
    color: #1A1A1A;
    text-decoration: none;
    padding: 8px 16px;
    display: inline-block;
}

.nav-button:hover {
    background-color: #F8F8F8;
}

/* Lists */
ul, ol {
    max-width: 65ch;
    margin-bottom: 1.5rem; /* Refined */
    padding-left: 24px;
}

li {
    margin-bottom: 0.5rem; /* Refined */
}

/* Blockquotes */
blockquote {
    border-left: 4px solid #E5E5E5;
    padding-left: 24px;
    margin: 24px 0;
    max-width: 65ch;
    color: #666666;
}

/* Footer */
footer {
    padding-top: 32px;
    margin-top: 64px;
    color: #666666;
    font-size: 0.875rem;
}

.reading-time {
    color: #666666;
}

/* Images */
.image-container {
    margin: 48px 0;
    max-width: 65ch; /* Consistent Max-Width */
}

.image-large {
    width: 100%;
    height: auto;
    display: block;
    border: 1px solid #E5E5E5;
}

.image-caption {
    font-size: 0.875rem;
    color: #666666;
    margin-top: 8px;
    text-align: center;
}

/* New rule for tables */
table {
    max-width: 65ch; /* Consistent Max-Width */
    display: block; /* For responsiveness */
    overflow-x: auto; /* For responsiveness */
    margin-bottom: 1.5rem; /* Consistent spacing */
    border-collapse: collapse;
    width: 100%;
}

table th, table td {
    border: 1px solid #E5E5E5;
    padding: 8px 12px;
    text-align: left;
}

.image-large {
    width: 100%;
    height: auto;
    display: block;
    border: 1px solid #E5E5E5;
}

.image-caption {
    font-size: 0.875rem;
    color: #666666;
    margin-top: 8px;
    text-align: center;
}

/* Background iframe styles */
#background-iframe {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw; /* Use viewport width */
    height: 100vh; /* Use viewport height */
    z-index: -1; /* Place behind other content */
    border: none; /* Ensure no border */
}

/* Ensure main content has a background to be readable over the iframe */
main {
    background-color: transparent; /* Make main content transparent */
    position: relative; /* To ensure z-index works correctly for content */
    z-index: 1; /* Place above the background iframe */
}