/* Enhanced Font Loading */
@font-face {
    font-family: 'ASM-Regular';
    src: url('asm-regular.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* CSS Variables for Light/Dark Theme */
:root {
    /* Base colors */
    --bg-color: #ffffff;
    --text-color: #24292e;
    --text-muted: #586069;
    --border-color: #e1e4e8;
    --bg-secondary: #f8f9fa;

    /* Accent colors (your existing theme) */
    --accent-color: #c54b99;
    --accent-hover: #a53d85;

    /* Enhanced color palette */
    --accent-light: color-mix(in srgb, var(--accent-color) 20%, white);
    --accent-dark: color-mix(in srgb, var(--accent-color) 80%, black);
    --accent-muted: color-mix(in srgb, var(--accent-color) 30%, var(--text-muted));

    /* Code styling */
    --code-bg: #f6f8fa;
    --code-border: #e1e4e8;
    --inline-code-bg: #2d3748;
    --inline-code-text: #e2e8f0;
    --inline-code-border: #4a5568;

    /* Special effects */
    --money-color: #22c55e;
    --money-shadow: rgba(34, 197, 94, 0.3);
    --money-shadow-intense: rgba(34, 197, 94, 0.6), rgba(34, 197, 94, 0.4), rgba(34, 197, 94, 0.2);

    /* UI elements */
    --toc-bg: #f8f9fa;
    --scrollbar-thumb: #d1d5da;
    --copy-btn-bg: #6c757d;
    --copy-btn-hover: #5a6268;
    --toc-branch-color: #cbd5e1;
    --toc-branch-color-light: #e2e8f0;
    --no-posts-code-bg: rgba(27,31,35,0.05);

    /* Semantic colors */
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-error: #ef4444;
}

/* Dark theme overrides */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #0d1117;
        --text-color: #f0f6fc;
        --text-muted: #8b949e;
        --border-color: #30363d;
        --bg-secondary: #161b22;
        --accent-color: #c54b99;
        --accent-hover: #a53d85;
        --accent-light: color-mix(in srgb, #c54b99 20%, white);
        --accent-dark: color-mix(in srgb, #c54b99 80%, black);
        --accent-muted: color-mix(in srgb, #c54b99 30%, #8b949e);
        --code-bg: #161b22;
        --code-border: #30363d;
        --inline-code-bg: #6e7681;
        --inline-code-text: #f0f6fc;
        --inline-code-border: #8b949e;
        --money-color: #4ade80;
        --money-shadow: rgba(74, 222, 128, 0.3);
        --money-shadow-intense: rgba(74, 222, 128, 0.6), rgba(74, 222, 128, 0.4), rgba(74, 222, 128, 0.2);
        --toc-bg: #161b22;
        --scrollbar-thumb: #6e7681;
        --copy-btn-bg: #8b949e;
        --copy-btn-hover: #6e7681;
        --toc-branch-color: #6e7681;
        --toc-branch-color-light: #8b949e;
        --no-posts-code-bg: rgba(240,246,252,0.1);
    }
}

/* Manual theme overrides - minimal overrides only for specific cases */

/* Accessibility - Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    html {
        scroll-behavior: auto;
    }
}

.post-content img {
    max-width: 100%;
    max-height: 70vh; /* Limits height to 70% of viewport height */
    width: auto;
    height: auto;
    display: block;
    margin: 2rem auto;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    object-fit: contain; /* Ensures entire image is visible */
}

/* For mobile devices, reduce max height further */
@media (max-width: 768px) {
    .post-content img {
        max-height: 50vh;
        margin: 1.5rem auto;
    }
}

/* For very wide images, you might want additional constraints */
.post-content img {
    max-width: min(100%, 800px); /* Never wider than 800px or container width */
}

/* High contrast support */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000;
        --text-muted: #333;
    }

    [data-theme="dark"] {
        --border-color: #fff;
        --text-muted: #ccc;
    }
}

/* Base styles with enhanced typography */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

html {
    scroll-behavior: smooth;
    background-color: var(--bg-color);
    color: var(--text-color);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    line-height: 1.65;
    color: var(--text-color);
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    background-color: inherit;
    font-optical-sizing: auto;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    container-type: inline-size;
}



/* Enhanced header */
.header {
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.header h1 {
    font-size: 2rem;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 0.5rem;
    text-wrap: balance;
}

.header .blog-title {
    color: var(--text-color);
    text-decoration: none;
    transition: color 0.2s ease;
}

.header .blog-title:hover {
    color: var(--accent-color);
}

.header p {
    color: var(--text-muted);
    font-size: 1rem;
}



/* Breadcrumb */
.breadcrumb {
    margin-bottom: 1.5rem;
}

.breadcrumb a {
    color: var(--accent-color);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s ease;
}

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

.breadcrumb a:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Enhanced two-column layout */
.post-layout {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

.toc-sidebar {
    flex: 0 0 250px;
    position: sticky;
    top: 2rem;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
    contain: layout style;
}

/* Enhanced scrollbar for TOC */
.toc-sidebar::-webkit-scrollbar {
    width: 6px;
}

.toc-sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.toc-sidebar::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
    transition: background 0.2s ease;
}

.toc-sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color);
}

