:root {
  /* UI Colors - 编辑器全局主色调统一为 #0050a4 */
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-hover: #30363d;
  --border: #30363d;
  --border-subtle: #21262d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  
  --ui-accent: #0050a4; 
  --ui-accent-bg: rgba(0, 80, 164, 0.15);
  
  --accent-green: #3fb950;
  --accent-orange: #d29922;
  --accent-red: #f85149;
  
  /* Brand Colors - 专属排版的品牌色，默认 #0050a4 */
  --brand-color: #0050a4;
  --brand-bg: rgba(0, 80, 164, 0.1);
  --brand-glow: rgba(0, 80, 164, 0.3);
  --brand-zebra: rgba(0, 80, 164, 0.03);
  --wechat-accent: #0050a4;

  /* Preview Colors */
  --editor-bg: #0d1117;
  --preview-bg: #ffffff;
  --preview-text: #24292f;
  --preview-heading: #1f2328;
  --preview-border: #d0d7de;
  --preview-code-bg: #f6f8fa;
  --preview-blockquote: #6e7781;
  
  --radius: 6px;
  --radius-lg: 10px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
  --font-editor: 'JetBrains Mono', 'Fira Code', monospace;
  --font-ui: 'Sora', system-ui, sans-serif;
  --font-preview: 'Noto Serif SC', Georgia, serif;
  --toolbar-h: 48px;
  --statusbar-h: 28px;
  --sidebar-w: 220px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.theme-light {
  --bg-primary: #f6f8fa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f0f2f5;
  --bg-hover: #e8ecf0;
  --border: #d0d7de;
  --border-subtle: #e8ecf0;
  --text-primary: #1f2328;
  --text-secondary: #656d76;
  --text-muted: #9198a1;
  --editor-bg: #ffffff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font-ui); background: var(--bg-primary); color: var(--text-primary); height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

/* ─── HEADER ─────────────────────────────────────────────── */
.header { height: 50px; background: var(--bg-secondary); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 16px; gap: 12px; z-index: 100; flex-shrink: 0; }
.logo { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 700; color: var(--text-primary); letter-spacing: -0.3px; }
.logo-icon { width: 28px; height: 28px; background: linear-gradient(135deg, var(--ui-accent), #bc8cff); border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 14px; color: white; }
.header-divider { width: 1px; height: 20px; background: var(--border); flex-shrink: 0; }

.format-tabs { display: flex; background: var(--bg-tertiary); border-radius: var(--radius); padding: 2px; gap: 2px; }
.format-tab { padding: 4px 10px; border-radius: 4px; font-size: 11px; font-weight: 600; cursor: pointer; color: var(--text-secondary); transition: all var(--transition); white-space: nowrap; border: none; background: none; font-family: var(--font-ui); }
.format-tab:hover { color: var(--text-primary); background: var(--bg-hover); }
.format-tab.active { background: var(--ui-accent); color: white; }
.format-tab.wechat.active { background: var(--wechat-accent); }

.header-spacer { flex: 1; }
.header-actions { display: flex; gap: 6px; align-items: center; }
.color-picker { width: 26px; height: 26px; padding: 0; border: 1px solid var(--border); border-radius: 4px; cursor: pointer; background: transparent; outline: none; }
.color-picker::-webkit-color-swatch-wrapper { padding: 0; }
.color-picker::-webkit-color-swatch { border: none; border-radius: 3px; }

.btn { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: var(--radius); font-size: 12px; font-weight: 500; cursor: pointer; transition: all var(--transition); border: none; font-family: var(--font-ui); }
.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-primary { background: var(--ui-accent); color: white; border: 1px solid transparent; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-wechat { background: var(--wechat-accent); color: white; border: 1px solid transparent; width: 100%; justify-content: center; padding: 12px;}
.btn-wechat:hover { filter: brightness(1.1); }

/* ─── TOOLBAR ─────────────────────────────────────────────── */
.toolbar { height: var(--toolbar-h); background: var(--bg-secondary); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 12px; gap: 2px; flex-shrink: 0; overflow-x: auto; }
.toolbar::-webkit-scrollbar { height: 2px; }
.toolbar-group { display: flex; align-items: center; gap: 1px; }
.toolbar-sep { width: 1px; height: 20px; background: var(--border); margin: 0 6px; flex-shrink: 0; }
.tb-btn { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius); cursor: pointer; font-size: 13px; color: var(--text-secondary); transition: all var(--transition); border: none; background: transparent; font-family: var(--font-ui); position: relative; flex-shrink: 0; }
.tb-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.tb-btn.active { background: var(--ui-accent-bg); color: var(--ui-accent); }
.tb-btn[title]:hover::after { content: attr(title); position: absolute; bottom: -30px; left: 50%; transform: translateX(-50%); background: var(--bg-tertiary); color: var(--text-primary); font-size: 11px; padding: 3px 8px; border-radius: 4px; white-space: nowrap; z-index: 999; border: 1px solid var(--border); pointer-events: none; }
.tb-select { height: 28px; padding: 0 8px; background: var(--bg-tertiary); color: var(--text-secondary); border: 1px solid var(--border); border-radius: var(--radius); font-size: 12px; cursor: pointer; font-family: var(--font-ui); outline: none; flex-shrink: 0;}
.tb-select:hover { border-color: var(--ui-accent); }

/* ─── MAIN LAYOUT ────────────────────────────────────────── */
.main { flex: 1; display: flex; overflow: hidden; }

/* ─── SIDEBAR ─────────────────────────────────────────────── */
.sidebar { width: var(--sidebar-w); background: var(--bg-secondary); border-right: 1px solid var(--border); display: flex; flex-direction: column; transition: width var(--transition); overflow: hidden; flex-shrink: 0; }
.sidebar.collapsed { width: 0; }
.sidebar-header { padding: 10px 14px; font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; border-bottom: 1px solid var(--border-subtle); flex-shrink: 0; }
.outline-list { flex: 1; overflow-y: auto; padding: 8px 0; }
.outline-item { padding: 5px 14px; font-size: 12px; color: var(--text-secondary); cursor: pointer; transition: all var(--transition); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 2px solid transparent; }
.outline-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.outline-item.active { color: var(--ui-accent); border-left-color: var(--ui-accent); }
.outline-item.h1 { padding-left: 14px; font-weight: 600; font-size: 13px; }
.outline-item.h2 { padding-left: 22px; }
.outline-item.h3 { padding-left: 30px; font-size: 11px; }
.outline-item.h4 { padding-left: 38px; font-size: 11px; }
.outline-item.h5 { padding-left: 46px; font-size: 10px; }
.outline-item.h6 { padding-left: 54px; font-size: 10px; }

/* ─── EDITOR PANE ─────────────────────────────────────────── */
.editor-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.pane-header { height: 36px; display: flex; align-items: center; padding: 0 14px; background: var(--bg-secondary); border-bottom: 1px solid var(--border-subtle); font-size: 11px; color: var(--text-muted); gap: 8px; flex-shrink: 0; }
.pane-header-title { font-weight: 600; color: var(--text-secondary); }
.editor-area { flex: 1; overflow: hidden; position: relative; }
#editor { width: 100%; height: 100%; resize: none; border: none; outline: none; background: var(--editor-bg); color: var(--text-primary); font-family: var(--font-editor); font-size: 14px; line-height: 1.7; padding: 20px 24px; tab-size: 2; overflow-y: auto; white-space: pre-wrap; word-break: break-word; caret-color: var(--ui-accent); }
#editor::-webkit-scrollbar { width: 6px; }
#editor::-webkit-scrollbar-track { background: transparent; }
#editor::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ─── DIVIDER ─────────────────────────────────────────────── */
.divider { width: 4px; background: var(--border); cursor: col-resize; flex-shrink: 0; transition: background var(--transition); position: relative; }
.divider:hover, .divider.dragging { background: var(--ui-accent); }

/* ─── PREVIEW PANE ─────────────────────────────────────────── */
.preview-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg-primary); }
.preview-inner { flex: 1; overflow-y: auto; background: var(--preview-bg); padding-bottom: 60px;}
.preview-inner::-webkit-scrollbar { width: 6px; }
.preview-inner::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

/* ─── MARKDOWN PREVIEW STYLES ─────────────────────────────── */
#preview { max-width: 800px; margin: 0 auto; padding: 32px 40px; font-family: var(--font-preview); font-size: 16px; line-height: 1.8; color: var(--preview-text); background: var(--preview-bg); }
#preview h1,#preview h2,#preview h3,#preview h4,#preview h5,#preview h6 { font-family: 'Sora', var(--font-preview); color: var(--preview-heading); margin: 1.5em 0 0.6em; line-height: 1.3; font-weight: 700; }
#preview h1 { font-size: 2em; padding-bottom: 0.3em; } 
#preview h2 { font-size: 1.5em; padding-bottom: 0.3em; } 
#preview h3 { font-size: 1.25em; }
#preview h4 { font-size: 1em; }
#preview h5 { font-size: 0.875em; }
#preview h6 { font-size: 0.85em; color: var(--text-secondary); }
#preview p { margin: 0.8em 0; }

#preview a { color: var(--brand-color); text-decoration: none; }
#preview a:hover { text-decoration: underline; }

#preview strong { font-weight: 700; }
#preview em { font-style: italic; }
#preview del { text-decoration: line-through; color: #6e7781; }

#preview mark { background: rgba(255, 212, 0, 0.5); color: inherit; padding: 2px 6px; border-radius: 4px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }

#preview ul,#preview ol { padding-left: 2em; margin: 0.6em 0; }
#preview li { margin: 0.3em 0; }
#preview blockquote { border-left: 4px solid var(--brand-color); margin: 1em 0; padding: 8px 16px; background: var(--brand-bg); color: var(--preview-blockquote); border-radius: 0 4px 4px 0; }

/* 代码样式全面区分 */
#preview code:not(pre code) { 
  font-family: var(--font-editor); 
  font-size: 0.875em; 
  background: var(--brand-bg); 
  color: var(--brand-color); 
  padding: 2px 6px; 
  border-radius: 4px; 
}
#preview pre { background: #1e2128; border-radius: 8px; overflow-x: auto; margin: 1em 0; padding: 16px 20px; }
#preview pre code { background: transparent; color: #abb2bf; padding: 0; display: block; line-height: 1.6; border: none; }

#preview table { border-collapse: collapse; width: 100%; margin: 1.5em 0; font-size: 0.95em; border-top: 2px solid var(--brand-color); border-bottom: 2px solid var(--brand-color); }
#preview th, #preview td { padding: 10px 14px; border: none; text-align: left; }
#preview th { font-weight: 600; color: var(--preview-heading); border-bottom: 1px solid var(--brand-color); background: transparent; }
#preview tr:nth-child(even) { background: transparent; }

#preview img { max-width: 100%; border-radius: 6px; margin: 0.5em 0; }
#preview hr { border: none; border-top: 2px dashed var(--brand-color); opacity: 0.4; margin: 2em 0; }

/* 脚注样式支持（移除了默认灰色边框） */
#preview .footnote-ref a { color: var(--brand-color); text-decoration: none; padding: 0 2px; }
#preview .footnotes { margin-top: 3em; padding-top: 1em; font-size: 0.9em; color: var(--text-secondary); }
#preview .footnotes ol { padding-left: 2em; }
#preview .footnotes li { margin-bottom: 0.5em; }
#preview .footnote-backref { color: var(--brand-color); text-decoration: none; margin-left: 6px; font-family: monospace; }

/* 图表背景透明化 */
#preview .mermaid { display: flex; justify-content: center; margin: 1.5em 0; padding: 20px; background: transparent; border-radius: 8px; border: 1px solid var(--preview-border); overflow-x: auto; line-height: normal; }
#preview .mermaid p { margin: 0; padding: 0; } 
#preview .mermaid svg { max-width: 100%; display: block; margin: 0 auto; background: transparent !important; }

/* ECharts */
.echarts-container { width: 100%; height: 350px; margin: 1.5em 0; border-radius: 8px; border: 1px solid var(--preview-border); background: transparent; }
.echarts-container svg { background: transparent !important; }

/* ABC Music */
.abcjs-container { margin: 1.5em 0; padding: 20px; background: transparent; border-radius: 8px; border: 1px solid var(--preview-border); overflow-x: auto; }
.abcjs-container svg { background: transparent !important; }

/* MathJax SVG Fix */
mjx-container[display="true"] { margin: 1.5em 0; display: block; text-align: center; overflow-x: auto; overflow-y: hidden; }
mjx-container svg { background: transparent !important; max-width: 100%; display: inline-block; }

/* PPT Slide */
.ppt-slide { width: 100%; aspect-ratio: 16/9; background: linear-gradient(135deg, #ffffff, var(--brand-bg)); border-radius: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 40px; margin: 1.5em 0; position: relative; overflow: hidden; box-shadow: 0 4px 20px rgba(0,0,0,0.05); border: 1px solid var(--brand-glow); }
.ppt-slide::before { content: ''; position: absolute; top: -50%; left: -50%; width: 200%; height: 200%; background: radial-gradient(circle at 30% 30%, var(--brand-glow), transparent 50%), radial-gradient(circle at 70% 70%, var(--brand-zebra), transparent 50%); z-index: 0; }
.ppt-slide h1 { color: var(--brand-color); font-size: 2.2em; border: none; font-family: 'Sora', sans-serif; z-index: 1; margin: 0 0 0.3em; }
.ppt-slide h2 { color: var(--text-muted); font-size: 1.2em; border: none; font-weight: 400; z-index: 1; margin: 0; }
.ppt-slide-number { position: absolute; bottom: 12px; right: 16px; font-size: 11px; color: var(--text-muted); z-index: 1; }
.ppt-slide-tag { position: absolute; top: 12px; left: 16px; font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 2px; z-index: 1; }

/* Video/Audio embed */
.media-container { margin: 1.5em 0; }
.media-container video, .media-container audio { width: 100%; border-radius: 8px; border: 1px solid var(--preview-border); }
.media-placeholder { padding: 20px; background: #f6f8fa; border: 1px solid var(--preview-border); border-radius: 8px; font-size: 13px; color: #6e7781; display: flex; align-items: center; gap: 10px; }

/* WeChat style override */
.wechat-mode #preview { font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB', sans-serif; font-size: 15px; max-width: 375px; background: white; padding: 20px 18px; }
.wechat-mode #preview h1 { font-size: 1.6em; border-bottom: none; color: #333; }
.wechat-mode #preview h2 { font-size: 1.3em; border-bottom: none; } 
.wechat-mode #preview h3 { font-size: 1.1em; color: var(--wechat-accent); }
.wechat-mode #preview blockquote { border-left-color: var(--wechat-accent); background: var(--brand-bg); }
.wechat-mode #preview code { color: var(--wechat-accent); }
.wechat-mode #preview a { color: var(--wechat-accent); }
.wechat-mode .preview-inner { background: #f0f0f0; }
.wechat-mode #preview { background: white; box-shadow: 0 2px 10px rgba(0,0,0,0.1); margin: 20px auto; border-radius: 4px; }

/* ─── STATUS BAR ─────────────────────────────────────────── */
.statusbar { height: var(--statusbar-h); background: var(--ui-accent); display: flex; align-items: center; padding: 0 16px; gap: 16px; font-size: 11px; color: rgba(255,255,255,0.85); flex-shrink: 0; }
.statusbar span { font-weight: 500; }
.statusbar .sep { color: rgba(255,255,255,0.3); }
.status-format { margin-left: auto; background: rgba(255,255,255,0.2); padding: 2px 8px; border-radius: 10px; font-weight: 600; }

/* ─── MODAL ──────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); z-index: 1000; display: flex; align-items: center; justify-content: center; opacity: 0; pointer-events: none; transition: opacity var(--transition); }
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; width: 520px; max-width: 90vw; max-height: 80vh; overflow-y: auto; box-shadow: var(--shadow); transform: scale(0.95) translateY(10px); transition: transform var(--transition); }
.modal-overlay.open .modal { transform: scale(1) translateY(0); }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-title { font-size: 15px; font-weight: 700; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-secondary); font-size: 18px; padding: 2px 6px; }
.modal-close:hover { color: var(--text-primary); }

/* ─── TOAST ──────────────────────────────────────────────── */
.toast { position: fixed; bottom: 50px; right: 20px; background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 16px; font-size: 13px; z-index: 2000; transform: translateY(10px); opacity: 0; transition: all var(--transition); pointer-events: none; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { border-color: var(--brand-color); color: var(--brand-color); }
.toast.error { border-color: var(--accent-red); color: var(--accent-red); }

/* ─── VIEW MODES ─────────────────────────────────────────── */
.view-editor-only .preview-pane, .view-editor-only .divider { display: none; }
.view-preview-only .editor-pane, .view-preview-only .divider { display: none; }
.view-preview-only .preview-pane { flex: 1; }