* {
    margin: 0;
    padding: 0;
    box-sizing: border-box
}

:root,
[data-theme="dark"] {
    --bg: #0d1117;
    --bg2: #161b22;
    --bg3: #1c2128;
    --bg4: #21262d;
    --bg5: #2d333b;
    --border: #30363d;
    --border2: #3d444d;
    --text: #e6edf3;
    --text2: #8b949e;
    --text3: #6e7681;
    --accent: #58a6ff;
    --accent2: #a371f7;
    --accent-bg: rgba(88, 166, 255, .12);
    --success: #3fb950;
    --warning: #d29922;
    --danger: #f85149;
    --sidebar-w: 280px;
    --header-h: 48px;
    --editor-font: 'JetBrains Mono', monospace;
}

[data-theme="light"] {
    --bg: #eef1f8;
    --bg2: #f8f9fc;
    --bg3: #e8ebf4;
    --bg4: #dde1ed;
    --bg5: #d2d7e5;
    --border: #d8dce8;
    --border2: #b8c0d2;
    --text: #1a1d2e;
    --text2: #5b6480;
    --text3: #8890a8;
    --accent: #5b6cf0;
    --accent2: #7c3aed;
    --accent-bg: rgba(91, 108, 240, .1);
    --success: #1a7f37;
    --warning: #9a6700;
    --danger: #d1242f;
}

html,
body {
    height: 100%;
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden
}

a {
    color: var(--accent);
    text-decoration: none
}

a:hover {
    text-decoration: underline
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px
}

::-webkit-scrollbar-track {
    background: transparent
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border2)
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh
}

.header {
    height: var(--header-h);
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 8px;
    z-index: 100;
    flex-shrink: 0
}

.header .logo {
    font-size: 15px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    white-space: nowrap;
    cursor: pointer
}

.header .spacer {
    flex: 1
}

.hbtn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg3);
    color: var(--text2);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap
}

.hbtn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-bg)
}

.hbtn.active {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-bg)
}

.hbtn svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round
}

.menu-toggle {
    display: none
}

.body {
    display: flex;
    flex: 1;
    overflow: hidden
}

.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--bg2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform .25s, width .25s;
    flex-shrink: 0
}

.sidebar-header {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    gap: 6px;
    border-bottom: 1px solid var(--border)
}

.sidebar-header input {
    flex: 1;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    outline: none;
    font-family: inherit
}

.sidebar-header input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-bg)
}

.sidebar-header input::placeholder {
    color: var(--text3)
}

.sidebar-actions {
    display: flex;
    gap: 2px
}

.sidebar-actions button {
    background: none;
    border: none;
    color: var(--text2);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    font-size: 16px;
    line-height: 1
}

.sidebar-actions button:hover {
    background: var(--bg4);
    color: var(--text)
}

.tree-wrap {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 0
}

.tree-item {
    cursor: pointer;
    user-select: none
}

.tree-label {
    display: flex;
    align-items: center;
    padding: 4px 10px 4px calc(10px + var(--depth, 0) * 16px);
    font-size: 13px;
    color: var(--text);
    border-radius: 0;
    transition: background .1s;
    gap: 4px
}

.tree-label:hover {
    background: var(--bg4)
}

.tree-label.active {
    background: var(--accent-bg);
    color: var(--accent)
}

.tree-label .arrow {
    width: 16px;
    text-align: center;
    font-size: 10px;
    flex-shrink: 0;
    transition: transform .15s;
    color: var(--text3)
}

.tree-label .arrow.expanded {
    transform: rotate(90deg)
}

.tree-label .arrow.hidden {
    visibility: hidden
}

.tree-label .icon {
    font-size: 14px;
    flex-shrink: 0
}

.tree-label .name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px
}

.tree-label .badge {
    font-size: 10px;
    color: var(--text3);
    padding: 0 5px;
    background: var(--bg);
    border-radius: 8px
}

.tree-children {
    display: none
}

.tree-children.open {
    display: block
}

.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0
}

.tab-bar {
    display: flex;
    align-items: center;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    flex-shrink: 0;
    min-height: 34px
}

.tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    font-size: 12px;
    color: var(--text2);
    cursor: pointer;
    border-right: 1px solid var(--border);
    white-space: nowrap;
    transition: background .1s;
    flex-shrink: 0
}

.tab:hover {
    background: var(--bg4)
}

