/* Base Typography and Colors */
:root {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-code: #262626;
    --text-primary: #f0f0f0;
    --text-secondary: #b0b0b0;
    --accent: #4a9eff;
    --accent-hover: #357abd;
    --border-color: #333;
    --mobile-menu-height: 3rem;
}

/* Reset and Base Styles */
* {
    box-sizing: border-box;
}

body {
    padding: 0;
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: rgba(74, 158, 255, 0.2);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    margin: 0 0 1rem 0;
    font-weight: 600;
    line-height: 1.25;
    color: var(--text-primary);
}

h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

h2 {
    font-size: 1.5rem;
    margin-top: 2rem;
}

h3 {
    font-size: 1.25rem;
    margin-top: 1.5rem;
}

p {
    margin: 0 0 1rem 0;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

h1 a {
    color: inherit;
}

h1 a:hover {
    color: var(--accent);
    text-decoration: none;
}

/* Header */
#top {
    background-color: var(--bg-secondary);
    padding: 1.5rem 0;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.site-title {
    color: var(--text-primary);
    font-size: 1.75rem;
    font-weight: 600;
    text-decoration: none;
}

.site-title:hover {
    color: var(--accent);
    text-decoration: none;
}

/* Layout */
#main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem 2rem;
    display: flex;
    gap: 3rem;
}

#left {
    flex: 1;
    min-width: 0; /* Prevents flex item from overflowing */
    order: 2; /* Display second on desktop */
}

#right {
    width: 280px;
    flex-shrink: 0;
    order: 1; /* Display first on desktop */
}

/* Content Styling */
#subheading {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin: 0 0 1.5rem 0;
}

#subheading a {
    color: var(--text-secondary);
}

/* Sidebar */
#right h2 {
    font-size: 1.125rem;
    margin-top: 0;
    margin-bottom: 0.75rem;
    padding-top: 1.5rem;
}

#right h2:first-child {
    padding-top: 0;
}

#right p {
    font-size: 0.875rem;
    line-height: 1.5;
    margin-bottom: 1.5rem;
}

#right ul {
    padding-left: 0;
    margin: 0 0 1rem 0;
    list-style: none;
}

#right ul li {
    margin-bottom: 0.5rem;
}

#right ul li a {
    font-size: 0.875rem;
}

