:root {
    --bg: #f5f5f5;
    --bg-elevated: #180f24;
    --bg-panel: #201530;
    --border: #362246;
    --text: #ebe6f5;
    --text-dim: #a99cc0;
    --text-faint: #756289;
    --heading: #ffffff;
    --accent: #b026e0;
    --accent-hover: #cf4bff;
    --accent-2: #e0159c;
    --accent-dim: rgba(176, 38, 224, 0.18);
    --accent-glow: rgba(176, 38, 224, 0.4);
    --accent-on: #ffffff;
    --code-bg: #1f1230;
    --code-text: #e4c9f0;
    --inline-code-color: #e59bff;
    --inline-code-border: rgba(176, 38, 224, 0.2);
    --table-stripe: rgba(255, 255, 255, 0.015);
    --overlay-bg: rgba(6, 3, 12, 0.6);
    --login-glow: rgba(224, 21, 156, 0.06);
    --error-bg: rgba(224, 21, 156, 0.1);
    --error-color: #ff9ede;
    --bg-glow-1: rgba(176, 38, 224, 0.1);
    --bg-glow-2: rgba(224, 21, 156, 0.07);

    /* syntax highlighting tokens */
    --hl-comment: #756289;
    --hl-keyword: #cf4bff;
    --hl-string: #4fae4f;
    --hl-number: #c97a1f;
    --hl-title: #1f8fc4;
    --hl-tag: #d1418f;
    --hl-attr: #9a3fbf;
    --hl-symbol: #e0159c;
    --hl-punct: #a99cc0;

    --radius: 10px;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
    --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

/* ---------- Light theme (applied automatically to match the device/OS setting) ---------- */
@media (prefers-color-scheme: light) {
    :root {
        --bg: #FBFDFF;
        --bg-elevated: #ffffff;
        --bg-panel: #edf3f9;
        --border: #d9e4ee;
        --text: #1f2a36;
        --text-dim: #5d6b7d;
        --text-faint: #8691a3;
        --heading: #121c26;
        --accent: #2078d0;
        --accent-hover: #1164b8;
        --accent-2: #2512d1;
        --accent-dim: rgba(32, 120, 208, 0.1);
        --accent-glow: rgba(32, 120, 208, 0.28);
        --accent-on: #ffffff;
        --code-bg: #edf3f9;
        --code-text: #2f4a5c;
        --inline-code-color: #1f59b0;
        --inline-code-border: rgba(32, 120, 208, 0.18);
        --table-stripe: rgba(30, 80, 100, 0.025);
        --overlay-bg: rgba(20, 40, 55, 0.35);
        --login-glow: rgba(32, 120, 208, 0.08);
        --error-bg: rgba(32, 120, 208, 0.08);
        --error-color: #1f59b0;
        --bg-glow-1: rgba(38, 131, 224, 0.02);
        --bg-glow-2: rgba(38, 21, 224, 0.02);

        --hl-comment: #8691a3;
        --hl-keyword: #1f59b0;
        --hl-string: #17843a;
        --hl-number: #b5620b;
        --hl-title: #1266a8;
        --hl-tag: #3710b8;
        --hl-attr: #1f75ae;
        --hl-symbol: #2112c2;
        --hl-punct: #5d6b7d;
    }

    ::-webkit-scrollbar-thumb { background: var(--border); }

    .code-block-wrapper,
    .search-result,
    .login-card {
        box-shadow: 0 1px 3px rgba(20, 40, 80, 0.06);
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background:
        radial-gradient(ellipse 900px 500px at 15% -10%, var(--bg-glow-1), transparent),
        radial-gradient(ellipse 700px 500px at 100% 10%, var(--bg-glow-2), transparent),
        var(--bg);
    background-attachment: fixed;
    color: var(--text);
    font-family: var(--font-sans);
    line-height: 1.6;
}

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

::selection { background: var(--accent-glow); }

/* ---------- Layout ---------- */
.wiki-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 280px;
    flex-shrink: 0;
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    padding: 20px 14px;
    overflow-y: auto;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 8px 18px 8px;
}

.sidebar-header .logo-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    box-shadow: 0 0 12px var(--accent-glow);
    flex-shrink: 0;
}

