:root {
    color-scheme: dark;
    --brand-blue: #00b0f0;
    --brand-orange: #f06000;
    --bg: #0b111a;
    --surface: #111a26;
    --surface-2: #172231;
    --surface-3: #202d3d;
    --text: #eef5ff;
    --muted: #96a6ba;
    --border: #28384a;
    --primary: #ff7a1a;
    --primary-hover: #ff923c;
    --primary-text: #1a0a00;
    --accent: #2cc8ff;
    --code-bg: #07101b;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.32);
    --focus: 0 0 0 3px rgba(255, 122, 26, 0.42);
    --motion-ease: cubic-bezier(0.22, 1, 0.36, 1);
    --transition: 200ms ease;
    --glass-fill: linear-gradient(
        165deg,
        color-mix(in srgb, var(--surface) 14%, transparent) 0%,
        color-mix(in srgb, var(--surface) 8%, transparent) 55%,
        color-mix(in srgb, #000000 2%, transparent) 100%
    );
    --glass-edge: color-mix(in srgb, #ffffff 7%, transparent);
    --glass-backdrop: blur(3px) saturate(1.15);
    --glass-inset: inset 0 1px 0 color-mix(in srgb, #ffffff 8%, transparent);
    --glass-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    --scrollbar-track: #0d1621;
    --scrollbar-thumb: #31465c;
    --scrollbar-thumb-hover: #44617f;
    --header-h: 64px;
    --sidebar-w: 292px;
    --toc-w: 240px;
    --radius: 8px;
    --font: "Noto Sans SC", "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, sans-serif;
    --mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
}

:root[data-theme="light"] {
    color-scheme: light;
    --bg: #f6f8fb;
    --surface: #ffffff;
    --surface-2: #edf4fa;
    --surface-3: #e4edf6;
    --text: #101827;
    --muted: #526170;
    --border: #d8e2ec;
    --primary: #e65c00;
    --primary-hover: #c94f00;
    --primary-text: #ffffff;
    --accent: #008cc2;
    --code-bg: #f0f5f9;
    --shadow: 0 16px 40px rgba(13, 38, 76, 0.12);
    --glass-fill: linear-gradient(
        165deg,
        color-mix(in srgb, #ffffff 18%, transparent) 0%,
        color-mix(in srgb, #ffffff 10%, transparent) 55%,
        color-mix(in srgb, var(--surface) 6%, transparent) 100%
    );
    --glass-edge: color-mix(in srgb, #ffffff 16%, transparent);
    --glass-backdrop: blur(3px) saturate(1.1);
    --glass-inset: inset 0 1px 0 color-mix(in srgb, #ffffff 22%, transparent);
    --glass-shadow: 0 4px 16px rgba(15, 23, 42, 0.04);
    --scrollbar-track: #e8eef5;
    --scrollbar-thumb: #b1c1d1;
    --scrollbar-thumb-hover: #8fa5bc;
}

* { box-sizing: border-box; }

html {
    scroll-behavior: smooth;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

body,
.sidebar,
.toc,
.article pre,
.article code {
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

html::-webkit-scrollbar,
body::-webkit-scrollbar,
.sidebar::-webkit-scrollbar,
.toc::-webkit-scrollbar,
.article pre::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

html::-webkit-scrollbar-track,
body::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track,
.toc::-webkit-scrollbar-track,
.article pre::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

html::-webkit-scrollbar-thumb,
body::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb,
.toc::-webkit-scrollbar-thumb,
.article pre::-webkit-scrollbar-thumb {
    border: 2px solid var(--scrollbar-track);
    border-radius: 999px;
    background: var(--scrollbar-thumb);
}

html::-webkit-scrollbar-thumb:hover,
body::-webkit-scrollbar-thumb:hover,
.sidebar::-webkit-scrollbar-thumb:hover,
.toc::-webkit-scrollbar-thumb:hover,
.article pre::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

html::-webkit-scrollbar-corner,
body::-webkit-scrollbar-corner,
.sidebar::-webkit-scrollbar-corner,
.toc::-webkit-scrollbar-corner,
.article pre::-webkit-scrollbar-corner {
    background: var(--scrollbar-track);
}

body {
    margin: 0;
    min-height: 100dvh;
    background:
        radial-gradient(circle at top left, color-mix(in srgb, var(--brand-blue) 12%, transparent), transparent 36rem),
        linear-gradient(180deg, color-mix(in srgb, var(--surface-2) 34%, transparent), transparent 24rem),
        var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.65;
}

a { color: inherit; }

button,
input {
    font: inherit;
}

.skip-link {
    position: fixed;
    left: 16px;
    top: -80px;
    z-index: 1000;
    padding: 10px 14px;
    border-radius: var(--radius);
    background: var(--primary);
    color: #1d0a00;
    text-decoration: none;
    transition: top 160ms ease;
}

.skip-link:focus {
    top: 12px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: minmax(232px, var(--sidebar-w)) minmax(260px, 720px) auto;
    align-items: center;
    gap: 16px;
    height: var(--header-h);
    padding: 0 20px;
    background: var(--glass-fill);
    backdrop-filter: var(--glass-backdrop);
    -webkit-backdrop-filter: var(--glass-backdrop);
    border-bottom: 1px solid var(--glass-edge);
    box-shadow: var(--glass-inset), var(--glass-shadow);
}

.brand {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 10px;
    text-decoration: none;
}

.brand__logo {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    flex: 0 0 auto;
}

.brand__text {
    display: grid;
    line-height: 1.1;
    min-width: 0;
}

.brand__title {
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand__subtitle {
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
}

.search {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    height: 42px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0 12px;
    background: var(--surface);
    transition: background var(--transition), border-color var(--transition), box-shadow var(--transition), transform 180ms var(--motion-ease);
}

.search:focus-within {
    box-shadow: var(--focus);
    border-color: var(--primary);
}

.search__icon {
    display: inline-grid;
    place-items: center;
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
    color: var(--brand-orange);
}

.search__icon svg {
    display: block;
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.search input {
    width: 100%;
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
}

.search kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-width: 28px;
    min-height: 26px;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0 8px;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
}

.topbar__actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.action-link,
.icon-button {
    min-width: 44px;
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    transition:
        background var(--transition),
        color var(--transition),
        border-color var(--transition),
        transform 220ms var(--motion-ease),
        box-shadow 220ms var(--motion-ease);
}

.action-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 14px;
    background: transparent;
    text-decoration: none;
    font-weight: 650;
}

.action-link--primary {
    border-color: var(--primary);
    background: var(--primary);
    color: var(--primary-text);
}

.action-link:not(.action-link--primary):hover {
    background: color-mix(in srgb, var(--primary) 10%, transparent);
    color: var(--primary);
    border-color: var(--primary);
}

.icon-button:hover {
    background: var(--surface-2);
    border-color: var(--primary);
}

.action-link--primary:hover,
.action-link--primary:focus-visible {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: var(--primary-text);
    box-shadow: 0 4px 14px color-mix(in srgb, var(--primary) 40%, transparent);
}

.action-link:not(.action-link--primary):focus-visible {
    border-color: var(--primary);
}

.action-link:active {
    transform: scale(0.98);
}

.icon-button {
    display: inline-grid;
    place-items: center;
    padding: 0;
    cursor: pointer;
}

.icon-button:active {
    transform: scale(0.98);
}

.icon-button:focus-visible,
.action-link:focus-visible,
.doc-link:focus-visible {
    outline: 0;
    box-shadow: var(--focus);
}

.theme-toggle {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: var(--surface-2);
    touch-action: manipulation;
    transition: background var(--transition), border-color var(--transition), transform 180ms var(--motion-ease);
}

.theme-toggle:hover {
    background: var(--surface);
    border-color: var(--primary);
}

.theme-toggle:active {
    transform: scale(0.96);
}

.theme-toggle svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.theme-toggle .icon-sun {
    display: none;
}

.theme-toggle .icon-moon {
    display: block;
}

:root[data-theme="light"] .theme-toggle .icon-sun,
:root:not([data-theme="light"]) .theme-toggle .icon-moon {
    display: none;
}

:root[data-theme="light"] .theme-toggle .icon-moon,
:root:not([data-theme="light"]) .theme-toggle .icon-sun {
    display: block;
}

@media (prefers-reduced-transparency: reduce) {
    .topbar {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: var(--surface);
        border-bottom-color: var(--border);
        box-shadow: 0 1px 0 color-mix(in srgb, var(--text) 6%, transparent);
    }
}

.mobile-menu-button {
    display: none;
}

.mobile-menu-button span {
    display: block;
    width: 18px;
    height: 2px;
    margin: 2px 0;
    background: currentColor;
}

.layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
    gap: 0;
    min-height: calc(100dvh - var(--header-h));
}

.sidebar,
.toc {
    position: sticky;
    top: var(--header-h);
    height: calc(100dvh - var(--header-h));
    overflow: auto;
    padding: 22px 16px;
}

.sidebar {
    border-right: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 76%, transparent);
}

.toc {
    border-left: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 54%, transparent);
}

.sidebar__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    font-weight: 700;
}

#close-menu {
    display: none;
    font-size: 26px;
}

.sidebar__meta {
    margin-bottom: 18px;
    color: var(--muted);
    font-size: 13px;
}

.doc-group {
    margin-bottom: 12px;
}

.doc-group__toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    min-height: 40px;
    border: 0;
    border-radius: var(--radius);
    padding: 6px 10px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.doc-group__toggle:hover {
    background: var(--surface-2);
    color: var(--text);
}

.doc-group__toggle:focus-visible {
    outline: 0;
    box-shadow: var(--focus);
}

.doc-group__title {
    font-size: 17px;
    font-weight: 750;
    letter-spacing: 0;
    color: var(--brand-blue);
}

.doc-group__toggle:hover .doc-group__title {
    color: var(--brand-blue-hover, var(--accent));
}

:root[data-theme="light"] .doc-group__title {
    color: var(--brand-blue);
}

:root[data-theme="light"] .doc-group__toggle:hover .doc-group__title {
    color: color-mix(in srgb, var(--brand-blue) 84%, black);
}

.doc-group__chevron {
    width: 8px;
    height: 8px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform 160ms ease;
}

.doc-group.is-collapsed .doc-group__chevron {
    transform: rotate(-45deg);
}

.doc-group__items {
    overflow: hidden;
    opacity: 1;
    transition: max-height 220ms ease, opacity 180ms ease;
}

.doc-group.is-collapsed .doc-group__items {
    opacity: 0;
}

.doc-link {
    position: relative;
    display: block;
    width: 100%;
    margin: 2px 0;
    border: 0;
    border-radius: var(--radius);
    padding: 9px 10px;
    background: transparent;
    color: var(--text);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    overflow: hidden;
    transition: background-color 170ms ease, color 170ms ease, transform 170ms ease, box-shadow 170ms ease;
}

.doc-link:hover {
    background: var(--surface-2);
    transform: translateX(2px);
}

.doc-link.is-active {
    background: linear-gradient(90deg, color-mix(in srgb, var(--primary) 20%, transparent), color-mix(in srgb, var(--accent) 12%, transparent));
    color: var(--text);
    box-shadow: inset 3px 0 0 var(--primary);
    animation: doc-link-select 240ms cubic-bezier(.2, .8, .2, 1);
}

.doc-link__title {
    display: block;
    font-size: 16px;
    line-height: 1.35;
}

.content {
    min-width: 0;
    padding: 34px min(5vw, 56px) 72px;
}

.article {
    width: min(100%, 860px);
    margin: 0 auto;
    outline: 0;
    transform-origin: top center;
    will-change: opacity, transform;
    transition: opacity 180ms ease, transform 180ms cubic-bezier(.4, 0, 1, 1);
}

.article.is-exiting {
    opacity: 0;
    transform: translateY(-32px);
}

.article.is-entering {
    animation: article-slide-enter 280ms cubic-bezier(.16, 1, .3, 1) both;
}

.article__loading,
.empty-state {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    background: var(--surface);
    color: var(--muted);
}

@keyframes article-slide-enter {
    from {
        opacity: 0;
        transform: translateY(36px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes doc-link-select {
    from {
        transform: translateX(-4px);
    }
    to {
        transform: translateX(0);
    }
}

.pill {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 10px;
    color: var(--muted);
    background: var(--surface);
    font-size: 13px;
    text-decoration: none;
}

.article h1,
.article h2,
.article h3,
.article h4 {
    scroll-margin-top: calc(var(--header-h) + 18px);
    line-height: 1.28;
}

.article h1 {
    margin: 0 0 14px;
    font-size: clamp(30px, 4vw, 44px);
}

.article h2 {
    margin: 42px 0 14px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    font-size: 26px;
}

.article h3 {
    margin: 28px 0 10px;
    font-size: 21px;
}

.article h4 {
    margin: 20px 0 8px;
    font-size: 17px;
}

.article p,
.article ul,
.article ol,
.article blockquote,
.article table,
.article pre {
    margin: 14px 0;
}

.article a {
    color: var(--accent);
    text-underline-offset: 3px;
}

.article img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 18px auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.article code {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.1em 0.35em;
    background: var(--code-bg);
    font-family: var(--mono);
    font-size: 0.92em;
}

.article pre {
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    background: var(--code-bg);
    line-height: 1.7;
}

.article pre code {
    border: 0;
    padding: 0;
    background: transparent;
}

.tok-keyword {
    color: #ff9b45;
    font-weight: 700;
}

.tok-string {
    color: #7ddf9f;
}

.tok-comment {
    color: var(--muted);
    font-style: italic;
}

.tok-number,
.tok-atom {
    color: #5fd7ff;
}

.tok-function {
    color: #ffd166;
}

.article blockquote {
    border-left: 4px solid var(--primary);
    margin-left: 0;
    padding: 10px 14px;
    border-radius: 0 var(--radius) var(--radius) 0;
    background: color-mix(in srgb, var(--primary) 10%, transparent);
    color: var(--text);
}

.callout {
    border: 1px solid color-mix(in srgb, var(--accent) 50%, var(--border));
    border-left: 4px solid var(--accent);
    border-radius: var(--radius);
    padding: 12px 14px;
    background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.callout__title {
    margin-bottom: 6px;
    font-weight: 700;
}

.article table {
    width: 100%;
    border-collapse: collapse;
    overflow: hidden;
    border-radius: var(--radius);
}

.article th,
.article td {
    border: 1px solid var(--border);
    padding: 9px 10px;
    vertical-align: top;
}

.article th {
    background: var(--surface-2);
}

.toc__title {
    margin-bottom: 12px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 750;
}

.toc a {
    display: block;
    border-left: 2px solid transparent;
    padding: 6px 0 6px 10px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.35;
    text-decoration: none;
}

.toc a:hover,
.toc a.is-active {
    border-left-color: var(--primary);
    color: var(--text);
}

.toc .toc-h3 { padding-left: 20px; }
.toc .toc-h4 { padding-left: 30px; }

.scrim {
    position: fixed;
    inset: 0;
    z-index: 80;
    background: rgba(0, 0, 0, 0.54);
}

@media (max-width: 1120px) {
    .topbar {
        grid-template-columns: minmax(198px, 260px) minmax(180px, 1fr) auto;
    }

    .layout {
        grid-template-columns: 260px minmax(0, 1fr);
    }

    .toc {
        display: none;
    }
}

@media (max-width: 780px) {
    :root {
        --header-h: 58px;
    }

    .topbar {
        grid-template-columns: 44px minmax(0, 1fr) auto;
        gap: 10px;
        padding: 0 12px;
    }

    .brand {
        display: none;
    }

    .mobile-menu-button {
        display: inline-grid;
    }

    .topbar__actions .action-link {
        display: none;
    }

    .search {
        height: 42px;
    }

    .search kbd {
        display: none;
    }

    .layout {
        display: block;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 100;
        width: min(86vw, 330px);
        height: 100dvh;
        transform: translateX(-105%);
        transition: transform 200ms ease;
        background: var(--bg);
        box-shadow: var(--shadow);
    }

    .sidebar.is-open {
        transform: translateX(0);
    }

    #close-menu {
        display: inline-grid;
    }

    .content {
        padding: 26px 18px 56px;
    }

    .article h1 {
        font-size: 30px;
    }

    .article h2 {
        font-size: 23px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}
