:root {
  --bg: #0c0f16;
  --bg-elev: #121724;
  --card: #171d2b;
  --card-2: #1d2434;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #e9ebf3;
  --muted: #8b93a9;
  --accent: #7c8cff;
  --accent-2: #b28cff;
  --grad: linear-gradient(135deg, #7c8cff 0%, #b28cff 100%);
  --grad-soft: linear-gradient(135deg, rgba(124, 140, 255, 0.14), rgba(178, 140, 255, 0.14));
  --danger: #ff8a8a;
  --ok: #6fe3b0;
  --radius: 16px;
  --radius-sm: 10px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  min-height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB",
    "Noto Sans SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: none;
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(12, 15, 22, 0.86);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

.mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--grad);
  position: relative;
  box-shadow: 0 0 20px rgba(140, 140, 255, 0.35);
}

.mark::after {
  content: "";
  position: absolute;
  inset: 8px 7px;
  border-radius: 2px;
  background: repeating-linear-gradient(
    to bottom,
    #0c0f16 0 3px,
    transparent 3px 7px
  );
}

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

.brand-text strong {
  font-size: 18px;
  letter-spacing: 0.5px;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-text small {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.4px;
}

.project-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 8px;
}

#project-select {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  min-width: 150px;
  max-width: 220px;
  outline: none;
}

#project-select:focus-visible {
  border-color: rgba(140, 150, 255, 0.5);
}

.actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.btn {
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, transform 0.1s, opacity 0.15s;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
}

.btn.ghost {
  background: var(--card);
  border-color: var(--line);
  color: var(--text);
}

.btn.ghost:hover {
  border-color: var(--line-strong);
}

.btn.ghost.danger {
  color: var(--danger);
}

.btn.primary {
  background: var(--grad);
  color: #0c0f16;
  font-weight: 650;
}

.btn.primary:disabled,
.btn.ghost:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ---------- 布局 ---------- */
.workspace {
  display: grid;
  grid-template-columns: 400px minmax(0, 1fr);
  gap: 0;
  min-height: calc(100vh - 63px);
  align-items: start;
}

.panel {
  border-right: 1px solid var(--line);
  padding: 24px 22px 40px;
  position: sticky;
  top: 63px;
  max-height: calc(100vh - 63px);
  overflow-y: auto;
}

.field-group + .field-group {
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}

.group-head h2 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 1.2px;
  color: var(--muted);
  text-transform: uppercase;
}

.save-state {
  font-size: 12px;
  color: var(--ok);
  opacity: 0.85;
}

.save-state.pending {
  color: var(--muted);
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field > span {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 6px;
}

.field > span em {
  font-style: normal;
  opacity: 0.6;
  margin-left: 4px;
}

.field input,
.field textarea {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  resize: vertical;
  line-height: 1.55;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input::placeholder,
.field textarea::placeholder {
  color: rgba(139, 147, 169, 0.62);
}

.field input:focus,
.field textarea:focus {
  border-color: rgba(140, 150, 255, 0.5);
  box-shadow: 0 0 0 3px rgba(124, 140, 255, 0.1);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ---------- 版式 ---------- */
.template-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.template-btn {
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  transition: border-color 0.15s, background 0.15s;
}

.template-btn:hover {
  border-color: var(--line-strong);
}

.template-btn[aria-checked="true"] {
  border-color: var(--accent);
  background: var(--grad-soft);
}

.template-btn b {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
}

.template-btn small {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.45;
}

/* ---------- 配色 ---------- */
.palette-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.palette-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: border-color 0.15s, background 0.15s;
}

.palette-btn:hover {
  background: var(--card);
}

.palette-btn[aria-checked="true"] {
  border-color: var(--accent);
  background: var(--card);
}

.palette-dot {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  position: relative;
  overflow: hidden;
}

.palette-dot::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  width: 50%;
  height: 50%;
  background: currentColor;
  border-top-left-radius: 100%;
}

.palette-btn span {
  font-size: 11.5px;
  color: var(--muted);
}

.panel-note {
  margin-top: 26px;
  font-size: 12px;
  color: var(--muted);
  opacity: 0.72;
  line-height: 1.65;
}

/* ---------- 预览 ---------- */
.preview {
  padding: 26px 28px 60px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.preview-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}

.preview-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.preview-head b {
  font-size: 14px;
  font-weight: 600;
}

.preview-head span {
  font-size: 12px;
  color: var(--muted);
}

.preview-head .dl {
  margin-left: auto;
  font-size: 12.5px;
  color: #b9c2ff;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  transition: border-color 0.15s;
}

.preview-head .dl:hover {
  border-color: rgba(140, 150, 255, 0.45);
}

.canvas-shell {
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  line-height: 0;
}

.canvas-shell canvas {
  width: 100%;
  height: auto;
  display: block;
}

/* 竖版预览限高，避免过长 */
.preview-card[data-platform="xhs"] .canvas-shell {
  max-width: 460px;
  margin: 0 auto;
}

.preview-card[data-platform="zhihu"] .canvas-shell {
  max-width: 680px;
  margin: 0 auto;
}

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 12, 0.7);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 60;
}

.modal {
  width: 100%;
  max-width: 460px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  max-height: 86vh;
  overflow-y: auto;
}

.modal h3 {
  font-size: 17px;
  margin-bottom: 4px;
}

.modal p.hint {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 16px;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 18px;
}

.ai-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}

.ai-item {
  text-align: left;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.5;
  transition: border-color 0.15s;
}

.ai-item:hover {
  border-color: var(--accent);
}

/* ---------- Toast ---------- */
#toast-root {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.toast {
  background: var(--card-2);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 13.5px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.2s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ---------- 响应式 ---------- */
@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .panel {
    position: static;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 20px 18px 28px;
  }

  .preview {
    padding: 20px 16px 48px;
  }

  .topbar {
    padding: 12px 16px;
    gap: 10px;
  }

  .project-bar {
    order: 3;
    width: 100%;
    margin-left: 0;
  }

  #project-select {
    flex: 1;
    max-width: none;
  }

  .actions {
    margin-left: auto;
  }
}

@media (max-width: 560px) {
  .brand-text small {
    display: none;
  }

  .btn {
    padding: 7px 11px;
    font-size: 13px;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .template-grid {
    grid-template-columns: 1fr;
  }
}
