* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* 浅色（默认） */
:root {
  --bg: #f7f8fa;
  --panel: #fff;
  --text: #333;
  --text-light: #666;
  --border: #e5e7eb;
  --border-dark: #d1d5db;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --hover: #eff6ff;
  --code-bg: #f1f5f9;
  --code-color: #2d3748;
}

/* 暗黑主题 */
body.dark {
  --bg: #1e1e1e;
  --panel: #252526;
  --text: #ccc;
  --text-light: #999;
  --border: #3c3c3c;
  --border-dark: #4a4a4a;
  --primary: #0e639c;
  --primary-dark: #1177bb;
  --hover: #2a2d2e;
  --code-bg: #1a1a1a;
  --code-color: #ffffff;
}

html, body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  font-family: "Microsoft YaHei", "Segoe UI", Tahoma, sans-serif;
  font-size: 13px;
  color: var(--text);
  transition: background 0.3s, color 0.3s;
}

/* 滚动条美化 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--panel);
}
::-webkit-scrollbar-thumb {
  background: var(--border-dark);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-light);
}

/* 顶部按钮栏 */
.btn-bar {
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  position: relative;
  height: 44px;
  gap: 6px;
}

.btn-bar button {
  background: var(--panel);
  border: 1px solid var(--border-dark);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-bar button:hover {
  background: var(--hover);
  border-color: var(--primary);
}

.view-switch {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  gap: 2px;
}
.view-btn {
  transition: all 0.2s !important;
}
.view-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary-dark);
}

.right-tools {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* 文件标签 */
.file-list {
  height: 30px;
  padding: 0 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  overflow-x: auto;
  overflow-y: hidden;
  flex-wrap: nowrap !important;
  white-space: nowrap;
  gap: 6px;
}

#fileItems {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap !important;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  height: 22px;
  background: var(--hover);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
}
.file-item:hover {
  background: var(--primary);
  color: #fff;
}
.file-close {
  width: 14px;
  height: 14px;
  line-height: 14px;
  text-align: center;
  font-size: 12px;
  color: var(--text-light);
  border-radius: 2px;
  cursor: pointer;
  transition: all 0.2s;
}
.file-close:hover {
  background: #ef4444;
  color: #fff;
}

/* 编辑器容器（含行号） */
.editor-container {
  display: flex;
  width: 100vw;
  height: calc(100vh - 74px);
  gap: 8px;
  padding: 8px;
  transition: all 0.3s ease;
}

/* 行号 + 编辑区 wrapper */
.edit-wrapper {
  position: relative;
  width: 50%;
  height: 100%;
}

/* ========== 编辑区行号 独立CLASS，不影响代码块 ========== */
.editor-lines {
  position: absolute;
  top: 0;
  left: 0;
  width: 40px;
  height: 100%;
  background: var(--hover);
  border-right: 1px solid var(--border);
  color: var(--text-light);
  font-family: Consolas, monospace;
  font-size: 14px;
  line-height: 1.6;
  text-align: right;
  padding: 12px 4px;
  overflow: hidden;
  user-select: none;
  z-index: 2;
  white-space: pre;
}

/* 编辑区当前行高亮背景 */
.current-line-highlight {
  position: absolute;
  left: 50px;
  width: calc(100% - 50px);
  height: 22.4px;
  background: rgba(59, 130, 246, 0.15);
  pointer-events: none;
  z-index: 1;
  display: none;
}

.edit-area {
  width: 100%;
  height: 100%;
  border: 1px solid var(--border-dark);
  background: var(--panel);
  padding: 12px 12px 12px 55px;
  font-family: Consolas, "Microsoft YaHei", monospace;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  border-radius: 6px;
  resize: none;
  outline: none;
  overflow-y: auto;
  transition: all 0.15s ease;
  position: relative;
  z-index: 0;
}

.preview-area {
  width: 50%;
  height: 100%;
  border: 1px solid var(--border-dark);
  background: var(--panel);
  padding: 16px;
  border-radius: 6px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  transition: all 0.3s ease;
}

/* 视图切换 */
.container-only-edit .edit-wrapper { width: 100% !important; }
.container-only-edit .preview-area { width: 0% !important; padding: 0; border: 0; overflow: hidden; }

