/* ======= Reset & Base ======= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #fafaf8;
    --bg-surface: #ffffff;
    --bg-nav: #f5f4f0;
    --text: #2d2d2d;
    --text-secondary: #5a5a5a;
    --text-muted: #888;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-bg: #eff6ff;
    --border: #e5e5e0;
    --border-light: #eeeeea;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.08);
    --radius: 8px;
    --font-body: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-heading: Georgia, 'Times New Roman', serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    --line-height: 1.7;
    --nav-width: 300px;
    --transition: 0.2s ease;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #18181b;
        --bg-surface: #1f1f23;
        --bg-nav: #141417;
        --text: #e4e4e7;
        --text-secondary: #a1a1aa;
        --text-muted: #71717a;
        --accent: #60a5fa;
        --accent-hover: #93c5fd;
        --accent-bg: #1e3a5f;
        --border: #2e2e35;
        --border-light: #27272a;
        --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
        --shadow-md: 0 2px 8px rgba(0,0,0,0.4);
    }
}

/* Accessible focus ring */
:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

html {
    scroll-behavior: smooth;
    font-size: 18px;
}

body {
    font-family: var(--font-body);
    line-height: var(--line-height);
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

/* ======= Layout ======= */
.site-wrapper {
    display: flex;
    min-height: 100vh;
}

/* ======= Navigation Sidebar ======= */
.nav-sidebar {
    width: var(--nav-width);
    min-width: var(--nav-width);
    background: var(--bg-nav);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: hidden;
    z-index: 10;
}

.nav-header {
    padding: 24px 20px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.nav-header h1 {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    color: var(--text);
    margin-bottom: 2px;
    letter-spacing: -0.01em;
}

.nav-header h1 a {
    color: inherit;
    text-decoration: none;
}

.nav-header h1 a:hover {
    color: var(--accent);
}

.nav-tagline {
    font-size: 0.72rem;
    color: var(--text-muted);
    line-height: 1.3;
}

.nav-controls {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.nav-search {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.78rem;
    font-family: var(--font-body);
    background: var(--bg-surface);
    color: var(--text);
    transition: border-color var(--transition);
}

.nav-search:focus {
    border-color: var(--accent);
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-bg);
}

.nav-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
}

.filter-btn {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 100px;
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 0.67rem;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font-body);
    white-space: nowrap;
}

.filter-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.filter-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.nav-list-container {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
}

/* Custom scrollbar */
.nav-list-container::-webkit-scrollbar {
    width: 6px;
}

.nav-list-container::-webkit-scrollbar-track {
    background: transparent;
}

.nav-list-container::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.nav-list {
    list-style: none;
    padding: 8px 0;
}

.nav-year-group {
    padding: 0;
}

.nav-year-label {
    padding: 12px 20px 4px;
    font-size: 0.67rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    position: sticky;
    top: 0;
    background: var(--bg-nav);
    z-index: 1;
}

.nav-item {
    display: block;
    padding: 8px 20px;
    text-decoration: none;
    color: var(--text);
    font-size: 0.78rem;
    line-height: 1.4;
    transition: background var(--transition);
    cursor: pointer;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background: rgba(128,128,128,0.1);
}

.nav-item.active {
    background: var(--accent-bg);
    border-left-color: var(--accent);
    color: var(--accent);
}

.nav-item-date {
    font-size: 0.67rem;
    color: var(--text-muted);
    display: block;
    margin-top: 1px;
}

.nav-item-cat {
    font-size: 0.61rem;
    color: var(--text-muted);
    background: var(--bg);
    padding: 1px 6px;
    border-radius: 3px;
    margin-left: 4px;
}

.nav-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    font-size: 0.67rem;
    color: var(--text-muted);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-footer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-footer a {
    color: var(--accent);
    text-decoration: none;
}

/* ======= Mobile menu toggle ======= */
.menu-toggle {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 100;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    border: none;
    box-shadow: var(--shadow-md);
    cursor: pointer;
    font-size: 1.2rem;
    align-items: center;
    justify-content: center;
}

/* ======= Content Area ======= */
.content-area {
    flex: 1;
    min-width: 0;
    padding: 40px;
}

/* ======= Post Styles ======= */
.post {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 36px 40px;
    margin-bottom: 32px;
    box-shadow: var(--shadow-sm);
    animation: fadeIn 0.3s ease;
}

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

.post-header {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-light);
}

