:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #1e293b;
  --sub: #64748b;
  --line: #e5e9f2;
  --brand: #2563eb;
  --brand-soft: #eff4ff;
  --radius: 14px;
  --shadow: 0 6px 22px rgba(20, 30, 60, .07);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'PingFang SC', 'Microsoft YaHei', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
header.top {
  padding: 15px 20px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
}
header.top h1 { margin: 0; font-size: 18px; font-weight: 700; }
header.top p { margin: 4px 0 0; font-size: 12.5px; opacity: .9; }

.layout {
  max-width: 1040px;
  width: 100%;
  box-sizing: border-box;
  margin: 16px auto;
  padding: 0 16px;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  gap: 16px;
  align-items: stretch;
}
.gen-col {
  flex: 1 1 auto;
  min-width: 0;
  overflow-y: auto;
  padding-right: 6px;
}
.side-col {
  flex: 0 0 340px;
  min-width: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
@media (max-width: 860px) {
  body { display: block; }
  .layout { display: block; flex: none; height: auto; }
  .gen-col, .side-col { overflow: visible; }
  .side-col { flex: none; }
}

.card-panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 15px;
  margin-bottom: 14px;
}
.card-panel h2 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-panel h2 .step {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--brand); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
}

/* 字段区：两列网格，显著压缩纵向高度 */
#fieldList {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 16px;
}
.field-row {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 7px 0;
}
.field-row[data-key="icon"] { grid-column: 1 / -1; }
.field-row .chk { margin-top: 8px; }
.field-row .meta { flex: 1; min-width: 0; }
.field-row label.lbl { display: block; font-size: 12.5px; font-weight: 600; color: var(--sub); margin-bottom: 5px; }
.field-row input[type=text], .field-row input[type=tel], .field-row input[type=email], .field-row input[type=url] {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 9px; font-size: 13.5px; outline: none; transition: border-color .15s;
}
.field-row input:focus { border-color: var(--brand); }
.field-row.off .meta { opacity: .45; }
.field-row .filehint { font-size: 11.5px; color: var(--sub); margin-top: 4px; }
@media (max-width: 560px) {
  #fieldList { grid-template-columns: 1fr; }
}

.template-grid, .color-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.tpl {
  flex: 1 1 130px; min-width: 120px; cursor: pointer;
  border: 2px solid var(--line); border-radius: 11px; padding: 10px;
  transition: border-color .15s, box-shadow .15s; background: #fff;
}
.tpl:hover { border-color: #c7d2fe; }
.tpl.active { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.tpl .tname { font-weight: 700; font-size: 13.5px; }
.tpl .tdesc { font-size: 11.5px; color: var(--sub); margin-top: 3px; }
.tpl .tswatch { height: 7px; border-radius: 4px; margin-top: 9px; }

.color-grid { gap: 9px; }
.color-chip {
  width: 48px; height: 48px; border-radius: 12px; cursor: pointer;
  border: 3px solid transparent; position: relative; overflow: hidden;
  display: flex; align-items: flex-end; justify-content: center;
}
.color-chip span { font-size: 10.5px; color: #fff; background: rgba(0,0,0,.25); width: 100%; text-align: center; padding: 2px 0; }
.color-chip.active { border-color: var(--ink); box-shadow: 0 3px 10px rgba(0,0,0,.15); }

.preview-panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  position: sticky; top: 14px;
}
.preview-panel h2 { margin: 0 0 10px; font-size: 14px; font-weight: 700; }
#preview {
  border-radius: 12px; padding: 14px; min-height: 150px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg,#eff6ff,#dbeafe);
}
#preview .ecard { margin: 0 auto; }

.generate-btn {
  width: 100%; margin-top: 4px; padding: 12px; border: none; border-radius: 11px;
  background: linear-gradient(135deg, #2563eb, #7c3aed); color: #fff;
  font-size: 15px; font-weight: 700; cursor: pointer; box-shadow: var(--shadow);
}
.generate-btn:disabled { opacity: .5; cursor: not-allowed; }
.hint { font-size: 11.5px; color: var(--sub); margin-top: 6px; text-align: center; }

/* 结果弹层（位于右栏，生成后显示） */
#result {
  display: none;
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; text-align: center;
}
#result.show { display: block; }
#result h2 { margin: 0 0 5px; font-size: 16px; }
#result .sub { color: var(--sub); font-size: 12.5px; margin-bottom: 14px; }
#qrImg { width: 200px; height: 200px; image-rendering: pixelated; border-radius: 11px; background:#fff; padding:6px; box-shadow: var(--shadow); }
#shareUrl {
  width: 100%; padding: 9px 11px; margin: 12px 0; border: 1px solid var(--line);
  border-radius: 9px; font-size: 12.5px; color: var(--sub); background: #f8fafc;
}
.result-btns { display: flex; gap: 9px; flex-wrap: wrap; justify-content: center; }
.result-btns button, .result-btns a {
  border: none; border-radius: 999px; padding: 10px 16px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; text-decoration: none;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-ghost { background: #eef2f9; color: var(--ink); }
