*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
    --bg: #ffffff;
    --bg-secondary: #f6f8fa;
    --text: #1f2328;
    --text-secondary: #656d76;
    --border: #d0d7de;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --code-bg: #f6f8fa;
    --toolbar-bg: #ffffff;
    --toolbar-border: #e5e7eb;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --radius: 8px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

[data-theme="dark"] {
    --bg: #0d1117;
    --bg-secondary: #161b22;
    --text: #e6edf3;
    --text-secondary: #8b949e;
    --border: #30363d;
    --accent: #818cf8;
    --accent-hover: #6366f1;
    --code-bg: #161b22;
    --toolbar-bg: #161b22;
    --toolbar-border: #30363d;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* Always-visible scrollbars */
html { overflow-y: scroll; font-size: 16px; -webkit-text-size-adjust: 100%; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }
* { scrollbar-width: thin; scrollbar-color: var(--border) var(--bg-secondary); }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    transition: background 0.2s, color 0.2s;
}

/* Toolbar */
#toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 48px;
    background: var(--toolbar-bg);
    border-bottom: 1px solid var(--toolbar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    z-index: 100;
    box-shadow: var(--shadow);
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    color: var(--accent);
    font-weight: 700;
    font-size: 15px;
    margin-right: 8px;
}

.logo svg { flex-shrink: 0; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-icon { padding: 6px; }

.btn-primary {
    background: var(--accent);
    color: white;
    border-color: transparent;
}

.btn-primary:hover {
    background: var(--accent-hover);
    color: white;
}

.btn-lg {
    padding: 12px 24px;
    font-size: 16px;
    border-radius: 8px;
}

/* Tab bar */
.tabbar {
    position: fixed;
    top: 48px;
    left: 0;
    right: 0;
    height: 36px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--toolbar-border);
    z-index: 90;
    overflow-x: scroll;
    overflow-y: hidden;
    padding: 0 8px;
}

.tabs {
    display: flex;
    gap: 2px;
    align-items: center;
    height: 100%;
}

.tab {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    font-size: 12px;
    border-radius: 4px 4px 0 0;
    cursor: pointer;
    white-space: nowrap;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid transparent;
    border-bottom: none;
    max-width: 180px;
    height: 32px;
    user-select: none;
}

.tab:hover { background: var(--bg); }

.tab.active {
    background: var(--bg);
    color: var(--text);
    border-color: var(--toolbar-border);
}

.tab-name {
    overflow: hidden;
    text-overflow: ellipsis;
}

.tab-dot {
    color: var(--accent);
    font-size: 16px;
    line-height: 1;
}

.tab-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0 2px;
    font-size: 15px;
    line-height: 1;
    border-radius: 3px;
    opacity: 0.5;
}

.tab-close:hover { opacity: 1; background: var(--border); }

/* Workspace */
.workspace {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: 84px;
    display: flex;
}

body:not(.has-tabs) .workspace { top: 48px; }

.workspace.split-v { flex-direction: row; }
.workspace.split-h { flex-direction: column; }
.workspace.edit-only .preview-pane { display: none; }
.workspace.edit-only .editor-pane { flex: 1; }
.workspace.preview-only .editor-pane { display: none; }
.workspace.preview-only .preview-pane { flex: 1; }

.editor-pane, .preview-pane {
    flex: 1;
    overflow: hidden;
    min-width: 0;
    min-height: 0;
    position: relative;
}

.workspace.split-v .editor-pane { border-right: 1px solid var(--border); }
.workspace.split-h .editor-pane { border-bottom: 1px solid var(--border); }

/* Editor */
#editor {
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    resize: none;
    padding: 24px;
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.6;
    background: var(--bg);
    color: var(--text);
    tab-size: 2;
    overflow-y: scroll;
}

#editor::placeholder { color: var(--text-secondary); }

.preview-pane { overflow-y: scroll; }

/* Drop zone */
.dropzone {
    position: fixed;
    inset: 0;
    background: rgba(99, 102, 241, 0.1);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dropzone-content {
    text-align: center;
    padding: 48px;
    border: 3px dashed var(--accent);
    border-radius: 16px;
    color: var(--accent);
}

.dropzone-content p {
    margin-top: 12px;
    font-size: 18px;
    font-weight: 500;
}

/* Modal dialogs */
.modal {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0;
    max-width: 560px;
    width: 90vw;
    max-height: 80vh;
    background: var(--bg);
    color: var(--text);
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.modal::backdrop { background: rgba(0,0,0,0.4); }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px 8px;
    border-radius: 4px;
    line-height: 1;
}

.modal-close:hover { background: var(--bg-secondary); }

.modal-body {
    padding: 20px;
    overflow-y: scroll;
    max-height: 60vh;
    font-size: 14px;
    line-height: 1.6;
}

.modal-body h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 20px 0 8px;
}

.modal-body h3:first-child { margin-top: 0; }

.modal-body p { margin-bottom: 10px; }

.modal-body ul {
    padding-left: 1.5em;
    margin-bottom: 10px;
}

.modal-body li { margin-bottom: 4px; }

.help-table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0 16px;
}

.help-table td {
    padding: 6px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    vertical-align: top;
}

.help-table td:first-child {
    font-family: var(--font-mono);
    white-space: nowrap;
    color: var(--accent);
    width: 100px;
    font-weight: 500;
}

