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

:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #ef4444;
  --bg: #f8fafc;
  --card: #fff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #94a3b8;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ---- Trust Bar ---- */
.trust-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding: 8px 20px;
  background: linear-gradient(135deg, #eef2ff, #e0e7ff);
  border-bottom: 1px solid #c7d2fe;
  font-size: 12px;
  color: #4338ca;
  font-weight: 500;
}
.trust-sep {
  color: #a5b4fc;
}
.trust-item {
  white-space: nowrap;
}
.trust-close {
  margin-left: 12px;
  background: none;
  border: none;
  color: #6366f1;
  font-size: 14px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.trust-close:hover {
  color: #312e81;
}

/* ---- Header ---- */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.logo {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}
.logo-dot {
  color: var(--primary);
}
.btn-pro {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff;
  border: none;
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
  transition: opacity .2s;
}
.btn-pro:hover { opacity: .9; }

/* ---- Main Layout ---- */
.main {
  display: flex;
  gap: 0;
  height: calc(100vh - 53px);
  overflow: hidden;
}

/* ---- Toolbar (Left) ---- */
.toolbar {
  width: 290px;
  min-width: 200px;
  max-width: 500px;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 16px;
  background: var(--card);
  border-right: 1px solid var(--border);
  position: relative;
}
.toolbar-resize-handle {
  position: absolute;
  top: 0;
  right: 0;
  width: 5px;
  height: 100%;
  cursor: col-resize;
  z-index: 10;
}
.toolbar-resize-handle:hover,
.toolbar-resize-handle.dragging {
  background: var(--primary);
  opacity: .3;
}
.panel {
  margin-bottom: 20px;
}
.panel-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
}

/* Drop zone */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--primary);
  background: #eef2ff;
}
.drop-icon {
  font-size: 32px;
  color: var(--primary);
  line-height: 1;
  margin-bottom: 6px;
}
.drop-text {
  font-size: 13px;
  color: var(--text);
  margin-bottom: 2px;
}
.drop-hint {
  font-size: 11px;
  color: var(--text-muted);
}

/* File list */
.file-list {
  margin-top: 8px;
}
.file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
  background: var(--bg);
  margin-top: 4px;
  cursor: pointer;
}
.file-item.active {
  background: #eef2ff;
  border: 1px solid var(--primary);
}
.file-item .thumb {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
}
.file-item .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-item .remove {
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
}
.file-item .remove:hover {
  color: var(--danger);
}

/* Tabs */
.tab-group {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
}
.tab {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  transition: all .2s;
}
.tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Settings fields */
.settings {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field span:first-child {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}
.field input[type="text"],
.field select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
}
.field input[type="text"]:focus,
.field select:focus {
  outline: none;
  border-color: var(--primary);
}
.field input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}
.field input[type="color"] {
  width: 40px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  padding: 2px;
}
.field-row {
  display: flex;
  gap: 10px;
}
.field-half {
  flex: 1;
}
.range-val {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
}

