/* ==========================================================================
   Article layout – rich text with an optional sticky table of contents.
   Used by the project description and the news detail page.
   Pair with static/js/article-toc.js.
   ========================================================================== */

/* The document scrolls (not #main_wrapper) so the TOC can be sticky */
#main_wrapper {
    overflow-y: visible;
}

.article-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 240px;
    gap: clamp(2rem, 5vw, 4rem);
    align-items: start;
}

/* Grid items default to min-width:auto – wide content (images, code) would otherwise widen the column */
.article-layout > * {
    min-width: 0;
}

.article-layout--no-toc {
    grid-template-columns: minmax(0, 1fr);
}

/* --- Body typography --------------------------------------------------- */
.article-body {
    max-width: 760px;
    overflow-wrap: break-word;
    font-size: 1.075rem;
    line-height: 1.8;
    color: var(--text-muted);
}

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

.article-body h1,
.article-body h2,
.article-body h3,
.article-body h4,
.article-body h5,
.article-body h6 {
    margin: 2.2rem 0 0.8rem;
    color: var(--text);
    line-height: 1.3;
    scroll-margin-top: calc(var(--navbar-height) + 24px);
}

.article-body h1 { font-size: 1.9rem; }
.article-body h2 { font-size: 1.6rem; }
.article-body h3 { font-size: 1.3rem; }
.article-body h4,
.article-body h5,
.article-body h6 { font-size: 1.1rem; }

.article-body p {
    margin-bottom: 1.1rem;
}

.article-body strong {
    color: var(--text);
}

.article-body ul,
.article-body ol {
    margin: 0 0 1.1rem 1.4rem;
}

.article-body li {
    margin-bottom: 0.35rem;
}

.article-body blockquote {
    margin: 1.5rem 0;
    padding: 0.9rem 1.25rem;
    border-left: 3px solid var(--accent);
    border-radius: 0 var(--radius) var(--radius) 0;
    background: rgba(var(--accent-rgb), 0.06);
    color: var(--text);
}

.article-body pre,
.article-body code {
    font-family: var(--font-mono);
    font-size: 0.9em;
}

.article-body pre {
    margin: 1.25rem 0;
    padding: 1rem 1.25rem;
    overflow-x: auto;
    border-radius: var(--radius);
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--border);
}

.article-body :not(pre) > code {
    padding: 0.1em 0.4em;
    border-radius: 6px;
    background: var(--surface-hover);
    color: var(--accent-soft);
}

.article-body img,
.article-body video,
.article-body iframe {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 1.75rem 0;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.article-body img {
    user-select: none;
    -webkit-user-drag: none;
}

.article-body a {
    color: var(--accent-strong);
    border-bottom: 1px solid rgba(var(--accent-rgb), 0.35);
}

.article-body a:hover {
    border-bottom-color: var(--accent-strong);
}

.article-body hr {
    margin: 2rem 0;
    border: 0;
    border-top: 1px solid var(--border);
}

/* --- Table of contents ------------------------------------------------- */
.article-toc {
    position: sticky;
    top: calc(var(--navbar-height) + 24px);
    max-height: calc(100vh - var(--navbar-height) - 48px);
    overflow-y: auto;
    padding: 1.25rem;
    border-radius: var(--radius);
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.article-toc__title {
    margin-bottom: 0.75rem;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-subtle);
}

.article-toc ul {
    list-style: none;
    display: grid;
    gap: 0.15rem;
}

.article-toc a {
    display: block;
    padding: 0.35rem 0.6rem;
    border-left: 2px solid transparent;
    border-radius: 0 6px 6px 0;
    font-size: 0.875rem;
    line-height: 1.4;
    color: var(--text-muted);
    overflow-wrap: anywhere;
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.article-toc a:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.article-toc a.is-active {
    color: var(--accent-soft);
    border-left-color: var(--accent);
    background: rgba(var(--accent-rgb), 0.08);
}

.article-toc .article-toc__l3 { padding-left: 1.2rem; }
.article-toc .article-toc__l4,
.article-toc .article-toc__l5,
.article-toc .article-toc__l6 { padding-left: 1.8rem; }

@media (max-width: 860px) {
    .article-layout {
        grid-template-columns: 1fr;
    }

    .article-toc {
        display: none;
    }
}
