:root {
    /* ===== LIGHT THEME ===== */
    --bg-primary: #ffffff;
    --bg-secondary: #f6f8fa;
    --bg-tertiary: #f1f3f4;

    --text-primary: #1f2328;
    --text-secondary: #45494c;
    --text-muted: #6e7681;
    --text-comment: #6a737d;

    --accent-primary: #0969da;
    --accent-hover: #0550ae;

    --border-primary: #d1d9e0;
}

[data-theme="dark"] {
    /* ===== DARK THEME ===== */
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;

    --text-primary: #e6edf3;
    --text-secondary: #c9d1d9;
    --text-muted: #7d8590;
    --text-comment: #8b949e;

    --accent-primary: #58a6ff;
    --accent-hover: #0969da;

    --border-primary: #30363d;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

/* Header */
.header {
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

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

.header-container-right {
  display: flex;
  flex-direction: row;
  align-items: center;
  flex-wrap: nowrap;
  gap: 2rem;
  position: relative;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-primary);
    text-decoration: none;
}

.nav {
    display: flex;
    gap: 2rem;
}

.nav a {
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

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

.header-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.theme-toggle,
.mobile-menu-toggle {
  background: none;
  color: var(--text-primary);
  border: 1px solid var(--border-primary);
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.2s;
  height: 36px;
  width: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle:hover,
.mobile-menu-toggle:hover {
    background-color: var(--bg-tertiary);
}

.mobile-menu-toggle {
  display: none;
}

/* Main Layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 2rem;
}

/* Main Content */
.main-content {
    background-color: var(--bg-primary);
    min-width: 0; /* Allows flex/grid items to shrink below content size */
    overflow-wrap: break-word;
}

.article-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-primary);
}

.article-title {
    font-size: 2rem;
    font-weight: 600;
    line-height: 1.4;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.article-meta {
    color: var(--text-muted);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
}

.article-meta > span {
    margin-right: 1rem;
}

.article-content h2 {
    color: var(--text-primary);
    font-size: 1.5rem;
    margin: 2rem 0 1rem 0;
    font-weight: 600;
}

.article-content h3 {
    color: var(--text-primary);
    font-size: 1.2rem;
    margin: 1.5rem 0 0.8rem 0;
    font-weight: 600;
}

.article-content p {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.article-content ul {
    margin: 1rem 0 1rem 2rem;
    color: var(--text-secondary);
}

.article-content li {
    margin-bottom: 0.5rem;
}

/* Code Blocks */
.code-block {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 6px;
    margin: 1.5rem 0;
    overflow: hidden;
}

.code-header {
    background-color: var(--bg-tertiary);
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-primary);
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.code-language {
    font-weight: 500;
    color: var(--accent-primary);
}

.copy-button {
    background-color: var(--accent-primary);
    color: white;
    border: none;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: background-color 0.2s;
}

.copy-button:hover {
    background-color: var(--accent-hover);
}

.code-block pre {
    margin: 0 !important;
    padding: 1rem !important;
    overflow-x: auto !important;
    background-color: var(--bg-secondary) !important;
    border: none !important;
    border-radius: 0 !important;
    font-family: 'JetBrains Mono', 'Consolas', 'Monaco', 'Courier New', monospace !important;
    font-size: 0.9rem !important;
    line-height: 1.5 !important;
}

.code-block code {
    background-color: transparent !important;
    padding: 0 !important;
    border-radius: 0 !important;
    font-family: inherit !important;
}

/* Let Prism.js handle syntax highlighting colors, but ensure proper integration */
.code-block pre[class*="language-"] {
    background-color: var(--bg-secondary) !important;
    border: none !important;
    margin: 0 !important;
    padding: 1rem !important;
    box-shadow: none !important;
}

/* Inline code */
.inline-code {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85em;
}

/* Tables */
.table-container {
    margin: 1.5rem 0;
    overflow-x: auto;
    border-radius: 6px;
    border: 1px solid var(--border-primary);
}

.markdown-table {
    width: 100%;
    border-collapse: collapse;
    background-color: var(--bg-primary);
    font-size: 0.9rem;
}

.markdown-table th {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    font-weight: 500;
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-primary);
    border-right: 1px solid var(--border-primary);
}

.markdown-table th:last-child {
    border-right: none;
}

.markdown-table td {
    padding: 0.75rem 1rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-primary);
    border-right: 1px solid var(--border-primary);
}

.markdown-table td:last-child {
    border-right: none;
}

.markdown-table tr:last-child td {
    border-bottom: none;
}

.markdown-table tr:hover {
    background-color: var(--bg-tertiary);
}

/* Sidebar */
.sidebar {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    padding: 1.1rem 1.5rem 1.3rem;
    height: fit-content;
    position: sticky;
    top: 100px;
}

.sidebar h3 {
    color: var(--text-primary);
    font-size: 1.1rem;
    margin-bottom: 1rem;
    font-weight: 600;
}

.similar-posts {
    list-style: none;
}

.similar-posts li {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-primary);
}

