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

:root {
    --bg: #faf9f7;
    --surface: #ffffff;
    --surface-2: #f3f2ef;
    --text: #1c1c1a;
    --text-2: #55544f;
    --muted: #98968e;
    --border: #e7e5e0;
    --accent: #a16207;
    --accent-soft: #faf3e3;
    --code-bg: #f3f2ef;
    --topbar-h: 56px;
    --sidebar-w: 280px;
}

[data-theme="dark"] {
    --bg: #161614;
    --surface: #1f1f1c;
    --surface-2: #282824;
    --text: #ecebe7;
    --text-2: #b5b3ab;
    --muted: #797770;
    --border: #33322e;
    --accent: #e3b341;
    --accent-soft: #2b2618;
    --code-bg: #232320;
}

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Ubuntu, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    font-size: 15.5px;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ---------- topbar ---------- */

.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-h);
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem 0 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar-brand {
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.3px;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
}

.topbar-brand .dot {
    color: var(--accent);
}

.topbar-docs {
    margin-left: 0.6rem;
    padding: 0.1rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-2);
    vertical-align: 2px;
}

.topbar-controls {
    display: flex;
    gap: 0.5rem;
}

.ctrl-btn {
    background: transparent;
    color: var(--text-2);
    border: 1px solid var(--border);
    width: 34px;
    height: 34px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.ctrl-btn:hover {
    color: var(--text);
    border-color: var(--muted);
}

#theme-btn {
    font-size: 1rem;
    font-weight: 400;
}

/* ---------- layout ---------- */

main {
    display: block;
    position: relative;
    width: 100%;
    min-height: 100vh;
    padding-top: var(--topbar-h);
}

.sidebar {
    position: fixed;
    top: var(--topbar-h);
    bottom: 0;
    left: 0;
    width: var(--sidebar-w);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1.25rem 0 2rem;
    transition: transform 0.25s ease;
    z-index: 30;
}

.sidebar > h1.app-name {
    display: none;
}

.content {
    position: relative;
    margin-left: var(--sidebar-w);
    min-height: calc(100vh - var(--topbar-h));
    transition: margin-left 0.25s ease;
}

.markdown-section {
    max-width: 780px;
    margin: 0 auto;
    padding: 2.5rem 2.5rem 5rem;
}

body.close .sidebar {
    transform: translateX(calc(-1 * var(--sidebar-w)));
}

body.close .content {
    margin-left: 0;
}

/* ---------- sidebar toggle ---------- */

.sidebar-toggle {
    position: fixed;
    top: calc(var(--topbar-h) + 10px);
    left: 10px;
    z-index: 50;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
}

.sidebar-toggle-button {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: center;
}

.sidebar-toggle span {
    display: block;
    width: 16px;
    height: 2px;
    border-radius: 1px;
    background: var(--text-2);
}

/* ---------- sidebar nav ---------- */

.sidebar-nav {
    padding: 0 0.75rem;
}

.sidebar-nav ul {
    list-style: none;
}

.sidebar-nav > ul > li {
    margin-bottom: 1.25rem;
}

.sidebar-nav > ul > li > p,
.sidebar-nav > ul > li > strong {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--muted);
    padding: 0 0.75rem;
    margin-bottom: 0.4rem;
}

.sidebar-nav li > a {
    display: block;
    padding: 0.4rem 0.75rem;
    border-radius: 8px;
    color: var(--text-2);
    text-decoration: none;
    font-size: 0.92rem;
    transition: all 0.15s;
}

.sidebar-nav li > a:hover {
    color: var(--text);
    background: var(--surface-2);
}

.sidebar-nav li.active > a {
    color: var(--accent);
    background: var(--accent-soft);
    font-weight: 600;
}

/* page TOC (auto sub-sidebar) */
.sidebar-nav li ul.app-sub-sidebar {
    margin: 0.2rem 0 0.4rem;
    border-left: 1px solid var(--border);
    margin-left: 0.9rem;
    padding-left: 0.4rem;
}

.sidebar-nav .app-sub-sidebar li > a {
    font-size: 0.85rem;
    padding: 0.28rem 0.6rem;
    color: var(--muted);
}

.sidebar-nav .app-sub-sidebar li.active > a {
    color: var(--accent);
    background: none;
    font-weight: 600;
}

/* ---------- search ---------- */

.search {
    padding: 0 1.5rem 1rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.25rem;
}

.search input {
    width: 100%;
    padding: 0.5rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

.search input:focus {
    border-color: var(--muted);
}

.search .clear-button {
    display: none;
}

.search .results-panel {
    display: none;
    padding-top: 0.75rem;
}

.search .results-panel.show {
    display: block;
}

.search .matching-post {
    border-bottom: 1px solid var(--border);
    padding: 0.6rem 0;
}

.search .matching-post a {
    text-decoration: none;
    color: var(--text-2);
}

.search .matching-post a:hover h2 {
    color: var(--accent);
}

.search .matching-post h2 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    margin: 0 0 0.2rem;
    border: none;
    padding: 0;
}