.tab.active {
    background: var(--bg);
    color: var(--text);
    border-bottom: 2px solid var(--accent);
    margin-bottom: -1px
}

.tab .close {
    font-size: 14px;
    opacity: .4;
    margin-left: 4px;
    padding: 0 2px;
    border-radius: 3px
}

.tab .close:hover {
    opacity: 1;
    background: var(--bg4)
}

.file-toolbar {
    display: flex;
    align-items: center;
    padding: 6px 16px;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    background: var(--bg2);
    flex-shrink: 0
}

.file-toolbar .path {
    font-size: 12px;
    color: var(--text2);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap
}

.file-toolbar .path span {
    cursor: pointer;
    transition: color .15s
}

.file-toolbar .path span:hover {
    color: var(--accent)
}

.file-toolbar .path .sep {
    color: var(--text3);
    margin: 0 3px
}

.main-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex
}

.reader-pane {
    flex: 1;
    padding: 32px 48px 60px;
    min-width: 0;
    overflow-x: hidden
}

.toc-pane {
    width: 200px;
    min-width: 200px;
    border-left: 1px solid var(--border);
    padding: 16px 12px;
    overflow-y: auto;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: fit-content;
    max-height: calc(100vh - 140px)
}

.toc-pane.hidden {
    display: none
}

.toc-pane h4 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text3);
    margin-bottom: 10px
}

.toc-pane a {
    display: block;
    font-size: 12px;
    color: var(--text2);
    padding: 3px 0 3px calc(var(--toc-depth, 0) * 10px);
    border-left: 2px solid transparent;
    transition: all .15s;
    text-decoration: none;
    line-height: 1.5
}

.toc-pane a:hover {
    color: var(--accent);
    border-left-color: var(--accent)
}

.toc-pane a.active {
    color: var(--accent);
    border-left-color: var(--accent)
}

.editor-pane {
    flex: 1;
    display: flex;
    flex-direction: row;
    overflow: hidden;
    position: relative;
}

/* 行号栏 */
.editor-pane .line-numbers {
    width: 48px;
    padding: 24px 8px 24px 0;
    background: var(--bg);
    color: var(--text3);
    font-family: var(--editor-font);
    font-size: 13px;
    line-height: 1.75;
    text-align: right;
    overflow: hidden;
    user-select: none;
    border-right: 1px solid var(--border);
    white-space: pre;
    flex-shrink: 0;
}

.editor-pane textarea {
    flex: 1;
    padding: 24px 40px 24px 16px;
    background: var(--bg);
    color: var(--text);
    border: none;
    outline: none;
    font-family: var(--editor-font);
    font-size: 14px;
    line-height: 1.75;
    resize: none;
    tab-size: 4
}

.editor-pane textarea::placeholder {
    color: var(--text3)
}

/* Drag & Drop */
#mainScroll.drag-over {
    position: relative
}

#mainScroll.drag-over::after {
    content: '\ud83d\udce4 \u62d6\u653e\u6587\u4ef6\u5230\u6b64\u5904\u4e0a\u4f20';
    position: absolute;
    inset: 8px;
    border: 2px dashed var(--accent);
    border-radius: 12px;
    background: rgba(59, 130, 246, .08);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: var(--accent);
    pointer-events: none;
    z-index: 10
}

/* Editor Toolbar */
.editor-toolbar {
    display: flex;
    gap: 2px;
    padding: 6px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg2);
    flex-shrink: 0
}

.editor-toolbar button {
    padding: 4px 10px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text2);
    font-size: 13px;
    cursor: pointer;
    transition: all .15s;
    font-family: var(--editor-font)
}

.editor-toolbar button:hover {
    background: var(--bg3);
    color: var(--accent)
}

.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 60px 20px;
    text-align: center
}

.welcome .hero-icon {
    font-size: 64px;
    margin-bottom: 20px;
    opacity: .7
}

.welcome h1 {
    font-size: 32px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 10px
}

.welcome p {
    color: var(--text2);
    font-size: 15px;
    max-width: 420px;
    line-height: 1.6
}

.welcome .shortcuts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 24px;
    text-align: left
}

.welcome .shortcut {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text2)
}

.welcome .shortcut kbd {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 11px;
    font-family: var(--editor-font);
    color: var(--text)
}

