/* --- RESET & BASICS --- */
:root {
    --bg-color: #ffffff;
    --text-color: #1a1a1a;
    --subtle-color: #888;
    --accent-color: #000;
    --sidebar-left-width: 200px;
    --sidebar-right-width: 260px;
    --topbar-height: 80px;
    --font-stack: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: all 0.15s ease;
}

* {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-stack);
    background-color: var(--bg-color);
    color: var(--text-color);
    font-weight: 400;
    line-height: 1.7;
    font-size: 17px;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    text-decoration: none;
    color: inherit;
    transition: var(--transition-smooth);
    position: relative;
}
a:hover { color: #000; }

/* Reading progress bar */
#reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 2px;
    background: linear-gradient(90deg, #000 0%, #666 100%);
    z-index: 9999;
    transition: width 0.1s ease;
}

/* --- GRID LAYOUT LOGIC --- */

/* DEFAULT: 2 Columns (Left Nav | Content) */
/* Used for Home, Section Lists (Ex Machina), etc. */
.layout-grid {
    display: grid;
    grid-template-columns: var(--sidebar-left-width) 1fr;
    min-height: 100vh;
}

/* ARTICLE MODE: 3 Columns (Left Nav | Content | Right Context) */
/* Only applied when class "has-sidebar" is added by HTML */
.layout-grid.has-sidebar {
    grid-template-columns: var(--sidebar-left-width) 1fr var(--sidebar-right-width);
}


/* --- LEFT SIDEBAR --- */
.sidebar-left {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-left-width);
    padding: 40px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;

    /* Hide scrollbar while maintaining scroll functionality */
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}

.sidebar-left::-webkit-scrollbar {
    display: none;  /* Chrome, Safari and Opera */
}

.logo a {
    font-weight: 600;
    font-size: 1.1rem;
    letter-spacing: -0.5px;
    margin-bottom: 60px;
    display: block;
    transition: var(--transition-smooth);
    position: relative;
}

.logo a::before {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 0;
    height: 2px;
    background: #000;
    transition: width 0.3s ease;
}

.logo a:hover::before {
    width: 100%;
}

.side-nav { display: flex; flex-direction: column; gap: 12px; margin-bottom: 30px; }
.side-nav a {
    color: var(--subtle-color);
    font-size: 0.85rem;
    padding: 4px 0;
    display: block;
    transition: var(--transition-smooth);
    transform: translateX(0);
}
.side-nav a:hover {
    color: var(--accent-color);
    font-weight: 500;
    transform: translateX(3px);
}
.side-nav a.active {
    color: var(--accent-color);
    font-weight: 500;
}

/* --- EX-MACHINA NAVIGATION IN SIDEBAR --- */
.ex-machina-details {
    margin: 0;
}

.ex-machina-summary {
    list-style: none;
    cursor: pointer;
    padding: 0;
    margin: 0;
}

.ex-machina-summary::-webkit-details-marker {
    display: none;
}

.ex-machina-summary a {
    color: var(--subtle-color);
    font-size: 0.85rem;
    display: block;
}

.ex-machina-summary a:hover,
.ex-machina-summary a.active,
.ex-machina-details[open] .ex-machina-summary a {
    color: var(--accent-color);
    font-weight: 500;
}

.ex-machina-nav {
    margin-top: 8px;
    margin-left: 12px;
    padding-left: 12px;
    border-left: 1px solid #f0f0f0;
    max-height: 60vh;
    overflow-y: auto;

    /* Hide scrollbar while maintaining scroll functionality */
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}

.ex-machina-nav::-webkit-scrollbar {
    display: none;  /* Chrome, Safari and Opera */
}

.ex-machina-nav details {
    margin-bottom: 8px;
}

.year-nav-heading {
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--subtle-color);
    list-style: none;
    padding: 4px 0;
    font-weight: 500;
}

.year-nav-heading::-webkit-details-marker {
    display: none;
}

.year-nav-heading:hover,
.ex-machina-nav details[open] .year-nav-heading {
    color: var(--accent-color);
}

.year-nav-posts {
    list-style: none;
    padding: 0;
    margin: 8px 0 12px 0;
    padding-left: 12px;
    border-left: 1px solid #f0f0f0;
}