.post-title {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    line-height: 1.3;
    color: var(--text);
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.post-title a {
    color: inherit;
    text-decoration: none;
}

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

.post-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.post-meta time {
    font-weight: 500;
}

.post-category {
    background: var(--accent-bg);
    color: var(--accent);
    padding: 2px 10px;
    border-radius: 100px;
    font-size: 0.72rem;
    text-decoration: none;
    transition: background var(--transition);
}

.post-category:hover {
    background: var(--accent-bg);
    filter: brightness(0.92);
}

.post-tag {
    font-size: 0.67rem;
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: 1px 8px;
    border-radius: 100px;
}

.post-permalink {
    margin-left: auto;
}

.permalink-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text-muted);
    font-size: 0.67rem;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font-body);
}

.permalink-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.permalink-btn.copied {
    border-color: #4ade80;
    color: #4ade80;
    background: color-mix(in srgb, #4ade80 12%, transparent);
}

/* ======= Post body content ======= */
.post-body {
    font-size: 1rem;
    line-height: var(--line-height);
    max-width: 75ch;
}

.post-body p {
    margin-bottom: 1.2em;
}

.post-body h2 {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    margin: 2em 0 0.8em;
    color: var(--text);
}

.post-body h3 {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    margin: 1.5em 0 0.6em;
    color: var(--text);
}

.post-body img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    margin: 1em 0;
}

.post-body a {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent);
    text-underline-offset: 2px;
    transition: text-decoration-color var(--transition);
}

.post-body a:hover {
    text-decoration-color: var(--accent);
}

.post-body blockquote {
    border-left: 3px solid var(--accent);
    margin: 1.5em 0;
    padding: 0.8em 1.2em;
    background: var(--accent-bg);
    border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--text-secondary);
}

.post-body pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 1.2em;
    border-radius: var(--radius);
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.83rem;
    line-height: 1.5;
    margin: 1.5em 0;
}

.post-body code {
    font-family: var(--font-mono);
    font-size: 0.88em;
    background: color-mix(in srgb, var(--text) 8%, transparent);
    padding: 2px 6px;
    border-radius: 4px;
}

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

.post-body ul, .post-body ol {
    margin: 1em 0;
    padding-left: 1.5em;
}

.post-body li {
    margin-bottom: 0.4em;
}

.post-body strong {
    font-weight: 600;
    color: var(--text);
}

.post-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5em 0;
    font-size: 0.89rem;
}

.post-body th, .post-body td {
    padding: 8px 12px;
    border: 1px solid var(--border);
    text-align: left;
}

.post-body th {
    background: var(--bg);
    font-weight: 600;
}

/* ======= Load more / pagination ======= */
.load-more-area {
    text-align: center;
    padding: 20px 0 40px;
}

.load-more-btn {
    padding: 10px 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 0.83rem;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font-body);
}

.load-more-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* ======= Skip to content (accessibility) ======= */
.skip-link {
    position: absolute;
    top: -100px;
    left: 16px;
    background: var(--accent);
    color: white;
    padding: 8px 16px;
    border-radius: var(--radius);
    z-index: 1000;
    font-size: 0.83rem;
    text-decoration: none;
}

.skip-link:focus {
    top: 16px;
}

/* ======= Loading state ======= */
.loading {
    padding: 60px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.89rem;
}

/* ======= No results ======= */
.no-results {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 0.89rem;
}

/* ======= Back to home ======= */
.back-to-home {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--accent);
    text-decoration: none;
    font-size: 0.83rem;
    margin-bottom: 24px;
    padding: 6px 0;
}

.back-to-home:hover {
    text-decoration: underline;
}

/* ======= Responsive ======= */
@media (max-width: 900px) {
    .site-wrapper {
        flex-direction: column;
    }

    .nav-sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        height: 100vh;
        width: 85vw;
        max-width: 360px;
        transition: left 0.3s ease;
        z-index: 100;
        box-shadow: var(--shadow-md);
    }

    .nav-sidebar.open {
        left: 0;
    }

    .menu-toggle {
        display: flex;
    }

    .nav-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.3);
        z-index: 99;
    }

    .nav-overlay.open {
        display: block;
    }

    .content-area {
        padding: 24px 16px;
    }

    .post {
        padding: 24px 20px;
    }

    .post-title {
        font-size: 1.3rem;
    }

    .post-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .post-permalink {
        margin-left: 0;
    }
}

/* ======= Reduced motion ======= */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ======= Print ======= */
@media print {
    .nav-sidebar, .menu-toggle, .nav-overlay, .permalink-btn, .load-more-btn, .back-to-home {
        display: none !important;
    }
    .content-area {
        padding: 0;
    }
    .post {
        box-shadow: none;
        border: none;
        page-break-inside: avoid;
    }
}