.sidebar-header h1 {
    font-size: 15px;
    font-weight: 600;
    margin: 0;
    letter-spacing: 0.2px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-close {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-dim);
    padding: 6px;
    border-radius: 6px;
    cursor: pointer;
    flex-shrink: 0;
}
.sidebar-close:hover { color: var(--text); background: var(--bg-panel); }

.sidebar-overlay {
    display: none;
}

.main {
    flex: 1;
    min-width: 0;
    padding: 32px 48px 80px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 28px;
}

.search-form {
    flex: 1;
    max-width: 480px;
    position: relative;
}

.search-form input[type="text"] {
    width: 100%;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 14px 10px 38px;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.search-form input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.search-form .icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-faint);
    pointer-events: none;
}

.user-box {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 13px;
    color: var(--text-dim);
    white-space: nowrap;
}

.user-box .username {
    color: var(--text);
    font-weight: 600;
}

.btn-logout {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 7px 12px;
    border-radius: 7px;
    font-size: 13px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.btn-logout:hover {
    border-color: var(--accent);
    color: var(--accent);
    text-decoration: none;
}

/* ---------- Tree nav ---------- */
.tree { list-style: none; margin: 0; padding: 0; }
.tree ul { list-style: none; margin: 2px 0 4px 14px; padding: 0; border-left: 1px solid var(--border); padding-left: 12px; }

.tree-folder > summary {
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 6px;
    color: var(--text-dim);
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    user-select: none;
    list-style: none;
}
.tree-folder > summary::-webkit-details-marker { display: none; }
.tree-folder > summary:hover { background: var(--bg-panel); color: var(--text); }
.tree-folder > summary::before {
    content: "";
    width: 0;
    height: 0;
    border-left: 5px solid var(--text-faint);
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    transition: transform 0.12s;
    flex-shrink: 0;
}
.tree-folder[open] > summary::before { transform: rotate(90deg); }

.tree-file a {
    display: block;
    padding: 6px 8px;
    border-radius: 6px;
    color: var(--text-dim);
    font-size: 13.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tree-file a:hover { background: var(--bg-panel); color: var(--text); text-decoration: none; }
.tree-file.active > a {
    background: var(--accent-dim);
    color: var(--accent-hover);
    font-weight: 600;
}

/* ---------- Breadcrumbs ---------- */
.breadcrumbs {
    font-size: 13px;
    color: var(--text-faint);
    margin-bottom: 18px;
}
.breadcrumbs a { color: var(--text-dim); }
.breadcrumbs a:hover { color: var(--accent-hover); }
.breadcrumbs .sep { margin: 0 6px; color: var(--text-faint); }

/* ---------- Article content ---------- */
.article {
    max-width: 820px;
}

.article h1, .article h2, .article h3, .article h4 {
    color: var(--heading);
    font-weight: 650;
    line-height: 1.3;
    margin-top: 1.6em;
    margin-bottom: 0.6em;
}
.article h1 {
    font-size: 28px;
    padding-bottom: 14px;
    margin-top: 0;
    border-image: linear-gradient(90deg, var(--accent), var(--accent-2), transparent) 1;
    border-bottom: 1px solid;
}
.article h2 { font-size: 22px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.article h3 { font-size: 18px; }
.article h4 { font-size: 15px; color: var(--text-dim); }

.article p { margin: 0.9em 0; color: var(--text); }
.article ul, .article ol { padding-left: 24px; margin: 0.8em 0; }
.article li { margin: 0.3em 0; }

.article blockquote {
    margin: 1em 0;
    padding: 4px 16px;
    border-left: 3px solid var(--accent);
    background: var(--bg-panel);
    color: var(--text-dim);
    border-radius: 0 6px 6px 0;
}

.article code {
    background: var(--code-bg);
    color: var(--inline-code-color);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.88em;
    border: 1px solid var(--inline-code-border);
}

.article pre.code-block {
    background: var(--code-bg);
    margin: 0;
    padding: 16px 18px;
    overflow-x: auto;
    border: none;
}
.article pre.code-block code {
    background: none;
    color: var(--code-text);
    padding: 0;
    font-size: 13.5px;
    line-height: 1.55;
    border: none;
    display: block;
}

.code-block-wrapper {
    margin: 1.2em 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--code-bg);
}

.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
}

.code-block-lang {
    font-family: var(--font-mono);
    font-size: 11.5px;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: var(--text-faint);
    font-weight: 600;
}

.copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 12px;
    font-family: var(--font-sans);
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.copy-btn::before {
    content: "";
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    background-color: currentColor;
    -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'><rect x='9' y='9' width='13' height='13' rx='2'/><path d='M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1'/></svg>") no-repeat center / contain;
    mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'><rect x='9' y='9' width='13' height='13' rx='2'/><path d='M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1'/></svg>") no-repeat center / contain;
}
.copy-btn:hover {
    border-color: var(--accent);
    color: var(--accent-hover);
    background: var(--accent-dim);
}
.copy-btn.copied {
    border-color: var(--accent);
    color: var(--accent-on);
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.copy-btn.copied::before { display: none; }

/* ---------- Syntax highlighting (highlight.js token classes) ---------- */
.hljs { color: var(--code-text); background: none; }
.hljs-comment,
.hljs-quote { color: var(--hl-comment); font-style: italic; }
.hljs-keyword,
.hljs-selector-tag,
.hljs-doctag,
.hljs-subst { color: var(--hl-keyword); font-weight: 600; }
.hljs-string,
.hljs-regexp,
.hljs-addition,
.hljs-attribute,
.hljs-meta-string { color: var(--hl-string); }
.hljs-number,
.hljs-literal { color: var(--hl-number); }
.hljs-title,
.hljs-title.function_,
.hljs-section,
.hljs-selector-id { color: var(--hl-title); font-weight: 600; }
.hljs-name,
.hljs-tag { color: var(--hl-tag); }
.hljs-attr,
.hljs-selector-attr,
.hljs-selector-class,
.hljs-selector-pseudo,
.hljs-template-variable,
.hljs-variable { color: var(--hl-attr); }
.hljs-built_in,
.hljs-class .hljs-title { color: var(--hl-title); }
.hljs-symbol,
.hljs-bullet,
.hljs-link,
.hljs-meta,
.hljs-deletion { color: var(--hl-symbol); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }
.hljs-params { color: var(--code-text); }
.hljs-operator,
.hljs-punctuation { color: var(--hl-punct); }

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

.article table {
    border-collapse: collapse;
    width: 100%;
    margin: 1.2em 0;
    font-size: 14px;
}
.article th, .article td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
}
.article th {
    background: var(--bg-panel);
    color: var(--heading);
    font-weight: 600;
}
.article tr:nth-child(even) td { background: var(--table-stripe); }

.article img { max-width: 100%; border-radius: 8px; }

.article a { border-bottom: 1px solid transparent; }
.article a:hover { border-bottom-color: var(--accent-hover); }

/* ---------- Search results ---------- */
.search-results-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-width: 720px;
}
.search-result {
    padding: 16px 18px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    transition: border-color 0.15s;
}
.search-result:hover { border-color: var(--accent); }
.search-result .result-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    display: block;
    margin-bottom: 4px;
}
.search-result:hover .result-title { color: var(--accent-hover); }
.search-result .result-path {
    font-size: 12px;
    color: var(--text-faint);
    font-family: var(--font-mono);
    margin-bottom: 8px;
}
.search-result .result-snippet {
    font-size: 13.5px;
    color: var(--text-dim);
    line-height: 1.5;
}
.search-result mark {
    background: var(--accent-dim);
    color: var(--accent-hover);
    padding: 0 2px;
    border-radius: 3px;
}

