:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #293548;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #facc15;
  --accent-hover: #eab308;
  --accent-ink: #0f172a;
  --primary: #38bdf8;
  --danger: #f87171;
  --radius: 14px;
  --radius-sm: 9px;
}

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

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  min-height: 100%;
  line-height: 1.5;
}

/* 顶部栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: rgba(11, 17, 32, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

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

.brand img {
  width: 30px;
  height: 30px;
  border-radius: 8px;
}

.brand-title {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.3px;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 主布局 */
.workspace {
  max-width: 1240px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(340px, 440px);
  gap: 18px;
  align-items: start;
}

/* 左侧预览区 */
.preview-panel {
  position: sticky;
  top: 72px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.canvas-stage {
  position: relative;
  width: 100%;
  min-height: 340px;
  max-height: 74vh;
  background:
    radial-gradient(circle at 20% 20%, rgba(56, 189, 248, 0.08), transparent 45%),
    repeating-conic-gradient(#141e33 0% 25%, #0f172a 0% 50%) 50% / 20px 20px;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed #334155;
}

.canvas-stage.has-image {
  border-style: solid;
  border-color: var(--border);
}

#previewCanvas {
  max-width: 100%;
  max-height: 72vh;
  width: auto;
  height: auto;
  display: block;
}

.empty-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  pointer-events: none;
}

.empty-hint strong {
  color: var(--text);
  font-size: 16px;
  margin-bottom: 6px;
}

.preview-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* 右侧控制面板 */
.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* 模板选择列表 */
.template-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.template-item {
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}

.template-item:hover {
  border-color: #475569;
}

.template-item.active {
  border-color: var(--accent);
  background: rgba(250, 204, 21, 0.1);
}

.template-name {
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.template-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(250, 204, 21, 0.2);
  color: var(--accent);
}

.template-desc {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.35;
}

/* 表单元素 */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 10px;
}

.field:last-child {
  margin-bottom: 0;
}

.field label {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

input[type="text"],
input[type="date"],
input[type="time"],
input[type="email"],
textarea,
select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.inline-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.inline-row > input {
  flex: 1;
}

/* 常用地点胶囊 */
.presets-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.preset-chip {
  font-size: 11px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preset-chip:hover {
  border-color: var(--primary);
  color: var(--text);
}

/* 开关行 */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
}

.toggle-row input[type="checkbox"] {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s, border-color 0.15s;
  font-family: inherit;
}

.btn:hover {
  background: #283548;
  border-color: #475569;
}

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

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

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

.btn-primary {
  background: rgba(56, 189, 248, 0.16);
  color: var(--primary);
  border-color: rgba(56, 189, 248, 0.45);
}

.btn-primary:hover {
  background: rgba(56, 189, 248, 0.25);
}

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

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

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.hidden-input {
  display: none;
}

/* 折叠高级选项 */
details.advanced-box {
  border-top: 1px solid var(--border);
  margin-top: 10px;
  padding-top: 10px;
}

details.advanced-box summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  user-select: none;
  margin-bottom: 8px;
}

/* 页脚与免责提示 */
.footer {
  max-width: 1240px;
  margin: 8px auto 32px;
  padding: 0 16px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
}

.footer a {
  color: var(--primary);
  text-decoration: none;
  cursor: pointer;
}

/* 弹窗 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(2, 6, 23, 0.78);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.modal h3 {
  margin: 0 0 10px;
  font-size: 17px;
}

.modal p {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text-muted);
}

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

.sample-preview {
  width: 100%;
  max-height: 180px;
  object-fit: contain;
  border-radius: 8px;
  margin-top: 8px;
  background: var(--surface-2);
  display: none;
}

/* Toast 提示 */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid #475569;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}

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

/* 移动端适配 */
@media (max-width: 860px) {
  .workspace {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .preview-panel {
    position: static;
  }

  .canvas-stage {
    min-height: 260px;
    max-height: 58vh;
  }

  #previewCanvas {
    max-height: 56vh;
  }
}