/* Position grid */
.pos-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  margin: 6px 0 8px;
}
.position-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}
.pos-btn {
  padding: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-muted);
  transition: all .2s;
}
.pos-btn:hover {
  border-color: var(--primary);
}
.pos-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Buttons */
.btn-primary {
  display: block;
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
  text-align: center;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { background: #cbd5e1; cursor: not-allowed; }

.btn-secondary {
  display: block;
  width: 100%;
  padding: 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: all .2s;
  text-align: center;
}
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }

.btn-danger {
  display: block;
  width: 100%;
  padding: 10px;
  background: transparent;
  color: var(--danger);
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: all .2s;
  text-align: center;
}
.btn-danger:hover { background: #fef2f2; border-color: #fecaca; }

/* Template Management */
.template-section {
  background: var(--bg);
  border-radius: 8px;
  padding: 10px;
  margin-top: 14px;
}
.template-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.template-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}
.tip-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid #a5b4fc;
  background: #eef2ff;
  color: #6366f1;
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
}
.tip-icon:hover {
  background: #6366f1;
  color: #fff;
}
.tip-wrapper {
  position: relative;
  display: inline-flex;
}
.tip-tooltip {
  display: none;
  position: fixed;
  background: #1e293b;
  color: #f1f5f9;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 11px;
  line-height: 1.7;
  white-space: normal;
  min-width: 240px;
  z-index: 9999;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  pointer-events: none;
}
.tip-tooltip strong {
  color: #fbbf24;
}
.btn-sm-primary {
  padding: 4px 10px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 5px;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-sm-primary:hover { background: var(--primary-hover); }
.template-select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  background: var(--card);
  color: var(--text);
  margin-bottom: 6px;
}
.template-actions {
  display: flex;
  gap: 6px;
}
.btn-sm-secondary, .btn-sm-danger {
  flex: 1;
  padding: 5px 0;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 11px;
  cursor: pointer;
  text-align: center;
  background: var(--card);
  color: var(--text);
}
.btn-sm-secondary:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm-danger {
  border-color: transparent;
  color: var(--danger);
}
.btn-sm-danger:hover { background: #fef2f2; }

.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}
.download-row {
  display: flex;
  gap: 0;
}
.download-row .btn-primary {
  flex: 1;
  border-radius: 8px 0 0 8px;
}
.download-dropdown {
  position: relative;
}
.download-dropdown-toggle {
  width: 28px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--primary);
  border-left: none;
  border-radius: 0 8px 8px 0;
  background: var(--card);
  cursor: pointer;
  transition: background-color .2s;
}
.download-dropdown-toggle:hover {
  background-color: #f8fafc;
}
.download-dropdown-panel {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  padding: 6px;
  z-index: 9999;
  min-width: 140px;
}
.download-dropdown-panel.hidden {
  display: none;
}
.download-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .15s;
}
.download-option:hover {
  background-color: #f1f5f9;
}
.download-option input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--primary);
  cursor: pointer;
  margin: 0;
}