.empty-state {
    color: var(--text-faint);
    padding: 40px 0;
    text-align: center;
}

/* ---------- Login page ---------- */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 36px 32px;
    box-shadow: 0 0 60px var(--login-glow);
}

.login-card .logo-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 16px var(--accent-glow);
    margin-bottom: 16px;
}

.login-card h1 {
    font-size: 20px;
    margin: 0 0 6px;
    color: var(--heading);
}
.login-card p.subtitle {
    color: var(--text-dim);
    font-size: 13.5px;
    margin: 0 0 26px;
}

.field { margin-bottom: 16px; }
.field label {
    display: block;
    font-size: 12.5px;
    color: var(--text-dim);
    margin-bottom: 6px;
    font-weight: 600;
    letter-spacing: 0.2px;
}
.field input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 11px 13px;
    border-radius: 8px;
    font-size: 14px;
}
.field input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.btn-primary {
    width: 100%;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: var(--accent-on);
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-size: 14.5px;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.15s, box-shadow 0.15s;
    margin-top: 6px;
}
.btn-primary:hover { filter: brightness(1.12); box-shadow: 0 0 24px var(--accent-glow); }

.error-box {
    background: var(--error-bg);
    border: 1px solid var(--accent);
    color: var(--error-color);
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 18px;
}

