:root {
  --bg: #f6f8fb;
  --card: #ffffff;
  --border: #e6e9ef;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --shadow: 0 1px 3px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.05);
}

* { box-sizing: border-box; }

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

/* 顶部栏 */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
.back {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
}
.back:hover { color: var(--accent); }

/* 布局 */
.layout {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 64px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 28px;
  align-items: start;
}

.panel { display: flex; flex-direction: column; gap: 20px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 20px; font-size: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-head h2 { margin: 0; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.row > label:first-child {
  min-width: 84px;
  color: var(--muted);
  font-size: 14px;
}
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }

input[type="range"] { flex: 1; min-width: 140px; accent-color: var(--accent); }
input[type="color"] {
  width: 46px; height: 34px; padding: 0; border: 1px solid var(--border);
  border-radius: 8px; background: none; cursor: pointer;
}
.text-input {
  flex: 1; min-width: 120px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.ext { color: var(--muted); font-size: 13px; }
.val { color: var(--accent); font-weight: 600; }
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; cursor: pointer; }
.check input { accent-color: var(--accent); }

/* 按钮 */
.btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; }
.btn-block { width: 100%; margin-top: 6px; padding: 11px; }
.btn-mini { padding: 6px 11px; font-size: 13px; border-radius: 8px; }

/* 图层卡片 */
.layer-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px 16px;
  margin-bottom: 14px;
  background: #fbfcfe;
}
.layer-head {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 14px;
}
.layer-title {
  display: flex; align-items: center; gap: 2px;
  font-weight: 600; font-size: 14px;
  min-width: 0; flex: 1;
}
.layer-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.layer-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.btn-del {
  border: none; background: none; color: #dc2626; cursor: pointer;
  font-size: 13px; padding: 2px 6px; border-radius: 6px;
}
.btn-del:hover { background: #fef2f2; }
.btn-remove {
  border: 1px solid var(--border); background: #fff; color: #dc2626;
  cursor: pointer;
}
.btn-remove:hover { background: #fef2f2; border-color: #fecaca; }

/* 内容类型切换（文字 / 图片） */
.seg {
  display: inline-flex; border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden; background: #fff; flex-shrink: 0;
}
.seg button {
  border: none; background: none; cursor: pointer;
  padding: 4px 11px; font-size: 12.5px; color: var(--muted);
  font-family: inherit; line-height: 1.4;
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button:hover { color: var(--accent); background: var(--accent-soft); }
.seg button.on { background: var(--accent); color: #fff; font-weight: 600; }
.seg button.on:hover { background: var(--accent); color: #fff; }

/* 统一字段块：标签在上，控件在下 */
.layer-body { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 22px; }
.field { display: flex; flex-direction: column; gap: 9px; min-width: 0; }
.field[hidden] { display: none; }
.field.span2 { grid-column: 1 / -1; }
.field > label { font-size: 12.5px; color: var(--muted); }
.field .ctl { display: flex; align-items: center; gap: 8px; }
.field .ctl input[type="range"] { flex: 1; min-width: 60px; }
.field .ctl .text-input { width: 100%; }
.field .val {
  flex-shrink: 0; min-width: 34px; text-align: right;
  color: var(--accent); font-weight: 600; font-size: 12.5px;
}
.field select {
  width: 100%; padding: 7px 9px;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; background: #fff;
}
.field input[type="color"] {
  width: 42px; height: 32px; padding: 0;
  border: 1px solid var(--border); border-radius: 8px;
  background: none; cursor: pointer;
}
.field .check {
  display: flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: 13px; cursor: pointer;
}
.field .check input { accent-color: var(--accent); }

/* 图片内容区 */
.img-ctl { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.img-btns { display: flex; align-items: center; gap: 8px; }

/* 图片缩略图 */
.layer-thumb {
  flex-shrink: 0;
  width: 44px; height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  object-fit: contain;
  background-color: #fbfcfe;
  background-image:
    linear-gradient(45deg, #eef1f6 25%, transparent 25%),
    linear-gradient(-45deg, #eef1f6 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef1f6 75%),
    linear-gradient(-45deg, transparent 75%, #eef1f6 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
}
.layer-thumb-empty {
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--muted);
  border-style: dashed; background: #fff;
}

/* 添加层按钮（位于图层列表下方） */
.add-layer-wrap { margin-top: 16px; }
.add-layer-wrap .btn-block { width: 100%; }
}

/* 属性面板（右侧，编辑激活层） */
.props-card { margin-top: 36px; }
.props-empty { color: var(--muted); font-size: 13px; margin: 8px 0 0; line-height: 1.6; }

/* 导出模块 */
.export-card { margin-top: 36px; }
.export-sizes {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  margin: 18px 0 20px;
}
.size-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px;
  background: #fbfcfe;
}
.size-row .check { margin: 0; }
.size-row .dl {
  border: 1px solid var(--accent); background: var(--accent-soft); color: var(--accent);
  padding: 4px 11px; border-radius: 7px; font-size: 12px; cursor: pointer; white-space: nowrap;
}
.size-row .dl:hover { background: var(--accent); color: #fff; }

/* 图层拖拽排序 */
.layer-actions { display: flex; align-items: center; gap: 4px; }
.drag-handle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; margin-right: 2px;
  color: var(--muted); cursor: grab; user-select: none;
  font-size: 15px; line-height: 1; border-radius: 6px;
}
.drag-handle:hover { background: var(--accent-soft); color: var(--accent); }
.drag-handle:active { cursor: grabbing; }
.layer-card.dragging { opacity: .5; border-style: dashed; }
.layer-card.drag-over { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.layer-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

/* 预览 */
.preview-pane { position: sticky; top: 24px; }
.preview-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.checker {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(45deg, #e9edf3 25%, transparent 25%),
    linear-gradient(-45deg, #e9edf3 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e9edf3 75%),
    linear-gradient(-45deg, transparent 75%, #e9edf3 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-color: #f4f6fa;
}
#preview {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  image-rendering: -webkit-optimize-contrast;
  cursor: grab; touch-action: none;
}
.preview-meta { margin-top: 20px; color: var(--muted); font-size: 13px; }
.export-card { margin-top: 28px; }
.preview-tiles { display: flex; gap: 12px; margin-top: 10px; align-items: flex-end; }
.tile {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  border: 1px solid var(--border); border-radius: 10px; padding: 9px;
  background: #fff; position: relative; overflow: hidden;
}
.tile .checker {
  position: absolute; inset: 0; z-index: 0;
}
.tile canvas { position: relative; z-index: 1; }
.tile span { font-size: 11px; color: var(--muted); position: relative; z-index: 1; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .preview-pane { position: static; order: -1; }
}
