/* ============================================================
   公众号排版 · 界面样式
   内容预览的样式由 packages/wechat-render 生成的内联样式决定,
   这里只管工具本身。所有可见文字不小于 12px。
   ============================================================ */

:root {
  --bg: #efece5;
  --bg-dot: rgba(29, 28, 25, 0.075);
  --surface: #fffefb;
  --surface-2: #f4f1ea;
  --surface-3: #ece8df;
  --ink: #1d1c19;
  --ink-2: #4c4942;
  --muted: #7b776e;
  --border: #ded9cf;
  --border-strong: #c7c0b3;
  --accent: #1f6f4a;
  --accent-ink: #ffffff;
  --accent-soft: #e3efe8;
  --danger: #b44533;
  --shadow-1: 0 1px 2px rgba(29, 28, 25, 0.06);
  --shadow-2: 0 18px 48px -18px rgba(29, 28, 25, 0.32), 0 2px 8px rgba(29, 28, 25, 0.05);
  --radius: 10px;
  --radius-lg: 16px;
  --font-ui: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, "Courier New", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121413;
    --bg-dot: rgba(236, 233, 226, 0.055);
    --surface: #1a1c1a;
    --surface-2: #222522;
    --surface-3: #2a2e2a;
    --ink: #ece9e2;
    --ink-2: #c4c0b6;
    --muted: #928e84;
    --border: #333731;
    --border-strong: #4a4f47;
    --accent: #79c49b;
    --accent-ink: #0f2418;
    --accent-soft: #20342a;
    --danger: #e28370;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-2: 0 20px 50px -18px rgba(0, 0, 0, 0.7), 0 2px 8px rgba(0, 0, 0, 0.3);
  }
}

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

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
::selection { background: var(--accent-soft); color: var(--ink); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 5px;
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.noscript {
  margin: 0;
  padding: 14px 18px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  color: var(--ink-2);
  font-size: 13px;
  text-align: center;
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-sm { width: 15px; height: 15px; }
.icon-xs { width: 12px; height: 12px; stroke-width: 2.2; }

/* ---------------- 顶栏 ---------------- */
.topbar {
  flex: none;
  height: 62px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--accent) 90%, #ffffff 10%), var(--accent));
  color: var(--accent-ink);
  font-family: "Songti SC", "Noto Serif SC", "SimSun", serif;
  font-size: 21px;
  font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 4px 12px -4px color-mix(in srgb, var(--accent) 60%, transparent);
}

.brand-text { min-width: 0; }
.brand-text h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.25;
  white-space: nowrap;
}
.brand-text p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.top-actions { display: flex; align-items: center; gap: 8px; min-width: 0; }

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.12s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: color-mix(in srgb, var(--accent) 80%, #000 20%);
  box-shadow: 0 3px 10px -3px color-mix(in srgb, var(--accent) 60%, transparent);
}
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000 12%); }
.btn-primary.copied { background: #2b6cb0; border-color: #245a94; }

.btn-soft {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--ink);
}
.btn-soft:hover { background: var(--surface-3); border-color: var(--border-strong); }

.btn-ghost { color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); }

.btn-square { width: 34px; padding: 0; }
.btn-block { width: 100%; }

.link-btn {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}
.link-btn:hover { text-decoration: underline; }

/* ---------------- 主题触发 ---------------- */
.theme-trigger { padding: 0 10px; }
.theme-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  background: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

/* ---------------- 下拉菜单 ---------------- */
.menu-wrap { position: relative; }

.menu {
  position: absolute;
  top: calc(100% + 7px);
  right: 0;
  min-width: 196px;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  box-shadow: var(--shadow-2);
  z-index: 40;
}
.menu[hidden] { display: none; }
.menu button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 9px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-2);
  font-size: 13px;
  text-align: left;
}
.menu button:hover { background: var(--surface-2); color: var(--ink); }
.menu button.danger { color: var(--danger); }
.menu button.danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }
.menu-sep { height: 1px; margin: 4px 6px; background: var(--border); }

