@font-face {
    font-family: 'Helvetica Neue';
    src: url('../fonts/HelveticaNeue-Roman.woff') format('woff');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Helvetica Neue';
    src: url('../fonts/HelveticaNeue-Medium.woff') format('woff');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Helvetica Neue';
    src: url('../fonts/HelveticaNeue-Bold.woff') format('woff');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

:root {
    --bg: #0a0a0a;
    --surface: #141414;
    --surface-elevated: #1e1e20;
    --surface-hover: #27272a;
    --border: #1f1f22;
    --text-primary: #ebebee;
    --text-body: #ebebee;
    --text-muted: #9898a0;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, Roboto, sans-serif;
    --font-display: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, 'Cascadia Mono', Consolas, Menlo, monospace;
    --fs-h1: 1.875rem;
    --fs-h2: 1.25rem;
    --fs-lg: 1rem;
    --fs-base: 0.9375rem;
    --fs-sm: 0.8125rem;
    --fs-xs: 0.75rem;
}

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

html, body {
    background-color: #010102;
    background-image:
        radial-gradient(ellipse 75% 26% at 55% 0%, rgba(190, 206, 224, 0.052), transparent 60%),
        linear-gradient(125deg, transparent 12%, rgba(255, 255, 255, 0.014) 28%, rgba(220, 232, 246, 0.032) 34%, rgba(255, 255, 255, 0.007) 42%, transparent 58%, rgba(200, 216, 234, 0.02) 76%, transparent 90%),
        linear-gradient(180deg, #020203 0%, #06080c 36%, #010102 68%, #07090d 100%);
    background-repeat: no-repeat;
    color: var(--text-body);
    font-family: var(--font-sans);
    font-size: 16px;
    font-weight: 400;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: clip;
    min-height: 100vh;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

body {
    padding-top: 56px;
}

html::-webkit-scrollbar,
body::-webkit-scrollbar,
.docs-sidebar::-webkit-scrollbar {
    display: none;
}

.docs-sidebar {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

a, button {
    font-family: inherit;
    color: inherit;
}

.hidden {
    display: none;
}

:focus-visible {
    outline: 2px solid var(--text-primary);
    outline-offset: 2px;
}

/* Fixed Single-Row Header */
.docs-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 70;
    height: 56px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.docs-header-inner {
    max-width: 1200px;
    height: 100%;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.mobile-menu-btn {
    display: none;
    position: relative;
    appearance: none;
    border: none;
    background: var(--surface);
    color: var(--text-primary);
    width: 34px;
    height: 34px;
    border-radius: 8px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.mobile-menu-btn::after {
    content: "";
    position: absolute;
    inset: -5px;
}

.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 400;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    user-select: none;
    padding: 0.25rem 0;
    transition: color 0.15s ease;
}

.btn-back:hover {
    color: var(--text-primary);
}

.btn-back-icon {
    width: 11px;
    height: 11px;
    stroke: currentColor;
    flex-shrink: 0;
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-back:hover .btn-back-icon {
    transform: translateX(-3px);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.header-icon-link {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    text-decoration: none;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.header-icon-link::after {
    content: "";
    position: absolute;
    inset: -8px;
}

.header-icon-link:hover {
    color: var(--text-primary);
    background: var(--surface-elevated);
}

/* 2-Column Layout with Fixed Left Sidebar */
.docs-layout {
    max-width: 1200px;
    margin: 0 auto;
    padding: 28px 24px 96px 310px;
}

.docs-sidebar {
    position: fixed;
    top: 56px;
    bottom: 0;
    left: max(24px, calc((100vw - 1200px) / 2 + 24px));
    width: 244px;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 18px 18px 28px 0;
    z-index: 40;
}

.docs-sidebar::after {
    content: "";
    position: fixed;
    top: 96px;
    bottom: 44px;
    left: calc(max(24px, calc((100vw - 1200px) / 2 + 24px)) + 244px);
    width: 1px;
    background: var(--border);
    pointer-events: none;
}

.sidebar-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
}

.sidebar-group-label {
    font-size: var(--fs-xs);
    font-weight: 500;
    color: var(--text-muted);
    padding: 0 12px 6px;
}

.sidebar-link {
    display: inline-block;
    width: fit-content;
    max-width: 100%;
    text-align: left;
    text-decoration: none;
    padding: 5px 12px;
    border-radius: 8px;
    font-size: var(--fs-sm);
    font-weight: 400;
    line-height: 1.35;
    color: var(--text-body);
    transition: background-color 0.14s ease, color 0.14s ease;
}

.sidebar-link:hover {
    background: var(--surface);
    color: #ffffff;
}

.sidebar-link.is-active {
    background: var(--surface-hover);
    color: #ffffff;
    font-weight: 500;
}

/* Centered Reading Column */
.docs-main {
    min-width: 0;
    width: 100%;
    max-width: 700px;
    margin: 0 auto;
}

.doc-header {
    margin-bottom: 1.75em;
}

.doc-title {
    max-width: 30ch;
    font-family: var(--font-display);
    font-size: var(--fs-h1);
    font-weight: 700;
    letter-spacing: -0.025em;
    line-height: 1.2;
    color: var(--text-primary);
}

.doc-subtitle {
    max-width: 700px;
    margin-top: 8px;
    font-size: var(--fs-lg);
    font-weight: 400;
    line-height: 1.6;
    color: var(--text-muted);
}

.doc-meta {
    margin-top: 12px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    font-size: var(--fs-sm);
    font-weight: 400;
    color: var(--text-muted);
}

.doc-meta-strong {
    color: var(--text-primary);
    font-weight: 500;
}

.doc-actions {
    margin-top: 16px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.doc-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 14px;
    border-radius: 8px;
    font-size: var(--fs-sm);
    font-weight: 500;
    line-height: 1.35;
    text-decoration: none;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.doc-btn-primary {
    background: var(--text-primary);
    color: var(--bg);
    border: 1px solid var(--text-primary);
}

.doc-btn-primary:hover {
    background: #ffffff;
    border-color: #ffffff;
}

.doc-btn-secondary {
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.doc-btn-secondary:hover {
    background: var(--surface-elevated);
    border-color: rgba(235, 235, 238, 0.22);
}

/* Layout measure owned by the article wrapper */
.article-measure > :where(h1, h2, h3, p, ul, ol, blockquote) {
    max-width: 65ch;
}

/* Evidence Image Container */
.evidence-block {
    margin-block-start: 1.5em;
}

.evidence-block--compact {
    max-width: 140px;
}

.evidence-frame {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}

.evidence-frame--padded {
    padding: 16px;
}

.evidence-frame img {
    display: block;
    width: 100%;
    height: auto;
}

.evidence-caption {
    margin-top: 8px;
    font-size: var(--fs-sm);
    font-weight: 400;
    line-height: 1.5;
    color: var(--text-muted);
}

.evidence-stack {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-block-start: 1.5em;
}

.evidence-stack .evidence-block {
    margin-block-start: 0;
}

/* Metric Summary Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-block-start: 1.25em;
}

.stats-grid--3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 12px;
    text-align: center;
}

.stat-value {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text-primary);
}

.stat-label {
    margin-top: 4px;
    font-size: var(--fs-xs);
    font-weight: 400;
    color: var(--text-muted);
}

/* Side-by-Side Comparison Grid */
.compare-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin-block-start: 1em;
}

.compare-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.compare-label {
    font-size: var(--fs-xs);
    font-weight: 500;
    color: var(--text-muted);
}

.compare-caption {
    font-size: var(--fs-xs);
    font-weight: 400;
    line-height: 1.55;
    color: var(--text-muted);
}

/* Feature / Card Grid */
.feature-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-block-start: 1.25em;
}

.feature-grid--3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.feature-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
}

.feature-title {
    font-family: var(--font-sans);
    font-size: var(--fs-sm);
    font-weight: 600;
    line-height: 1.35;
    color: var(--text-primary);
}

.feature-desc {
    margin-top: 6px;
    font-size: var(--fs-xs);
    font-weight: 400;
    line-height: 1.6;
    color: var(--text-muted);
}

/* Repository Card Grid */
.repo-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-block-start: 1.25em;
}

.repo-card {
    display: block;
    text-decoration: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.repo-card:hover {
    background: var(--surface-elevated);
    border-color: rgba(235, 235, 238, 0.22);
}

.repo-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.repo-card-title {
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--text-primary);
    word-break: break-word;
}

.repo-card-arrow {
    color: var(--text-muted);
    flex-shrink: 0;
    transition: color 0.15s ease, transform 0.15s ease;
}

.repo-card:hover .repo-card-arrow {
    color: var(--text-primary);
    transform: translate(1px, -1px);
}

.repo-card-desc {
    margin-top: 8px;
    font-size: var(--fs-xs);
    font-weight: 400;
    line-height: 1.55;
    color: var(--text-muted);
}

/* Diagram / Formula Block */
.diagram-block {
    margin-block-start: 1.25em;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    line-height: 1.7;
    color: var(--text-body);
    overflow-x: auto;
    white-space: nowrap;
}

/* Code Box with Copy Button */
.code-box {
    margin-block-start: 1em;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
}

.code-box-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.code-box-row--center {
    align-items: center;
}

.code-box-pre {
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    line-height: 1.65;
    color: var(--text-body);
}

.code-box-pre::-webkit-scrollbar {
    display: none;
}

.code-copy-btn {
    appearance: none;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    width: 30px;
    height: 30px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.code-copy-btn:hover {
    color: var(--text-primary);
    background: var(--surface-elevated);
}

.code-label {
    margin-block-start: 1.25em;
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text-primary);
}

.code-label + .code-box {
    margin-block-start: 0.5em;
}

.table-frame {
    margin-block-start: 1.25em;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    overflow: hidden;
}

.table-frame table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--fs-sm);
    line-height: 1.6;
    text-align: left;
}

.table-frame th {
    padding: 10px 14px;
    font-size: var(--fs-xs);
    font-weight: 500;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.table-frame td {
    padding: 10px 14px;
    vertical-align: top;
    border-top: 1px solid var(--border);
    color: var(--text-body);
}

.table-frame tbody tr:first-child td {
    border-top: none;
}

.table-mono {
    font-family: var(--font-mono);
    color: var(--text-primary);
}

.table-muted {
    color: var(--text-muted);
}

/* Flat Bottom Prev/Next Navigation */
.doc-bottom-nav {
    margin-top: 48px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.bottom-nav-link {
    text-decoration: none;
    padding: 8px 0;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: var(--fs-sm);
    font-weight: 500;
    transition: color 0.15s ease;
}

.bottom-nav-link:hover {
    color: var(--text-primary);
}

.bottom-nav-link--next {
    margin-left: auto;
    text-align: right;
}

/* Mobile Drawer Lock */
html.drawer-open,
body.drawer-open {
    overflow: hidden;
    overscroll-behavior: none;
}

@media (max-width: 820px) {
    .docs-header-inner {
        padding: 0 16px;
        gap: 8px;
    }

    .header-left {
        width: 100%;
        justify-content: space-between;
        gap: 10px;
    }

    .btn-back {
        order: 1;
    }

    .header-right {
        display: none;
    }

    .mobile-menu-btn {
        order: 2;
        display: inline-flex;
    }

    .docs-layout {
        padding: 24px 16px 64px;
    }

    .docs-sidebar {
        display: none;
        position: fixed;
        top: 56px;
        left: 0;
        right: 0;
        bottom: 0;
        width: auto;
        z-index: 60;
        gap: 18px;
        padding: 18px 20px 40px;
        background: var(--bg);
        overflow-y: auto;
        overscroll-behavior: contain;
        touch-action: pan-y;
    }

    .docs-sidebar.is-open {
        display: flex;
    }

    .docs-sidebar::after {
        display: none;
    }

    .sidebar-link {
        min-height: 44px;
        padding: 8px 14px;
        display: inline-flex;
        align-items: center;
        font-size: var(--fs-base);
        color: var(--text-body);
    }

    .doc-title {
        font-size: 1.5625rem;
        line-height: 1.25;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .stats-grid--3 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .compare-grid,
    .feature-grid,
    .feature-grid--3,
    .repo-grid {
        grid-template-columns: 1fr;
    }

    .doc-bottom-nav {
        flex-wrap: wrap;
        gap: 8px;
    }
}
