:root {
    --main-rgb: 59, 130, 246;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --surface: #ffffff;
    --background: #f9fafb;
    --code-bg: #f3f4f6;

    /* Note box colors */
    --note-text: #000000;
    --note-bg: #f0fdf4;
    --note-border: #86efac;
    --note-accent: #15803d;
    --note-title-bg: #dcfce7;

    /* Exercise box colors */
    --exercise-text: #000000;
    --exercise-bg: #eff6ff;
    --exercise-border: #93c5fd;
    --exercise-accent: #2563eb;
    --exercise-title-bg: #dbeafe;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: 'Nunito', sans-serif;
    color: var(--text);
    background: var(--background);
    line-height: 1.6;
}

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

a:hover {
    text-decoration: underline;
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(8px);
}

.site-header-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}

.brand {
    display: flex;
    align-items: baseline;
    gap: 10px;
    min-width: 0;
}

.brand-name {
    color: #111827;
    font-weight: 800;
    font-size: 1.05rem;
    white-space: nowrap;
}

.brand-section {
    color: var(--muted);
    font-size: 0.95rem;
}

.site-nav {
    display: flex;
    gap: 18px;
    font-size: 0.95rem;
    white-space: nowrap;
}

.page {
    max-width: 1180px;
    margin: 0 auto;
    padding: 56px 24px 96px;
}

.blog-home {
    max-width: 820px;
}

.eyebrow {
    margin: 0 0 6px;
    color: rgb(var(--main-rgb));
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-size: 0.78rem;
}

.blog-title {
    margin: 0;
    font-size: clamp(2.25rem, 6vw, 4rem);
    line-height: 1.05;
    letter-spacing: -0.035em;
    color: #111827;
}

.blog-description {
    max-width: 800px;
    margin: 18px 0 48px;
    color: var(--muted);
    font-size: 1.08rem;
}

.blog-description > p {
    margin: 0 0 1.2em;
}

.blog-quote {
    margin: 1.6em 0;
    padding: 0 0 0.25em 1.2em;
    border-left: 3px solid rgb(var(--main-rgb));
    font-style: italic;
    line-height: 1.65;
}

.blog-quote footer {
    margin-top: -0.5em;
    margin-left: 1.5em;
    font-size: 1.00rem;
    font-style: normal;
}

.post-list {
    border-top: 1px solid var(--border);
}

.post-card {
    padding: 30px 0;
    border-bottom: 1px solid var(--border);
}

.post-card h2 {
    margin: 0 0 8px;
    font-size: 1.6rem;
    line-height: 1.25;
}

.post-card h2 a {
    color: #111827;
}

.post-card h2 a:hover {
    color: rgb(var(--main-rgb));
}

.post-card p {
    margin: 0 0 12px;
    color: #4b5563;
}

.post-meta {
    color: var(--muted);
    font-size: 0.9rem;
}

.post-layout {
    display: grid;
    grid-template-columns: minmax(0, 760px) 230px;
    justify-content: center;
    gap: 64px;
    align-items: start;
}

.article-header {
    padding-bottom: 26px;
    margin-bottom: 30px;
    border-bottom: 1px solid var(--border);
}

.article-header h1 {
    margin: 4px 0 12px;
    font-size: clamp(1.9rem, 4vw, 3rem);
    line-height: 1.08;
    letter-spacing: -0.035em;
    color: #111827;
}

.article-description {
    margin: 0 0 14px;
    font-size: 1.08rem;
    color: #4b5563;
}

.article-content {
    min-width: 0;
    font-size: 1.05rem;
}

.article-content li {
    margin: 0.25em 0;
}

.article-content li > p {
    margin: 0;
}

.article-content > :first-child {
    margin-top: 0;
}

.article-content h2,
.article-content h3,
.article-content h4 {
    color: #111827;
    line-height: 1.25;
    scroll-margin-top: 90px;
}

.article-content h2 {
    margin: 2.6em 0 0.7em;
    font-size: 1.75rem;
    padding-bottom: 0.3em;
    border-bottom: 1px solid var(--border);
}

