:root {
  --bg: #0b1220;
  --bg-soft: #111c34;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e5e9f0;
  --accent: #2563eb;
  --accent-ink: #1d4ed8;
  --accent-soft: #eff6ff;
  --ok: #16a34a;
  --err: #dc2626;
  --radius: 14px;
  --topbar-h: 60px;
  --shadow-card: 0 18px 40px rgba(2, 6, 23, 0.45);
  --shadow-pop: 0 12px 32px rgba(2, 6, 23, 0.35);

  /* 蓝色系标题色阶（深→浅） */
  --h1: #0b3d91;
  --h2: #1d4ed8;
  --h3: #2563eb;
  --h4: #3b82f6;
  --h5: #60a5fa;
  --h6: #93c5fd;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(37, 99, 235, 0.22), transparent 60%),
    radial-gradient(1000px 500px at 110% 10%, rgba(99, 102, 241, 0.18), transparent 55%),
    var(--bg);
  min-height: 100vh;
  line-height: 1.6;
}

code {
  font-family: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  background: rgba(148, 163, 184, 0.18);
  padding: 0.1em 0.4em;
  border-radius: 5px;
  font-size: 0.9em;
}

.hidden { display: none !important; }

/* loader */
.loader {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: #e2e8f0;
  background: var(--bg);
  z-index: 50;
}
.loader p { color: #94a3b8; font-size: 14px; }
.spinner {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 4px solid rgba(148, 163, 184, 0.25);
  border-top-color: #60a5fa;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ 顶部浮动栏 ============ */
.topbar {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  height: var(--topbar-h);
  z-index: 40;
  pointer-events: none; /* 让外层不挡住，仅内部交互 */
}
.topbar-inner {
  pointer-events: auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  border-radius: 16px;
  background: rgba(17, 28, 52, 0.72);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border: 1px solid rgba(148, 163, 184, 0.22);
  box-shadow: var(--shadow-pop);
}

.brand { display: flex; align-items: center; gap: 10px; color: #e2e8f0; min-width: 0; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #60a5fa);
  color: #fff; font-weight: 800; font-size: 14px;
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.45);
}
.brand-title {
  font-size: 14.5px; font-weight: 700; letter-spacing: 0.2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.arrow { color: #60a5fa; font-weight: 800; }

.topbar-tools { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }

.tool-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 12px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(255, 255, 255, 0.06);
  color: #e2e8f0;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s, color 0.15s;
  white-space: nowrap;
}
.tool-btn svg { width: 16px; height: 16px; fill: currentColor; }
.tool-btn:hover { background: rgba(96, 165, 250, 0.18); border-color: rgba(96, 165, 250, 0.5); color: #fff; }
.tool-btn:active { transform: translateY(1px); }
.tool-btn.primary {
  background: linear-gradient(135deg, var(--accent), #3b82f6);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 22px rgba(37, 99, 235, 0.4);
}
.tool-btn.primary:hover:not(:disabled) { background: linear-gradient(135deg, var(--accent-ink), #2563eb); }
.tool-btn.primary:disabled { background: rgba(148, 163, 184, 0.35); cursor: not-allowed; box-shadow: none; }
.tool-btn.ghost { background: transparent; border-color: transparent; color: #cbd5e1; }
.tool-btn.ghost:hover { background: rgba(248, 113, 113, 0.16); color: #fecaca; border-color: transparent; }

/* 下拉面板 */
.dropdown { position: relative; }
.dropdown-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 240px;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-pop);
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 60;
}
.dropdown-panel.hidden { display: none; }
.dropdown-panel .opt { font-size: 13px; }
.dropdown-panel .opt input[type="text"] { width: 100%; margin-top: 4px; }
.dropdown-panel .opt select { margin-left: 4px; }

.status {
  font-size: 12.5px; color: #cbd5e1; max-width: 260px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.status.ok { color: #86efac; }
.status.err { color: #fca5a5; }
.status.busy { color: #bfdbfe; }
.status.busy::before {
  content: ""; display: inline-block; width: 12px; height: 12px;
  border: 2px solid rgba(148, 163, 184, 0.3); border-top-color: #60a5fa;
  border-radius: 50%; margin-right: 6px; vertical-align: -2px;
  animation: spin 0.9s linear infinite;
}

/* ============ 主体两栏布局 ============ */
.app {
  max-width: 1600px;
  margin: 0 auto;
  padding: calc(var(--topbar-h) + 24px) 16px 32px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: stretch;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-card);
  border: 1px solid rgba(148, 163, 184, 0.18);
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--topbar-h) - 80px);
}

.pane-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 10px;
  padding: 0 4px;
}
.pane-label { font-size: 13px; font-weight: 700; color: var(--muted); }
.pane-hint { font-size: 11.5px; color: #93a3b8; background: var(--accent-soft); color: var(--accent-ink); padding: 2px 8px; border-radius: 999px; font-weight: 600; }

.file-info { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; }
.file-info.hidden { display: none; }
.file-name { font-weight: 600; color: var(--ink); }
.file-size { color: var(--muted); }

/* 编辑器 */
.md-editor {
  flex: 1;
  width: 100%;
  min-height: 360px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  font-family: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.65;
  color: var(--ink);
  background: #fafbfc;
  tab-size: 2;
}
.md-editor:focus { outline: none; border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }

/* MD 阅读器（预览） */
.md-preview {
  flex: 1;
  overflow: auto;
  padding: 18px 22px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.7;
  color: #1f2937;
}
.preview-empty { color: #94a3b8; font-size: 13px; padding: 24px 4px; text-align: center; }

/* 预览内 Markdown 排版（蓝色系标题） */
.md-preview h1, .md-preview h2, .md-preview h3,
.md-preview h4, .md-preview h5, .md-preview h6 {
  margin: 1.2em 0 0.5em;
  line-height: 1.3;
  font-weight: 700;
}
.md-preview h1 { color: var(--h1); font-size: 1.7em; border-bottom: 2px solid #dbeafe; padding-bottom: 0.25em; }
.md-preview h2 { color: var(--h2); font-size: 1.45em; border-bottom: 1px solid #e0edff; padding-bottom: 0.2em; }
.md-preview h3 { color: var(--h3); font-size: 1.25em; }
.md-preview h4 { color: var(--h4); font-size: 1.1em; }
.md-preview h5 { color: var(--h5); font-size: 1em; }
.md-preview h6 { color: var(--h6); font-size: 0.92em; }
.md-preview p { margin: 0.5em 0; }
.md-preview ul, .md-preview ol { margin: 0.4em 0 0.6em; padding-left: 1.6em; }
.md-preview li { margin: 0.2em 0; }
.md-preview code {
  font-family: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  background: #f1f5f9; color: #be185d; padding: 0.1em 0.4em; border-radius: 5px; font-size: 0.88em;
}
.md-preview pre {
  background: #0f172a; color: #e2e8f0; padding: 12px 14px; border-radius: 10px;
  overflow: auto; margin: 0.6em 0; font-size: 12.5px; line-height: 1.55;
}
.md-preview pre code { background: transparent; color: inherit; padding: 0; font-size: inherit; }
.md-preview blockquote {
  margin: 0.6em 0; padding: 0.2em 1em; color: #475569;
  border-left: 4px solid #93c5fd; background: #f8fbff; border-radius: 0 8px 8px 0;
}
.md-preview a { color: var(--accent); text-decoration: none; }
.md-preview a:hover { text-decoration: underline; }
.md-preview img { max-width: 100%; border-radius: 8px; margin: 0.5em 0; }
.md-preview hr { border: none; border-top: 1px solid var(--line); margin: 1em 0; }
.md-preview table { border-collapse: collapse; margin: 0.6em 0; width: 100%; font-size: 13px; }
.md-preview th, .md-preview td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.md-preview th { background: #f1f5f9; color: var(--h1); font-weight: 700; }
.md-preview tr:nth-child(even) td { background: #fafbfc; }

/* ============ 响应式 ============ */
@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .card { min-height: 420px; }
  .brand-title { display: none; }
}
@media (max-width: 640px) {
  .topbar { top: 8px; left: 8px; right: 8px; }
  .topbar-inner { padding: 0 8px; gap: 6px; border-radius: 12px; }
  .tool-btn { padding: 0 8px; }
  .tool-btn span { display: none; }
  .status { display: none; }
  .app { padding: calc(var(--topbar-h) + 20px) 10px 24px; }
  .md-preview { padding: 14px; font-size: 13px; }
}
