:root {
  --text: #1d2129;
  --muted: #86909c;
  --placeholder: #c5c7ce;
  --border: #e5e6eb;
  --bg: #fff;
  --soft: #f7f8fa;
  --hover: #f2f3f5;
  --primary: #f05f3d;
  --primary-soft: #fff5f1;
  --chip-bg: #eaf3ff;
  --chip-text: #2b6cb0;
  --danger: #b42318;
  --ok: #26816a;
  --warn: #b45309;
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", Inter, ui-sans-serif, system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }

.editor-app {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 320px;
  background: var(--bg);
}

.editor-top, .mode-bar, .toolbar, .editor-bottom {
  flex: none;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.editor-top {
  height: 56px;
  padding: 0 16px 0 20px;
  gap: 16px;
}
.brand {
  flex: none;
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: .04em;
}
.title-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
#title {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 18px;
  line-height: 1.4;
}
#title::placeholder { color: var(--placeholder); }
#title-count {
  width: 52px;
  text-align: right;
  color: var(--placeholder);
  font-size: 13px;
}
.top-actions { display: flex; align-items: center; gap: 10px; flex: none; }
.status {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: #4c637d;
  font-size: 12px;
  white-space: nowrap;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ghost, .text-btn, .icon-btn, .secondary, .split-caret {
  border: 1px solid transparent;
  background: transparent;
  color: #4e5969;
}
.ghost {
  border-color: var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
}
.ghost:hover, .text-btn:hover, .icon-btn:hover, .split-caret:hover, .secondary:hover { background: var(--hover); }

.mode-bar {
  height: 52px;
  padding: 0 20px;
  justify-content: flex-start;
  gap: 12px;
}
.modes {
  display: inline-flex;
  align-items: center;
  background: transparent;
  padding: 0;
  gap: 10px;
}
.modes button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: #f2f3f5;
  padding: 7px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  color: #1d2129;
}
.modes button[aria-selected="true"] {
  background: #1d2129;
  color: #fff;
}

.toolbar {
  height: 46px;
  padding: 0 16px;
  gap: 2px;
  overflow: auto hidden;
}
.toolbar-group { display: flex; align-items: center; gap: 0; position: relative; }
.toolbar-spacer { flex: 1; min-width: 12px; }
.toolbar-divider {
  width: 1px;
  height: 16px;
  margin: 0 8px;
  background: #e5e6eb;
  flex: none;
}
.icon-btn, .text-btn, .letter-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  border-radius: 8px;
  padding: 0 10px;
  font-size: 13px;
  gap: 5px;
  color: #1d2129;
}
.letter-btn {
  width: 32px;
  padding: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  font-weight: 700;
}
.letter-btn i { font-style: italic; font-weight: 600; }
.letter-btn s { text-decoration: line-through; font-weight: 600; }
.icon-btn { width: 32px; padding: 0; color: #333; }
.text-btn.open, .letter-btn.open, .icon-btn.open { background: #f2f3f5; }
.save-btn { position: relative; }
.save-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #f53f3f;
  box-shadow: 0 0 0 2px #fff;
}
.caret {
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 3.5px solid transparent;
  border-right: 3.5px solid transparent;
  border-top: 4px solid currentColor;
  opacity: .7;
}
.dropdown { position: relative; }
.menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20;
  min-width: 168px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(29, 33, 41, .12);
}
.menu-right { left: auto; right: 0; }
.menu-up { top: auto; bottom: calc(100% + 4px); }
.menu-scroll { max-height: 280px; overflow: auto; min-width: 180px; }
.menu-sub { left: calc(100% + 4px); top: 0; }
.menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  color: var(--text);
}
.menu button:hover { background: var(--hover); }
.menu-ico {
  width: 18px;
  text-align: center;
  color: #4e5969;
  font-size: 13px;
}
.hidden { display: none !important; }

