/* ========================================
   Atelier · 文章工坊
   杂志编辑部美学 · 多主题系统
   ======================================== */

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

:root {
  /* 字体系统 */
  --font-display: 'Fraunces', 'Noto Serif SC', Georgia, serif;
  --font-body: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
  --font-serif: 'Fraunces', 'Noto Serif SC', serif;

  /* 间距节奏 */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  /* 圆角 */
  --r-sm: 2px;
  --r-md: 4px;
  --r-lg: 8px;

  /* 过渡 */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* 主题：杂志（默认） */
[data-theme="magazine"] {
  --bg: #f4f0e8;
  --bg-elevated: #faf7f0;
  --bg-deep: #e8e2d4;
  --ink: #1a1a1a;
  --ink-soft: #4a4a4a;
  --ink-muted: #8a8578;
  --rule: #d4cdb8;
  --accent: #c8553d;
  --accent-soft: #e8a89a;
  --highlight: #f5e6c8;
}

/* 主题：极简 */
[data-theme="minimal"] {
  --bg: #fafafa;
  --bg-elevated: #ffffff;
  --bg-deep: #f0f0f0;
  --ink: #0a0a0a;
  --ink-soft: #3a3a3a;
  --ink-muted: #8a8a8a;
  --rule: #e0e0e0;
  --accent: #0a0a0a;
  --accent-soft: #6a6a6a;
  --highlight: #fff4a3;
}

/* 主题：墨色 */
[data-theme="ink"] {
  --bg: #e8e4d8;
  --bg-elevated: #f2ede0;
  --bg-deep: #d8d2c0;
  --ink: #1a2420;
  --ink-soft: #3a4a40;
  --ink-muted: #7a8478;
  --rule: #c4beae;
  --accent: #2d3e2e;
  --accent-soft: #5a7a5c;
  --highlight: #d4e4c4;
}

/* 主题：暮光 */
[data-theme="dusk"] {
  --bg: #1a1424;
  --bg-elevated: #241c32;
  --bg-deep: #0f0a18;
  --ink: #f0e8f5;
  --ink-soft: #c0b4d0;
  --ink-muted: #8a7a9a;
  --rule: #3a2e4a;
  --accent: #b89cd4;
  --accent-soft: #6b4f8a;
  --highlight: #3a2e4a;
}

/* ======== 基础 ======== */
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background 0.4s var(--ease), color 0.4s var(--ease);
}

/* 页面背景：淡淡的纸张纹理 */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(0,0,0,0.015) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(0,0,0,0.015) 0%, transparent 50%);
  z-index: 0;
}

/* ======== 顶部 Masthead ======== */
.masthead {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
  backdrop-filter: blur(10px);
}

.masthead-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-4) var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.brand-mark {
  width: 40px;
  height: 40px;
  background: var(--ink);
  color: var(--bg);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-style: italic;
  letter-spacing: -0.02em;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 20px;
  font-style: italic;
  letter-spacing: -0.02em;
}

.brand-sub {
  font-size: 10px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-top: 2px;
}

/* 导航 */
.nav {
  display: flex;
  gap: var(--space-2);
  border-left: 1px solid var(--rule);
  border-right: 1px solid var(--rule);
  padding: 0 var(--space-4);
}

.nav-item {
  background: none;
  border: none;
  color: var(--ink-muted);
  cursor: pointer;
  padding: var(--space-2) var(--space-4);
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  font-family: var(--font-body);
  transition: color 0.2s var(--ease);
  position: relative;
}

.nav-item:hover {
  color: var(--ink-soft);
}

.nav-item.active {
  color: var(--ink);
}

.nav-item.active::after {
  content: '';
  position: absolute;
  bottom: -16px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 2px;
  background: var(--accent);
}

.nav-num {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-muted);
  letter-spacing: 0.05em;
}

.nav-label {
  font-size: 14px;
  font-weight: 500;
}

/* 主题切换 */
.theme-switcher {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.theme-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--dot);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--rule);
  cursor: pointer;
  transition: transform 0.2s var(--ease);
  padding: 0;
}

.theme-dot:hover {
  transform: scale(1.15);
}

.theme-dot.active {
  box-shadow: 0 0 0 2px var(--ink);
}

/* ======== 主工作区 ======== */
.stage {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-6);
  position: relative;
  z-index: 1;
}

.tool-panel {
  display: none;
  animation: fadeIn 0.4s var(--ease);
}

.tool-panel.active {
  display: block;
}

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

/* ======== 编辑器布局 ======== */
.editor-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-5);
  min-height: calc(100vh - 180px);
}