.similar-posts li:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.similar-posts a {
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: 500;
    display: block;
    margin-bottom: 0.25rem;
}

.similar-posts a:hover {
    text-decoration: underline;
}

.similar-posts .meta {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Tags */
.tags {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.tag {
    background-color: var(--bg-tertiary);
    color: var(--accent-primary);
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.8rem;
    text-decoration: none;
    border: 1px solid var(--border-primary);
}

.tag:hover {
    background-color: var(--border-primary);
}

/* Loading and Error States */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
    color: var(--text-muted);
    font-size: 1.2rem;
}

.error {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 400px;
    color: #d73a49;
    font-size: 1.2rem;
    text-align: center;
    gap: 1rem;
}

.retry-btn {
    background-color: var(--accent-primary);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s;
}

.retry-btn:hover {
    background-color: var(--accent-hover);
}

/* Home Page Styles */
/* Posts Section */

.posts-section h2 {
    font-size: 1.8rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
}

.posts-list {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.post-card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    padding: 1.3rem 1.5rem 1.5rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.post-card:hover {
    border-color: var(--accent-primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.post-card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
    gap: 1rem;
}

.post-header {
    flex: 1;
    min-width: 0; /* Allows flex item to shrink */
}

.post-header h3 {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 600;
    line-height: 1.3;
}

.post-title-link {
    color: var(--text-primary);
    text-decoration: none;
    transition: color 0.2s;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

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

.post-category-container {
    flex-shrink: 0;
    display: flex;
    align-items: flex-start;
    margin: 0.2rem 0 0 0.5rem;
}

.post-category {
    background-color: var(--accent-primary);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s;
    display: inline-block;
    white-space: nowrap;
}

.post-category:hover {
    background-color: var(--accent-hover);
    color: white;
}

.post-preview {
    margin-bottom: 1rem;
}

.post-preview p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
    margin: 0;
}

/* Preview markdown styling */
.post-preview h1,
.post-preview h2,
.post-preview h3,
.post-preview h4,
.post-preview h5,
.post-preview h6 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0.5rem 0 0.25rem 0;
}

.post-preview ul,
.post-preview ol {
    margin: 0.5rem 0 0.5rem 1.5rem;
    color: var(--text-secondary);
}

.post-preview li {
    margin-bottom: 0.25rem;
}

.post-preview blockquote {
    border-left: 3px solid var(--accent-primary);
    padding-left: 1rem;
    margin: 0.5rem 0;
    color: var(--text-muted);
    font-style: italic;
}

.post-preview pre {
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 4px;
    padding: 0.5rem;
    margin: 0.5rem 0;
    overflow-x: auto;
    font-size: 0.85rem;
}

.post-preview code {
    background-color: var(--bg-tertiary);
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-size: 0.85rem;
    font-family: 'Fira Code', 'Monaco', monospace;
}

.post-preview .markdown-table {
    font-size: 0.85rem;
    margin: 0.5rem 0;
}

.preview-truncated {
    color: var(--text-muted);
    font-style: italic;
    margin-left: 0.25rem;
}

.post-card-bottom {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
}

.post-tags {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    flex: 1;
    min-width: 0; /* Allows flex item to shrink */
}

.post-date-container {
    flex-shrink: 0;
    display: flex;
    align-items: flex-end;
}

.post-date {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1;
    white-space: nowrap;
}

.no-posts {
    text-align: center;
    color: var(--text-muted);
    font-size: 1.1rem;
    padding: 3rem 0;
}

/* Pagination */
.pagination-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding-top: 2rem;
}

.pagination {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.pagination-btn {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    min-width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.pagination-btn:hover {
    background-color: var(--bg-tertiary);
    border-color: var(--accent-primary);
}

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

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        grid-template-columns: 1fr;
        padding: 1rem;
        gap: 1rem;
    }

    .header-container {
        padding: 0 1rem;
    }

    .header-container-right {
        gap: 0.5rem;
    }

    /* Mobile Navigation */
    .mobile-menu-toggle {
        display: flex;
    }

    .nav {
        position: absolute;
        top: 100%;
        right: 0;
        background-color: var(--bg-secondary);
        border: 1px solid var(--border-primary);
        border-radius: 8px;
        padding: 0 1rem;
        flex-direction: column;
        gap: 0;
        min-width: 200px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        z-index: 1000;
        transform: translateY(-10px);
        opacity: 0;
        visibility: hidden;
        transition: all 0.2s ease-in-out;
    }

    .nav-mobile-open {
        transform: translateY(0);
        opacity: 1;
        visibility: visible;
    }

    .nav a {
        padding: 1rem 0;
        border-bottom: 1px solid var(--border-primary);
    }

    .nav a:last-child {
        border-bottom: none;
    }

    /* Content improvements */
    .article-title {
        font-size: 1.75rem;
        word-wrap: break-word;
        overflow-wrap: break-word;
        hyphens: auto;
    }

    .article-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .article-meta > span {
        margin-right: 0;
    }

    /* Hide bullet separators in mobile column layout */
    .article-meta span:nth-child(2),
    .article-meta span:nth-child(4) {
        display: none;
    }

    .article-content {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .article-content h2,
    .article-content h3 {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .article-content p {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    /* Code blocks */
    .code-block {
        margin: 1rem 0;
        border-radius: 6px;
    }

    .code-header {
        padding: 0.5rem 1rem;
    }

    /* Tables */
    .table-container {
        margin: 1rem 0;
        border-radius: 6px;
    }

    .home-header h1 {
        font-size: 2rem;
    }

    .home-subtitle {
        font-size: 1rem;
    }

    .post-card-top {
        flex-direction: column;
        gap: 0.75rem;
        margin-bottom: 0.75rem;
    }

    .post-card-bottom {
        flex-direction: column;
        gap: 0.75rem;
        align-items: flex-start;
    }

    .post-category-container {
        align-self: flex-start;
    }

    .post-date-container {
        align-self: flex-end;
    }

    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }

    /* Force word wrapping on text elements only */
    .article-content,
    .article-title,
    .article-content h1,
    .article-content h2,
    .article-content h3,
    .article-content h4,
    .article-content h5,
    .article-content h6,
    .article-content p,
    .article-content li,
    .article-content span,
    .post-title-link,
    .post-preview p {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    /* Prevent horizontal overflow */
    body {
        overflow-x: hidden;
    }

    .main-content {
        max-width: 100%;
        overflow-x: hidden;
    }
}

/* 404 Error Page */
.error-content {
    max-width: 100%;
    text-align: left;
}

.error-title {
    font-size: 4rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    line-height: 1;
}

.error-subtitle {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.error-description {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
    line-height: 1.6;
}

.error-actions {
    display: flex;
    justify-content: flex-start;
    gap: 1rem;
}

.home-button {
    display: inline-flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background-color: var(--accent-primary);
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-weight: 500;
    border: none;
    cursor: pointer;
}

.home-button:hover {
    background-color: var(--accent-hover);
}

@media (max-width: 768px) {
    .error-title {
        font-size: 3rem;
    }

    .error-subtitle {
        font-size: 1.2rem;
    }

    .error-page {
        padding: 1rem 0;
    }

    .error-content {
        padding: 0 1rem;
    }
}

/* Error Page Styles (add after existing 404 styles) */
.error-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    text-align: center;
}