.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  background: var(--bg);
}
.pane { min-width: 0; min-height: 0; overflow: auto; }
.editor-pane, .preview-pane { flex: 1 1 0; }
#markdown {
  width: 100%;
  height: 100%;
  border: 0;
  outline: 0;
  resize: none;
  padding: 20px 28px 40px;
  background: var(--bg);
  line-height: 1.75;
  font-size: 15px;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, "PingFang SC", monospace;
  tab-size: 2;
}
#markdown::placeholder { color: var(--placeholder); }
.splitter {
  flex: none;
  width: 6px;
  margin: 0 -3px;
  cursor: col-resize;
  position: relative;
  z-index: 2;
}
.splitter::before {
  content: "";
  position: absolute;
  inset: 0 2px;
  background: var(--border);
}
.splitter::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 18px;
  width: 14px;
  height: 22px;
  margin-left: -7px;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='14'%3E%3Ccircle cx='3' cy='3' r='1' fill='%23999'/%3E%3Ccircle cx='7' cy='3' r='1' fill='%23999'/%3E%3Ccircle cx='3' cy='7' r='1' fill='%23999'/%3E%3Ccircle cx='7' cy='7' r='1' fill='%23999'/%3E%3Ccircle cx='3' cy='11' r='1' fill='%23999'/%3E%3Ccircle cx='7' cy='11' r='1' fill='%23999'/%3E%3C/svg%3E") center no-repeat;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.workspace.mode-markdown .preview-pane,
.workspace.mode-markdown .splitter,
.workspace.mode-preview .editor-pane,
.workspace.mode-preview .splitter { display: none; }
.workspace.help-open .preview-pane { display: none; }
.workspace.mode-preview.help-open .preview-pane { display: block; }
.workspace.mode-preview.help-open .splitter { display: block; }

.preview {
  padding: 20px 36px 48px;
  max-width: 860px;
  line-height: 1.8;
  font-size: 15px;
}
.preview:empty::before {
  content: "预览会显示在这里";
  color: var(--placeholder);
}
.preview h1, .preview h2, .preview h3, .preview h4, .preview h5, .preview h6 {
  margin: 1.4em 0 .6em;
  line-height: 1.35;
  font-weight: 700;
}
.preview h1 { font-size: 28px; }
.preview h2 { font-size: 22px; border-bottom: 1px solid var(--border); padding-bottom: .3em; }
.preview h3 { font-size: 18px; }
.preview p, .preview ul, .preview ol, .preview blockquote, .preview pre, .preview table { margin: 0 0 1em; }
.preview img, .preview video { max-width: 100%; }
.preview a { color: var(--primary); }
.preview blockquote {
  border-left: 4px solid var(--border);
  padding: 0 1em;
  color: #4e5969;
  background: var(--soft);
}
.preview code {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px;
  background: #f4f5f7;
  padding: .1em .35em;
  border-radius: 4px;
}
.preview pre {
  background: #f6f8fa;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  overflow: auto;
}
.preview pre code { background: none; padding: 0; }
.preview table { border-collapse: collapse; width: 100%; }
.preview th, .preview td { border: 1px solid var(--border); padding: 6px 10px; }
.preview th { background: var(--soft); }
.preview hr { border: 0; border-top: 1px solid var(--border); margin: 1.5em 0; }

