:root {
  --color-primary: #0f172a;
  --color-secondary: #334155;
  --color-tertiary: #64748b;
  --color-accent: #315efb;
  --color-bg: #eef3fb;
  --color-surface: #ffffff;
  --color-border: #d6deea;
  --color-light-border: #e6edf7;
  --bg-primary: #ffffff;
  --bg-secondary: #f4f7fd;
  --border-color: #d6deea;
  --primary-color: #315efb;
  --text-primary: #0f172a;
  --text-muted: #64748b;
  --space-unit: 8px;
  --space-xs: calc(var(--space-unit) * 1);
  --space-sm: calc(var(--space-unit) * 2);
  --space-md: calc(var(--space-unit) * 3);
  --space-lg: calc(var(--space-unit) * 4);
  --space-xl: calc(var(--space-unit) * 6);
  /* 不引入外链 Web 字体，保证无翻墙环境可离线/弱网使用；中文以系统黑体为准 */
  --font-sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Source Han Sans SC",
    "Source Han Sans CN", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "Segoe UI Mono", Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  --shadow-soft: 0 8px 22px rgba(15, 23, 42, 0.06);
  --shadow-deep: 0 18px 50px rgba(36, 63, 119, 0.16);
  --pane-padding-x: 24px;
  --pane-padding-y: 16px;
  --pane-edge-padding: 24px;
  --pane-seam-padding: 10px;
}

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

html {
  height: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--color-primary);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #f0f2f5;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  background: transparent;
}

/* ── App header（与 cover/index.html 顶栏一致；工具栏在顶栏右侧） ── */
.app-header {
  min-height: 52px;
  height: auto;
  flex: none;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  padding: 8px 20px;
  gap: 12px;
  flex-wrap: wrap;
}

.home-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  color: #9ca3af;
  text-decoration: none;
  flex: none;
  transition: background 0.15s, color 0.15s;
}

.home-link:hover {
  background: #f3f4f6;
  color: #374151;
}

.header-logo {
  font-size: 14px;
  font-weight: 700;
  color: #111;
  font-family: sans-serif;
  letter-spacing: 0.02em;
  flex: none;
}

/* 与 cover/index.html .header-ratio 一致：标题右侧元信息 */
.header-ratio {
  font-size: 11px;
  font-family: sans-serif;
  color: #9ca3af;
  letter-spacing: 0.06em;
  text-transform: none;
  background: #f3f4f6;
  padding: 3px 8px;
  border-radius: 4px;
  flex: none;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.header-spacer {
  flex: 1;
}

/* 顶栏右侧：上传、样式、复制（与 cover 页 .btn 一致） */
.app-header-tools {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

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

.header-style-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  min-width: 0;
}

.header-style-label {
  font-size: 10px;
  font-weight: 700;
  color: #9ca3af;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-family: sans-serif;
  white-space: nowrap;
}

.header-style-select {
  min-width: 132px;
  max-width: min(220px, 36vw);
  padding: 7px 9px;
  font-size: 12px;
  font-family: sans-serif;
  color: #111;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.header-style-select:hover:not(:disabled) {
  border-color: #d1d5db;
}

.header-style-select:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
  background: #fff;
}

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