.editor-pane, .preview-pane {
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pane-header {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.pane-title {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 15px;
  font-style: italic;
  flex-shrink: 0;
}

.pane-num {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
  letter-spacing: 0.05em;
  font-style: normal;
}

/* 右侧操作区：按钮 + 主题选择 + 字数统计 */
.pane-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: nowrap;
  overflow: hidden;
}

.pane-stats {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
  letter-spacing: 0.05em;
  white-space: nowrap;
  padding-left: var(--space-2);
  border-left: 1px solid var(--rule);
}

.stat-sep {
  margin: 0 2px;
  opacity: 0.4;
}

/* 小尺寸按钮变体 */
.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  gap: 5px;
}

/* 小尺寸 select 变体 */
.select-sm {
  padding: 5px 8px;
  font-size: 12px;
  max-width: 120px;
}

.md-editor {
  flex: 1;
  padding: var(--space-6);
  background: transparent;
  color: var(--ink);
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.75;
  min-height: 500px;
}

.md-editor::placeholder {
  color: var(--ink-muted);
  font-style: italic;
}

/* ======== 预览区：手机模拟 ======== */
.preview-frame {
  flex: 1;
  padding: var(--space-6);
  background: var(--bg-deep);
  overflow-y: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.phone-mock {
  width: 100%;
  max-width: 420px;
  background: #fff;
  color: #1a1a1a;
  padding: 32px 24px;
  border-radius: 2px;
  box-shadow:
    0 1px 3px rgba(0,0,0,0.05),
    0 10px 40px rgba(0,0,0,0.08);
  min-height: 500px;
}

.md-preview {
  font-family: 'PingFang SC', 'Noto Sans SC', -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.75;
  color: #1a1a1a;
  word-break: break-word;
}

.pane-actions {
  display: flex;
  gap: var(--space-2);
}

/* ======== 按钮 ======== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 8px 14px;
  border: 1px solid var(--rule);
  background: var(--bg-elevated);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s var(--ease);
  text-decoration: none;
}

.btn:hover {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--bg);
}

.btn-primary {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

.btn-primary:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: var(--rule);
}

.btn-full {
  width: 100%;
}

.select, .input {
  padding: 7px 12px;
  border: 1px solid var(--rule);
  background: var(--bg-elevated);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s var(--ease);
}

.select:focus, .input:focus {
  border-color: var(--ink);
}

.input-area {
  width: 100%;
  font-family: var(--font-mono);
  resize: vertical;
}

/* ======== 封面工具 ======== */
.cover-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: var(--space-5);
  min-height: calc(100vh - 180px);
}

.cover-controls {
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  overflow-y: auto;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.control-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.template-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}

.template-btn {
  background: none;
  border: 1px solid var(--rule);
  padding: var(--space-2);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  transition: border-color 0.2s var(--ease);
  font-family: var(--font-body);
  font-size: 11px;
  color: var(--ink-soft);
}

.template-btn:hover {
  border-color: var(--ink-soft);
}

.template-btn.active {
  border-color: var(--ink);
  background: var(--bg-deep);
}

.template-preview {
  aspect-ratio: 2.35/1;
  border-radius: 1px;
}

