:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #e2e4e9;
  --ink: #1c1e23;
  --muted: #6a6f7a;
  --accent: #2b6cff;
  --danger: #d23b3b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar h1 {
  font-size: 16px;
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.topbar__actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

/* Segmented shape switch */
.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.seg__btn {
  appearance: none;
  border: 0;
  background: #fff;
  color: var(--muted);
  font: inherit;
  padding: 7px 14px;
  cursor: pointer;
}
.seg__btn + .seg__btn { border-left: 1px solid var(--line); }
.seg__btn.is-active { background: var(--accent); color: #fff; }

/* ---------- Layout ---------- */
.workspace {
  display: grid;
  grid-template-columns: 220px 1fr 300px;
  gap: 16px;
  padding: 16px;
  align-items: start;
}
.rail, .inspector {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------- Stage / canvas ---------- */
.stage {
  display: flex;
  justify-content: center;
}
.canvas-host {
  line-height: 0;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
  overflow: hidden;
}
/* Fabric wraps the canvas in .canvas-container. The slate mockup is mirrored
   here as a CSS background so knockout (destination-out) elements visually
   reveal the slate on screen. It is NOT part of the exported pixels. */
.canvas-container {
  background-size: 100% 100%;
  background-repeat: no-repeat;
}

/* ---------- Panels ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}
.panel__title { font-size: 14px; margin: 0 0 10px; }
.panel__subtitle { font-size: 13px; margin: 0 0 6px; }
.panel__note { font-size: 12px; color: var(--muted); margin: 0 0 10px; }
.panel__note code { background: var(--bg); padding: 1px 4px; border-radius: 4px; }
.panel__empty { color: var(--muted); margin: 0; }

.rail__title { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 0; }
.rail__group { display: flex; flex-direction: column; gap: 6px; }
.rail__hint { font-size: 12px; color: var(--muted); margin: 4px 0 0; }

.sep { border: none; border-top: 1px solid var(--line); margin: 14px 0; }

/* ---------- Fields ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field > span { font-size: 12px; color: var(--muted); }
.field--row { flex-direction: row; align-items: center; gap: 8px; }
.field--row > span { color: var(--ink); }
.field input[type="range"] { width: 100%; }
.field input:disabled { opacity: 0.4; }
.field:has(input:disabled) > span { opacity: 0.4; }
.field select, .field input[type="color"] {
  width: 100%;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 6px;
}

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}
.btn:hover { border-color: #c9ccd3; }
.btn:active { transform: translateY(1px); }
.btn--block { width: 100%; text-align: center; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { filter: brightness(1.05); }
.btn--danger { color: var(--danger); border-color: #f0c9c9; }

/* ---------- Export preview ---------- */
.export-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 10px;
  /* checkerboard so transparency is visible */
  background-image:
    linear-gradient(45deg, #ddd 25%, transparent 25%),
    linear-gradient(-45deg, #ddd 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ddd 75%),
    linear-gradient(-45deg, transparent 75%, #ddd 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.export-preview img { display: block; width: 100%; border-radius: 8px; }

/* ---------- Busy overlay ---------- */
.busy[hidden] { display: none; }   /* author display:flex would otherwise beat [hidden] */
.busy {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 22, 28, 0.55);
}
.busy__box {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 320px;
  padding: 18px 22px;
  background: var(--panel);
  border-radius: 12px;
  font-size: 13px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}
.busy__spinner {
  flex: none;
  width: 18px;
  height: 18px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; }
  .stage { order: -1; }
}
