:root {
  --bg: #f6f3ff;
  --card: #ffffff;
  --muted: #7e78a6;
  --text: #2c2459;
  --primary: #7f5af0;
  --ring: #d9cffb;

  --gap: 16px;
  --radius: 14px;
  --device-width: 390px;
}

* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica,
    Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    Noto Sans CJK SC, sans-serif;
  color: var(--text);
  background: radial-gradient(
      1200px 800px at 15% -10%,
      #efe9ff 0%,
      transparent 60%
    ),
    radial-gradient(900px 700px at 100% 0%, #f7f3ff 0%, transparent 60%),
    linear-gradient(180deg, #fbfaff, #f6f3ff 40%, #f3f0ff);
}

.app-header {
  padding: 18px 24px 10px;
}
.header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.header-actions {
  display: flex;
  gap: 14px;
}
.header-template select#tpl-select {
  font-size: 17px;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--ring), transparent 50%);
  background: #fff;
  box-shadow: 0 6px 18px rgba(17, 12, 46, 0.06);
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #7f5af0 50%),
    linear-gradient(135deg, #7f5af0 50%, transparent 50%),
    linear-gradient(to right, #ddd, #ddd);
  background-position: calc(100% - 20px) calc(50% - 3px),
    calc(100% - 15px) calc(50% - 3px), calc(100% - 40px) 50%;
  background-size: 5px 5px, 5px 5px, 1px 60%;
  background-repeat: no-repeat;
  padding-right: 44px;
}
.header-template {
  margin-right: 12px;
}
.app-header h1 {
  margin: 0 0 6px;
  font-size: 22px;
}
.app-header .sub {
  color: var(--muted);
  font-size: 13px;
}

.app {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
  padding: 0 24px 20px;
}
.pane-input {
  display: flex;
  flex-direction: column;
}
.controls-top {
  padding: 16px 12px 10px;
  border-bottom: 1px dashed color-mix(in srgb, var(--ring), transparent 40%);
}
.controls-top input#doc-title {
  width: 100%;
  max-width: 980px;
}
.controls-top-2 {
  padding: 12px;
  border-bottom: 1px dashed color-mix(in srgb, var(--ring), transparent 40%);
}
.pane-input .toolbar {
  margin-top: auto;
  position: sticky;
  bottom: 0;
  background: linear-gradient(0deg, rgba(127, 90, 240, 0.06), transparent);
}

.pane {
  background: color-mix(in srgb, var(--card), black 0%);
  border: 1px solid color-mix(in srgb, var(--ring), transparent 30%);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(127, 90, 240, 0.08);
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px;
  border-bottom: 1px solid color-mix(in srgb, var(--ring), transparent 40%);
  background: linear-gradient(180deg, rgba(127, 90, 240, 0.06), transparent);
}
.pane-head .actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.pane-head .actions .btn-ghost {
  margin-right: 0;
}
.pane-title {
  font-weight: 600;
}
.tips {
  color: var(--muted);
  font-size: 12px;
}

textarea#md-input {
  width: 100%;
  flex: 1 1 auto;
  height: 100%;
  padding: 14px;
  resize: vertical;
  min-height: 220px;
  color: var(--text);
  background: transparent;
  border: none;
  outline: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, "JetBrains Mono",
    Consolas, monospace;
  font-size: 14px;
  line-height: 1.7;
}

/* Markdown 工具栏（顶栏样式） */
#md-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}
#md-toolbar .btn {
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
}
#md-toolbar .sep {
  width: 1px;
  height: 22px;
  background: color-mix(in srgb, var(--ring), transparent 35%);
  margin: 0 2px;
}

.controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  padding: 0 12px 12px;
}
.control {
  display: flex;
  gap: 8px;
  align-items: center;
  background: rgba(127, 90, 240, 0.06);
  padding: 6px 10px;
  border-radius: 10px;
}
.control span {
  color: var(--muted);
  font-size: 12px;
}
select,
input[type="range"] {
  accent-color: var(--primary);
}

.toolbar {
  display: flex;
  gap: 10px;
  padding: 12px;
  border-top: 1px dashed color-mix(in srgb, var(--ring), transparent 35%);
  background: linear-gradient(0deg, rgba(127, 90, 240, 0.06), transparent);
}
.btn {
  appearance: none;
  border: 1px solid color-mix(in srgb, var(--ring), transparent 60%);
  background: rgba(127, 90, 240, 0.08);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
}
.btn:hover {
  border-color: color-mix(in srgb, var(--ring), transparent 20%);
}
.btn-primary {
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--primary), white 18%),
    var(--primary)
  );
  border-color: color-mix(in srgb, var(--primary), black 20%);
}
.btn-secondary {
  background: rgba(127, 90, 240, 0.12);
}
.btn-ghost {
  background: transparent;
}

