*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3347;
  --accent: #6c63ff;
  --accent-hover: #7b73ff;
  --accent-glow: rgba(108, 99, 255, 0.25);
  --text-primary: #e8eaf6;
  --text-secondary: #8b93b0;
  --text-muted: #555e7a;
  --green: #43d98a;
  --radius: 10px;
  --shadow: 0 8px 32px rgba(0,0,0,0.5);
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  overflow: hidden;
}

/* ── Header ───────────────────────────────────── */
header {
  height: 54px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  flex-shrink: 0;
  z-index: 10;
  position: relative;
}

.logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 15px;
}
.logo-icon {
  width: 30px; height: 30px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}
.logo-title { color: var(--text-primary); }
.logo-sub {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 12px;
  margin-left: 2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 20px;
  display: flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.badge .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.options-group {
  display: flex;
  gap: 6px;
}
.options-group select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 7px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}
.options-group select:hover { border-color: var(--accent); color: var(--text-primary); }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface2); color: var(--text-primary); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 14px var(--accent-glow);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Workspace ────────────────────────────────── */
.workspace {
  display: flex;
  height: calc(100vh - 54px);
}

.pane {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.pane-header {
  height: 40px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  flex-shrink: 0;
}
.pane-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  display: flex; align-items: center; gap: 6px;
}
.pane-meta { font-size: 11px; color: var(--text-muted); }

/* ── Toolbar ──────────────────────────────────── */
.toolbar { display: flex; gap: 2px; }
.tool-btn {
  height: 26px;
  min-width: 26px;
  padding: 0 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.12s;
}
.tool-btn:hover {
  background: var(--surface2);
  border-color: var(--border);
  color: var(--text-primary);
}

/* ── Editor ───────────────────────────────────── */
#editor {
  flex: 1;
  background: var(--surface);
  color: var(--text-primary);
  border: none;
  outline: none;
  resize: none;
  padding: 22px 26px;
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Menlo, monospace;
  font-size: 13.5px;
  line-height: 1.8;
  caret-color: var(--accent);
  overflow-y: auto;
  tab-size: 2;
}
#editor::placeholder { color: var(--text-muted); }
#editor::-webkit-scrollbar { width: 6px; }
#editor::-webkit-scrollbar-track { background: transparent; }
#editor::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
#editor::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Status bar ───────────────────────────────── */
.statusbar {
  height: 26px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 14px;
  flex-shrink: 0;
}
.stat {
  font-size: 11px;
  color: var(--text-muted);
  display: flex; align-items: center; gap: 4px;
}
.stat b { color: var(--text-secondary); font-weight: 500; }

/* ── Divider ──────────────────────────────────── */
.divider {
  width: 5px;
  background: var(--border);
  cursor: col-resize;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.divider-handle {
  width: 3px; height: 36px;
  background: var(--text-muted);
  border-radius: 2px;
  opacity: 0.4;
  transition: opacity 0.15s;
}
.divider:hover, .divider.dragging {
  background: var(--accent);
}
.divider:hover .divider-handle,
.divider.dragging .divider-handle {
  opacity: 1;
  background: var(--accent);
}

/* ── Preview pane ─────────────────────────────── */
.right-header { background: #f0f2f5; border-bottom: 1px solid #dde1e7; }
.right-header .pane-title { color: #666; }

.preview-pane {
  flex: 1;
  background: #fff;
  overflow-y: auto;
  padding: 36px 44px;
}
.preview-pane::-webkit-scrollbar { width: 6px; }
.preview-pane::-webkit-scrollbar-thumb { background: #d0d0d0; border-radius: 3px; }

/* ── GitHub Markdown 样式 ─────────────────────── */
.markdown-body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.8;
  color: #24292f;
  max-width: 800px;
  margin: 0 auto;
}
.markdown-body h1,.markdown-body h2,.markdown-body h3,
.markdown-body h4,.markdown-body h5,.markdown-body h6 {
  font-weight: 700;
  margin: 1.5em 0 0.5em;
  line-height: 1.3;
  color: #111;
}
.markdown-body h1 { font-size: 2em; border-bottom: 2px solid #e6e8eb; padding-bottom: 8px; margin-top: 0; }
.markdown-body h2 { font-size: 1.5em; border-bottom: 1px solid #e6e8eb; padding-bottom: 6px; }
.markdown-body h3 { font-size: 1.2em; }
.markdown-body p { margin: 0 0 12px; }
.markdown-body ul,.markdown-body ol { padding-left: 2em; margin: 0 0 12px; }
.markdown-body li { margin-bottom: 4px; }
.markdown-body code {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 0.875em;
  background: #f0f2f5;
  color: #d63384;
  padding: 2px 6px;
  border-radius: 4px;
}
.markdown-body pre {
  background: #f6f8fa;
  border: 1px solid #e2e5e9;
  border-radius: 8px;
  padding: 14px 18px;
  overflow-x: auto;
  margin: 0 0 16px;
}
.markdown-body pre code {
  background: none; color: inherit;
  padding: 0; border-radius: 0; font-size: 0.875em;
}
.markdown-body blockquote {
  border-left: 4px solid #6c63ff;
  background: #f7f6ff;
  margin: 0 0 14px;
  padding: 10px 18px;
  border-radius: 0 6px 6px 0;
  color: #555;
}
.markdown-body blockquote p:last-child { margin: 0; }
.markdown-body table { border-collapse: collapse; width: 100%; margin-bottom: 16px; font-size: 0.9em; }
.markdown-body th,.markdown-body td { border: 1px solid #dfe2e5; padding: 8px 14px; }
.markdown-body th { background: #f6f8fa; font-weight: 600; }
.markdown-body tr:nth-child(even) td { background: #fafbfc; }
.markdown-body a { color: #6c63ff; }
.markdown-body a:hover { text-decoration: underline; }
.markdown-body hr { border: none; border-top: 2px solid #e6e8eb; margin: 24px 0; }
.markdown-body img { max-width: 100%; border-radius: 6px; }

/* ── Loading overlay ──────────────────────────── */
#pdf-loading {
  position: fixed; inset: 0;
  background: rgba(10, 11, 18, 0.75);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
#pdf-loading.show { opacity: 1; pointer-events: all; }

.loading-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
}
.spinner {
  width: 44px; height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
.spinner.sm { width: 14px; height: 14px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.loading-sub { font-size: 12px; color: var(--text-muted); }

/* ── Toast ────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  display: flex; align-items: center; gap: 8px;
  box-shadow: var(--shadow);
  transform: translateY(70px);
  opacity: 0;
  transition: all 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 1000;
  max-width: 340px;
}
#toast.show { transform: translateY(0); opacity: 1; }