.welcome .recent-files {
    margin-top: 24px;
    text-align: left;
    width: 100%;
    max-width: 360px
}

.welcome .recent-files h3 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text3);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px
}

.welcome .recent-item {
    display: flex;
    flex-direction: column;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background .15s
}

.welcome .recent-item:hover {
    background: var(--bg3)
}

.welcome .recent-name {
    font-size: 13px;
    color: var(--text);
    font-weight: 500
}

.welcome .recent-path {
    font-size: 11px;
    color: var(--text3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis
}

/* Markdown */
.md-body {
    max-width: 880px;
    line-height: 1.8;
    font-size: 15px;
    word-wrap: break-word
}

.md-body h1 {
    font-size: 26px;
    font-weight: 700;
    margin: 28px 0 14px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border)
}

.md-body h2 {
    font-size: 21px;
    font-weight: 600;
    margin: 24px 0 12px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border)
}

.md-body h3 {
    font-size: 17px;
    font-weight: 600;
    margin: 20px 0 8px
}

.md-body h4 {
    font-size: 15px;
    font-weight: 600;
    margin: 16px 0 6px
}

.md-body h5,
.md-body h6 {
    font-size: 14px;
    font-weight: 600;
    margin: 14px 0 6px;
    color: var(--text2)
}

.md-body p {
    margin: 10px 0
}

.md-body ul,
.md-body ol {
    margin: 10px 0;
    padding-left: 24px
}

.md-body li {
    margin: 3px 0
}

.md-body li>p {
    margin: 4px 0
}

.md-body code {
    font-family: var(--editor-font);
    font-size: 13px;
    background: var(--bg3);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--border)
}

.md-body pre {
    margin: 14px 0;
    border-radius: 8px;
    overflow-x: auto;
    border: 1px solid var(--border);
    position: relative
}

.md-body pre code {
    display: block;
    padding: 14px 16px;
    background: var(--bg3);
    font-size: 13px;
    line-height: 1.6;
    border: none;
    border-radius: 0
}

.md-body blockquote {
    margin: 14px 0;
    padding: 10px 16px;
    border-left: 4px solid var(--accent);
    background: var(--accent-bg);
    border-radius: 0 8px 8px 0;
    color: var(--text2)
}

.md-body blockquote p {
    margin: 4px 0
}

.md-body .table-wrap {
    overflow-x: auto;
    margin: 14px 0;
    -webkit-overflow-scrolling: touch
}

.md-body table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    min-width: 320px
}

.md-body th,
.md-body td {
    padding: 8px 12px;
    border: 1px solid var(--border);
    text-align: left
}

.md-body th {
    background: var(--bg3);
    font-weight: 600;
    white-space: nowrap
}

.md-body tr:nth-child(even) {
    background: rgba(255, 255, 255, .02)
}

.md-body img {
    max-width: 100%;
    border-radius: 8px;
    margin: 10px 0
}

.md-body hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 20px 0
}

.md-body .task-list-item {
    list-style: none;
    margin-left: -20px
}

.md-body input[type="checkbox"] {
    margin-right: 6px;
    accent-color: var(--accent)
}

.md-body a {
    color: var(--accent)
}

.img-viewer {
    text-align: center;
    padding: 20px;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center
}

.img-viewer img {
    max-width: 100%;
    max-height: 75vh;
    border-radius: 8px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, .4)
}

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 60px;
    color: var(--text2);
    gap: 12px
}

.loading::before {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .6s linear infinite
}

@keyframes spin {
    to {
        transform: rotate(360deg)
    }
}

/* Search */
.search-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    z-index: 200;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 12vh;
    backdrop-filter: blur(4px)
}

.search-overlay.open {
    display: flex
}

.search-modal {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 90%;
    max-width: 580px;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 16px 60px rgba(0, 0, 0, .5);
    overflow: hidden
}

.search-modal input {
    padding: 14px 18px;
    border: none;
    border-bottom: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font-size: 15px;
    outline: none;
    font-family: inherit
}

.search-modal input::placeholder {
    color: var(--text3)
}

.search-results {
    overflow-y: auto;
    flex: 1;
    padding: 4px
}

.search-results .result {
    padding: 10px 16px;
    cursor: pointer;
    border-radius: 6px;
    margin: 2px 4px;
    transition: background .1s
}

.search-results .result:hover {
    background: var(--accent-bg)
}

