/* ======================================================
   WxMark — 微信公众号 Markdown 排版工具
   主样式文件：布局、工具栏、编辑器、动画
   ====================================================== */

/* ---------- Google Fonts ---------- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ---------- CSS Custom Properties ---------- */
:root {
  /* Brand */
  --brand-hue: 234;
  --brand-primary: hsl(var(--brand-hue), 75%, 65%);
  --brand-primary-hover: hsl(var(--brand-hue), 75%, 58%);
  --brand-gradient: linear-gradient(135deg, hsl(var(--brand-hue), 75%, 65%), hsl(280, 50%, 55%));

  /* Surface */
  --bg-app: #0f1117;
  --bg-surface: #1a1d27;
  --bg-surface-hover: #22263a;
  --bg-elevated: #252a3a;
  --bg-editor: #12141c;
  --bg-preview: #ffffff;

  /* Text */
  --text-primary: #e8eaf0;
  --text-secondary: #9ca3b8;
  --text-muted: #636b82;

  /* Border */
  --border-color: rgba(255, 255, 255, 0.06);
  --border-active: rgba(255, 255, 255, 0.12);

  /* Spacing */
  --toolbar-height: 60px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-spring: 350ms cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(102, 126, 234, 0.15);
}

/* ---------- Reset ---------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- App Layout ---------- */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--toolbar-height);
  padding: 0 20px;
  background: rgba(26, 29, 39, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  z-index: 100;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
}

.logo-icon {
  width: 34px;
  height: 34px;
  background: var(--brand-gradient);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  color: #fff;
  box-shadow: var(--shadow-glow);
}

.logo-text {
  font-size: 18px;
  font-weight: 700;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 20px;
  background: rgba(102, 126, 234, 0.15);
  color: var(--brand-primary);
  letter-spacing: 0.5px;
}

/* Toolbar divider */
.toolbar-divider {
  width: 1px;
  height: 28px;
  background: var(--border-color);
  margin: 0 4px;
}

/* Toolbar center: theme selector */
.toolbar-center {
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.theme-selector {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.theme-btn {
  position: relative;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  cursor: pointer;
  transition: var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  background: none;
  outline: none;
}

.theme-btn::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  padding: 4px 10px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: var(--transition-fast);
  border: 1px solid var(--border-color);
}

.theme-btn:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.theme-btn:hover {
  transform: scale(1.15);
  border-color: var(--border-active);
  background: var(--bg-surface-hover);
}

.theme-btn.active {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.25);
  background: rgba(102, 126, 234, 0.1);
}

.theme-btn.active:hover {
  transform: scale(1.05);
}

/* Toolbar right: actions */
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition-fast);
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-active);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--brand-gradient);
  border: none;
  color: #fff;
  box-shadow: var(--shadow-glow);
}

.btn-primary:hover {
  box-shadow: 0 0 25px rgba(102, 126, 234, 0.3);
  filter: brightness(1.1);
}

.btn-icon {
  font-size: 16px;
  line-height: 1;
}

/* ---------- Editor Area ---------- */
.editor-area {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Pane base */
.pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Pane header */
.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  height: 40px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.pane-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.pane-info {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}

/* Editor pane */
.pane-editor {
  border-right: 1px solid var(--border-color);
}

.editor-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#editor {
  width: 100%;
  height: 100%;
  padding: 24px 28px;
  background: var(--bg-editor);
  color: #c8cdd8;
  border: none;
  outline: none;
  resize: none;
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 14px;
  line-height: 1.75;
  tab-size: 2;
  -moz-tab-size: 2;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

#editor::placeholder {
  color: var(--text-muted);
}

#editor::-webkit-scrollbar {
  width: 6px;
}

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

#editor::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

#editor::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Preview pane */
.pane-preview {
  background: #f8f9fb;
}

.preview-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: 30px 36px;
  background: var(--bg-preview);
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

.preview-wrapper::-webkit-scrollbar {
  width: 6px;
}

.preview-wrapper::-webkit-scrollbar-track {
  background: transparent;
}

.preview-wrapper::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}

.preview-wrapper::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

#preview {
  max-width: 100%;
  min-height: 100%;
}

/* ---------- Resize Handle ---------- */
.resize-handle {
  width: 4px;
  cursor: col-resize;
  background: var(--border-color);
  transition: background var(--transition-fast);
  flex-shrink: 0;
  position: relative;
}

.resize-handle:hover,
.resize-handle.active {
  background: var(--brand-primary);
}

.resize-handle::after {
  content: '';
  position: absolute;
  top: 0;
  left: -4px;
  right: -4px;
  bottom: 0;
}