/* ---------------- 移动端切换 ---------------- */
.mobile-switch {
  display: none;
  flex: none;
  align-items: center;
  gap: 3px;
  height: 40px;
  padding: 5px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.mobile-switch button {
  flex: 1;
  height: 29px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.mobile-switch button.active { background: var(--surface-2); color: var(--ink); box-shadow: var(--shadow-1); }

/* ---------------- 工作区 ---------------- */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.pane-editor { background: var(--surface); border-right: 1px solid var(--border); }
.pane-preview { background: var(--bg); }

.pane-head {
  flex: none;
  min-height: 46px;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
}

.pane-title {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: none;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink-2);
  white-space: nowrap;
}
.pane-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--border-strong); }
.pane-dot.green { background: var(--accent); }
.pane-hint {
  margin-left: 3px;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  letter-spacing: 0;
  max-width: 14em;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pane-tools {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.pane-tools::-webkit-scrollbar { display: none; }

.tool {
  flex: none;
  height: 27px;
  padding: 0 7px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}
.tool:hover { background: var(--surface-2); color: var(--ink); }
.tool:active { background: var(--surface-3); }
.tool-strong { font-weight: 800; }
.tool-em { font-family: Georgia, "Times New Roman", serif; font-style: italic; font-size: 14px; }
.tool-sep { flex: none; width: 1px; height: 16px; margin: 0 3px; background: var(--border); }

/* ---------------- 编辑器 ---------------- */
.editor {
  flex: 1;
  width: 100%;
  min-height: 0;
  padding: 22px 24px 48px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--ink-2);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.8;
  tab-size: 2;
  caret-color: var(--accent);
}
.editor::placeholder { color: var(--muted); }

.pane-foot {
  flex: none;
  min-height: 33px;
  padding: 5px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12px;
  color: var(--muted);
}
.foot-note { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-state { flex: none; display: inline-flex; align-items: center; gap: 5px; }
.save-state::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
}
.save-state.saving::before { background: #c9973f; }
.save-state.error { color: var(--danger); }
.save-state.error::before { background: var(--danger); }

/* ---------------- 预览 ---------------- */
.preview-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 22px 18px 34px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  background-image: radial-gradient(circle, var(--bg-dot) 1px, transparent 1px);
  background-size: 22px 22px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.device {
  width: 390px;
  max-width: 100%;
  flex: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow-2);
  transition: width 0.22s ease, border-color 0.2s ease;
}
.device[data-view="wide"] { width: 720px; }

.device-bar {
  height: 36px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}
.device-dots { display: inline-flex; gap: 4px; }
.device-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--border-strong); }
.device-label { flex: 1; text-align: center; letter-spacing: 0.1em; }
.device-theme { flex: none; font-size: 12px; }