/* Landing */
#landing {
    padding-top: 48px;
    min-height: 100vh;
}

.hero {
    text-align: center;
    padding: 80px 20px 40px;
    max-width: 640px;
    margin: 0 auto;
}

.hero h1 {
    font-size: 2.5rem;
    font-weight: 800;
    line-height: 1.15;
    margin-bottom: 16px;
    letter-spacing: -0.02em;
}

.subtitle {
    font-size: 1.125rem;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.subtitle code {
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.95em;
}

.hero-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.hint { font-size: 13px; color: var(--text-secondary); }

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 24px;
    max-width: 900px;
    margin: 40px auto;
    padding: 0 20px 60px;
}

.feature {
    padding: 24px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.feature h2 { font-size: 1rem; font-weight: 600; margin-bottom: 8px; }
.feature p { font-size: 0.875rem; color: var(--text-secondary); line-height: 1.5; }

/* Install section */
.install-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 24px;
    max-width: 600px;
    margin: 0 auto 40px;
    padding: 0 20px;
}

.install-card {
    padding: 24px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    text-align: center;
}

.install-card svg { color: var(--accent); margin-bottom: 12px; }
.install-card h3 { font-size: 1rem; font-weight: 600; margin-bottom: 8px; }
.install-card p { font-size: 0.875rem; color: var(--text-secondary); line-height: 1.5; margin-bottom: 16px; }

/* Extension install steps */
.ext-steps { display: flex; flex-direction: column; gap: 16px; }

.ext-step {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.step-num {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
}

.ext-step p { margin: 0; font-size: 14px; line-height: 1.5; }

.landing-footer {
    text-align: center;
    padding: 24px 20px 48px;
    font-size: 13px;
    color: var(--text-secondary);
}

.landing-footer a { color: var(--accent); text-decoration: none; }
.landing-footer a:hover { text-decoration: underline; }
.landing-footer p + p { margin-top: 4px; }

/* TOC panel */
.toc-panel {
    position: fixed;
    top: 84px;
    right: 0;
    width: 260px;
    bottom: 0;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    overflow-y: scroll;
    padding: 16px;
    z-index: 50;
}

body:not(.has-tabs) .toc-panel { top: 48px; }

.toc-panel a {
    display: block;
    padding: 4px 0;
    font-size: 13px;
    color: var(--text-secondary);
    text-decoration: none;
    border-left: 2px solid transparent;
    padding-left: 8px;
    transition: all 0.15s;
}

.toc-panel a:hover { color: var(--accent); border-left-color: var(--accent); }
.toc-panel a.toc-h2 { padding-left: 20px; }
.toc-panel a.toc-h3 { padding-left: 32px; }
.toc-panel a.toc-h4 { padding-left: 44px; }

/* Markdown body */
.markdown-body {
    max-width: 860px;
    margin: 0 auto;
    padding: 24px;
    font-size: 16px;
    line-height: 1.7;
    word-wrap: break-word;
}

.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; padding-bottom: 0.3em; border-bottom: 1px solid var(--border); }
.markdown-body h2 { font-size: 1.5em; padding-bottom: 0.3em; border-bottom: 1px solid var(--border); }
.markdown-body h3 { font-size: 1.25em; }
.markdown-body h4 { font-size: 1em; }
.markdown-body p { margin-bottom: 16px; }
.markdown-body a { color: var(--accent); text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }
.markdown-body img { max-width: 100%; height: auto; border-radius: 4px; }

.markdown-body blockquote {
    margin: 0 0 16px; padding: 0 16px;
    border-left: 4px solid var(--border); color: var(--text-secondary);
}

.markdown-body code {
    font-family: var(--font-mono); font-size: 0.875em;
    background: var(--code-bg); padding: 0.2em 0.4em; border-radius: 3px;
}

.markdown-body pre {
    margin-bottom: 16px; padding: 16px; overflow-x: auto;
    background: var(--code-bg); border-radius: 6px; border: 1px solid var(--border);
}

.markdown-body pre code { background: none; padding: 0; font-size: 0.85em; line-height: 1.5; }

.markdown-body table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.markdown-body th, .markdown-body td { padding: 8px 12px; border: 1px solid var(--border); text-align: left; }
.markdown-body th { font-weight: 600; background: var(--bg-secondary); }
.markdown-body ul, .markdown-body ol { margin-bottom: 16px; padding-left: 2em; }
.markdown-body li + li { margin-top: 4px; }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
.markdown-body .task-list-item { list-style: none; margin-left: -1.5em; }
.markdown-body .task-list-item input { margin-right: 0.5em; }

/* Responsive */
@media (max-width: 768px) {
    .hero h1 { font-size: 1.75rem; }
    .hero { padding: 60px 16px 32px; }
    .features { grid-template-columns: 1fr; gap: 16px; }
    .markdown-body { padding: 16px; }
    .toc-panel { width: 220px; }
    .logo-text { display: none; }
}

/* Print */
@media print {
    #toolbar, #landing, .dropzone, .toc-panel, .tabbar, .editor-pane { display: none !important; }
    .workspace { position: static !important; display: block !important; }
    .preview-pane { overflow: visible !important; }
    .markdown-body { max-width: 100%; padding: 0; }
    body { background: white; color: black; }
}
