:root {
  --bg: #fff6f8;
  --surface: #ffffff;
  --ink: #4a2c2a;
  --muted: #8a6a68;
  --line: #f0d6dc;
  --pink: #ff8fa3;
  --pink-deep: #e86b88;
  --pink-soft: #ffe4ec;
  --shadow: 0 12px 40px rgba(180, 90, 110, 0.12);
  --radius: 18px;
  --font-ui: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    sans-serif;
  --font-display: "ZCOOL KuaiLe", "Noto Sans SC", "PingFang SC", sans-serif;
  --poster-w: 1600;
  --poster-h: 1200;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-ui);
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 50% at 10% 0%, #ffe8ef 0%, transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 20%, #fff0e0 0%, transparent 50%),
    var(--bg);
}

body {
  min-height: 100vh;
}

.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 20px 40px;
}

.header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, #ffb3c4, #ff8fa3);
  color: #fff;
  font-size: 22px;
  box-shadow: 0 6px 16px rgba(255, 143, 163, 0.35);
}

.header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.template-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.template-label {
  white-space: nowrap;
  font-weight: 600;
  color: var(--ink);
}

.template-select {
  min-width: 160px;
  max-width: 220px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 14px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--pink-deep) 50%),
    linear-gradient(135deg, var(--pink-deep) 50%, transparent 50%);
  background-position: calc(100% - 16px) calc(50% - 3px), calc(100% - 11px) calc(50% - 3px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 28px;
}

.template-select:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px rgba(255, 143, 163, 0.2);
}

.btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

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

.btn-primary {
  background: linear-gradient(145deg, var(--pink), var(--pink-deep));
  color: #fff;
  box-shadow: 0 8px 20px rgba(232, 107, 136, 0.35);
}

.btn-primary:hover {
  box-shadow: 0 10px 24px rgba(232, 107, 136, 0.45);
}

.btn-primary:disabled {
  opacity: 0.65;
  cursor: wait;
  box-shadow: none;
}

.btn-ghost {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn-ghost:hover {
  background: var(--pink-soft);
}

.main {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(300px, 0.85fr);
  gap: 20px;
  align-items: start;
}

.preview-panel {
  position: sticky;
  top: 16px;
}

.preview-frame {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 16px 16px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.8);
}

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

.selection-label {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.35;
}

.tool-groups {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  margin-bottom: 10px;
  padding: 8px 10px;
  background: #fffafb;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.tool-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

.tool-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  margin-right: 2px;
  letter-spacing: 0.04em;
}

.tool-divider {
  width: 1px;
  height: 22px;
  background: var(--line);
  flex-shrink: 0;
}

.btn-icon {
  appearance: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.btn-icon-wide {
  width: auto;
  min-width: 36px;
  padding: 0 8px;
  font-size: 0.78rem;
}

.btn-icon:hover {
  background: var(--pink-soft);
  border-color: var(--pink);
}

.btn-icon.is-active {
  background: linear-gradient(145deg, var(--pink), var(--pink-deep));
  border-color: transparent;
  color: #fff;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 12px;
  background: #fff8f0;
  user-select: none;
  touch-action: none;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.04);
}

#editor-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: default;
  /* crisp downscale of 1600×1200 */
  image-rendering: auto;
}

.hint {
  margin: 10px 4px 0;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

.controls {
  max-height: calc(100vh - 120px);
  overflow: auto;
  padding-right: 4px;
}

.editor-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.control-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px 16px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.85);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  cursor: default;
}

.control-card.is-selected {
  border-color: var(--pink);
  box-shadow:
    var(--shadow),
    0 0 0 3px rgba(255, 143, 163, 0.22);
}

.control-card h2 {
  margin: 0 0 12px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--pink-deep);
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-card h2::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--pink);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.field-row {
  display: flex;
  gap: 12px;
  margin-top: 10px;
}

.field input[type="text"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  background: #fff;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input[type="text"]:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px rgba(255, 143, 163, 0.2);
}

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

.field input[type="color"] {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
  background: #fff;
  cursor: pointer;
}

.field-select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  background: #fff;
  outline: none;
  cursor: pointer;
}

.field-select:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px rgba(255, 143, 163, 0.2);
}

.field output {
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  font-weight: 600;
}

.param-block {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.param-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.param-block-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--pink-deep);
}

.check-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}

.check-field input {
  width: 16px;
  height: 16px;
  accent-color: var(--pink-deep);
  cursor: pointer;
}

.lively-params {
  transition: opacity 0.15s ease;
}

.lively-params.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.param-hint {
  margin: 8px 0 0;
  font-size: 0.72rem;
  line-height: 1.4;
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(12px);
  background: rgba(74, 44, 42, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
}

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

@media (max-width: 900px) {
  .main {
    grid-template-columns: 1fr;
  }

  .preview-panel {
    position: static;
  }

  .controls {
    max-height: none;
  }
}

@media (max-width: 520px) {
  .app {
    padding: 14px 12px 28px;
  }

  .header-actions {
    width: 100%;
  }

  .btn {
    flex: 1;
  }

  .field-row {
    flex-direction: column;
    gap: 10px;
  }
}