/* ---------- Toast ---------- */
.toast-container {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(20px);
  animation: toast-in 0.35s var(--transition-spring) forwards;
  transform: translateX(120%);
}

.toast.toast-success {
  border-color: rgba(52, 211, 153, 0.3);
}

.toast.toast-error {
  border-color: rgba(239, 68, 68, 0.3);
}

.toast-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.toast.leaving {
  animation: toast-out 0.3s ease forwards;
}

@keyframes toast-in {
  0% {
    transform: translateX(120%);
    opacity: 0;
  }

  100% {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes toast-out {
  0% {
    transform: translateX(0);
    opacity: 1;
  }

  100% {
    transform: translateX(120%);
    opacity: 0;
  }
}

/* ---------- Footer Bar ---------- */
.footer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 28px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.footer-left,
.footer-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.footer-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #34d399;
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

/* ---------- Quick Insert Toolbar ---------- */
.quick-insert {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  overflow-x: auto;
  flex-shrink: 0;
}

.quick-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 26px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition-fast);
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
}

.quick-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.quick-btn:active {
  transform: scale(0.92);
}

.quick-divider {
  width: 1px;
  height: 18px;
  background: var(--border-color);
  margin: 0 4px;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .toolbar {
    padding: 0 12px;
    height: 52px;
  }

  .logo-text,
  .logo-badge,
  .theme-label,
  .btn-text {
    display: none;
  }

  .toolbar-center {
    gap: 8px;
  }

  .theme-selector {
    gap: 4px;
    padding: 3px;
  }

  .theme-btn {
    width: 24px;
    height: 24px;
    font-size: 12px;
  }

  .btn {
    padding: 6px 10px;
    font-size: 12px;
  }

  .editor-area {
    flex-direction: column;
  }

  .pane-editor {
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  .resize-handle {
    display: none;
  }

  #editor {
    padding: 16px;
    font-size: 13px;
  }

  .preview-wrapper {
    padding: 20px;
  }

  .quick-insert {
    padding: 4px 8px;
  }
}

/* ---------- Selection Colors ---------- */
::selection {
  background: rgba(102, 126, 234, 0.3);
}

#editor::selection {
  background: rgba(102, 126, 234, 0.4);
}

/* ---------- Focus States ---------- */
#editor:focus {
  box-shadow: inset 0 0 0 1px rgba(102, 126, 234, 0.2);
}

/* ---------- Customizer Panel ---------- */
.customizer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.customizer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.customizer-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 340px;
  max-width: 90vw;
  height: 100vh;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-color);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -8px 0 30px rgba(0, 0, 0, 0.4);
}

.customizer-panel.open {
  transform: translateX(0);
}

.customizer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.customizer-title {
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(135deg, #6366f1, #06b6d4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.customizer-close {
  width: 30px;
  height: 30px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.customizer-close:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--border-active);
}

.customizer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.customizer-section {
  margin-bottom: 24px;
}

.customizer-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Preset Grid */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.preset-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition-fast);
  font-family: inherit;
}

.preset-btn:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-active);
  transform: translateY(-1px);
}

.preset-btn.active {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
  background: rgba(102, 126, 234, 0.08);
}

.preset-swatch {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.preset-name {
  font-size: 12px;
  white-space: nowrap;
}

/* Color Row */
.color-row {
  display: flex;
  gap: 12px;
}

.color-field {
  flex: 1;
}

.color-field-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.color-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: var(--transition-fast);
}

.color-input-wrap:hover {
  border-color: var(--border-active);
}

.color-input {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
  background: none;
  -webkit-appearance: none;
  appearance: none;
}

.color-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-input::-webkit-color-swatch {
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

.color-hex {
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-secondary);
}

/* Gradient Preview */
.gradient-preview {
  height: 48px;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  transition: background 0.3s ease;
}

/* Reset Button */
.customizer-actions {
  padding-top: 8px;
  border-top: 1px solid var(--border-color);
}

.customizer-reset {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition-fast);
}

.customizer-reset:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--border-active);
}

/* Settings Button glow effect for custom theme */
.btn-settings {
  position: relative;
}

.btn-settings::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: inherit;
  background: linear-gradient(135deg, #6366f1, #06b6d4);
  z-index: -1;
  opacity: 0;
  filter: blur(6px);
  transition: opacity 0.3s ease;
}

.btn-settings:hover::before {
  opacity: 0.4;
}

@media (max-width: 768px) {
  .customizer-panel {
    width: 100%;
    max-width: 100vw;
  }
}