/* ==========================================================================
   0. IMPORTS & CORE VARIABLES
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@300;500;700&display=swap');

:root {
    --bg: #0a0a0a;       /* Deep Black */
    --fg: #e0e0e0;       /* Terminal White */
    --accent: #ffb000;   /* Amber */
    --dim: #444444;      /* Grey/Border color */
    --font: 'Fira Code', 'Courier New', monospace;
}

/* ==========================================================================
   1. RESET & BASE
   ========================================================================== */
body {
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font);
    margin: 0;
    line-height: 1.6;
    font-size: 16px;
}

a {
    color: var(--fg);
    text-decoration: none;
    transition: color 0.2s;
}
a:hover { color: var(--accent); }

/* ==========================================================================
   2. LAYOUT UTILITIES
   ========================================================================== */
.viewport {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    width: 100%;
    box-sizing: border-box;
}

/* FIXED: Add padding for sticky header */
main.container {
    padding-top: 20px;
}

/* The Split Layout (Content Left, Sidebar Right) */
.layout-split {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 40px;
    align-items: start;
    /* IMPROVED: Add padding to prevent content touching viewport edges */
    padding: 0 20px;
}

@media (max-width: 900px) {
    .layout-split { 
        grid-template-columns: 1fr;
        padding: 0 15px; /* Slightly less padding on mobile */
    }
}

/* ==========================================================================
   3. HEADER / NAV (STICKY)
   ========================================================================== */
header {
    position: sticky !important;
    top: 0;
    z-index: 9999 !important;
    background-color: var(--bg);
    border-bottom: 1px solid var(--dim);
    padding: 15px 0;
    margin-bottom: 0;
    /* IMPROVED: Add subtle shadow for better depth perception */
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    /* IMPROVED: Add flex-wrap for better mobile handling */
    flex-wrap: wrap;
    gap: 15px;
}

.brand {
    font-weight: 700;
    color: var(--accent);
    font-size: 1.1rem;
}

.nav ul {
    list-style: none;
    display: flex;
    gap: 20px;
    padding: 0;
    margin: 0;
    /* IMPROVED: Allow wrapping on narrow screens */
    flex-wrap: wrap;
}

.nav a { font-size: 0.9rem; text-transform: lowercase; }
.nav-current a { text-decoration: underline; color: var(--accent); }

