:root {
  --bg: #eef1f6;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #3b82f6;
  --accent-dark: #2563eb;
  --danger: #dc2626;
  --stage-bg: #d1d5db;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 12px;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
  flex-wrap: wrap;
  z-index: 2;
}

.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.topbar .spacer { flex: 1; }
.topbar .muted,
.muted { color: var(--muted); font-size: 13px; }
.tiny { font-size: 12px; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: #fff;
}
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.block { display: block; width: 100%; text-align: center; margin: 8px 0 0; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.file-btn { display: inline-flex; align-items: center; cursor: pointer; }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 280px;
  gap: 12px;
  padding: 12px;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-section {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}
.panel-section:last-child { border-bottom: none; }
.panel-section.flex-grow { flex: 1; }
.panel-section.templates { max-height: 220px; }
.panel-section.tip { border-top: 1px solid var(--line); margin-top: auto; }

.panel h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: none;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.source-area {
  width: 100%;
  min-height: 140px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  font-size: 13px;
  line-height: 1.55;
  font-family: inherit;
  background: #fafafa;
}
.source-area:focus {
  outline: 2px solid rgba(59, 130, 246, 0.35);
  border-color: var(--accent);
  background: #fff;
}

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

.input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
  min-width: 0;
}
.input.compact { padding: 4px 8px; font-size: 12px; }
.input:focus {
  outline: 2px solid rgba(59, 130, 246, 0.35);
  border-color: var(--accent);
}

.strip-list {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 2px;
}

.strip-item {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 6px;
  align-items: start;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafafa;
  cursor: pointer;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.strip-item:hover { border-color: #93c5fd; background: #f0f7ff; }
.strip-item.active {
  border-color: var(--accent);
  background: #eff6ff;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}
.strip-item.placed { border-left: 3px solid #22c55e; }
.strip-item textarea {
  width: 100%;
  min-height: 44px;
  border: none;
  background: transparent;
  resize: vertical;
  font-size: 12px;
  line-height: 1.45;
  font-family: inherit;
  color: var(--ink);
  padding: 0;
}
.strip-item textarea:focus { outline: none; }
.strip-item .badge {
  font-size: 10px;
  color: #16a34a;
  white-space: nowrap;
  padding-top: 2px;
}
.strip-item .idx {
  font-size: 11px;
  color: var(--muted);
  padding-top: 2px;
  text-align: center;
}

.tpl-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  max-height: 120px;
}
.tpl-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 13px;
}
.tpl-list li:last-child { border-bottom: none; }
.tpl-list .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.stage-wrap {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.stage-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.custom-size { display: inline-flex; align-items: center; gap: 6px; }
.custom-size.hidden,
.hidden { display: none !important; }

.stage {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background:
    linear-gradient(45deg, #e5e7eb 25%, transparent 25%),
    linear-gradient(-45deg, #e5e7eb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e5e7eb 75%),
    linear-gradient(-45deg, transparent 75%, #e5e7eb 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-color: #f3f4f6;
}

#canvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 140px);
  width: auto;
  height: auto;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
  background: #f8fafc;
  cursor: default;
  touch-action: none;
}

.inspector .field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--muted);
}
.inspector .field textarea,
.inspector .field input[type="number"],
.inspector .field input[type="text"],
.inspector .field select,
.inspector .field input[type="color"] {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
}
.inspector .field textarea { resize: vertical; min-height: 80px; }
.inspector .field input[type="color"] { padding: 2px; height: 36px; cursor: pointer; }
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tips {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(420px, 1fr) auto;
  }
  .left-panel, .right-panel { max-height: 360px; }
}

.import-row { margin-top: 2px; }
.val-hint {
  float: right;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.inspector .field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  margin: 4px 0 0;
}