.device.is-dark { border-color: #2c3034; }
.device.is-dark .device-bar { background: #0f1114; border-bottom-color: #262a2e; color: #928e84; }
.device.is-dark .device-dots i { background: #3a3f45; }

/* 预览里的文章要按微信的默认盒模型来,否则表格/内边距会和粘贴后的结果不一致。
   页面自己的 * { box-sizing: border-box } 不应该渗进文章内容。 */
.article, .article * { box-sizing: content-box; }
.article { min-height: 300px; }

.preview-note {
  margin: 0;
  max-width: 34em;
  text-align: center;
  font-size: 12px;
  line-height: 1.65;
  color: var(--muted);
}

/* ---------------- 状态栏 ---------------- */
.statusbar {
  flex: none;
  height: 33px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.status-left, .status-right { display: flex; align-items: center; gap: 9px; min-width: 0; }
.sep { width: 1px; height: 11px; background: var(--border); flex: none; }
.status-brand { letter-spacing: 0.08em; color: var(--border-strong); }

.spec-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.spec-badge.pass { color: var(--accent); background: var(--accent-soft); }
.spec-badge.warn { color: #8a5a12; background: #f8ecd7; }
.warn-mark {
  width: 12px;
  height: 12px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: currentColor;
  color: var(--surface);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}
@media (prefers-color-scheme: dark) {
  .spec-badge.warn { color: #e6b86f; background: #3a2e1b; }
}

/* ---------------- 主题抽屉 ---------------- */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(12, 12, 10, 0.36);
  opacity: 0;
  transition: opacity 0.22s ease;
}
.scrim[hidden] { display: none; }
.scrim.open { opacity: 1; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 60;
  width: 400px;
  max-width: 100vw;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -20px 0 60px -24px rgba(0, 0, 0, 0.45);
  transform: translateX(102%);
  transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.drawer[hidden] { display: none; }
.drawer.open { transform: none; }

.drawer-head {
  flex: none;
  padding: 16px 18px 14px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}
.drawer-head h2 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: 0.01em; }
.drawer-head p { margin: 3px 0 0; font-size: 12px; color: var(--muted); }

.drawer-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 18px 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.drawer-section { display: flex; flex-direction: column; gap: 10px; }

.section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ink-2);
  text-transform: uppercase;
}
.section-note { font-size: 12px; font-weight: 400; letter-spacing: 0; color: var(--muted); text-transform: none; }

.theme-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.theme-card {
  display: block;
  width: 100%;
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  text-align: left;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.theme-card:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.theme-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.theme-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.theme-mini {
  height: 78px;
  padding: 10px 11px;
  border-radius: 7px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  overflow: hidden;
}
.tm-kicker { display: block; width: 38%; height: 5px; border-radius: 2px; margin-bottom: 8px; }
.tm-title { display: block; width: 64%; height: 7px; border-radius: 2px; margin-bottom: 7px; }
.tm-line { display: block; height: 4px; border-radius: 2px; margin-bottom: 4px; opacity: 0.45; }
.tm-line.w80 { width: 80%; }
.tm-line.w64 { width: 64%; }
.tm-code { display: flex; gap: 3px; align-items: center; height: 13px; margin-top: 7px; padding: 0 5px; border-radius: 3px; }
.tm-code i { width: 3px; height: 3px; border-radius: 50%; }

.theme-meta { padding: 7px 3px 1px; }
.theme-name { display: block; font-size: 13px; font-weight: 700; color: var(--ink); }
.theme-tagline {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.accent-row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.accent-swatch {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px var(--surface);
}
.accent-swatch.active { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); border-color: transparent; }
.accent-custom {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
}
.accent-custom input {
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
}
.accent-custom input::-webkit-color-swatch-wrapper { padding: 0; }
.accent-custom input::-webkit-color-swatch { border: 1px solid var(--border); border-radius: 50%; }

.seg {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}
.seg button {
  height: 26px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.seg button:hover { color: var(--ink); }
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
.seg-wide { display: flex; }
.seg-wide button { flex: 1; }

.chip {
  height: 27px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.chip:hover { border-color: var(--border-strong); color: var(--ink); }
.chip.active { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 30%, transparent); color: var(--accent); }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
  cursor: pointer;
}
.switch-row:last-of-type { border-bottom: 0; }
.switch-row > span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.switch-row b { font-size: 13px; font-weight: 600; color: var(--ink); }
.switch-row small { font-size: 12px; line-height: 1.55; color: var(--muted); }

input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 38px;
  height: 21px;
  margin: 0;
  border-radius: 999px;
  background: var(--border-strong);
  position: relative;
  cursor: pointer;
  transition: background-color 0.18s ease;
}
input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
}
input[type="checkbox"]:checked { background: var(--accent); }
input[type="checkbox"]:checked::after { transform: translateX(17px); }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 48px;
  z-index: 100;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  text-align: center;
  box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.warn { background: #7a3b13; color: #fff6ea; }

/* ---------------- 响应式 ---------------- */
@media (max-width: 980px) {
  .brand-text p { display: none; }
  .pane-head { flex-wrap: nowrap; }
  .pane-hint { display: none; }
}

@media (max-width: 860px) {
  .topbar { height: 58px; padding: 0 12px; gap: 10px; }
  .brand-mark { width: 34px; height: 34px; font-size: 19px; }
  .mobile-switch { display: flex; }
  .workspace { grid-template-columns: 1fr; }
  .workspace[data-mobile="editor"] .pane-preview { display: none; }
  .workspace[data-mobile="preview"] .pane-editor { display: none; }
  .pane-editor { border-right: 0; }
  .device[data-view="wide"] { width: 100%; }
  .editor { padding: 18px 16px 40px; }
  .preview-scroll { padding: 16px 12px 26px; }
  .status-brand { display: none; }
  .statusbar { padding: 0 12px; }
  .theme-trigger { padding: 0 9px; }
}

@media (max-width: 560px) {
  .brand-text h1 { font-size: 15px; }
  .copy-label { display: none; }
  #copyBtn { width: 36px; padding: 0; }
  .theme-trigger #themeName { display: none; }
  .theme-trigger { width: 34px; padding: 0; }
  .pane-tools { gap: 0; }
  .tool { padding: 0 6px; }
  .preview-note { display: none; }
  .device { border-radius: 16px; }
  .foot-note { display: none; }
  .pane-foot { justify-content: flex-end; }
  .drawer-body { padding: 16px 14px 28px; }
  .theme-grid { gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.001ms !important; animation-duration: 0.001ms !important; }
}