.year-nav-posts li {
    margin-bottom: 4px;
    line-height: 1.3;
}

.year-nav-posts a {
    font-size: 0.75rem;
    color: #999;
    display: block;
    transition: var(--transition-smooth);
    padding: 3px 0;
}

.year-nav-posts a:hover {
    color: var(--accent-color);
    padding-left: 6px;
}

.year-nav-posts a.active {
    color: var(--accent-color);
    font-weight: 500;
}


/* --- RIGHT SIDEBAR (Context) --- */
.sidebar-right {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-right-width);
    padding: 40px 20px 40px 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    /* Ensure it doesn't show up in 2-col mode just in case */
    display: none; 
}

/* Only show it if the grid says we have a sidebar */
.has-sidebar .sidebar-right {
    display: flex; 
}

.tag-header {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #ccc;
    margin-bottom: 30px;
}

.tag-list details { margin-bottom: 8px; border-bottom: 1px solid transparent; }

.tag-summary {
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--subtle-color);
    list-style: none;
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
}
.tag-summary::-webkit-details-marker { display: none; }
.tag-summary:hover, details[open] .tag-summary { color: #000; }
.count { font-size: 0.75rem; color: #eee; }

.tag-posts {
    list-style: none;
    padding: 0;
    margin: 5px 0 15px 0;
    border-left: 1px solid #f0f0f0;
    padding-left: 10px;
}
.tag-posts li { margin-bottom: 6px; line-height: 1.3; }
.tag-posts a { font-size: 0.75rem; color: #999; display: block; }
.tag-posts a:hover { color: #000; }

/* Interactive Card Grid */
.tag-posts-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 10px 0 15px 0;
}

.related-card {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 8px 10px;
    border: 1px solid #f0f0f0;
    border-radius: 6px;
    background: #fff;
    transition: var(--transition-smooth);
    cursor: pointer;
    text-decoration: none;
    position: relative;
    overflow: visible;
    min-height: 40px;
}

.related-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 2px;
    height: 100%;
    background: #000;
    transform: scaleY(0);
    transition: transform 0.3s ease;
}

.related-card:hover {
    border-color: #ddd;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    transform: translateX(4px);
    padding: 10px 12px 12px 10px;
}

.related-card:hover::before {
    transform: scaleY(1);
}

.card-content {
    flex: 1;
    min-width: 0;
}

.card-title {
    font-size: 0.72rem;
    font-weight: 500;
    color: #1a1a1a;
    margin-bottom: 0;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    transition: color 0.2s ease;
}

.related-card:hover .card-title {
    color: #000;
}

.card-summary {
    font-size: 0.68rem;
    color: #666;
    font-style: italic;
    line-height: 1.4;
    margin-top: 0;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.3s ease 0.05s,
                margin-top 0.3s ease;
}

.related-card:hover .card-summary {
    max-height: 300px;
    opacity: 1;
    margin-top: 6px;
}

/* Link Preview Tooltip */
.link-preview {
    position: absolute;
    left: calc(100% + 15px);
    top: 0;
    width: 320px;
    padding: 16px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    opacity: 0;
    visibility: hidden;
    transform: translateX(-10px);
    transition: var(--transition-smooth);
    z-index: 1000;
    pointer-events: none;
}

.related-card:hover .link-preview {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
    transition-delay: 0.5s;
}

.link-preview::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 20px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 8px 8px 8px 0;
    border-color: transparent #ddd transparent transparent;
}

.link-preview::after {
    content: '';
    position: absolute;
    left: -7px;
    top: 20px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 8px 8px 8px 0;
    border-color: transparent #fff transparent transparent;
}

.preview-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: #000;
    margin-bottom: 8px;
    line-height: 1.3;
}

.preview-excerpt {
    font-size: 0.75rem;
    color: #666;
    line-height: 1.5;
    margin-bottom: 10px;
}

.preview-meta {
    font-size: 0.65rem;
    color: #999;
    padding-top: 8px;
    border-top: 1px solid #f0f0f0;
}

.card-arrow {
    font-size: 0.9rem;
    color: #ddd;
    margin-left: 6px;
    margin-top: 1px;
    transition: var(--transition-smooth);
    flex-shrink: 0;
    align-self: flex-start;
}

.related-card:hover .card-arrow {
    color: #000;
    transform: translateX(4px);
}