/* IMPROVED: Better mobile navigation */
@media (max-width: 600px) {
    header .container {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .nav ul {
        gap: 15px;
        font-size: 0.85rem;
    }
}

/* ==========================================================================
   4. HOME GRID (POST FEED)
   ========================================================================== */
.post-feed {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 30px;
    /* IMPROVED: Add bottom margin for better spacing before pagination */
    margin-bottom: 40px;
}

/* IMPROVED: Better mobile grid behavior */
@media (max-width: 650px) {
    .post-feed {
        grid-template-columns: 1fr; /* Single column on mobile */
        gap: 20px;
    }
}

.post-card {
    border: 1px solid var(--dim);
    padding: 15px;
    display: flex;
    flex-direction: column;
    background: #000;
    transition: border-color 0.2s;
    /* IMPROVED: Prevent content overflow */
    overflow: hidden;
}

.post-card:hover { border-color: var(--accent); }

/* --- UPDATED IMAGE STYLE (SUBTLE HOVER) --- */
.post-card-image {
    width: 100%;
    height: 180px;
    object-fit: cover;
    border-bottom: 1px solid var(--dim);
    margin-bottom: 15px;
    
    /* Subtle Desaturation - Default State */
    filter: grayscale(80%) contrast(0.95);
    opacity: 0.85; 
    transition: all 0.4s ease; 
}

.post-card:hover .post-card-image { 
    /* Full Color - Hover State */
    filter: grayscale(0%) contrast(1);
    opacity: 1;
}

.post-card h2 {
    margin: 0 0 10px 0;
    font-size: 1.2rem;
    color: var(--accent);
    /* IMPROVED: Prevent long titles from breaking layout */
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.post-card-excerpt { 
    font-size: 0.85rem; 
    color: #888;
    /* IMPROVED: Ensure consistent spacing */
    margin: 0;
}

/* ==========================================================================
   5. SIDEBAR
   ========================================================================== */
.site-sidebar {
    margin-top: 0;
    position: sticky;
    /* Positioned below main header + article header (~60px + 80px) */
    top: 150px; 
    align-self: start;
    /* IMPROVED: Prevent sidebar from being too tall on short screens */
    max-height: calc(100vh - 170px);
    overflow-y: auto;
    /* IMPROVED: Custom scrollbar for terminal aesthetic */
    scrollbar-width: thin;
    scrollbar-color: var(--dim) var(--bg);
}

/* IMPROVED: Webkit scrollbar styling */
.site-sidebar::-webkit-scrollbar {
    width: 8px;
}

.site-sidebar::-webkit-scrollbar-track {
    background: var(--bg);
}

.site-sidebar::-webkit-scrollbar-thumb {
    background: var(--dim);
    border-radius: 4px;
}

.site-sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

@media (max-width: 900px) {
    .site-sidebar {
        margin-top: 40px;
        border-top: 1px dashed var(--dim);
        padding-top: 40px;
        /* IMPROVED: Remove sticky positioning on mobile */
        position: static;
        max-height: none;
        overflow-y: visible;
    }
}

.widget {
    margin-bottom: 30px;
    border: 1px solid var(--dim);
    background: #0f0f0f;
    /* IMPROVED: Add padding to widget content */
    padding: 15px;
}

.widget-title {
    background: transparent;
    color: var(--accent);
    border-bottom: 1px dashed var(--dim);
    font-size: 0.9rem;
    font-weight: bold;
    padding: 5px 0;
    margin-bottom: 15px;
    text-transform: uppercase;
    letter-spacing: 1px;
    /* IMPROVED: Move title outside of padding */
    margin-left: -15px;
    margin-right: -15px;
    margin-top: -15px;
    padding-left: 15px;
    padding-right: 15px;
}

.widget-content {
    font-size: 0.85rem;
    color: #aaa;
}
.widget-content p { margin: 0 0 10px 0; }
.widget-content strong { color: var(--accent); }

/* Link Lists */
.link-list ul, .link-list { list-style: none; padding: 0; margin: 0; }
.link-list li { margin-bottom: 8px; }
.link-list a { display: block; color: var(--fg); transition: padding-left 0.2s; }
.link-list a:hover { color: var(--accent); padding-left: 5px; }
.link-list a::before { content: "- "; color: var(--dim); }
.link-list a:hover::before { content: "> "; color: var(--accent); }

/* ==========================================================================
   6. SINGLE POST VIEW
   ========================================================================== */
.main-content {
    position: relative;
    z-index: 1 !important;
}

.post-full {
    width: 100%;
    /* IMPROVED: Better readability with max-width on content */
    max-width: 800px;
    position: relative;
    z-index: 1 !important;
}

.article-header {
    margin-bottom: 30px;
    margin-top: 0;
    border-bottom: 1px dashed var(--dim);
    padding-bottom: 20px;
    padding-top: 10px; /* Keep your existing padding */
    
    /* STICKY BEHAVIOR FIXES */
    position: sticky !important;
    
    /* 1. Tweak Top: Lowered slightly to ensure it tucks UNDER the main header's shadow */
    top: 58px !important; 
    
    z-index: 999 !important;
    background-color: var(--bg) !important;

    /* 2. THE MAGIC FIX: Box Shadow Mask 
       Values: 0 (x) | -20px (y - extends UP) | 0 (blur) | 10px (spread - extends OUT)
       This creates a solid block of your background color that extends 
       upwards to fill the gap between headers. */
    box-shadow: 0 -20px 0 10px var(--bg);
}

.article-title {
    font-size: 2rem;
    line-height: 1.2;
    color: var(--accent);
    margin-bottom: 10px;
    margin-top: 0;
    /* IMPROVED: Better word breaking for long titles */
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    position: relative;
    z-index: 1 !important;
}

/* IMPROVED: Better mobile title sizing */
@media (max-width: 650px) {
    .article-title {
        font-size: 1.5rem;
    }
}

.article-meta { 
    font-size: 0.8rem; 
    color: #888; 
    margin-bottom: 10px;
    /* IMPROVED: Make meta info wrap better */
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    position: relative;
    z-index: 1 !important;
}

.article-image {
    margin: 20px 0;
    width: 100%;
    height: auto;
    border: 1px solid var(--dim);
}

.gh-content { 
    font-size: 1rem; 
    color: #ccc;
    /* IMPROVED: Better line height for readability */
    line-height: 1.8;
    /* FIXED: Constrain all content including galleries */
    max-width: 100%;
    overflow-x: hidden;
    /* Add scroll margin for sticky headers */
    scroll-margin-top: 200px;
}

.gh-content h2, .gh-content h3 { 
    color: var(--accent); 
    margin-top: 2em;
    margin-bottom: 0.75em;
    /* IMPROVED: Better word breaking */
    word-wrap: break-word;
}

.gh-content h2 {
    font-size: 1.5rem;
    border-bottom: 1px dashed var(--dim);
    padding-bottom: 0.5em;
}

.gh-content h3 {
    font-size: 1.25rem;
}

.gh-content p { 
    margin-bottom: 1.5em;
}

.gh-content a {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-style: dashed;
}

.gh-content a:hover {
    text-decoration-style: solid;
}

.gh-content ul, .gh-content ol {
    margin: 1.5em 0;
    padding-left: 2em;
}

.gh-content li {
    margin-bottom: 0.5em;
}

.gh-content blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 20px;
    margin: 1.5em 0;
    color: #888;
    font-style: italic;
}

.gh-content pre {
    background: #111;
    padding: 15px;
    border: 1px solid var(--dim);
    overflow-x: auto;
    border-radius: 4px;
    margin: 1.5em 0;
}

.gh-content code {
    background: #111;
    padding: 2px 6px;
    border: 1px solid var(--dim);
    border-radius: 3px;
    font-family: var(--font);
    font-size: 0.9em;
}

.gh-content pre code {
    background: none;
    padding: 0;
    border: none;
}

/* ==========================================================================
   7. PAGINATION (FIXED)
   ========================================================================== */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin: 60px 0 40px 0;
    padding-top: 20px;
    border-top: 1px solid var(--dim);
    font-family: var(--font);
    font-size: 0.9rem;
    width: 100%;
    /* IMPROVED: Better wrapping on mobile */
    flex-wrap: wrap;
}

