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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    background: #fff;
    color: #333;
    height: 100vh;
    overflow: hidden;
}

.app {
    display: flex;
    height: 100vh;
}

/* ---- sidebar ---- */
.sidebar {
    width: 280px;
    min-width: 280px;
    height: 100vh;
    background: #f6f8fa;
    border-right: 1px solid #e1e4e8;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar h2 {
    padding: 20px 16px 12px;
    font-size: 16px;
    color: #24292f;
    border-bottom: 1px solid #e1e4e8;
    flex-shrink: 0;
}

.file-tree {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

/* ---- tree nodes ---- */
.tree-node { }
.tree-children { display: none; }
.tree-children.open { display: block; }

.tree-node-header {
    display: flex;
    align-items: center;
    padding: 4px 16px;
    cursor: pointer;
    user-select: none;
    font-size: 14px;
    line-height: 28px;
    color: #24292f;
    transition: background 0.15s;
}

.tree-node-header:hover {
    background: #eaeef2;
}

.tree-node-header.active {
    background: #ddf4ff;
    color: #0969da;
    font-weight: 500;
}

.tree-node-header .icon {
    width: 20px;
    margin-right: 4px;
    flex-shrink: 0;
    text-align: center;
    font-size: 13px;
}

.tree-node-header .name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* indent */
.tree-children .tree-node-header {
    padding-left: 36px;
}
.tree-children .tree-children .tree-node-header {
    padding-left: 56px;
}
.tree-children .tree-children .tree-children .tree-node-header {
    padding-left: 76px;
}

/* ---- content ---- */
.content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    justify-content: center;
}

.markdown-body {
    max-width: 860px;
    width: 100%;
    padding: 40px 48px;
    line-height: 1.7;
}

/* markdown element styles */
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 600;
    line-height: 1.25;
}
.markdown-body h1 { font-size: 2em; border-bottom: 1px solid #d8dee4; padding-bottom: 8px; }
.markdown-body h2 { font-size: 1.5em; border-bottom: 1px solid #d8dee4; padding-bottom: 7px; }
.markdown-body h3 { font-size: 1.25em; }
.markdown-body p { margin-bottom: 16px; }
.markdown-body ul, .markdown-body ol { margin-bottom: 16px; padding-left: 2em; }
.markdown-body li { margin-bottom: 4px; }
.markdown-body code {
    background: #f0f0f0;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}
.markdown-body pre {
    background: #f6f8fa;
    border-radius: 6px;
    padding: 16px;
    overflow-x: auto;
    margin-bottom: 16px;
    line-height: 1.45;
}
.markdown-body pre code {
    background: none;
    padding: 0;
    font-size: 0.85em;
}
.markdown-body blockquote {
    border-left: 4px solid #d0d7de;
    padding: 0 16px;
    color: #656d76;
    margin-bottom: 16px;
}
.markdown-body table {
    border-collapse: collapse;
    margin-bottom: 16px;
    width: 100%;
}
.markdown-body th, .markdown-body td {
    border: 1px solid #d8dee4;
    padding: 8px 12px;
    text-align: left;
}
.markdown-body th { background: #f6f8fa; font-weight: 600; }
.markdown-body a { color: #0969da; text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }
.markdown-body img { max-width: 100%; }
.markdown-body hr {
    border: none;
    border-top: 1px solid #d8dee4;
    margin: 24px 0;
}

.welcome {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    font-size: 18px;
    color: #999;
}

/* ---- toc ---- */
.toc {
    width: 220px;
    min-width: 220px;
    height: 100vh;
    background: #fff;
    border-left: 1px solid #e1e4e8;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.toc h2 {
    padding: 20px 16px 12px;
    font-size: 14px;
    color: #24292f;
    border-bottom: 1px solid #e1e4e8;
    flex-shrink: 0;
}

.toc-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.toc-empty {
    padding: 16px;
    color: #999;
    font-size: 13px;
}

.toc-item {
    display: block;
    padding: 3px 16px;
    font-size: 13px;
    color: #656d76;
    text-decoration: none;
    border-left: 2px solid transparent;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: all 0.15s;
    cursor: pointer;
}

.toc-item:hover {
    color: #0969da;
}

.toc-item.active {
    color: #0969da;
    border-left-color: #0969da;
    background: #ddf4ff;
}

.toc-item.toc-h1 { padding-left: 16px; font-weight: 500; }
.toc-item.toc-h2 { padding-left: 28px; }
.toc-item.toc-h3 { padding-left: 40px; font-size: 12px; }

.toc-item.parent {
    cursor: pointer;
}

.toc-toggle-icon {
    display: inline-block;
    width: 14px;
    margin-right: 2px;
    font-size: 10px;
    flex-shrink: 0;
    color: #999;
    transition: transform 0.15s;
}

.toc-children { display: block; }
.toc-children.collapsed { display: none; }

/* ---- menu toggle (mobile) ---- */
.menu-toggle,
.toc-toggle {
    display: none;
    position: fixed;
    top: 12px;
    z-index: 100;
    width: 40px;
    height: 40px;
    border: 1px solid #d0d7de;
    background: #fff;
    border-radius: 6px;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.menu-toggle { left: 12px; }
.toc-toggle { right: 12px; }

.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 49;
}
.overlay.show { display: block; }

/* ---- mobile ---- */
@media (max-width: 768px) {
    .menu-toggle { display: flex; align-items: center; justify-content: center; }

    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        z-index: 50;
        transition: left 0.25s ease;
        box-shadow: 2px 0 8px rgba(0,0,0,0.15);
    }
    .sidebar.open { left: 0; }

    .content { padding-top: 0; }
    .markdown-body { padding: 24px 20px; }

    .content.shifted { margin-left: 0; }
}

@media (max-width: 900px) {
    .toc-toggle { display: flex; align-items: center; justify-content: center; }

    .toc {
        position: fixed;
        right: -240px;
        top: 0;
        z-index: 50;
        transition: right 0.25s ease;
        box-shadow: -2px 0 8px rgba(0,0,0,0.15);
    }
    .toc.open { right: 0; }
}
