.article-toc {
    --article-toc-width: 220px;
    --article-toc-surface: #fff;
    --article-toc-text: #374151;
    --article-toc-title: #111827;
    --article-toc-border: #e5e7eb;
    --article-toc-highlight: #eff6ff;
    --article-toc-accent: #1d4ed8;
    box-sizing: border-box;
    border: 1px solid var(--article-toc-border);
    border-radius: 8px;
    background: var(--article-toc-surface);
    color: var(--article-toc-text);
    font-family: inherit;
    font-size: 13px;
    line-height: 1.5;
    text-align: left;
}

.article-toc *,
.article-toc *::before,
.article-toc *::after {
    box-sizing: border-box;
}

.article-toc[hidden],
.article-toc [hidden] {
    display: none !important;
}

.article-toc[data-layout="sidebar"] {
    position: fixed;
    right: auto;
    bottom: auto;
    z-index: 25;
    width: var(--article-toc-width);
}

.article-toc[data-layout="inline"] {
    width: 100%;
    margin: 0 0 24px;
}

.article-toc__toggle {
    display: flex;
    width: 100%;
    min-height: 48px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--article-toc-title);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.article-toc__toggle:disabled {
    opacity: 1;
    cursor: default;
    color: var(--article-toc-title);
}

.article-toc__chevron {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    transition: transform 150ms ease-out;
}

.article-toc__toggle[aria-expanded="true"] .article-toc__chevron {
    transform: rotate(180deg);
}

.article-toc[data-layout="sidebar"] .article-toc__chevron {
    display: none;
}

.article-toc__navigation {
    max-height: min(60vh, 480px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0 8px 10px;
    scrollbar-width: thin;
    scrollbar-color: var(--article-toc-border) transparent;
}

.article-toc[data-layout="sidebar"] .article-toc__navigation {
    max-height: var(--article-toc-list-height, 60vh);
}

.article-toc .article-toc__list {
    display: block;
    margin: 0;
    padding: 0;
    list-style: none;
}

.article-toc .article-toc__item {
    margin: 2px 0;
    padding: 0;
    list-style: none;
}

.article-toc .article-toc__link {
    display: block;
    min-width: 0;
    padding: 8px 10px;
    padding-left: calc(10px + var(--article-toc-depth, 0) * 12px);
    overflow: hidden;
    border-radius: 4px;
    color: var(--article-toc-text);
    font-size: 13px;
    font-weight: 400;
    line-height: 1.5;
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: background-color 150ms ease-out, color 150ms ease-out;
}

.article-toc .article-toc__link[aria-current="location"] {
    background: var(--article-toc-highlight);
    color: var(--article-toc-accent);
    font-weight: 600;
}

.article-toc__toggle:focus-visible,
.article-toc__link:focus-visible {
    outline: 2px solid var(--article-toc-accent);
    outline-offset: -2px;
}

.article-toc ::selection {
    background: var(--article-toc-highlight);
    color: var(--article-toc-accent);
}

.dark .article-toc {
    --article-toc-surface: #1f2937;
    --article-toc-text: #d1d5db;
    --article-toc-title: #f9fafb;
    --article-toc-border: #4b5563;
    --article-toc-highlight: #1e3a5f;
    --article-toc-accent: #93c5fd;
}

@media (hover: hover) {
    .article-toc .article-toc__link:hover,
    .article-toc__toggle:not(:disabled):hover {
        background: var(--article-toc-highlight);
        color: var(--article-toc-accent);
    }
}

@media (prefers-reduced-motion: reduce) {
    .article-toc__chevron,
    .article-toc__link {
        transition: none;
    }
}