/* ---------- Mobile ---------- */
.menu-toggle {
    display: none;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
}
.menu-toggle:hover { border-color: var(--accent); color: var(--accent-hover); }

@media (max-width: 860px) {
    .wiki-shell { display: block; }

    .menu-toggle { display: inline-flex; }
    .sidebar-close { display: inline-flex; }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        width: 82%;
        max-width: 320px;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
    }
    .sidebar.open { transform: translateX(0); }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: var(--overlay-bg);
        backdrop-filter: blur(2px);
        z-index: 99;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.22s ease;
    }
    .sidebar-overlay.visible {
        opacity: 1;
        pointer-events: auto;
    }

    .main { padding: 16px 16px 56px; }

    .topbar {
        flex-wrap: nowrap;
        gap: 10px;
        margin-bottom: 20px;
    }
    .search-form { max-width: none; }
    .search-form input[type="text"] {
        padding: 9px 12px 9px 34px;
        font-size: 13.5px;
    }

    .user-box .signed-in-text { display: none; }
    .btn-logout { padding: 7px 10px; font-size: 12.5px; }

    .breadcrumbs { font-size: 12px; margin-bottom: 14px; }

    .article { max-width: 100%; }
    .article h1 { font-size: 22px; padding-bottom: 10px; }
    .article h2 { font-size: 19px; }
    .article h3 { font-size: 16.5px; }
    .article p, .article li { font-size: 14.5px; }

    .article ul, .article ol { padding-left: 20px; }

    /* Tables scroll horizontally instead of squeezing/breaking layout */
    .article table { display: block; overflow-x: auto; white-space: nowrap; }
    .article th, .article td { padding: 7px 10px; font-size: 13px; }

    .code-block-header { padding: 7px 10px; }
    .code-block-lang { font-size: 10.5px; }
    .copy-btn { padding: 4px 8px; font-size: 11.5px; }
    .copy-btn-label { display: none; }
    .copy-btn::before { width: 14px; height: 14px; }
    .article pre.code-block { padding: 12px 14px; }
    .article pre.code-block code { font-size: 12.5px; }

    .login-card { padding: 28px 22px; }

    .search-results-list { max-width: 100%; }
    .search-result { padding: 13px 14px; }
}

@media (max-width: 420px) {
    .sidebar-header h1 { font-size: 14px; }
    .main { padding: 12px 12px 48px; }
    .article h1 { font-size: 20px; }
}