/* Keyboard hint removed - summary takes priority */

/* Card entrance animation */
@keyframes cardSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/* --- CENTER CONTENT --- */
.content-wrapper {
    grid-column: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.top-bar {
    width: 100%;
    max-width: 700px;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.breadcrumbs {
    font-size: 0.75rem;
    color: var(--subtle-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.breadcrumbs a {
    transition: var(--transition-fast);
    position: relative;
}
.breadcrumbs a::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 1px;
    background: #000;
    transition: width 0.2s ease;
}
.breadcrumbs a:hover::after {
    width: 100%;
}
.breadcrumbs .divider { margin: 0 8px; color: #ddd; }
.breadcrumbs .current { color: #000; font-weight: 500; }

main {
    width: 100%;
    max-width: 700px;
    padding-bottom: 100px;
    animation: fadeInUp 0.6s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/* --- LIST STYLES (Ex Machina page) --- */
.section-description {
    margin-bottom: 40px;
    color: var(--subtle-color);
    font-size: 0.95rem;
    line-height: 1.7;
    max-width: 600px;
}

details {
    margin-bottom: 10px;
    transition: var(--transition-smooth);
}
summary.year-heading {
    list-style: none;
    cursor: pointer;
    font-size: 1.2rem;
    color: #bbb;
    transition: var(--transition-smooth);
    padding: 8px 0;
    position: relative;
}
summary.year-heading::before {
    content: '›';
    position: absolute;
    left: -20px;
    transition: var(--transition-smooth);
    opacity: 0;
}
summary.year-heading:hover::before {
    opacity: 1;
}
summary.year-heading::-webkit-details-marker { display: none; }
details[open] summary.year-heading { color: #000; }
details[open] summary.year-heading::before {
    transform: rotate(90deg);
    opacity: 1;
}
summary.year-heading:hover { color: #000; transform: translateX(2px); }

.year-content {
    margin-top: 15px;
    margin-bottom: 30px;
    padding-left: 20px;
    border-left: 1px solid #eee;
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.month-heading {
    font-size: 0.9rem;
    font-weight: 600;
    color: #000;
    margin-top: 2rem;
    margin-bottom: 0.8rem;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    font-size: 0.75rem;
}

.post-list { list-style: none; padding: 0; margin: 0; }
.post-list li {
    margin-bottom: 6px;
    display: flex;
    align-items: baseline;
    transition: var(--transition-smooth);
    padding: 4px 0;
    border-radius: 4px;
}
.post-list li:hover {
    padding-left: 8px;
    background: linear-gradient(90deg, rgba(0,0,0,0.02) 0%, rgba(0,0,0,0) 100%);
}
.date-short { font-size: 0.85rem; color: #999; width: 40px; flex-shrink: 0; transition: var(--transition-fast); }
.post-list li:hover .date-short { color: #000; font-weight: 500; }
.post-list a {
    font-size: 0.85rem;
    color: #111;
    transition: var(--transition-smooth);
    position: relative;
}
.post-list a::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 1px;
    background: #000;
    transition: width 0.3s ease;
}
.post-list a:hover {
    color: #000;
    font-weight: 500;
}
.post-list a:hover::after {
    width: 100%;
}


/* --- ARTICLE STYLES (Single Page) --- */
article h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.2;
}
article .date {
    display: block;
    font-size: 0.8rem;
    color: #999;
    margin-bottom: 2.5rem;
    font-weight: 400;
}

/* Enhanced article typography */
article p {
    margin-bottom: 1.5em;
    line-height: 1.8;
}

article h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-top: 2.5rem;
    margin-bottom: 1rem;
    letter-spacing: -0.01em;
}

article h3 {
    font-size: 1.2rem;
    font-weight: 600;
    margin-top: 2rem;
    margin-bottom: 0.8rem;
}

/* Scroll-to-top button */
#scroll-to-top {
    position: fixed;
    bottom: 40px;
    right: 40px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #000;
    color: #fff;
    border: none;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition-smooth);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1000;
}

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

#scroll-to-top:hover {
    transform: translateY(-4px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}

#scroll-to-top:active {
    transform: translateY(-2px);
}


/* --- MOBILE --- */
@media (max-width: 1100px) {
    .layout-grid, .layout-grid.has-sidebar { 
        display: block; 
    }
    .sidebar-left {
        position: relative; width: 100%; padding: 20px;
        flex-direction: row; justify-content: space-between; align-items: center;
        border-bottom: 1px solid #f5f5f5;
    }
    .logo a { margin-bottom: 0; }
    .side-nav { flex-direction: row; gap: 20px; }
    
    /* On mobile, context sidebar goes to bottom */
    .sidebar-right {
        position: relative; width: 100%; padding: 40px;
        border-top: 1px solid #f5f5f5;
        height: auto;
    }
    .content-wrapper { padding: 20px; }
    .top-bar { display: none; }
}

/* --- SOURCES FOOTER (Refined) --- */
.sources-section {
    margin-top: 80px;
    padding-top: 30px;
    border-top: 1px solid #ddd; /* The line separator */
    margin-bottom: 60px;
}

.source-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #bbb;
    margin-bottom: 5px; /* Reduced space below the label */
}

.source-links {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    
    /* NEW: Indent and Tighten */
    margin-left: 15px;      /* Indents links relative to "SOURCES" */
    gap: 2px;               /* Single line spacing feel */
}

.source-links a {
    font-size: 0.75rem;     /* Small footnote size */
    color: #999;            /* Light Grey */
    font-weight: 300;
    text-decoration: none;
    line-height: 1.4;       /* Tight line height */
    border-bottom: 1px solid transparent;
    transition: all 0.2s ease;
}

.source-links a:hover {
    color: #000;
    border-bottom: 1px solid #000;
}

/* --- FIX: Make links inside articles visible --- */
.post-content a,
.section-description a {
    color: #000;
    text-decoration: none;
    background-image: linear-gradient(to right, #ccc 0%, #ccc 100%);
    background-size: 100% 1px;
    background-position: 0 100%;
    background-repeat: no-repeat;
    transition: var(--transition-smooth);
    padding: 2px 4px;
    margin: 0 -4px;
    border-radius: 2px;
    position: relative;
}

.post-content a:hover,
.section-description a:hover {
    background-color: rgba(0,0,0,0.05);
    background-image: linear-gradient(to right, #000 0%, #000 100%);
}

/* External link tooltip - just URL */
.post-content a[href^="http"]::after,
.section-description a[href^="http"]::after {
    content: attr(href);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(-5px);
    padding: 8px 12px;
    background: #000;
    color: #fff;
    font-size: 0.7rem;
    white-space: nowrap;
    border-radius: 4px;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition-smooth);
    pointer-events: none;
    z-index: 1000;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.post-content a[href^="http"]:hover::after,
.section-description a[href^="http"]:hover::after {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
    transition-delay: 0.3s;
}

/* External link tooltip arrow */
.post-content a[href^="http"]::before,
.section-description a[href^="http"]::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 6px 6px 0 6px;
    border-color: #000 transparent transparent transparent;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition-smooth);
    pointer-events: none;
    z-index: 1000;
}

.post-content a[href^="http"]:hover::before,
.section-description a[href^="http"]:hover::before {
    opacity: 1;
    visibility: visible;
    transition-delay: 0.3s;
}


/* --- VIDEO PLAYER (Cinematic Mode) --- */
.video-container {
    /* Break out of the 700px text limit */
    width: 120%;             
    margin-left: -10%;       /* Pull it back to center (half of the extra 20%) */
    
    margin-top: 40px;
    margin-bottom: 50px;
    background-color: #000;
    
    /* Force standard HD aspect ratio */
    aspect-ratio: 16 / 9;
    
    /* subtle shadow to make it pop */
    box-shadow: 0 10px 30px -10px rgba(0,0,0,0.15); 
}

.video-container iframe {
    width: 100%;
    height: 100%;
    display: block;
}

/* On mobile, we can't be wider than the screen, so we reset it */
@media (max-width: 900px) {
    .video-container {
        width: 100%;
        margin-left: 0;
    }
}

/* --- PODCAST PLAYERS --- */
.podcast-container {
    margin-top: 30px;
    margin-bottom: 40px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 20px; /* Space between Spotify and Apple if you have both */
}

/* Optional: Slight shadow for Apple player to match Spotify's depth */
.podcast-container iframe {
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    border-radius: 12px;
}