.pagination a {
    background: var(--dim);
    color: #fff;
    padding: 8px 18px;
    font-weight: bold;
    border: 1px solid transparent;
    transition: all 0.2s ease;
    /* IMPROVED: Prevent text from wrapping inside buttons */
    white-space: nowrap;
}

.pagination a:hover {
    background: var(--accent);
    color: #000;
    box-shadow: 0 0 8px var(--accent);
}

.pagination .disabled {
    color: #333;
    border: 1px solid #333;
    padding: 8px 18px;
    cursor: not-allowed;
    text-decoration: line-through;
    white-space: nowrap;
}

.page-number { 
    color: var(--accent); 
    font-weight: bold;
    white-space: nowrap;
}

/* IMPROVED: Mobile pagination styling */
@media (max-width: 600px) {
    .pagination {
        gap: 10px;
        font-size: 0.8rem;
    }
    
    .pagination a,
    .pagination .disabled {
        padding: 6px 12px;
        font-size: 0.8rem;
    }
}

/* ==========================================================================
   8. FOOTER
   ========================================================================== */
footer {
    margin-top: auto;
    padding: 40px 0;
    text-align: center;
    border-top: 1px solid var(--dim);
    color: #666;
    font-size: 0.8rem;
}

/* ==========================================================================
   9. GHOST EDITOR COMPLIANCE
   ========================================================================== */
.kg-width-wide {
    position: relative;
    width: 85vw;
    max-width: 100vw;
    margin-left: calc(50% - 42.5vw);
    transform: translateX(calc(50vw - 50%));
}
.kg-width-full {
    position: relative;
    width: 100vw;
    left: 50%;
    right: 50%;
    margin-left: -50vw;
    margin-right: -50vw;
}
.kg-width-full img { width: 100%; height: auto; }

/* --- BOOKMARKS --- */

.kg-bookmark-card { 
    width: 100%; 
    display: block; 
    margin: 20px 0;
}

.kg-bookmark-container {
    display: flex;
    text-decoration: none;
    background: #0f0f0f !important; 
    /* UPDATED: Added !important to force the dashed style */
    border: 1px dashed var(--dim) !important;
    color: var(--fg) !important;
    min-height: 120px;
    position: relative;
}

/* Hover state: make border amber and solid for emphasis */
.kg-bookmark-container:hover { 
    /* UPDATED: Added !important to ensure hover works */
    border: 1px solid var(--accent) !important; 
}

.kg-bookmark-content {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 15px;
    width: 66%; 
    flex-grow: 1;
    overflow: hidden;
}