.search-results .result .rname {
    font-size: 14px;
    font-weight: 500;
    color: var(--text)
}

.search-results .result .rpath {
    font-size: 11px;
    color: var(--text3);
    margin-top: 2px
}

.search-results .result .rmatch {
    font-size: 12px;
    color: var(--text2);
    margin-top: 4px;
    font-family: var(--editor-font);
    background: var(--bg);
    padding: 4px 8px;
    border-radius: 4px;
    border-left: 2px solid var(--accent)
}

.search-results mark {
    background: rgba(255, 180, 50, .35);
    color: var(--text);
    border-radius: 2px;
    padding: 0 1px
}

.search-results .empty {
    padding: 24px;
    text-align: center;
    color: var(--text3);
    font-size: 13px
}

/* Context menu */
.ctx-menu {
    position: fixed;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, .4);
    min-width: 180px;
    z-index: 300;
    display: none;
    overflow: hidden;
    padding: 4px
}

.ctx-menu.open {
    display: block
}

.ctx-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    border-radius: 4px;
    transition: background .1s
}

.ctx-item:hover {
    background: var(--bg4)
}

.ctx-item.danger {
    color: var(--danger)
}

.ctx-sep {
    height: 1px;
    background: var(--border);
    margin: 4px 8px
}

/* Status bar */
.status-bar {
    height: 24px;
    background: var(--bg2);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 12px;
    font-size: 11px;
    color: var(--text3);
    gap: 16px;
    flex-shrink: 0
}

.status-bar .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success)
}

.status-bar .dot.saving {
    background: var(--warning);
    animation: pulse 1s infinite
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1
    }

    50% {
        opacity: .4
    }
}

/* Theme popup */
.theme-popup {
    position: fixed;
    top: var(--header-h);
    right: 8px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .4);
    min-width: 160px;
    display: none;
    z-index: 200;
    overflow: hidden;
    padding: 4px
}

.theme-popup.open {
    display: block
}

.theme-opt {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text2);
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    transition: all .12s;
    font-family: inherit;
    border-radius: 6px
}

.theme-opt:hover {
    background: var(--bg4);
    color: var(--text)
}

.theme-opt.active {
    color: var(--accent);
    font-weight: 600
}

.theme-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0
}

/* Dialog */
.dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    z-index: 300;
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px)
}

.dialog-overlay.open {
    display: flex
}

.dialog {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 16px 60px rgba(0, 0, 0, .5)
}

.dialog h3 {
    font-size: 16px;
    margin-bottom: 14px
}

.dialog input {
    width: 100%;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    outline: none;
    font-family: inherit
}

.dialog input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-bg)
}

.dialog .actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px
}

.dialog .btn {
    padding: 8px 18px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg3);
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: all .15s
}

.dialog .btn:hover {
    border-color: var(--border2)
}

.dialog .btn.primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent)
}

.dialog .btn.primary:hover {
    opacity: .85
}

/* Responsive */
@media(max-width:1024px) {
    .toc-pane {
        display: none !important
    }
}

@media(max-width:768px) {
    .menu-toggle {
        display: inline-flex
    }

    .sidebar {
        position: fixed;
        top: var(--header-h);
        left: 0;
        bottom: 24px;
        z-index: 90;
        transform: translateX(-100%)
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0, 0, 0, .3)
    }

    .reader-pane {
        padding: 16px 12px 40px
    }

    .editor-pane textarea {
        padding: 12px
    }

    .toc-pane {
        display: none !important
    }

    .tab {
        padding: 6px 10px;
        font-size: 11px
    }

    .welcome h1 {
        font-size: 24px
    }

    .welcome .shortcuts {
        grid-template-columns: 1fr
    }

    .md-body {
        font-size: 14px
    }

    .md-body h1 {
        font-size: 20px
    }

    .md-body h2 {
        font-size: 17px
    }

    .md-body h3 {
        font-size: 15px
    }

    .md-body pre code {
        font-size: 12px;
        padding: 10px
    }

    .md-body th,
    .md-body td {
        padding: 6px 8px;
        font-size: 12px
    }

    .file-toolbar {
        padding: 4px 10px
    }

    .header {
        padding: 0 8px;
        gap: 4px
    }
}

@media(max-width:480px) {
    .hbtn span {
        display: none
    }

    .reader-pane {
        padding: 12px 8px 40px
    }
}