/* Enhanced TOC */
.toc {
    background-color: color-mix(in srgb, var(--toc-bg) 90%, transparent);
    backdrop-filter: blur(10px);
    border: 1px solid color-mix(in srgb, var(--border-color) 60%, transparent);
    border-radius: 12px;
    padding: 1.5rem;
    position: relative;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.toc::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-color), var(--accent-hover), var(--accent-color));
    background-size: 200% 100%;
    animation: gradient-shift 3s ease-in-out infinite;
    border-radius: 12px 12px 0 0;
}

@keyframes gradient-shift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.toc h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-muted);
    text-transform: lowercase;
    letter-spacing: 0.025em;
    position: relative;
    text-wrap: balance;
}

.toc h2::after {
    content: '';
    position: absolute;
    bottom: -0.5rem;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent-color), transparent);
}

.toc ul {
    list-style: none;
}

.toc li {
    margin-bottom: 0.25rem;
    position: relative;
}

.toc a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 400;
    font-size: 0.9rem;
    display: block;
    padding: 0.4rem 0;
    transition: all 0.2s ease;
    border-left: 2px solid transparent;
    padding-left: 0.5rem;
    position: relative;
    will-change: transform;
}

.toc a:hover {
    color: var(--accent-color);
    transform: translateX(2px);
}

.toc a::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 2px;
    background: var(--accent-color);
    transition: width 0.2s ease;
    border-radius: 1px;
    will-change: width;
}

.toc a:hover::before {
    width: 3px;
}

.toc .toc-h1 {
    font-weight: 500;
    color: var(--text-color);
    display: flex;
    align-items: center;
}

.toc .toc-h1::after {
    content: '';
    margin-left: auto;
    width: 4px;
    height: 4px;
    background: var(--accent-color);
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.toc .toc-h1:hover::after,
.toc .toc-h1.active::after {
    opacity: 1;
}

.toc .toc-h2 {
    margin-left: 1rem;
    font-size: 0.85rem;
}

.toc .toc-h3 {
    margin-left: 2rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.toc .toc-h2::before,
.toc .toc-h3::before {
    position: absolute;
    left: -0.5rem;
    font-weight: 400;
}

.toc a.active {
    color: var(--accent-color);
    font-weight: 500;
    border-left-color: var(--accent-color);
    background: linear-gradient(90deg,
        color-mix(in srgb, var(--accent-color) 10%, transparent),
        color-mix(in srgb, var(--accent-color) 5%, transparent)
    );
    border-radius: 4px;
    margin: 0 -0.5rem;
    padding: 0.4rem 1rem;
}

.toc a.active::before {
    width: 3px;
}

.toc a.active:hover {
    color: var(--accent-hover);
}

/* Enhanced money shimmer animation */
.money {
    color: var(--money-color);
    font-weight: 600;
    position: relative;
    display: inline-block;
    animation: shimmer 2s ease-in-out infinite;
}

@keyframes shimmer {
    0%, 100% {
        text-shadow: 0 0 5px var(--money-shadow);
    }
    50% {
        text-shadow: 0 0 10px var(--money-shadow-intense);
    }
}

.money:hover {
    animation-duration: 0.5s;
}

/* Main content area */
.post-layout .content {
    flex: 1;
    min-width: 0;
    contain: layout style;
}

/* Enhanced posts list */
.posts-list {
    display: grid;
    gap: 2rem;
}

.posts-list h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-color);
    text-wrap: balance;
}

/* Enhanced post preview cards */
.post-preview {
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem; /* Reduced top/bottom padding */
    margin: 0 -1.5rem 0rem -1.5rem; /* Reduced bottom margin */
    border-radius: 12px;
    transition: all 0.3s ease;
    contain: layout style;
}

.post-preview:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.1);
    background-color: var(--bg-secondary);
    border-bottom-color: transparent;
}

.post-preview:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.post-preview h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    text-wrap: balance;
}

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

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

.post-preview h3 a:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
    border-radius: 4px;
}

.post-preview .meta {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 0.75rem;
}

.post-excerpt {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
    line-height: 1.5;
    max-width: 70ch;
}

.read-more {
    color: var(--accent-color);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.read-more:hover {
    text-decoration: underline;
    color: var(--accent-hover);
}

.read-more:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Enhanced single post styles */
.single-post .post-header {
    margin-bottom: 2rem;
}

.single-post .post-header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    line-height: 1.2;
    color: var(--text-color);
    text-wrap: balance;
}