/* cover/index.html 同款按钮 */
.btn {
  padding: 7px 14px;
  font-size: 12px;
  cursor: pointer;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-family: sans-serif;
  letter-spacing: 0.02em;
  background: #f9fafb;
  color: #374151;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:hover:not(:disabled) {
  background: #f3f4f6;
  border-color: #d1d5db;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}

.btn-primary:hover:not(:disabled) {
  background: #1d4ed8;
  border-color: #1d4ed8;
}

.app-header .upload-label-top {
  height: 32px;
  padding: 0 12px;
  font-size: 12px;
}

.creator-info {
  font-size: 11px;
  font-weight: 400;
  color: var(--color-tertiary);
  margin-left: 12px;
}

.creator-info a {
  color: var(--color-accent);
  text-decoration: none;
  transition: opacity 120ms;
}

.creator-info a:hover {
  opacity: 0.7;
}

.header-links {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.header-link {
  font-size: 13px;
  color: var(--color-secondary);
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  transition: all 120ms;
}

.header-link:hover {
  color: var(--color-primary);
  background: var(--color-bg);
  border-color: var(--color-border);
}

.header-link.primary {
  color: #fff;
  background: var(--color-accent);
  border-color: var(--color-accent);
  font-weight: 600;
}

.header-link.primary:hover {
  background: #0052cc;
  border-color: #0052cc;
  color: #fff;
}

.styles-section {
  grid-column: 1 / -1;
  padding: 12px calc(26px + env(safe-area-inset-right, 0px)) 12px calc(26px + env(safe-area-inset-left, 0px));
  border-bottom: 1px solid var(--color-light-border);
  background: rgba(248, 251, 255, 0.92);
  backdrop-filter: blur(10px);
}

.styles-container {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.styles-left,
.styles-right {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
  min-width: 0;
}

.styles-right {
  justify-content: flex-end;
  flex: 1 1 auto;
}

.styles-label {
  font-size: 12px;
  color: var(--color-tertiary);
  font-weight: 500;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.style-select {
  min-width: 160px;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-surface);
  color: var(--color-primary);
  font-size: 13px;
}

.style-select:focus {
  outline: none;
  border-color: var(--color-accent);
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-surface);
  color: var(--color-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: transform 120ms, border-color 120ms, color 120ms, background 120ms, box-shadow 120ms;
}

.toolbar-btn:hover {
  border-color: var(--color-accent);
  background: #f6f9ff;
  color: var(--color-primary);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(49, 94, 251, 0.12);
}

.toolbar-btn svg {
  width: 16px;
  height: 16px;
}

.toolbar-btn.primary {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-surface);
  box-shadow: 0 8px 20px rgba(49, 94, 251, 0.28);
}

.toolbar-btn.primary:hover {
  background: #2b52dd;
  border-color: #2b52dd;
  color: var(--color-surface);
}

.main-content {
  display: grid;
  grid-template-columns: minmax(0, 0.46fr) minmax(0, 0.54fr);
  grid-template-rows: minmax(0, 1fr);
  flex: 1;
  min-height: 0;
  align-items: stretch;
  overflow: hidden;
}

.editor-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid #e5e7eb;
  overflow: hidden;
  background: #fff;
  position: relative;
}

.editor-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  justify-content: flex-end;
}

/* 与右侧 .preview-content 同高：flex 占位 + min-height:0，避免 textarea 默认行高撑破对齐 */
.markdown-input-container {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  padding: 0;
  background: transparent;
}

.markdown-input {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  padding: var(--space-lg);
  border: none;
  border-radius: 0;
  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 1.6;
  resize: none;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--color-surface);
  color: var(--color-primary);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.95), 0 8px 20px rgba(39, 64, 121, 0.07);
  transition: border-color 120ms, box-shadow 120ms, background-color 120ms;
}

.markdown-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(49, 94, 251, 0.18), 0 14px 30px rgba(49, 94, 251, 0.14);
}

.markdown-input.drag-over {
  background: var(--color-bg);
  border-color: var(--color-accent);
  box-shadow: 0 0 0 4px rgba(0, 102, 255, 0.1);
}

.upload-label {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-surface);
  color: var(--color-secondary);
  font-size: 13px;
  transition: transform 120ms, border-color 120ms, color 120ms, background 120ms;
}

.upload-label-top {
  height: 40px;
  padding: 0 12px;
  white-space: nowrap;
  flex-shrink: 0;
}

.upload-label:hover {
  background: var(--color-surface);
  border-color: var(--color-accent);
  color: var(--color-accent);
  transform: translateY(-1px);
}

.preview-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: #fff;
  position: relative;
}

.mode-switcher {
  display: flex;
  gap: 4px;
  background: var(--color-bg);
  border-radius: 6px;
  padding: 2px;
}

.mode-toggle-btn {
  padding: 6px 12px;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--color-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 120ms;
  display: flex;
  align-items: center;
  gap: 4px;
  text-transform: none;
  font-weight: normal;
}

.mode-toggle-btn:hover {
  color: var(--color-primary);
}