/* 预览 iframe */
.pane-preview {
  height: 80vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.pane-preview iframe {
  width: min(var(--device-width), 100%);
  height: calc(100% - 54px - 58px);
  border: 0;
  background: #f7f8fa;
  border-radius: 20px;
  box-shadow: 0 8px 30px rgba(127, 90, 240, 0.12);
}

.controls-preview {
  padding: 10px 12px;
  border-bottom: 1px dashed color-mix(in srgb, var(--ring), transparent 40%);
}

.app-footer {
  padding: 12px 24px 24px;
  color: var(--muted);
  font-size: 12px;
  display: flex;
  gap: 12px;
  align-items: center;
}
.app-footer a {
  color: #7f5af0;
  text-decoration: none;
}

@media (max-width: 1000px) {
  .app {
    grid-template-columns: 1fr;
  }
  .pane-preview {
    height: 70vh;
  }
}

/* -------------------------
   模板基础：公众号容器与通用排版
   ------------------------- */
.wx-container {
  max-width: 780px;
  margin: 0 auto;
  padding: 28px 20px 80px;
  color: #2a2a2a;
  background: white;
}
.wx-container h1,
.wx-container h2,
.wx-container h3,
.wx-container h4,
.wx-container h5 {
  line-height: 1.35;
}
.wx-container h1 {
  font-size: 30px;
  margin: 0 0 18px;
}
.wx-container h2 {
  font-size: 24px;
  margin: 28px 0 12px;
}
.wx-container h3 {
  font-size: 20px;
  margin: 22px 0 10px;
}
.wx-container p {
  margin: 12px 0;
}
.wx-container a {
  color: inherit;
  text-decoration: underline;
}
.wx-container img {
  max-width: 100%;
  border-radius: 10px;
}
.wx-container blockquote {
  margin: 16px 0;
  padding: 12px 16px;
  border-left: 4px solid #eee;
  background: #fafafa;
  color: #333;
}
.wx-container code {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas,
    monospace;
  background: #f5f6f8;
  padding: 2px 6px;
  border-radius: 6px;
}
.wx-container pre code {
  display: block;
  padding: 16px;
  overflow: auto;
}
.wx-container table {
  width: 100%;
  border-collapse: collapse;
  margin: 18px 0;
  font-size: 14px;
}
.wx-container th,
.wx-container td {
  border: 1px solid #eceff3;
  padding: 10px 12px;
}
.wx-container thead th {
  background: #f6f8fb;
}
.wx-divider {
  height: 1px;
  background: #efeff4;
  margin: 24px 0;
}

/* -------------------------
   5 套主题模板
   ------------------------- */

/* 1. 雅致·墨蓝 */
.theme-elegant {
  --t-accent: #3056d3;
  --t-accent-weak: #e9eeff;
  --t-text: #1e2330;
  --t-muted: #5a6275;
  --t-bg-soft: #f5f7ff;
}
.theme-elegant .wx-header {
  padding: 26px 24px;
  border-radius: 16px;
  margin-bottom: 16px;
  color: #0f1a40;
  background: linear-gradient(180deg, #eef3ff, #e6ecff);
}
.theme-elegant .wx-header .title {
  font-size: 32px;
  font-weight: 700;
}
.theme-elegant .wx-header .desc {
  color: #4b5a86;
  margin-top: 6px;
}
.theme-elegant h2 {
  position: relative;
  padding-left: 14px;
}
.theme-elegant h2::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.45em;
  width: 6px;
  height: 0.9em;
  background: var(--t-accent);
  border-radius: 3px;
}
.theme-elegant a {
  color: var(--t-accent);
}
.theme-elegant blockquote {
  background: var(--t-bg-soft);
  border-left-color: var(--t-accent);
}
.theme-elegant .callout {
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--t-bg-soft);
  border: 1px dashed #d7def7;
}
.theme-elegant .tag {
  display: inline-block;
  background: var(--t-accent-weak);
  color: var(--t-accent);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
}