.single-post .meta {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.post-description {
    font-size: 1.1rem;
    color: var(--text-muted);
    font-style: italic;
    margin-bottom: 1rem;
    max-width: 70ch;
}

/* Enhanced post content */
.post-content {
    margin-top: 2rem;
}

.post-content h1, .post-content h2, .post-content h3 {
    text-wrap: balance;
}

.post-content h1 {
    font-size: 2rem;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3rem;
    margin-bottom: 1rem;
    margin-top: 3rem;
    color: var(--text-color);
}

.post-content h1:first-child {
    margin-top: 0;
}

.post-content h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1rem;
    margin-top: 2rem;
    color: var(--text-color);
}

.post-content h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    margin-top: 1.5rem;
    color: var(--text-color);
}

.post-content p {
    margin-bottom: 1.25rem;
    line-height: 1.65;
    color: var(--text-color);
    max-width: 70ch;
}

.post-content ul,
.post-content ol {
    margin-bottom: 1rem;
    margin-left: 2rem;
}

.post-content li {
    margin-bottom: 0.25rem;
    color: var(--text-color);
}

/* Enhanced inline code */
.post-content code {
    background-color: var(--inline-code-bg);
    color: var(--inline-code-text);
    border-radius: 6px;
    font-size: 0.85em;
    padding: 0.4em 0.6em;
    font-family: 'ASM-Regular', 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-weight: 500;
    border: 1px solid var(--inline-code-border);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    white-space: nowrap;
    display: inline-block;
    margin: 0 2px;
}

/* Enhanced code blocks */
.post-content pre {
    background-color: var(--code-bg);
    border-radius: 12px;
    font-size: 85%;
    line-height: 1.45;
    overflow: auto;
    padding: 1rem;
    margin-bottom: 1rem;
    border: 1px solid var(--code-border);
    position: relative;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.post-content pre::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg,
        transparent,
        var(--accent-color),
        transparent
    );
}

.post-content pre[data-language]::after {
    content: attr(data-language);
    position: absolute;
    top: 0.5rem;
    left: 1rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.post-content pre code {
    background-color: transparent !important;
    color: var(--text-color) !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    display: inline !important;
    white-space: pre !important;
    font-family: 'ASM-Regular', 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
}

/* Enhanced no posts state */
.no-posts {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}

.no-posts h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--text-color);
}

.no-posts code {
    background-color: var(--no-posts-code-bg);
    border-radius: 6px;
    font-size: 85%;
    padding: 0.3em 0.5em;
    color: var(--text-color);
}

/* Enhanced back to top button */
.back-to-top {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 1.2rem;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1000;
}

.back-to-top:hover {
    background-color: var(--accent-hover);
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.25);
}

.back-to-top:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
}



/* Enhanced mobile responsiveness with container queries */
@container (max-width: 768px) {
    .post-layout {
        flex-direction: column;
        gap: 1rem;
    }

    .toc-sidebar {
        flex: none;
        position: relative;
        top: auto;
        max-height: none;
        order: -1;
    }
}

/* Traditional media queries for body-level changes */
@media (max-width: 768px) {
    body {
        padding: 1rem;
    }

    .header {
        position: sticky;
        top: 0;
        background: color-mix(in srgb, var(--bg-color) 95%, transparent);
        backdrop-filter: blur(20px);
        z-index: 100;
        margin: -1rem -1rem 2rem -1rem;
        padding: 1rem;
        border-radius: 0 0 12px 12px;
        flex-direction: column;
        gap: 1rem;
    }

    .theme-toggle {
        align-self: flex-end;
        margin-left: 0;
    }

    .toc {
        margin-bottom: 1rem;
    }

    .toc h2 {
        font-size: 1rem;
    }

    .toc .toc-h2 {
        margin-left: 0.8rem;
    }

    .toc .toc-h3 {
        margin-left: 1.6rem;
    }

    .back-to-top {
        bottom: 1rem;
        right: 1rem;
        width: 45px;
        height: 45px;
    }

    .header h1,
    .single-post .post-header h1 {
        font-size: 1.75rem;
    }

    .post-content h1 {
        font-size: 1.75rem;
    }

    .post-content h2 {
        font-size: 1.35rem;
    }

    .post-preview {
        margin: 0 0 1rem 0; /* Tighter mobile spacing */
        padding: 1rem;
    }
}

@media (max-width: 600px) {
    .single-post .post-header h1 {
        font-size: 1.5rem;
    }

    .post-content h1 {
        font-size: 1.5rem;
    }

    .post-content h2 {
        font-size: 1.25rem;
    }
}

/* Print styles */
@media print {
    .header, .theme-toggle, .back-to-top, .toc-sidebar, .copy-code-btn {
        display: none;
    }

    body {
        background: white;
        color: black;
        padding: 0;
        max-width: none;
    }

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

.post-tags {
    margin: 10px 0 5px 0;
    font-size: 0.9em;
    color: var(--text-muted);
}

.tag {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.85em;
    color: var(--text-muted);
    transition: all 0.2s ease;
}
.tag:hover {
    background-color: color-mix(in srgb, var(--accent-color) 10%, var(--bg-secondary));
    border-color: var(--accent-color);
    color: var(--accent-color);
}