.article-content h3 {
    margin: 2em 0 0.6em;
    font-size: 1.35rem;
}

.article-content h4 {
    margin: 1.8em 0 0.5em;
    font-size: 1.12rem;
}

.article-content p,
.article-content ul,
.article-content ol,
.article-content blockquote,
.article-content pre,
.article-content table {
    margin: 1.1em 0;
}

.article-content ul,
.article-content ol {
    padding-left: 1.5em;
}

.article-content blockquote {
    margin-left: 0;
    padding: 0.3em 1em;
    color: #4b5563;
    border-left: 4px solid rgb(var(--main-rgb));
    background: #f8fafc;
}

.article-content code {
    padding: 0.12em 0.32em;
    border-radius: 4px;
    background: var(--code-bg);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.9em;
}

.article-content pre {
    overflow-x: auto;
    padding: 18px;
    border-radius: 8px;
    background: #111827;
    color: #f9fafb;
}

.article-content pre code {
    padding: 0;
    background: transparent;
    color: inherit;
}

.article-content img {
    max-width: 100%;
}

.article-content table {
    width: 100%;
    border-collapse: collapse;
}

.article-content th,
.article-content td {
    padding: 8px 10px;
    border: 1px solid var(--border);
    text-align: left;
}

.article-content .MathJax {
    overflow-x: auto;
    overflow-y: hidden;
}

/* LaTeX-style note and exercise boxes. In Markdown, write:
   > [!NOTE] Optional title
   > ...
   or
   > [!EXERCISE] Optional title
   > ...
*/
.article-content blockquote.notebox,
.article-content blockquote.exercisebox {
    margin: 1.5em auto;
    padding: 0.85em 1em 0.9em;
    border-radius: 8px;
    border-left-width: 4px;
    max-width: 90%;
}

.article-content blockquote.notebox {
    color: var(--note-text);
    background: var(--note-bg);
    border: 1px solid var(--note-border);
    border-left: 4px solid var(--note-accent);
}

.article-content blockquote.exercisebox {
    color: var(--exercise-text);
    background: var(--exercise-bg);
    border: 1px solid var(--exercise-border);
    border-left: 4px solid var(--exercise-accent);
}

.article-content blockquote.notebox .admonition-title,
.article-content blockquote.exercisebox .admonition-title {
    margin: -0.85em -1em 0.8em !important;
    padding: 0.55em 1em;
    font-weight: 800;
}

.article-content blockquote.notebox .admonition-title {
    background: var(--note-title-bg);
}

.article-content blockquote.exercisebox .admonition-title {
    background: var(--exercise-title-bg);
}

.article-content blockquote.notebox > :last-child,
.article-content blockquote.exercisebox > :last-child {
    margin-bottom: 0;
}

.toc {
    position: sticky;
    top: 92px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    padding-left: 18px;
    border-left: 1px solid var(--border);
}

.toc-title {
    margin: 0 0 12px;
    font-weight: 800;
    font-size: 0.82rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #374151;
}

.toc a {
    display: block;
    margin: 7px 0;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.35;
}

.toc a:hover,
.toc a.active {
    color: rgb(var(--main-rgb));
    text-decoration: none;
}

.toc .toc-h3 {
    padding-left: 12px;
    font-size: 0.85rem;
}

.toc .toc-h4 {
    padding-left: 24px;
    font-size: 0.82rem;
}

.back-link {
    display: inline-block;
    margin-top: 44px;
    font-weight: 700;
}

.status {
    color: var(--muted);
}

.error {
    padding: 14px 16px;
    border: 1px solid #fecaca;
    border-radius: 8px;
    background: #fef2f2;
    color: #991b1b;
}

@media (max-width: 980px) {
    .post-layout {
        grid-template-columns: minmax(0, 760px);
    }

    .toc {
        display: none;
    }
}

@media (max-width: 640px) {
    .site-header-inner {
        padding: 12px 18px;
    }

    .brand-section {
        display: none;
    }

    .site-nav {
        gap: 12px;
    }

    .page {
        padding: 40px 18px 72px;
    }

    .blog-description {
        margin-bottom: 34px;
    }
}