.tp-editorial { background: linear-gradient(135deg, #f4f0e8 50%, #c8553d 50%); }
.tp-gradient { background: linear-gradient(135deg, #c8553d, #6b4f8a); }
.tp-minimal { background: #fff; border: 1px solid #1a1a1a; }
.tp-stamp { background: #1a1a1a; position: relative; }
.tp-stamp::after {
  content: '';
  position: absolute;
  inset: 4px;
  border: 1px solid #c8553d;
}

.color-row {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.color-dot, .qr-color-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--bg-elevated);
  box-shadow: 0 0 0 1px var(--rule);
  cursor: pointer;
  transition: transform 0.2s var(--ease);
  padding: 0;
}

.color-dot:hover, .qr-color-dot:hover {
  transform: scale(1.1);
}

.color-dot.active, .qr-color-dot.active {
  box-shadow: 0 0 0 2px var(--ink);
}

.cover-stage {
  background: var(--bg-deep);
  border: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  overflow: auto;
}

/* 封面画布（2.35:1 公众号标准） */
.cover-canvas {
  width: 100%;
  max-width: 900px;
  aspect-ratio: 2.35/1;
  position: relative;
  overflow: hidden;
  color: #fff;
  font-family: var(--font-display);
}

.cover-inner {
  position: absolute;
  inset: 0;
  padding: 48px 60px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.cover-meta {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  opacity: 0.8;
}

.cover-dot {
  width: 4px;
  height: 4px;
  background: currentColor;
  border-radius: 50%;
}

.cover-main-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(28px, 4vw, 52px);
  line-height: 1.15;
  font-style: italic;
  max-width: 80%;
  letter-spacing: -0.01em;
}

.cover-sub {
  font-family: var(--font-mono);
  font-size: 14px;
  opacity: 0.7;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-top: 8px;
}

.cover-footer {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.cover-author-name {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 16px;
  letter-spacing: 0;
  text-transform: none;
}

.cover-rule {
  flex: 1;
  height: 1px;
  background: currentColor;
  opacity: 0.4;
}

/* 封面模板：编辑部 */
.template-editorial {
  background: var(--bg-elevated);
  color: var(--ink);
  border: 1px solid var(--ink);
}

.template-editorial::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 40%;
  height: 100%;
  background: var(--main);
}

.template-editorial .cover-main-title {
  position: relative;
  z-index: 2;
}

/* 封面模板：渐变 */
.template-gradient {
  background: linear-gradient(135deg, var(--main) 0%, #2a1a3a 100%);
  color: #fff;
}

.template-gradient::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 80%, rgba(255,255,255,0.1) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(255,255,255,0.08) 0%, transparent 50%);
}

/* 封面模板：极简 */
.template-minimal {
  background: #faf7f0;
  color: #1a1a1a;
  border: 2px solid #1a1a1a;
}

.template-minimal .cover-meta,
.template-minimal .cover-footer {
  color: var(--main);
}

/* 封面模板：印章 */
.template-stamp {
  background: #0f0f0f;
  color: #fff;
}

.template-stamp::before {
  content: '';
  position: absolute;
  inset: 20px;
  border: 1px solid var(--main);
  pointer-events: none;
}

.template-stamp .cover-main-title {
  color: var(--main);
}

/* ======== 二维码工具 ======== */
.qr-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: var(--space-5);
  min-height: calc(100vh - 180px);
}

.qr-controls {
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.qr-stage {
  background: var(--bg-deep);
  border: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}

.qr-frame {
  background: var(--bg-elevated);
  padding: var(--space-7);
  border: 1px solid var(--rule);
  position: relative;
}

.qr-frame::before,
.qr-frame::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid var(--ink);
}

.qr-frame::before {
  top: -1px;
  left: -1px;
  border-right: none;
  border-bottom: none;
}

.qr-frame::after {
  bottom: -1px;
  right: -1px;
  border-left: none;
  border-top: none;
}

#qr-canvas {
  display: block;
  max-width: 280px;
  max-height: 280px;
}

/* ======== 草稿管理 ======== */
.drafts-layout {
  max-width: 900px;
  margin: 0 auto;
  padding: var(--space-7) var(--space-6);
}

.drafts-header {
  border-bottom: 1px solid var(--rule);
  padding-bottom: var(--space-5);
  margin-bottom: var(--space-6);
}

.section-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 36px;
  font-style: italic;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-2);
}

.section-desc {
  color: var(--ink-muted);
  font-size: 14px;
}

.drafts-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.draft-item {
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  padding: var(--space-5);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-4);
  align-items: start;
  transition: border-color 0.2s var(--ease);
}

.draft-item:hover {
  border-color: var(--ink-soft);
}

.draft-main {
  min-width: 0;
}

.draft-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  margin-bottom: var(--space-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.draft-excerpt {
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: var(--space-3);
}

.draft-meta {
  display: flex;
  gap: var(--space-3);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
  letter-spacing: 0.05em;
}

.draft-actions {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}

.draft-empty {
  text-align: center;
  padding: var(--space-8) var(--space-5);
  color: var(--ink-muted);
  font-family: var(--font-display);
  font-style: italic;
  font-size: 18px;
}

/* ======== Markdown 预览容器（样式由 themes.js 主题 CSS 注入控制）======== */
.md-preview {
  font-family: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  font-size: 16px;
  line-height: 1.75;
  color: #1a1a1a;
  word-break: break-word;
}
/* 保底：图片不溢出、pre 可横滚 */
.md-preview img { max-width: 100%; }
.md-preview pre { overflow-x: auto; }

/* ======== Toast ======== */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--bg);
  padding: 12px 20px;
  font-size: 13px;
  font-family: var(--font-body);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s var(--ease);
  z-index: 1000;
  letter-spacing: 0.02em;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ======== 响应式 ======== */
@media (max-width: 900px) {
  .masthead-inner {
    flex-wrap: wrap;
    gap: var(--space-3);
  }
  .nav {
    order: 3;
    width: 100%;
    border: none;
    border-top: 1px solid var(--rule);
    padding: var(--space-2) 0;
    justify-content: space-around;
  }
  .editor-layout,
  .cover-layout,
  .qr-layout {
    grid-template-columns: 1fr;
  }
  .brand-sub { display: none; }
}

/* 滚动条 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--rule);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--ink-muted);
}
