/* =========================================
   1. VARIABLES & RESET
   ========================================= */
:root {
    /* Colors - Academic Theme */
    --bg-color: #ffffff;
    --text-main: #111111;
    /* Đen thuần cho văn bản chính */
    --text-muted: #555555;
    /* Xám cho chú thích */
    --link-color: #2563EB;
    /* Xanh classic cho link */
    --border-color: #E5E7EB;
    --code-bg: #F3F4F6;
    --pill-bg: #F1F5F9;

    /* Dimensions */
    --header-height: 60px;
    --container-width: 1100px;
    /* Rộng hơn chút để chứa Sidebar + Content */

    /* Fonts */
    /* Font nội dung: Serif (Georgia/Times) cho cảm giác "giấy" */
    --font-serif: 'Georgia', 'Cambria', 'Times New Roman', serif;
    /* Font tiêu đề/UI: Sans-serif hiện đại */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Menlo', monospace;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: var(--font-serif);
    /* Mặc định là Serif */
    line-height: 1.7;
    /* Dãn dòng rộng để dễ đọc */
    font-size: 17px;
    /* Cỡ chữ lớn hơn web thường */
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--link-color);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* =========================================
   2. HEADER (Global Navigation)
   ========================================= */
.site-header {
    height: var(--header-height);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    z-index: 100;
    font-family: var(--font-sans);
    /* UI dùng Sans-serif */
}

.container {
    max-width: var(--container-width);
    margin: 0 auto;
    padding: 0 24px;
    width: 100%;
}

.site-header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: #000;
}

.nav a {
    margin-left: 20px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.nav a[aria-current="page"] {
    color: var(--text-main);
    font-weight: 600;
}

/* =========================================
   3. ARTICLE LAYOUT (Grid)
   ========================================= */
.article-layout {
    display: grid;
    /* Sidebar 240px, Content chiếm phần còn lại */
    grid-template-columns: 240px minmax(0, 1fr);
    gap: 60px;
    padding-top: 60px;
    padding-bottom: 100px;
}

/* =========================================
   4. SIDEBAR (Table of Contents)
   ========================================= */
.toc {
    font-family: var(--font-sans);
    position: sticky;
    top: calc(var(--header-height) + 40px);
    /* Dính khi scroll */
    height: fit-content;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
}

.toc-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
    color: #999;
    margin-bottom: 16px;
}

.toc-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toc-link {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.4;
    border-left: 2px solid transparent;
    padding-left: 12px;
    transition: all 0.2s;
}

.toc-link:hover {
    color: var(--link-color);
    border-left-color: var(--border-color);
    text-decoration: none;
}

/* Sub-headings (h3) indent */
.toc-link-sub {
    margin-left: 12px;
    font-size: 0.8rem;
    color: #888;
}

.toc-footer {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    line-height: 1.4;
}

/* =========================================
   5. ARTICLE CONTENT
   ========================================= */
.article {
    max-width: 100%;
    /* Đảm bảo không tràn grid */
}

/* --- Header --- */
.article-header {
    margin-bottom: 60px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 40px;
}

.article-header h1 {
    font-family: var(--font-sans);
    font-size: 2.5rem;
    line-height: 1.2;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 16px;
}

.article-header p {
    font-size: 1.1rem;
    color: var(--text-muted);
    margin-bottom: 24px;
}

/* Metadata Pills */
.meta-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.pill {
    background: var(--pill-bg);
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 99px;
    /* Viên thuốc tròn */
}

/* --- Body Text --- */
section {
    margin-bottom: 50px;
}

h2,
h3 {
    font-family: var(--font-sans);
    color: var(--text-main);
    margin-top: 40px;
    margin-bottom: 16px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

h2 {
    font-size: 1.75rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

h3 {
    font-size: 1.35rem;
    margin-top: 30px;
}

p {
    margin-bottom: 20px;
}

/* Lists */
ul,
ol {
    margin-bottom: 20px;
    padding-left: 20px;
}

li {
    margin-bottom: 8px;
}

/* --- Math (KaTeX adjustments) --- */
.katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 10px 0;
}

/* --- Citations / References --- */
.refs {
    list-style: none;
    padding: 0;
    font-size: 0.9rem;
    line-height: 1.5;
}

.refs li {
    margin-bottom: 12px;
    padding-left: 24px;
    text-indent: -24px;
    /* Hanging indent: dòng 2 thụt vào */
}

.refs li a {
    overflow-wrap: break-word;
    /* Ngắt link dài */
}

/* --- Utilities --- */
.muted {
    color: var(--text-muted);
}

.small {
    font-size: 0.85rem;
}

/* Footer */
.article-footer {
    margin-top: 80px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    font-family: var(--font-sans);
}

/* =========================================
   6. RESPONSIVE DESIGN (Mobile)
   ========================================= */
@media (max-width: 900px) {
    .article-layout {
        grid-template-columns: 1fr;
        /* Một cột duy nhất */
        gap: 40px;
    }

    .toc {
        display: none;
        /* Ẩn TOC trên mobile cho gọn, hoặc chuyển thành dropdown nếu muốn */
    }

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

/* Citation Box Styles */
#citation {
    margin-top: 60px;
    margin-bottom: 60px;
}

.citation-box {
    background-color: var(--code-bg);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--link-color);
    border-radius: 4px;
    padding: 15px 20px;
    margin-top: 15px;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    overflow-x: auto;
}

.citation-box pre {
    background: transparent;
    /* Ghi đè style pre mặc định để tránh bị trùng nền */
    padding: 0;
    margin: 0;
    border: none;
    color: #333;
}

.citation-box code {
    background: transparent;
    padding: 0;
    color: inherit;
}