.help-panel {
  flex: none;
  width: 360px;
  border-left: 1px solid var(--border);
  overflow: auto;
  background: var(--bg);
  padding: 16px 16px 32px;
}
.help-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.help-chip {
  border: 0;
  background: var(--chip-bg);
  color: var(--chip-text);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
}
.help-chip.active, .help-chip:hover { background: #d7e9ff; }
.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.help-head h3 { font-size: 16px; }
.help-actions { display: flex; gap: 12px; }
.linkish {
  border: 0;
  background: none;
  color: var(--chip-text);
  font-size: 13px;
  padding: 0;
}
.help-body {
  margin: 0;
  white-space: pre-wrap;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, "PingFang SC", monospace;
  font-size: 13px;
  line-height: 1.7;
  color: #3d3d3d;
}

.editor-bottom {
  height: 56px;
  padding: 0 20px;
  border-bottom: 0;
  border-top: 1px solid var(--border);
  justify-content: space-between;
  gap: 16px;
}
.counts {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--muted);
  font-size: 12px;
  min-width: 0;
}
.counts b { font-weight: 600; color: #4e5969; }
.message { color: var(--muted); }
.message.error { color: var(--danger); }
.bottom-actions { display: flex; align-items: center; gap: 10px; }
.split-btn { display: flex; align-items: stretch; position: relative; }
#save-draft, .secondary, .split-caret {
  border: 1px solid var(--border);
  background: #fff;
  height: 36px;
}
#save-draft {
  border-radius: 4px 0 0 4px;
  padding: 0 16px;
  font-size: 14px;
}
.split-caret {
  width: 28px;
  border-left: 0;
  border-radius: 0 4px 4px 0;
}
.primary {
  border: 0;
  background: var(--primary);
  color: #fff;
  border-radius: 4px;
  height: 36px;
  padding: 0 22px;
  font-size: 14px;
  font-weight: 600;
}
.primary:hover { filter: brightness(1.05); }
.primary:disabled, #save-draft:disabled { opacity: .6; cursor: default; }
.secondary { border-radius: 6px; padding: 0 14px; height: 36px; font-size: 13px; font-weight: 600; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(29, 33, 41, .32);
  z-index: 30;
}
.drawer, .modal {
  position: fixed;
  z-index: 40;
}
.drawer {
  top: 0;
  right: 0;
  width: min(400px, 100%);
  height: 100%;
  background: #fff;
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 30px rgba(29, 33, 41, .08);
  padding: 20px 20px 32px;
  overflow: auto;
}
.modal {
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal.hidden { display: none !important; }
.modal-card {
  width: min(720px, 100%);
  max-height: min(80vh, 640px);
  overflow: auto;
  background: #fff;
  border-radius: 12px;
  padding: 20px 22px 22px;
  box-shadow: 0 18px 50px rgba(40, 62, 90, .18);
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.drawer-head h2 { font-size: 18px; }
.close-drawer { font-size: 22px; line-height: 1; width: 32px; height: 32px; }
.side-copy, .empty { color: var(--muted); font-size: 13px; line-height: 1.6; }
.token {
  display: block;
  overflow-wrap: anywhere;
  margin: 14px 0 0;
  border: 1px solid #eadfd9;
  border-radius: 8px;
  background: var(--primary-soft);
  padding: 12px;
  color: #a7472e;
  font-size: 12px;
  line-height: 1.5;
}
#copy-token { margin-top: 12px; }
#login-status { margin-top: 14px; }
.platform-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.platform {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.platform:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: #d94e30;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.tasks { display: grid; gap: 8px; }
.task { border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.task > div { display: flex; justify-content: space-between; gap: 10px; }
.task strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.task span, .task p { color: var(--muted); font-size: 11px; }
.task p { margin-top: 8px; }
.task b { display: inline-block; margin-top: 8px; color: var(--primary); font-size: 11px; }
.task-completed b, .task-completed { color: var(--ok); }
.result-list { margin: 8px 0 0; padding-left: 16px; color: #5b6b7c; font-size: 11px; line-height: 1.55; }
.result-list a { color: #d94e30; }
.result-error, .result-warning { margin-top: 4px; color: var(--warn); }
.result-error { color: var(--danger); }
.retry {
  margin-top: 10px;
  border: 0;
  border-radius: 7px;
  padding: 7px 10px;
  background: #edf2f7;
  color: #334155;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.task-failed b, .task-manual_required b { color: var(--danger); }
.task-running b { color: var(--warn); }

.insert-pop {
  position: fixed;
  z-index: 50;
  width: 320px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(29, 33, 41, .12);
}
.insert-pop label { display: block; font-size: 12px; font-weight: 700; color: #334155; }
.insert-pop label + label { margin-top: 10px; }
.insert-pop input {
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  outline: 0;
}
.insert-pop input:focus { border-color: var(--primary); }

@media (max-width: 820px) {
  .editor-top { gap: 8px; padding: 0 10px; }
  .brand { display: none; }
  #title { font-size: 16px; }
  .platform-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workspace.mode-compare { flex-direction: column; }
  .workspace.mode-compare .splitter { width: auto; height: 6px; cursor: row-resize; margin: -3px 0; }
  .workspace.mode-compare .splitter::before { inset: 2px 0; }
  .workspace.mode-compare .splitter::after { left: 50%; bottom: auto; top: -8px; }
  .help-panel { width: 100%; height: 40%; border-left: 0; border-top: 1px solid var(--border); }
  .counts { flex-wrap: wrap; gap: 8px; }
  .status { max-width: 120px; }
}