/* Lists */
.list {
    width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* Code Blocks */
pre {
    background-color: var(--bg-code);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 1rem;
    margin: 0 0 1rem 0;
    overflow-x: auto;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 0.875rem;
    line-height: 1.5;
    position: relative;
}

/* Code block scroll indicator for mobile */
pre::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 3rem;
    background: linear-gradient(to right, transparent, var(--bg-code));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

pre:hover::after {
    opacity: 1;
}

code {
    background-color: var(--bg-code);
    padding: 0.125rem 0.375rem;
    border-radius: 3px;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 0.875em;
}

pre code {
    background: none;
    padding: 0;
    font-size: inherit;
}

/* Syntax Highlighting */
.highlight {
    background-color: var(--bg-code);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin-bottom: 1rem;
    overflow: hidden;
}

.highlight pre {
    margin: 0;
    border: none;
}

/* Syntax colors optimized for dark theme */
.highlight .d { color: #f0f0f0; }
.highlight .kt { color: #66d9ef; font-weight: normal; }
.highlight .k { color: #66d9ef; font-weight: normal; }
.highlight .s { color: #e6db74; }
.highlight .mi { color: #ae81ff; }
.highlight .mf { color: #ae81ff; }
.highlight .nt { color: #f92672; }
.highlight .c { color: #75715e; font-style: italic; }
.highlight .cm { color: #75715e; font-style: italic; }
.highlight .cp { color: #75715e; }
.highlight .c1 { color: #75715e; font-style: italic; }
.highlight .cs { color: #75715e; font-style: italic; }
.highlight .kd { color: #66d9ef; }
.highlight .nc { color: #a6e22e; }
.highlight .nf { color: #a6e22e; }
.highlight .o { color: #f92672; }
.highlight .p { color: #f0f0f0; }
.highlight .n { color: #f0f0f0; }

/* Blockquotes */
blockquote {
    border-left: 4px solid var(--border-color);
    margin: 0 0 1rem 0;
    padding-left: 1rem;
    color: var(--text-secondary);
    font-style: italic;
}

/* Tables */
table {
    border-collapse: collapse;
    width: 100%;
    margin-bottom: 1rem;
    overflow-x: auto;
    display: block;
}

table, tr, td, th {
    border: 1px solid var(--border-color);
}

td, th {
    padding: 0.5rem;
    white-space: nowrap;
}

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

/* Images */
img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}

.profile-image {
    width: 100%;
    max-width: 200px;
    height: auto;
    aspect-ratio: 1 / 1;
    margin: 0 auto 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    filter: grayscale(0.2) contrast(1.2) brightness(0.85) sepia(0.3);
    opacity: 0.85;
    transition: all 0.3s ease;
    display: block;
}

.profile-image:hover {
    filter: grayscale(0.2) contrast(1.1) brightness(0.9) sepia(0.05);
    opacity: 0.95;
}

/* Figure */
figure {
    margin: 0 0 1rem 0;
}

/* Related Posts */
#related {
    margin: 3rem 0 0 0;
    padding: 2rem 0 0 0;
    border-top: 1px solid var(--border-color);
}

#related h2 {
    margin-top: 0;
}

/* Comments */
#comments {
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

/* Mobile Navigation Toggle (hidden by default) */
#mobile-menu-toggle {
    display: none;
}

/* Social Links Icons */
.social-links {
    display: flex;
    gap: 0.75rem;
}

#right .social-links {
    margin-top: 1rem;
    margin-right: 0;
}

.social-links a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0.5rem;
    border-radius: 0.25rem;
    transition: all 0.2s ease;
    min-height: unset;
    line-height: 1;
    margin: 0;
}

.social-links a:hover {
    background-color: var(--bg-code);
    transform: translateY(-2px);
}

.social-links svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        font-size: 16px;
        line-height: 1.7;
    }
    
    #top {
        padding: 1rem 0;
        margin-bottom: 1.5rem;
        position: relative;
    }
    
    .header-content {
        padding: 0 1.5rem;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .social-links {
        margin-right: 0;
        margin-top: 1rem;
        width: 100%;
        justify-content: center;
    }
    
    .site-title {
        font-size: 1.5rem;
        width: 100%;
        text-align: center;
    }
    
    #main {
        flex-direction: column;
        padding: 0 1.5rem 1.5rem;
        gap: 0;
    }
    
    #left {
        width: 100%;
        margin-bottom: 2rem;
        order: 1; /* Display first on mobile */
    }
    
    #right {
        width: 100%;
        border-top: 1px solid var(--border-color);
        padding-top: 2rem;
        margin-top: 2rem;
        order: 2; /* Display second on mobile */
    }
    
    /* Enhanced mobile typography */
    h1 {
        font-size: 1.75rem;
        line-height: 1.3;
        margin-bottom: 0.75rem;
    }
    
    h2 {
        font-size: 1.375rem;
        margin-top: 1.75rem;
    }
    
    h3 {
        font-size: 1.125rem;
        margin-top: 1.5rem;
    }
    
    p {
        margin-bottom: 1.25rem;
    }
    
    /* Better mobile code blocks */
    pre {
        padding: 1rem;
        font-size: 0.8125rem;
        margin-left: -1.5rem;
        margin-right: -1.5rem;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    
    .highlight {
        margin-left: -1.5rem;
        margin-right: -1.5rem;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    
    /* Show scroll indicator on mobile code blocks */
    pre::after {
        opacity: 1;
    }
    
    /* Better touch targets */
    a {
        display: inline-block;
        min-height: 44px;
        line-height: 44px;
        padding: 0 0.5rem;
        margin: 0 -0.5rem;
    }
    
    #right a {
        display: block;
        padding: 0.5rem 0;
        margin: 0;
        min-height: 44px;
        line-height: 1.5;
    }
    
    /* Better list spacing on mobile */
    #right ul li {
        margin-bottom: 0;
    }
    
    /* Improved table handling */
    table {
        font-size: 0.875rem;
    }
    
    /* Better blockquote styling */
    blockquote {
        margin-left: 0;
        margin-right: 0;
        padding-left: 1.25rem;
    }
}

/* Small mobile devices */
@media (max-width: 375px) {
    .site-title {
        font-size: 1.25rem;
    }
    
    h1 {
        font-size: 1.5rem;
    }
    
    #main {
        padding: 0 1rem 1rem;
    }
    
    pre {
        margin-left: -1rem;
        margin-right: -1rem;
        padding: 0.75rem;
        font-size: 0.75rem;
    }
    
    .highlight {
        margin-left: -1rem;
        margin-right: -1rem;
    }
}

/* Utility Classes */
.text-muted {
    color: var(--text-secondary);
}

/* Improve readability of long-form content */
#left > p,
#left > ul,
#left > ol,
#left > blockquote {
    max-width: 65ch;
}

/* Mobile-specific: remove max-width constraint */
@media (max-width: 768px) {
    #left > p,
    #left > ul,
    #left > ol,
    #left > blockquote {
        max-width: none;
    }
}

/* Add smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
    
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

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

/* Print styles */
@media print {
    body {
        background: white;
        color: black;
    }
    
    #right,
    #top,
    #comments,
    #related {
        display: none;
    }
    
    #main {
        max-width: none;
        padding: 0;
    }
    
    a {
        color: black;
        text-decoration: underline;
    }
}