.mode-toggle-btn.active {
  background: var(--color-surface);
  color: var(--color-primary);
  font-weight: 500;
}

.mode-toggle-btn svg {
  width: 14px;
  height: 14px;
}

/* 桌面端：顶栏工具不换行 */
@media (min-width: 901px) {
  .app-header-tools {
    flex-wrap: nowrap;
  }

  .app-header .editor-actions {
    flex-wrap: nowrap;
  }

  .header-copy-actions {
    flex-wrap: nowrap;
  }
}

.markdown-input-container,
.preview-content {
  flex: 1 1 0;
  min-height: 0;
}

.preview-content {
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  background: linear-gradient(180deg, #f8fbff 0%, #eef3fb 100%);
  position: relative;
}

/* 左右可滚动但不显示滚动条（仍可滚轮 / 触控滑动） */
.markdown-input,
.preview-content {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.markdown-input::-webkit-scrollbar,
.preview-content::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.preview-container {
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: var(--pane-padding-y) var(--pane-padding-x) 60px var(--pane-padding-x);
  line-height: 1.8;
  position: relative;
  box-sizing: border-box;
  animation: contentFadeIn 260ms ease-out;
}

@keyframes contentFadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.preview-container.layout-mode img {
  cursor: pointer;
  transition: all 120ms;
}

.preview-container.layout-mode img:hover {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.image-control-panel {
  background: white;
  border: 2px solid var(--color-accent);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  padding: 16px;
  animation: fadeIn 200ms ease-out;
  min-width: 300px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.control-panel-inner {
  display: flex;
  gap: 16px;
  align-items: center;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-group label {
  font-size: 12px;
  color: var(--color-secondary);
  font-weight: 500;
}

.width-slider {
  width: 120px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--color-border);
  border-radius: 2px;
  outline: none;
}

.width-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  background: var(--color-accent);
  border-radius: 50%;
  cursor: pointer;
}

.width-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  background: var(--color-accent);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

.width-value {
  font-size: 11px;
  color: var(--color-tertiary);
  font-family: var(--font-mono);
  min-width: 45px;
}

.align-buttons {
  display: flex;
  gap: 4px;
}

.align-buttons button {
  width: 24px;
  height: 24px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: all 120ms;
  display: flex;
  align-items: center;
  justify-content: center;
}

.align-buttons button:hover {
  background: var(--color-bg);
  border-color: var(--color-accent);
}

.align-buttons button.active {
  background: var(--color-accent);
  color: var(--color-surface);
  border-color: var(--color-accent);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--color-tertiary);
  animation: contentFadeIn 280ms ease-out;
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  margin-bottom: var(--space-lg);
  opacity: 0.3;
}

.empty-state h3 {
  font-size: 15px;
  font-weight: 500;
  color: var(--color-secondary);
  margin-bottom: var(--space-xs);
}

.empty-state p {
  font-size: 13px;
  color: var(--color-tertiary);
}

.xiaohongshu-preview {
  padding: var(--space-lg);
  overflow-y: auto;
}

.xiaohongshu-controls {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
  justify-content: center;
  flex-wrap: wrap;
}

.xiaohongshu-btn {
  padding: 8px 16px;
  background: var(--color-primary);
  color: var(--color-surface);
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 120ms;
}

.xiaohongshu-btn:hover {
  opacity: 0.8;
}

.xiaohongshu-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.xiaohongshu-btn.secondary {
  background: var(--color-surface);
  color: var(--color-primary);
  border: 1px solid var(--color-border);
}

.xiaohongshu-images-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-md);
  max-width: 1200px;
  margin: 0 auto;
}

.xiaohongshu-image-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: all 120ms;
  cursor: pointer;
}

.xiaohongshu-image-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.xiaohongshu-image-card img {
  width: 100%;
  height: auto;
  display: block;
}

.xiaohongshu-image-label {
  padding: var(--space-sm);
  text-align: center;
  font-size: 12px;
  color: var(--color-secondary);
  background: var(--color-bg);
}

.xiaohongshu-loading {
  text-align: center;
  padding: var(--space-xl);
  color: var(--color-secondary);
}

