* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }
  
  :root {
    /* 浅色模式 */
    --bg-body: #fafafa;
    --bg-pane: white;
    --bg-input: #fdfdfd;
    --bg-line-num: #f4f4f4;
    --text: #333;
    --text-secondary: #666;
    --border: #e0e0e0;
    --primary: #3498db;
    --primary-dark: #2980b9;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-strong: 0 8px 24px rgba(0, 0, 0, 0.15);
  }
  
  [data-theme="dark"] {
    /* 深色模式 */
    --bg-body: #121212;
    --bg-pane: #1e1e1e;
    --bg-input: #161616;
    --bg-line-num: #252526;
    --text: #e6e6e6;
    --text-secondary: #aaa;
    --border: #333;
    --primary: #4da4f3;
    --primary-dark: #348ae2;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-strong: 0 8px 24px rgba(0, 0, 0, 0.4);
  }
  
  body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text);
    line-height: 1.6;
    transition: background-color 0.3s, color 0.3s;
  }
  
  /* ============== Header ============== */
  header {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    padding: 1rem 2rem;
    box-shadow: var(--shadow);
  }
  
  .header-content {
    max-width: none;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
  }
  
  .title-group h1 {
    font-size: 2rem;
    margin: 0;
  }
  
  .title-group p {
    opacity: 0.9;
    font-size: 1rem;
    margin-top: 0.3rem;
  }
  
  /* ============== 工具栏 ============== */
  .toolbar {
    display: flex;
    align-items: center;
    gap: 1rem;
  }
  
  /* 深色模式开关 */
  .theme-toggle {
    width: 52px; /* ✅ 修复 2：从 44px → 52px */
    height: 26px; /* 微调高度 */
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 13px;
    position: relative;
    cursor: pointer;
    outline: none;
    display: flex;
    align-items: center;
    padding: 0 6px; /* ✅ 增加内边距 */
    transition: background 0.3s;
  }
  
  .theme-toggle::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    top: 3px;
    left: 4px;
    transition: transform 0.3s;
  }
  
  [data-theme="dark"] .theme-toggle::after {
    transform: translateX(24px);
  }
  
  .theme-toggle .sun-icon,
  .theme-toggle .moon-icon {
    position: absolute;
    font-size: 12px;
    pointer-events: none;
  }
  
  .theme-toggle .sun-icon {
    left: 10px; /* ✅ 右移避让 */
    color: #fbbf24;
  }
  
  .theme-toggle .moon-icon {
    right: 10px; /* ✅ 左移避让 */
    color: #cbd5e1;
  }
  
  /* 导出按钮 */
  .export-toolbar {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
  }
  
  .export-toolbar button {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    gap: 0.4rem;
  }
  
  .export-toolbar button:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: translateY(-2px);
  }
  
  .export-toolbar button:active {
    transform: translateY(0);
  }

  /* ============== Editor Container ============== */
  .editor-container {
    display: flex;
    min-height: calc(100vh - 180px);
    max-width: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: visible;
    box-shadow: var(--shadow);
    background: var(--bg-pane);
  }
  
  .pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: visible;
    min-height: 0;
  }
  
  .pane-header {
    background-color: var(--bg-pane);
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  
  .pane-header h2 {
    font-size: 1.2rem;
    color: var(--primary);
    font-weight: 600;
  }
  
  /* 编辑区工具栏 */
  .editor-toolbar {
    display: flex;
    gap: 6px;
  }
  
  .tool-btn {
    /* ✅ 修复 4：统一尺寸 & 居中 */
    width: 30px;
    height: 30px;
    background: #f1f1f1;
    border: none;
    border-radius: 50%;
    font-weight: bold;
    cursor: pointer;
    color: #888;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px; /* 统一 icon 大小 */
    font-family: "Segoe UI Emoji", "Apple Color Emoji", sans-serif;
  }
  
  [data-theme="dark"] .tool-btn {
    background: #444;
    color: #ccc;
  }
  
  .tool-btn:hover {
    background: #007bff;
    color: white;
  }
  
  #clear-btn:hover {
    background: #ff6b6b;
    color: white;
  }

  footer {
    text-align: center;
    margin-top: 20px;
    color: var(--text-secondary);
    font-size: 0.9rem;
  }

  footer a,
  footer a:visited,
  footer a:hover,
  footer a:active {
    color: var(--text-secondary);
    text-decoration: none;
  }

  /* ============== 编辑区（含行号） ============== */
  .editor-wrapper {
    position: relative;
    flex: 1;
    display: flex;
    overflow: visible;
  }
  
  #line-numbers {
    width: 52px;
    text-align: right;
    padding: 16px 8px 16px 6px;
    background-color: var(--bg-line-num);
    color: var(--text-secondary);
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 14px;
    line-height: 1.5;
    user-select: none;
    border-right: 1px solid var(--border);
  }
  
  .line-numbers .line {
    display: block;
    min-height: calc(1.5em);
  }
  
  /* 高亮样式 */
  .line-numbers .line.hover {
    background-color: rgba(52, 152, 219, 0.1);
    color: var(--primary);
    position: relative;
  }
  .line-numbers .line.hover::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--primary);
    border-radius: 0 2px 2px 0;
  }
  
  .line-numbers .line.selected {
    background-color: rgba(52, 152, 219, 0.2);
    color: var(--primary);
  }
  
  #markdown-input {
    flex: 1;
    padding: 16px;
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    outline: none;
    border: none;
    background-color: var(--bg-input);
    color: var(--text);
    tab-size: 2;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: pre; /* ← 关键：禁止自动换行 */
  }
  
  #markdown-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
  }
  
  /* ============== 预览区 ============== */
  .preview-content {
    flex: 1;
    padding: 20px;
    overflow-x: auto;
    overflow-y: visible;
    background-color: var(--bg-input);
    color: var(--text);
    font-size: 16px;
    word-break: break-word;
  }
  
  /* Markdown 渲染样式 */
  .preview-content h1,
  .preview-content h2,
  .preview-content h3,
  .preview-content h4,
  .preview-content h5,
  .preview-content h6 {
    margin-top: 1.5em;
    margin-bottom: 0.8em;
    color: var(--primary-dark);
    font-weight: 700;
  }
  
  .preview-content h1 {
    font-size: 2em;
    border-bottom: 2px solid var(--primary);
    padding-bottom: 0.3em;
  }
  
  .preview-content h2 {
    font-size: 1.6em;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.3em;
  }
  
  .preview-content p {
    margin: 1em 0;
  }
  
  .preview-content ul,
  .preview-content ol {
    padding-left: 2em;
    margin: 1em 0;
  }
  
  .preview-content li {
    margin: 0.4em 0;
  }
  
  .preview-content a {
    color: var(--primary);
    text-decoration: none;
  }
  
  .preview-content a:hover {
    text-decoration: underline;
  }
  
  .preview-content code {
    background: #f0f0f0;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.95em;
  }
  
  [data-theme="dark"] .preview-content code {
    background: #3a3a3a;
  }
  
  .preview-content pre {
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 16px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 1.2em 0;
  }
  
  [data-theme="dark"] .preview-content pre {
    background: #1e1e1e;
  }
  
  .preview-content blockquote {
    border-left: 4px solid var(--primary);
    margin: 1.5em 0;
    padding: 0.5em 1em;
    background-color: #f8f9fa;
    font-style: italic;
  }
  
  [data-theme="dark"] .preview-content blockquote {
    background-color: #2a2a2a;
  }
  
  .preview-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5em 0;
  }
  
  .preview-content th,
  .preview-content td {
    border: 1px solid var(--border);
    padding: 0.6em 1em;
    text-align: left;
  }
  
  .preview-content th {
    background-color: #f1f8ff;
    font-weight: 600;
  }
  
  [data-theme="dark"] .preview-content th {
    background-color: #2a3a4a;
  }
  
  /* 分割线 */
  .divider {
    width: 4px;
    background-color: var(--border);
    user-select: none;
  }
  
  /* ============== 通用遮罩 ============== */
  .pdf-export-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
  }
  
  .pdf-export-popup {
    background: var(--bg-pane);
    padding: 1.5rem;
    border-radius: 10px;
    text-align: center;
    box-shadow: var(--shadow-strong);
    max-width: 90%;
    width: 400px;
    color: var(--text);
  }
  
  .pdf-export-popup h3 {
    color: var(--primary);
    margin-bottom: 0.8rem;
  }
  
  .pdf-export-popup p {
    margin-bottom: 1rem;
    color: var(--text-secondary);
  }
  
  .pdf-export-popup .spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
  }
  
  [data-theme="dark"] .pdf-export-popup .spinner {
    border-color: #444;
  }
  
  @keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
  }
  
  /* 响应式 */
  @media (max-width: 768px) {
    .editor-container {
      flex-direction: column;
      min-height: auto;
      height: auto;
      margin: 0 10px;
      margin-left: 10px;
    }
    .header-content {
      padding: 0 10px;
      padding-left: 10px;
    }
    .divider {
      width: 100%;
      height: 6px;
      cursor: row-resize;
    }
    #line-numbers {
      display: none;
    }
    .toolbar {
      flex-direction: column;
      align-items: flex-start;
    }
  }