/* Logo upload */
.logo-upload {
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo-ai-actions {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.btn-ai-bg {
  padding: 5px 12px;
  background: linear-gradient(135deg, #8b5cf6, #7c3aed);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
}
.btn-ai-bg:hover { opacity: .9; }
.btn-ai-bg:disabled { opacity: .5; cursor: wait; }
.btn-ai-restore {
  padding: 5px 10px;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-ai-restore:hover { color: var(--text); border-color: #94a3b8; }
.ai-loading {
  font-size: 11px;
  color: #7c3aed;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.ai-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #e2e8f0;
  border-top-color: #7c3aed;
  border-radius: 50%;
  animation: ai-spin .8s linear infinite;
}
@keyframes ai-spin {
  to { transform: rotate(360deg); }
}

.logo-upload .btn-secondary {
  width: auto;
  padding: 6px 12px;
  font-size: 12px;
}
.logo-upload span {
  font-size: 11px;
  color: var(--text-muted);
}

/* Toggle switch */
.toggle-label {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.toggle-label input {
  display: none;
}
.toggle-switch {
  width: 40px;
  height: 22px;
  background: #cbd5e1;
  border-radius: 11px;
  position: relative;
  transition: background .2s;
}
.toggle-switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
}
.toggle-label input:checked + .toggle-switch {
  background: var(--primary);
}
.toggle-label input:checked + .toggle-switch::after {
  transform: translateX(18px);
}

/* ---- Canvas Area (Center) ---- */
.canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #e2e8f0;
  min-width: 0;
}
.canvas-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden;
}
.canvas-container canvas {
  max-width: 100%;
  max-height: 100%;
  border-radius: 4px;
  box-shadow: 0 4px 24px rgba(0,0,0,.12);
  display: none;
}
.empty-state {
  text-align: center;
  color: var(--text-muted);
}
.empty-icon {
  font-size: 64px;
  margin-bottom: 16px;
}
.empty-title {
  font-size: 18px;
  color: var(--text);
  font-weight: 600;
  margin-bottom: 4px;
}
.empty-desc {
  font-size: 13px;
}
.canvas-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 24px;
  font-size: 11px;
  color: var(--text-muted);
}
.drag-hint {
  color: #6366f1;
  font-weight: 500;
}
}

/* ---- Ad Area (Right) ---- */
.ad-area {
  width: 170px;
  flex-shrink: 0;
  padding: 20px 10px;
  background: var(--card);
  border-left: 1px solid var(--border);
}
.ad-slot {
  position: sticky;
  top: 70px;
}
.ad-zone {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.ad-zone:last-child {
  border-bottom: none;
  margin-bottom: 0;
}
.ad-zone-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 10px;
  text-align: center;
}

/* ① CPS 商品卡片 */
.ad-product {
  display: block;
  text-decoration: none;
  background: var(--bg);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 8px;
  transition: box-shadow .2s;
  border: 1px solid var(--border);
}
.ad-product:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,.1);
}
.ad-product-img {
  width: 100%;
  height: 60px;
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin-bottom: 6px;
}
.ad-product-name {
  font-size: 11px;
  color: var(--text);
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ad-product-price {
  font-size: 13px;
  font-weight: 700;
  color: #ef4444;
}
.ad-product-price span {
  font-size: 9px;
  font-weight: 400;
  color: var(--text-muted);
}

/* ② CPM 广告位 */
.ad-cpm-slot {
  background: linear-gradient(135deg, #f8fafc, #f1f5f9);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 20px 10px;
  text-align: center;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}
.ad-cpm-slot p {
  font-size: 12px;
  color: var(--text-muted);
}
.ad-cpm-slot small {
  font-size: 10px;
  color: #cbd5e1;
}

/* ③ 打赏按钮 */
.tip-btn {
  display: block;
  width: 100%;
  padding: 10px;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
  transition: opacity .2s;
}
.tip-btn:hover { opacity: .9; }

/* 打赏弹窗 */
.modal-tip-content {
  max-width: 360px;
  text-align: center;
}
.qrcode-row {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin: 24px auto;
}
.qrcode-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.qrcode-img {
  width: 180px;
  height: 180px;
  border-radius: 12px;
  border: 1px solid var(--border);
  object-fit: contain;
  background: #fff;
}
.qrcode-label {
  font-size: 14px;
  color: var(--text);
  font-weight: 600;
  margin: 0;
}
.qrcode-hint {
  font-size: 11px;
  color: var(--text-muted);
}
.tip-thanks {
  font-size: 13px;
  color: #f59e0b;
  font-weight: 500;
}

/* ---- Modal ---- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}
.hidden { display: none; }
.modal.hidden { display: none; }
.modal-content {
  background: var(--card);
  border-radius: 16px;
  padding: 36px;
  max-width: 560px;
  width: 90%;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-muted);
}
.modal-sub {
  text-align: center;
  color: var(--text-muted);
  margin: 6px 0 24px;
}
.modal h2 {
  text-align: center;
  font-size: 22px;
}
.pricing {
  display: flex;
  gap: 16px;
}
.pricing-card {
  flex: 1;
  padding: 24px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  text-align: center;
  position: relative;
}
.pricing-card.recommended {
  border-color: var(--primary);
  border-width: 2px;
}
.pricing-card h3 {
  font-size: 15px;
  margin-bottom: 8px;
}
.price {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 16px;
}
.price span {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-muted);
}
.pricing-card ul {
  list-style: none;
  text-align: left;
  margin-bottom: 20px;
  font-size: 13px;
  color: var(--text);
}
.pricing-card li {
  padding: 4px 0;
}
.badge {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: #fff;
  padding: 4px 14px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.buy-btn.highlight {
  background: linear-gradient(135deg, #f59e0b, #ef4444);
}

/* ---- Footer ---- */
.footer {
  text-align: center;
  padding: 12px 24px;
  background: var(--card);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
}
.footer-links {
  margin-top: 4px;
}
.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
}
.footer-links a:hover { color: var(--primary); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
  .main {
    flex-direction: column;
    height: auto;
  }
  .toolbar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 40vh;
  }
  .ad-area {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    padding: 12px;
  }
  .ad-placeholder {
    width: 100%;
    height: 80px;
  }
  .canvas-container {
    min-height: 50vh;
  }
  .pricing {
    flex-direction: column;
  }
}