.search .matching-post p {
    font-size: 0.8rem;
    margin: 0;
    color: var(--muted);
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.search .search-keyword {
    color: var(--accent);
    font-style: normal;
    font-weight: 600;
}

/* ---------- markdown content ---------- */

.markdown-section h1,
.markdown-section h2,
.markdown-section h3,
.markdown-section h4 {
    color: var(--text);
    font-weight: 700;
    line-height: 1.3;
    margin: 2.2rem 0 0.9rem;
}

.markdown-section h1 {
    font-size: 2rem;
    letter-spacing: -1px;
    margin-top: 0.5rem;
}

.markdown-section h2 {
    font-size: 1.4rem;
    letter-spacing: -0.5px;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
}

.markdown-section h3 {
    font-size: 1.12rem;
}

.markdown-section h4 {
    font-size: 1rem;
}

.markdown-section a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.15s;
}

.markdown-section a:hover {
    border-bottom-color: var(--accent);
}

.markdown-section h1 a,
.markdown-section h2 a,
.markdown-section h3 a,
.markdown-section h4 a,
.markdown-section h5 a {
    color: inherit;
    border-bottom: none;
}

.markdown-section p {
    margin: 0 0 1rem;
}

.markdown-section ul,
.markdown-section ol {
    margin: 0 0 1rem;
    padding-left: 1.4rem;
}

.markdown-section li {
    margin-bottom: 0.3rem;
}

.markdown-section img {
    max-width: 100%;
    border-radius: 10px;
    border: 1px solid var(--border);
    margin: 0.5rem 0 1rem;
}

.markdown-section code {
    font-family: ui-monospace, 'Cascadia Code', Consolas, 'Courier New', monospace;
    font-size: 0.85em;
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 0.1em 0.4em;
    color: var(--text);
}

.markdown-section pre {
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem 1.25rem;
    margin: 0 0 1.25rem;
    overflow-x: auto;
    position: relative;
}

.markdown-section pre > code {
    background: none;
    border: none;
    padding: 0;
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--text);
}

.markdown-section blockquote {
    margin: 0 0 1.25rem;
    padding: 0.8rem 1.25rem;
    background: var(--accent-soft);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 0 10px 10px 0;
    color: var(--text-2);
}

.markdown-section blockquote p {
    margin: 0;
}

.markdown-section table {
    width: 100%;
    border-collapse: collapse;
    margin: 0 0 1.25rem;
    font-size: 0.9rem;
    display: block;
    overflow-x: auto;
}

.markdown-section th {
    text-align: left;
    font-weight: 600;
    color: var(--text-2);
    border-bottom: 2px solid var(--border);
    padding: 0.5rem 0.9rem;
    white-space: nowrap;
}

.markdown-section td {
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 0.9rem;
}

.markdown-section tr:hover td {
    background: var(--surface-2);
}

.markdown-section hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2rem 0;
}

.markdown-section strong {
    font-weight: 700;
}

/* prism tokens */
.token.comment { color: var(--muted); }
.token.string { color: #3b8a4e; }
[data-theme="dark"] .token.string { color: #8fce9b; }
.token.number, .token.boolean { color: #b45309; }
[data-theme="dark"] .token.number, [data-theme="dark"] .token.boolean { color: #e3b341; }
.token.keyword, .token.function { color: #6d4fc4; }
[data-theme="dark"] .token.keyword, [data-theme="dark"] .token.function { color: #a48fd6; }
.token.property { color: #185fa5; }
[data-theme="dark"] .token.property { color: #6d96d6; }
.token.punctuation, .token.operator { color: var(--text-2); }

/* copy-code plugin */
.docsify-copy-code-button {
    background: var(--surface) !important;
    color: var(--text-2) !important;
    border: 1px solid var(--border) !important;
    border-radius: 6px !important;
    font-size: 0.7rem !important;
    padding: 0.25rem 0.6rem !important;
}

/* ---------- landing language cards ---------- */

.lang-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 1.5rem;
}

.lang-card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border) !important;
    border-radius: 14px;
    padding: 1.5rem;
    text-decoration: none;
    transition: all 0.2s;
}

.lang-card:hover {
    border-color: var(--muted) !important;
    transform: translateY(-2px);
}

.lang-card strong {
    display: block;
    font-size: 1.1rem;
    color: var(--text);
    margin-bottom: 0.25rem;
}

.lang-card span {
    color: var(--text-2);
    font-size: 0.875rem;
}

/* override styles injected by the search plugin (it appends its own <style>) */
aside.sidebar {
    padding-top: 1.25rem;
}

aside.sidebar .search {
    margin-bottom: 1.25rem;
    padding: 0 1.5rem 1rem;
    border-bottom: 1px solid var(--border);
}

@media (max-width: 860px) {
    aside.sidebar {
        padding-top: 0.7rem;
    }

    aside.sidebar .search {
        padding-left: 3.6rem;
    }
}

/* progress bar */
.progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent);
    z-index: 60;
    transition: width 0.2s, opacity 0.4s;
}

/* ---------- mobile ---------- */

@media (max-width: 860px) {
    .sidebar {
        transform: translateX(calc(-1 * var(--sidebar-w)));
        box-shadow: none;
        padding-top: 0.625rem;
    }

    .search {
        padding-left: 3.6rem;
    }

    .content {
        margin-left: 0;
    }

    body.close {
        overflow: hidden;
    }

    body.close .sidebar {
        transform: translateX(0);
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    }

    body.close .content {
        margin-left: 0;
    }

    body.close .content::after {
        content: '';
        position: fixed;
        top: var(--topbar-h);
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.35);
        z-index: 25;
    }

    .sidebar-toggle {
        display: flex;
    }

    .markdown-section {
        padding: 3.5rem 1.25rem 4rem;
    }

    .lang-cards {
        grid-template-columns: 1fr;
    }
}
