:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #eef2f6;
  --border: #d8dee8;
  --text: #172033;
  --muted: #617089;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #e8f0ff;
  --ok: #0f766e;
  --warn: #b45309;
  --code-bg: #f1f5f9;
  --shadow: 0 18px 45px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Inter",
    "Segoe UI",
    "Microsoft YaHei",
    system-ui,
    sans-serif;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 8px;
  background: #172033;
  color: #ffffff;
  font-weight: 800;
  letter-spacing: 0;
}

.file-summary {
  min-width: 0;
}

h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
  font-weight: 760;
}

.file-line {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

#fileName {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dirty-badge,
.mode-pill {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  color: #7c2d12;
  background: #ffedd5;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

.mode-pill {
  color: #115e59;
  background: #ccfbf1;
}

.file-actions,
.formatbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.button,
.tool-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(23, 32, 51, 0.04);
}

.button {
  gap: 8px;
  padding: 0 12px;
  font-weight: 650;
}

.button-icon {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.button:hover,
.tool-button:hover {
  border-color: #b8c3d4;
  background: #fbfcfe;
}

.button:focus-visible,
.tool-button:focus-visible,
textarea:focus-visible,
.preview:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.22);
  outline-offset: 2px;
}

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.button.primary:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.button.primary .button-icon {
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

.button.quiet {
  background: #f8fafc;
}

.formatbar {
  min-width: 0;
  padding: 10px 22px;
  background: #fbfcfe;
  border-bottom: 1px solid var(--border);
}

.tool-button {
  width: 34px;
  height: 34px;
  padding: 0;
  color: #26364d;
  font-weight: 720;
}

.tool-button.mono {
  font-family: "Cascadia Mono", "Consolas", monospace;
  font-size: 12px;
}

.spacer {
  flex: 1 1 auto;
}

.editor-stats {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  min-height: 0;
  padding: 14px;
  gap: 14px;
}

.pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.pane-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  background: #fbfcfe;
  color: #334155;
  font-size: 13px;
  font-weight: 720;
}

#editor {
  width: 100%;
  min-width: 0;
  height: 100%;
  min-height: 0;
  padding: 22px;
  resize: none;
  border: 0;
  outline: 0;
  background: #ffffff;
  color: #111827;
  font-family:
    "Cascadia Mono",
    "SFMono-Regular",
    Consolas,
    "Liberation Mono",
    monospace;
  font-size: 15px;
  line-height: 1.65;
  tab-size: 2;
}

#editor::placeholder {
  color: #94a3b8;
}

.preview {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 22px;
  color: #1f2937;
  line-height: 1.72;
  overflow-wrap: anywhere;
}

.preview[contenteditable="true"] {
  caret-color: var(--accent);
  cursor: text;
}

.preview[contenteditable="true"]:focus {
  background: #fbfdff;
}

.preview:empty::before {
  content: "暂无内容";
  color: #94a3b8;
}

.preview > :first-child {
  margin-top: 0;
}

.preview > :last-child {
  margin-bottom: 0;
}

.preview h1,
.preview h2,
.preview h3,
.preview h4,
.preview h5,
.preview h6 {
  margin: 1.3em 0 0.55em;
  color: #111827;
  line-height: 1.25;
}

.preview h1 {
  padding-bottom: 0.35em;
  border-bottom: 1px solid var(--border);
  font-size: 30px;
}

.preview h2 {
  font-size: 24px;
}

.preview h3 {
  font-size: 20px;
}

.preview p,
.preview ul,
.preview ol,
.preview blockquote,
.preview pre,
.preview table {
  margin: 0 0 1em;
}

.preview ul,
.preview ol {
  padding-left: 1.5em;
}

.preview blockquote {
  padding: 0.05em 1em;
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  color: #334155;
}

.preview code {
  border-radius: 6px;
  background: var(--code-bg);
  padding: 0.12em 0.35em;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 0.92em;
}

.preview pre {
  overflow: auto;
  border: 1px solid #dbe4ef;
  border-radius: 8px;
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px;
}

.preview pre code {
  display: block;
  padding: 0;
  background: transparent;
  color: inherit;
}

.preview a {
  color: var(--accent);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
}

.preview img {
  max-width: 100%;
  border-radius: 8px;
}

.preview hr {
  height: 1px;
  border: 0;
  background: var(--border);
  margin: 1.4em 0;
}

.empty-preview {
  display: grid;
  place-items: center;
  height: 100%;
  min-height: 220px;
  color: #94a3b8;
  font-size: 14px;
}

.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 34px;
  padding: 0 22px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

body.dragging::after {
  content: "释放打开 Markdown 文件";
  position: fixed;
  inset: 12px;
  z-index: 10;
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 8px;
  background: rgba(232, 240, 255, 0.86);
  color: var(--accent-strong);
  font-size: 20px;
  font-weight: 800;
  pointer-events: none;
}

@media (max-width: 860px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .file-actions {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .button {
    width: 100%;
    padding: 0 8px;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(420px, 1.15fr) minmax(320px, 0.85fr);
  }
}

@media (max-width: 560px) {
  .topbar,
  .formatbar,
  .statusbar {
    padding-left: 12px;
    padding-right: 12px;
  }

  .workspace {
    padding: 10px;
    gap: 10px;
  }

  .file-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .formatbar {
    flex-wrap: wrap;
  }

  .spacer {
    display: none;
  }

  .editor-stats {
    width: 100%;
  }

  #editor,
  .preview {
    padding: 16px;
    font-size: 14px;
  }

  .statusbar {
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    padding-top: 8px;
    padding-bottom: 8px;
  }
}
