/* ===== 主题变量 ===== */
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --editor-bg: #fbfbfd;
  --editor-ink: #2a2a2a;
  --line: #e3e5e9;
  --ink: #1f2329;
  --sub: #6b7280;
  --head-bg: #fafbfc;
  --brand: #3a7afe;
  --brand-d: #2f6ae0;
  --ok: #28c840;
  --warn: #f0b400;
  --radius: 10px;
}
body.dark {
  --bg: #14171c;
  --panel: #1b1f26;
  --editor-bg: #161a20;
  --editor-ink: #d6d9de;
  --line: #2a2f37;
  --ink: #e6e8eb;
  --sub: #8b93a0;
  --head-bg: #1f242c;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: flex; flex-direction: column; height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg); color: var(--ink);
}

/* ===== 顶栏 ===== */
header {
  flex: 0 0 auto; display: flex; align-items: center; gap: 14px;
  padding: 12px 20px; background: #161a20; color: #fff;
  box-shadow: 0 1px 0 rgba(0,0,0,.2);
}
.logo { display: flex; align-items: center; gap: 9px; }
.logo .mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, #3a7afe, #7a5cff);
  display: grid; place-items: center; font-size: 16px;
}
.logo h1 { font-size: 16px; margin: 0; font-weight: 700; letter-spacing: .3px; }
.logo .tag { font-size: 11px; color: #9aa0a6; margin-top: 1px; }
header .spacer { flex: 1; }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.btn {
  border: 0; border-radius: 7px; padding: 8px 13px; font-size: 13px; cursor: pointer;
  background: #2a2f37; color: #e8eaed; transition: .15s; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 5px;
}
.btn:hover { background: #353b44; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-d); }
.btn:disabled { opacity: .6; cursor: default; }
select.btn { appearance: none; padding-right: 26px;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23bbb'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }

/* ===== 主体 ===== */
main { flex: 1 1 auto; display: flex; min-height: 0; }
.pane { min-width: 120px; display: flex; flex-direction: column; background: var(--panel); }
#paneL { flex: 0 0 50%; }
#paneR { flex: 1 1 auto; }
/* 拖拽分隔条 */
#splitter {
  flex: 0 0 6px; cursor: col-resize; background: var(--line);
  position: relative; transition: background .15s;
}
#splitter:hover, #splitter.active { background: var(--brand); }
#splitter::after {
  content: ''; position: absolute; left: 1px; top: 50%; transform: translateY(-50%);
  width: 2px; height: 30px; background: rgba(127,127,127,.5); border-radius: 2px;
}
.pane-head {
  flex: 0 0 auto; padding: 7px 16px; font-size: 12px; color: var(--sub);
  background: var(--head-bg); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px;
}
.pane-head .dot { width: 8px; height: 8px; border-radius: 50%; }
.pane-head .right { margin-left: auto; font-size: 11px; }

#editor {
  flex: 1; width: 100%; border: 0; resize: none; padding: 18px;
  font-family: "SF Mono", "JetBrains Mono", Consolas, Menlo, monospace;
  font-size: 13px; line-height: 1.65; outline: none;
  background: var(--editor-bg); color: var(--editor-ink); white-space: pre; overflow: auto; tab-size: 2;
}
.editor-wrap { flex: 1; position: relative; display: flex; }
.drop-hint {
  position: absolute; inset: 10px; border: 2px dashed var(--brand); border-radius: 12px;
  background: rgba(58,122,254,.06); display: none; place-items: center;
  color: var(--brand); font-size: 15px; font-weight: 600; pointer-events: none; z-index: 5;
}
.editor-wrap.dragover .drop-hint { display: grid; }

#previewWrap { flex: 1; overflow: auto; background: #fff; }
#preview { max-width: 720px; margin: 0 auto; padding: 30px 34px 60px; color: #2c2c2c; line-height: 1.8; }
#preview h1 { font-size: 24px; border-bottom: 2px solid #eee; padding-bottom: 10px; }
#preview h2 { font-size: 20px; margin-top: 32px; border-left: 4px solid var(--brand); padding-left: 10px; }
#preview h3 { font-size: 16px; }
#preview blockquote { margin: 14px 0; padding: 8px 16px; border-left: 4px solid #d0d0d0; background: #f7f7f9; color: #555; }
#preview table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: 14px; }
#preview th, #preview td { border: 1px solid #e0e0e0; padding: 8px 12px; text-align: left; }
#preview th { background: #f2f4f8; }
#preview code { background: #f0f0f2; padding: 2px 5px; border-radius: 4px; font-size: 13px; }
#preview pre code { display: block; padding: 12px; overflow-x: auto; }
#preview img { max-width: 100%; }
#preview hr { border: 0; border-top: 1px solid #eee; margin: 28px 0; }

.mermaid-block { position: relative; margin: 18px 0; text-align: center; }
.mermaid-block .dl-btn {
  position: absolute; top: 6px; right: 6px; z-index: 2;
  background: var(--brand); color: #fff; border: 0; border-radius: 5px;
  padding: 4px 9px; font-size: 11px; cursor: pointer; opacity: 0; transition: opacity .15s;
}
.mermaid-block:hover .dl-btn { opacity: 1; }
.mermaid-block svg { max-width: 100%; height: auto; }
.mermaid-err { color: #c0392b; font-size: 12px; text-align: left; background: #fdecea; padding: 8px; border-radius: 4px; }

/* ===== 页脚 ===== */
footer {
  flex: 0 0 auto; padding: 7px 20px; font-size: 12px; color: var(--sub);
  background: var(--head-bg); border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
footer .saved { color: var(--ok); }
footer .spacer { flex: 1; }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: 60px; transform: translateX(-50%) translateY(20px);
  background: #161a20; color: #fff; padding: 11px 18px; border-radius: 9px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 99; max-width: 80vw; text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 760px) {
  main { flex-direction: column; }
  #paneL, #paneR { flex: 1 1 auto !important; }
  #splitter { display: none; }
  .logo .tag { display: none; }
}