.xiaohongshu-empty {
  text-align: center;
  padding: var(--space-xl);
  color: var(--color-tertiary);
}

.toast {
  position: fixed;
  bottom: var(--space-lg);
  right: var(--space-lg);
  padding: var(--space-md) var(--space-lg);
  max-width: min(92vw, 360px);
  word-wrap: break-word;
  background: var(--color-primary);
  color: var(--color-surface);
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  z-index: 1000;
  animation: slideUp 200ms ease-out;
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.22);
  padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom, 0px));
}

@keyframes slideUp {
  from {
    transform: translateY(100px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.toast.success {
  background: #00C853;
}

.toast.error {
  background: #D32F2F;
}

.toast.warning {
  background: #e65100;
  color: #fff;
}

.toast.processing {
  background: #374151;
  color: #fff;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-tertiary);
}

@media (max-width: 900px) {
  :root {
    --pane-padding-x: 14px;
    --pane-padding-y: 12px;
    --pane-edge-padding: 14px;
    --pane-seam-padding: 14px;
  }

  body {
    height: auto;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #app {
    height: auto;
    min-height: 100dvh;
    max-height: none;
  }

  .app-header {
    position: sticky;
    top: 0;
    z-index: 30;
    height: auto;
    min-height: 48px;
    flex-wrap: wrap;
    row-gap: 8px;
    padding: 8px 12px;
  }

  .header-logo {
    font-size: 13px;
    flex: 1 1 140px;
    min-width: 0;
  }

  .header-ratio {
    font-size: 10px;
    padding: 2px 6px;
  }

  .header-spacer {
    display: none;
  }

  .app-header-tools {
    flex: 1 1 100%;
    justify-content: flex-start;
    align-items: stretch;
    gap: 8px;
  }

  .app-header .editor-actions {
    flex: 1 1 100%;
  }

  .header-style-tools {
    flex: 1 1 100%;
    min-width: 0;
  }

  .header-style-select {
    flex: 1;
    min-width: 0;
    max-width: none;
  }

  .header-copy-actions {
    flex: 1 1 100%;
    justify-content: flex-start;
  }

  .app-header .btn {
    padding: 6px 10px;
    font-size: 11px;
  }

  .header-links {
    gap: 6px;
  }

  .header-link {
    font-size: 11px;
    padding: 3px 6px;
  }

  .styles-section {
    padding: var(--space-xs) var(--space-sm);
  }

  .styles-left,
  .styles-right {
    width: 100%;
  }

  .style-select {
    width: 100%;
  }

  .upload-label-top {
    width: auto;
    justify-content: center;
  }

  .toolbar-btn-text {
    display: none;
  }

  .editor-panel {
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    max-height: none;
    min-height: 0;
  }

  .main-content {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, min(42vh, 400px)) minmax(0, 1fr);
  }

  .markdown-input-container {
    padding: 0;
  }

  .markdown-input {
    font-size: 13px;
    padding: var(--space-md);
  }

  .upload-label {
    width: 100%;
    justify-content: center;
  }

  .preview-panel {
    height: auto;
  }

  .preview-container {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 14px 14px 44px 14px;
  }

  .toast {
    left: var(--space-md);
    right: var(--space-md);
    bottom: var(--space-md);
  }
}

@media (min-width: 901px) and (max-width: 1024px) {
  #app {
    max-width: 100%;
  }

  .main-content {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .styles-section {
    padding: var(--space-sm) var(--space-lg);
  }

  .preview-container {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 16px 12px 40px 12px;
  }
}

/* 键盘焦点可见性（不改动鼠标点击外观） */
.app-header .toolbar-btn:focus-visible,
.toolbar-btn:focus-visible,
.app-header .btn:focus-visible,
.header-style-select:focus-visible,
.style-select:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* 编辑器保留 :focus 上的 ring，避免再叠一层 outline */

.upload-label:focus-within {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .preview-container,
  .empty-state,
  .image-control-panel,
  .toast {
    animation: none;
  }

  .toolbar-btn:hover,
  .upload-label:hover {
    transform: none;
  }
}