.container-only-preview .preview-area { width: 100% !important; }
.container-only-preview .edit-wrapper { width: 0% !important; padding: 0; border: 0; overflow: hidden; }

/* 预览区内部缩放 */
.preview-inner {
  transform-origin: top left;
  width: 100%;
  transition: transform 0.2s ease;
}

/* Markdown 渲染美化（暗黑适配） */
.preview-inner h1 { font-size: 24px; margin: 16px 0 12px; color: var(--text); }
.preview-inner h2 { font-size: 20px; margin: 14px 0 10px; color: var(--text); }
.preview-inner h3 { font-size: 18px; margin: 12px 0 8px; color: var(--text); }
.preview-inner h4 { font-size: 16px; margin: 10px 0 6px; color: var(--text); }

.preview-inner p { margin: 0.6em 0; }
.preview-inner strong { font-weight: 600; }
.preview-inner em { font-style: italic; }

.preview-inner ul,
.preview-inner ol {
  padding-left: 28px;
  margin: 8px 0;
}
.preview-inner li { margin: 4px 0; }

.preview-inner blockquote {
  border-left: 4px solid var(--primary);
  background: var(--hover);
  padding: 10px 14px;
  margin: 10px 0;
  border-radius: 0 4px 4px 0;
  color: var(--text);
}

.preview-inner table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  background: var(--panel);
}
.preview-inner th,
.preview-inner td {
  border: 1px solid var(--border);
  padding: 8px 12px;
}
.preview-inner th {
  background: var(--hover);
  font-weight: 600;
}
.preview-inner tr:hover {
  background: var(--hover);
}

/* 行内代码 */
.preview-inner code {
  background: var(--hover);
  color: var(--primary);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: Consolas, monospace;
  font-size: 0.9em;
}

/* 代码块 */
.preview-inner pre {
  background: var(--code-bg);
  color: var(--code-color);
  padding: 12px;
  border-radius: 6px;
  margin: 10px 0;
  overflow-x: auto;
  transition: all 0.3s;
}
.preview-inner pre code {
  background: transparent;
  color: inherit;
}

.preview-inner img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: 10px 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.preview-inner hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* 弹窗 */
.modal {
  display: none;
  position: fixed;
  z-index: 999;
  left: 0; top: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.5);
}
.modal-content {
  background: var(--panel);
  margin: 8% auto;
  padding: 24px;
  width: 600px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  color: var(--text);
}
.close-modal {
  float: right;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-light);
}

/* 任务列表 */
.preview-inner input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-dark);
  border-radius: 3px;
  margin-right: 6px;
  cursor: pointer;
  position: relative;
  vertical-align: middle;
  transition: all 0.2s;
}

.preview-inner input[type="checkbox"]:checked {
  background-color: #10b981;
  border-color: #10b981;
}

.preview-inner input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 30%;
  width: 4px;
  height: 8px;
  margin-left: -2px;
  margin-top: -4px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.preview-inner input[type="checkbox"]:hover {
  border-color: #10b981;
}

.preview-inner li:has(input[type="checkbox"]) {
  list-style: none;
  margin-left: -24px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* 手机端适配 */
@media (max-width: 768px) {
  .btn-bar {
    height: auto;
    flex-wrap: wrap;
    justify-content: center;
    padding: 6px 8px;
    gap: 4px;
  }

  .view-switch {
    position: static;
    transform: none;
    margin: 4px 0;
  }

  .right-tools {
    width: 100%;
    justify-content: center;
    margin-top: 4px;
    gap: 6px;
  }

  .editor-container {
    flex-direction: column;
    height: calc(100vh - 130px);
    padding: 6px;
    gap: 6px;
  }

  .edit-wrapper,
  .preview-area {
    width: 100% !important;
    height: 50%;
  }

  .edit-area {
    padding-left: 40px;
  }

  .modal-content {
    width: 92%;
    margin: 20% auto;
    padding: 16px;
  }
}

/* 缩放文字固定宽度 */
#zoomText {
  display: inline-block;
  width: 40px;
  text-align: right;
}