:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --ink: #1e2235;
  --muted: #6b7280;
  --line: #e6e8f0;
  --primary: #6366f1;
  --primary-d: #4f46e5;
  --danger: #ef4444;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(31, 34, 53, 0.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; }
.brand img { border-radius: 8px; }
.brand em { font-style: normal; color: var(--muted); font-weight: 500; font-size: 13px; }
.actions { display: flex; gap: 8px; }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: 0.15s;
}
.btn:hover:not(:disabled) { border-color: #c7cbe0; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-d); }
.btn.ghost { background: transparent; }

/* Workspace */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 64px 1fr 240px;
  min-height: 0;
}

/* Tool rail */
.toolrail {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
}
.tool {
  width: 44px;
  height: 44px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 12px;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--ink);
  transition: 0.15s;
}
.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tool:hover:not(:disabled) { background: #f1f2f9; }
.tool.active { background: #eef2ff; color: var(--primary); border-color: #c7d2fe; }
.tool:disabled { opacity: 0.35; cursor: not-allowed; }
.tool.danger:hover:not(:disabled) { background: #fef2f2; color: var(--danger); }
.divider { width: 28px; height: 1px; background: var(--line); margin: 4px 0; }

/* Stage */
.stage {
  position: relative;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(45deg, #eceef4 25%, transparent 25%),
    linear-gradient(-45deg, #eceef4 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eceef4 75%),
    linear-gradient(-45deg, transparent 75%, #eceef4 75%);
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
  background-color: #f6f7fb;
}
#canvas { display: none; box-shadow: var(--shadow); border-radius: 6px; touch-action: none; }
#canvas.ready { display: block; }
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}
.empty svg { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; opacity: 0.6; }
.empty.hide { display: none; }

/* Props panel */
.props {
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 16px;
  overflow: auto;
}
.props h3 { margin: 0 0 12px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.row { display: grid; grid-template-columns: 84px 1fr auto; align-items: center; gap: 10px; margin-bottom: 14px; font-size: 13px; }
.row span { color: var(--muted); }
.row b { font-weight: 600; min-width: 26px; text-align: right; font-variant-numeric: tabular-nums; }
input[type="color"] { width: 100%; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 2px; cursor: pointer; }
input[type="range"] { width: 100%; accent-color: var(--primary); }
.hint { margin-top: 8px; font-size: 12px; color: var(--muted); line-height: 1.5; background: #f8f9fc; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #1e2235;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 50;
}

@media (max-width: 760px) {
  .workspace { grid-template-columns: 56px 1fr; }
  .props { position: fixed; right: 0; bottom: 0; width: 220px; max-height: 50%; box-shadow: var(--shadow); border-radius: 14px 0 0 0; }
}