.kg-bookmark-title { 
    font-weight: 700; 
    color: var(--accent) !important; 
    margin-bottom: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.kg-bookmark-description {
    font-size: 0.85rem;
    color: var(--fg) !important; 
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.kg-bookmark-metadata { 
    display: flex;
    align-items: center;
    font-size: 0.75rem; 
    color: var(--fg) !important; 
    margin-top: 10px; 
}

.kg-bookmark-icon {
    width: 20px !important;
    height: 20px !important;
    min-width: 20px;
    margin-right: 8px;
    vertical-align: middle;
    border: none !important;
    box-shadow: none !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}

/* --- IMAGE CONTAINER --- */
.kg-bookmark-thumbnail { 
    position: absolute; 
    top: 0;
    right: 0;
    bottom: 0; 
    width: 33%; 
    overflow: hidden;
    /* UPDATED: Added !important to the internal border */
    border-left: 1px dashed var(--dim) !important; 
}

.kg-bookmark-container:hover .kg-bookmark-thumbnail {
    /* UPDATED: Added !important to the hover border */
    border-left: 1px solid var(--accent) !important;
}

.kg-bookmark-thumbnail img {
    display: block;
    width: 100%;
    height: 100% !important; 
    object-fit: cover; 
    filter: none !important; 
    border: none !important;
    margin: 0 !important; 
}

/* --- MOBILE --- */
@media (max-width: 650px) {
    .kg-bookmark-container {
        flex-direction: column;
        min-height: auto;
    }

    .kg-bookmark-content {
        width: auto;
        padding-bottom: 200px; /* Space for the image below */
    }

    .kg-bookmark-thumbnail {
        position: absolute;
        top: auto; 
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 180px; 
        border-left: none !important;
        /* UPDATED: Added !important for mobile border */
        border-top: 1px dashed var(--dim) !important; 
    }
    
    .kg-bookmark-container:hover .kg-bookmark-thumbnail {
        border-left: none !important;
        /* UPDATED: Added !important for mobile hover */
        border-top: 1px solid var(--accent) !important;
   }
}
/* ==========================================================================
   10. IMAGE DISPLAY FIX
   ========================================================================== */

/* 1. Basic image styling in content */
.gh-content img {
    display: block;
    width: 100%;
    height: auto;
    max-width: 100%;
    margin: 20px 0;
    border: 1px solid var(--dim);
}

/* 2. Single image cards */
.kg-image-card {
    display: block;
    margin: 30px 0;
}

.kg-image-card img {
    width: 100%;
    height: auto;
    max-width: 100%;
}

/* 3. Gallery containers - OVERRIDE INLINE STYLES */
.kg-gallery-container {
    display: flex !important;
    flex-direction: column !important;
    margin: 40px 0 !important;
    gap: 15px !important;
    max-width: 100% !important;
    width: 100% !important;
    overflow: hidden !important;
}

.kg-gallery-row {
    display: flex !important;
    flex-direction: row !important;
    gap: 15px !important;
    max-width: 100% !important;
    width: 100% !important;
    height: 200px !important;
    min-height: 0 !important;
}

/* Override Ghost's inline flex styles */
.kg-gallery-image[style] {
    flex: 1 1 0% !important;
    min-width: 0 !important;
    max-height: 200px !important;
    height: 200px !important;
    overflow: hidden !important;
    position: relative !important;
}

.kg-gallery-image {
    flex: 1 1 0% !important;
    min-width: 0 !important;
    max-height: 200px !important;
    height: 200px !important;
    overflow: hidden !important;
    position: relative !important;
}

/* Force all gallery images to constrained size */
.kg-gallery-image img[loading="lazy"],
.kg-gallery-image img {
    width: 100% !important;
    height: 100% !important;
    max-height: 200px !important;
    min-height: 0 !important;
    object-fit: cover !important;
    border: 1px solid var(--dim) !important;
    transition: border-color 0.2s !important;
    display: block !important;
}

/* 4. Hover effects */
.kg-gallery-image:hover img,
.gh-content img:hover {
    border-color: var(--accent) !important;
}

/* 5. Ensure Ghost's lazy loading doesn't hide images */
.gh-content img[loading="lazy"] {
    opacity: 1 !important;
    visibility: visible !important;
}

/* 6. Mobile gallery adjustments */
@media (max-width: 650px) {
    .kg-gallery-row {
        flex-direction: column !important;
        height: auto !important;
    }
    
    .kg-gallery-image[style],
    .kg-gallery-image {
        max-height: 200px !important;
        height: 200px !important;
    }
    
    .kg-gallery-image img[loading="lazy"],
    .kg-gallery-image img {
        max-height: 200px !important;
    }
}