/* Reset + base — inspired by original abc.css */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica,
        Tahoma, Arial, "PingFang SC", "Microsoft YaHei", "微软雅黑", sans-serif;
    font-size: 15px;
    color: #333;
    background: #ebeef2;
}
a { color: #4a90d9; text-decoration: none; }
a:hover { text-decoration: underline; }
*:focus { outline: none; }

/* Layout — matches original .stack/.layer/.flag */
.stack {
    position: fixed; left: 0; right: 0; top: 0; bottom: 1.8em;
}
.layer {
    position: absolute; left: 0; right: 0; top: 0; bottom: 1px;
    background: #fff;
    box-shadow: 0 0 5px 0 #e4e4e4;
    display: flex; flex-direction: column;
}
.flag {
    position: fixed; left: 0; right: 0; bottom: .6em;
    text-align: center;
    color: #aaa;
    font-size: 13px;
}
.flag a { color: #aaa; }
.flag .sep { margin: 0 .6em; color: #ddd; }

/* Toolbar (edit mode) */
.toolbar {
    height: 36px;
    border-bottom: 1px solid #eee;
    padding: 0 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.toolbar button {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 13px;
    color: #555;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.toolbar button:hover { background: #f0f0f0; }
.toolbar button.active { background: #e0ecf8; color: #2974a8; }
.toolbar svg { width: 16px; height: 16px; vertical-align: middle; }
.toolbar .spacer { flex: 1; }
.toolbar .lock-on { color: #d33; border-color: #d33; }

/* Edit/preview split */
.editor-pane {
    flex: 1;
    display: flex;
    overflow: hidden;
}
.editor-pane > textarea,
.editor-pane > .preview {
    flex: 1 1 50%;
    overflow: auto;
    border: none;
    padding: 14px 18px;
}
.editor-pane > textarea {
    resize: none;
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 14px;
    line-height: 1.6;
    color: #333;
    background: #fafafa;
    border-right: 1px solid #eee;
    tab-size: 4;
}
.editor-pane > .preview {
    background: #fff;
}

/* Mobile: tab toggle */
@media (max-width: 768px) {
    .editor-pane > textarea,
    .editor-pane > .preview { flex-basis: 100%; border-right: none; }
    body.mode-preview .editor-pane > textarea { display: none; }
    body.mode-edit .editor-pane > .preview { display: none; }
    .toolbar .desktop-only { display: none; }
}
@media (min-width: 769px) {
    .toolbar .mobile-only { display: none; }
}

/* Default page: WYSIWYG contenteditable editor */
.editor {
    flex: 1;
    overflow: auto;
    padding: 32px max(16px, calc((100% - 820px) / 2));
    background: #fff;
    outline: none;
    caret-color: #2974a8;
}
.editor:empty::before {
    content: attr(data-placeholder);
    color: #b0b0b0;
    pointer-events: none;
}
.editor img { max-width: 100%; }

/* Password overlay */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
}
.overlay.show { display: flex; }
.overlay .box {
    background: #fff;
    padding: 24px;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 280px;
    box-shadow: 0 6px 30px rgba(0, 0, 0, 0.3);
}
.overlay input {
    padding: 10px 12px;
    font-size: 15px;
    border: 1px solid #ccc;
    border-radius: 4px;
}
.overlay button {
    padding: 10px 12px;
    font-size: 15px;
    background: #4a90d9;
    color: #fff;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
}
.overlay .hint { color: #888; font-size: 13px; }
.overlay .error { color: #d33; font-size: 13px; min-height: 1em; }

/* Upload progress */
.upload-toast {
    position: fixed;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #ed6100;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 13px;
    z-index: 50;
    display: none;
}
.upload-toast.show { display: block; }

/* Markdown body — minimal GitHub-like */
.markdown-body {
    color: #24292f;
    line-height: 1.65;
    word-wrap: break-word;
    font-size: 15px;
}
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
    margin-top: 1.4em;
    margin-bottom: .6em;
    font-weight: 600;
    line-height: 1.25;
}
.markdown-body h1 { font-size: 1.9em; border-bottom: 1px solid #eaecef; padding-bottom: .3em; }
.markdown-body h2 { font-size: 1.5em; border-bottom: 1px solid #eaecef; padding-bottom: .3em; }
.markdown-body h3 { font-size: 1.25em; }
.markdown-body h4 { font-size: 1em; }
.markdown-body p, .markdown-body ul, .markdown-body ol, .markdown-body blockquote, .markdown-body table {
    margin: 0 0 1em;
}
.markdown-body ul, .markdown-body ol { padding-left: 2em; }
.markdown-body blockquote {
    border-left: 4px solid #dfe2e5;
    padding: 0 1em;
    color: #6a737d;
}
.markdown-body code {
    background: rgba(175, 184, 193, 0.2);
    padding: .15em .35em;
    border-radius: 3px;
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 85%;
}
.markdown-body pre {
    background: #f6f8fa;
    padding: 14px 16px;
    border-radius: 6px;
    overflow: auto;
    line-height: 1.45;
    margin: 0 0 1em;
}
.markdown-body pre code {
    background: transparent;
    padding: 0;
    font-size: 85%;
}
.markdown-body table {
    border-collapse: collapse;
    display: block;
    overflow: auto;
}
.markdown-body th, .markdown-body td {
    border: 1px solid #dfe2e5;
    padding: 6px 12px;
}
.markdown-body th { background: #f6f8fa; font-weight: 600; }
.markdown-body img { max-width: 100%; }
.markdown-body hr { border: 0; border-top: 1px solid #eaecef; margin: 1.5em 0; }
.markdown-body input[type="checkbox"] { margin-right: .3em; }
.markdown-body a.attachment::before { content: "📎 "; }

@media print {
    .toolbar, .flag, .overlay, .upload-toast { display: none !important; }
    .stack { position: static; }
    .layer { box-shadow: none; }
}