/* 2. 活力·橙阳 */
.theme-sunny {
  --t-accent: #ff7a1a;
  --t-accent-2: #ffd8b0;
  --t-text: #2a1e14;
}
.theme-sunny .wx-header {
  background: linear-gradient(180deg, #fff3e5, #ffe8d1);
  color: #6a2800;
  padding: 22px 20px;
  border-radius: 14px;
}
.theme-sunny h2 {
  border-bottom: 2px solid #ffe0c2;
  padding-bottom: 6px;
}
.theme-sunny a {
  color: #e85f00;
}
.theme-sunny blockquote {
  background: #fff5eb;
  border-left-color: #ffd1ad;
}
.theme-sunny .badge {
  display: inline-block;
  background: #fff1e3;
  color: #b64800;
  padding: 2px 8px;
  border: 1px solid #ffd9bf;
  border-radius: 8px;
  font-size: 12px;
}
.theme-sunny .divider {
  height: 2px;
  background: linear-gradient(90deg, #ffedd8, #ffd9bf);
  margin: 20px 0;
}

/* 3. 清新·森绿 */
.theme-forest {
  --t-accent: #2b9a66;
  --t-bg: #ecf8f2;
}
.theme-forest .wx-header {
  background: linear-gradient(180deg, #f0faf5, #e6f5ee);
  padding: 24px;
  border-radius: 16px;
  color: #0c3b27;
}
.theme-forest h2 {
  color: #0c5132;
}
.theme-forest blockquote {
  background: var(--t-bg);
  border-left-color: #7bd8ab;
}
.theme-forest .note {
  background: #f3fbf7;
  border: 1px solid #d7f2e5;
  padding: 12px 14px;
  border-radius: 12px;
}
.theme-forest .kbd {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid #cfe9dc;
  background: white;
  box-shadow: 0 1px 0 #cfe9dc;
  font-family: ui-monospace, "JetBrains Mono";
  font-size: 12px;
}

/* 4. 浪漫·紫雾 */
.theme-violet {
  --t-accent: #7f5af0;
  --t-mist: #f3efff;
}
.theme-violet .wx-header {
  background: linear-gradient(180deg, #f7f3ff, #efe9ff);
  padding: 22px;
  border-radius: 16px;
  color: #37276a;
}
.theme-violet h2 {
  position: relative;
}
.theme-violet h2::after {
  content: "";
  display: inline-block;
  margin-left: 8px;
  width: 28px;
  height: 8px;
  background: radial-gradient(circle at 50% 50%, #b9a4ff 0, transparent 70%);
}
.theme-violet a {
  color: #6a4ae0;
}
.theme-violet blockquote {
  background: var(--t-mist);
  border-left-color: #c8b8ff;
}
.theme-violet .quote {
  font-style: italic;
  color: #5b4aa8;
}

/* 5. 极简·纯白 */
.theme-minimal .wx-container {
  color: #1a1a1a;
}
.theme-minimal .wx-header {
  background: #ffffff;
  padding: 0;
  margin-bottom: 16px;
}
.theme-minimal h1 {
  font-weight: 700;
  letter-spacing: -0.02em;
}
.theme-minimal h2 {
  border-left: 4px solid #111;
  padding-left: 12px;
}
.theme-minimal blockquote {
  background: #fff;
  border-left-color: #111;
}
.theme-minimal .wx-divider {
  background: #111;
  height: 1px;
  opacity: 0.1;
}

/* 6. 简约·微信绿（参考微信风格：清爽留白 + 微信绿强调） */
.theme-wechat .wx-header {
  background: linear-gradient(180deg, #f6fffb, #f0fff7);
  padding: 22px 20px;
  border-radius: 16px;
  color: #0f5132;
}
.theme-wechat h2 {
  position: relative;
  padding-left: 12px;
  color: #0f5132;
}
.theme-wechat h2::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.5em;
  width: 6px;
  height: 0.9em;
  background: #07c160;
  border-radius: 3px;
}
.theme-wechat a {
  color: #0aa15a;
}
.theme-wechat blockquote {
  background: #f2fff8;
  border-left-color: #b8f1d0;
  color: #0f3d29;
}
.theme-wechat .wx-divider {
  height: 2px;
  background: linear-gradient(90deg, #e8fff2, #d8ffea);
}
.theme-wechat table thead th {
  background: #f1fff7;
}
.theme-wechat .tag {
  display: inline-block;
  background: #e9fff4;
  color: #099e59;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
}

/* 6. 对话·气泡（适合大量对话内容） */
.theme-dialog .wx-container {
  font-size: 17px;
  line-height: 1.9;
}
.theme-dialog .wx-header {
  background: linear-gradient(180deg, #f6f2ff, #efe9ff);
  padding: 18px 20px;
  border-radius: 14px;
  color: #493a93;
}
.theme-dialog .dialog {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  margin: 12px 0;
}
.theme-dialog .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: #ddd;
}
.theme-dialog .bubble {
  max-width: 80%;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid #eadfff;
}
.theme-dialog .bubble p {
  margin: 0;
}
.theme-dialog .bubble + .time {
  color: #9c90cf;
  font-size: 12px;
  margin-left: 44px;
}

/* 左右两侧气泡配色 */
.theme-dialog .left .bubble {
  background: #ffffff;
}
.theme-dialog .right {
  flex-direction: row-reverse;
}
.theme-dialog .right .bubble {
  background: #f6f1ff;
  border-color: #e6dcff;
}
.theme-dialog .right .time {
  text-align: right;
  margin-right: 44px;
}

/* 将 Markdown 普通段落转气泡：
   - 约定以 “A:” 开头为左侧、以 “B:” 开头为右侧
   - 可在生成时由 JS 做 DOM 转换，这里仅提供样式支持
*/
.theme-dialog .as-bubble p {
  margin: 8px 0;
}
.theme-dialog .as-bubble p.left {
  background: #fff;
  border: 1px solid #eadfff;
  padding: 10px 12px;
  border-radius: 14px;
  display: inline-block;
}
.theme-dialog .as-bubble p.right {
  background: #f6f1ff;
  border: 1px solid #e6dcff;
  padding: 10px 12px;
  border-radius: 14px;
  display: inline-block;
}

/* 7. 杂志·版式（大标题横幅、章节编号、首字下沉、拉引语、题注） */
.theme-magazine .wx-header {
  background: linear-gradient(120deg, #111, #444);
  color: #fff;
  padding: 28px 24px;
  border-radius: 18px;
}
.theme-magazine .wx-header .title {
  font-size: 36px;
  letter-spacing: 0.5px;
}
.theme-magazine .wx-header .desc {
  opacity: 0.85;
}
.theme-magazine h2 {
  counter-increment: sect;
  position: relative;
  padding-left: 48px;
  margin-top: 36px;
}
.theme-magazine h2::before {
  content: counter(sect, decimal-leading-zero);
  position: absolute;
  left: 0;
  top: 0;
  font-size: 14px;
  letter-spacing: 1px;
  padding: 6px 10px;
  border-radius: 8px;
  background: #111;
  color: #fff;
}
.theme-magazine p:first-of-type::first-letter {
  float: left;
  font-size: 3.2em;
  line-height: 1;
  padding: 0 8px 0 0;
  font-weight: 600;
}
.theme-magazine blockquote {
  font-size: 18px;
  line-height: 1.7;
  background: #f6f6f8;
  border-left: 4px solid #111;
}
.theme-magazine .wx-divider {
  height: 1px;
  background: #e6e6ea;
}
.theme-magazine figure {
  margin: 18px 0;
}
.theme-magazine figure img {
  display: block;
  width: 100%;
  border-radius: 12px;
}
.theme-magazine figure figcaption {
  text-align: center;
  color: #666;
  font-size: 13px;
  margin-top: 6px;
}

/* 8. 经典·黑白（简洁强对比，适合严肃内容） */
.theme-classic .wx-header {
  background: #111;
  color: #fff;
  padding: 18px 20px;
  border-radius: 12px;
}
.theme-classic .wx-divider {
  background: #111;
  opacity: 0.15;
}
.theme-classic h2 {
  border-bottom: 1.5px solid #111;
  padding-bottom: 8px;
  margin-top: 28px;
}
.theme-classic blockquote {
  background: #f7f7f8;
  border-left-color: #111;
}
.theme-classic a {
  color: #111;
}

/* 9. 水墨·雅韵（灰度与描边，国风水墨感） */
.theme-ink .wx-header {
  background: linear-gradient(180deg, #fafafa, #f3f3f3);
  border: 1px solid #e6e6e6;
  padding: 20px;
  border-radius: 14px;
  color: #1d1d1d;
}
.theme-ink h2 {
  position: relative;
  padding-left: 14px;
}
.theme-ink h2::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.5em;
  width: 5px;
  height: 0.9em;
  background: #222;
}
.theme-ink blockquote {
  background: #fbfbfb;
  border-left-color: #d8d8d8;
}
.theme-ink .wx-divider {
  background: #ececec;
}

/* 10. 湛蓝·海洋（蓝色层次与卡片） */
.theme-ocean {
  --t-accent: #1b6fff;
  --t-weak: #e7f0ff;
  --t-ink: #0a1f44;
}
.theme-ocean .wx-header {
  background: linear-gradient(180deg, #eef5ff, #e3efff);
  color: var(--t-ink);
  padding: 22px 20px;
  border-radius: 14px;
}
.theme-ocean a {
  color: var(--t-accent);
}
.theme-ocean blockquote {
  background: var(--t-weak);
  border-left-color: #bfd6ff;
}
.theme-ocean .badge {
  display: inline-block;
  background: #f1f6ff;
  color: #0e3d9a;
  padding: 2px 8px;
  border: 1px solid #d7e6ff;
  border-radius: 8px;
  font-size: 12px;
}

/* 11. 赤玫·玫瑰（红玫强调，温暖拉引） */
.theme-rose {
  --t-accent: #d83a56;
  --t-soft: #fff2f4;
}
.theme-rose .wx-header {
  background: linear-gradient(180deg, #fff6f7, #ffecef);
  color: #7a0e1f;
  padding: 22px;
  border-radius: 16px;
}
.theme-rose h2 {
  color: #8a1426;
}
.theme-rose a {
  color: #c72440;
}
.theme-rose blockquote {
  background: var(--t-soft);
  border-left-color: #ffc6cf;
}
.theme-rose .wx-divider {
  background: linear-gradient(90deg, #ffe5ea, #ffd6dc);
  height: 2px;
}

/* 12. 简洁·Notion（浅灰边线、无衬线、轻量化） */
.theme-notion .wx-container {
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Inter, Roboto,
    Helvetica, Arial, "PingFang SC", "Noto Sans CJK SC", sans-serif;
}
.theme-notion .wx-header {
  background: #fbfbfb;
  border: 1px solid #ededed;
  border-radius: 12px;
  padding: 18px 16px;
  color: #1f2328;
}
.theme-notion h2 {
  border-bottom: 1px solid #ececec;
  padding-bottom: 6px;
}
.theme-notion blockquote {
  background: #fafafa;
  border-left-color: #e9e9e9;
}
.theme-notion code {
  background: #f6f7f8;
}

/* 13. 科技·霓虹（深色背景 + 霓虹边框） */
.theme-tech .wx-container {
  color: #e6e8ef;
  background: #0b0f1a;
}
.theme-tech .wx-header {
  background: linear-gradient(180deg, #0f1526, #0b1020);
  border: 1px solid rgba(0, 212, 255, 0.25);
  box-shadow: 0 0 0 1px rgba(0, 212, 255, 0.14) inset,
    0 0 24px rgba(0, 212, 255, 0.08);
  color: #bfe9ff;
  padding: 20px;
  border-radius: 14px;
}
.theme-tech a {
  color: #44d1ff;
}
.theme-tech h2 {
  position: relative;
  padding-left: 12px;
  color: #bfe9ff;
}
.theme-tech h2::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 4px;
  height: 0.9em;
  background: linear-gradient(180deg, #44d1ff, #7c4dff);
  box-shadow: 0 0 8px rgba(68, 209, 255, 0.6);
}
.theme-tech blockquote {
  background: #0e1426;
  border-left-color: #44d1ff;
  color: #cdd7ff;
}
.theme-tech .wx-divider {
  background: linear-gradient(
    90deg,
    rgba(68, 209, 255, 0.25),
    rgba(124, 77, 255, 0.25)
  );
}

/* 14. 蔷薇·紫（柔和蔷薇紫，浅紫背景、细边与下划） */
.theme-roseviolet {
  --t-accent: #664d9d;
  --t-soft: #f6eeff;
  --t-border: #dec6fb;
  --t-text: #595959;
}
.theme-roseviolet .wx-header {
  background: linear-gradient(180deg, #fbf7ff, #f3ecff);
  padding: 22px;
  border-radius: 16px;
  color: #3f2f6d;
}
.theme-roseviolet a {
  color: var(--t-accent);
}
.theme-roseviolet h2 {
  padding-left: 10px;
  border-left: 5px solid var(--t-border);
  color: var(--t-text);
}
.theme-roseviolet h3 {
  border-bottom: 2px solid var(--t-border);
  color: var(--t-text);
}
.theme-roseviolet blockquote {
  background: var(--t-soft);
  border-left-color: var(--t-border);
  color: var(--t-text);
}
.theme-roseviolet em {
  background: var(--t-soft);
  color: var(--t-text);
  font-style: normal;
}
.theme-roseviolet .wx-divider {
  height: 2px;
  background: #d9b8fa;
}
