.bg-wrapper {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  height: calc(100vh - 120px);
}

.bg-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.bg-title h2 { margin: 0 0 0.25rem; font-size: 1.5rem; }
.bg-title p { margin: 0; color: #64748b; font-size: 0.95rem; }

.bg-actions { display: flex; gap: 0.75rem; }

.bg-btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 1rem; border-radius: 8px; font-weight: 600; cursor: pointer;
  border: none; font-size: 0.95rem; transition: 0.2s;
}
.bg-btn.primary { background: #7c5cff; color: #fff; }
.bg-btn.primary:hover { background: #6b4de0; }
.bg-btn.secondary { background: #f1f5f9; color: #334155; }
.bg-btn.secondary:hover { background: #e2e8f0; }

.bg-workspace {
  flex: 1;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.04);
  border: 1px solid #e2e8f0;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Upload Zone */
.bg-upload {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: #f8fafc;
}
.bg-upload.dragover { background: #f1f5f9; border: 2px dashed #7c5cff; }
.bg-upload-inner {
  text-align: center; max-width: 300px;
}
.bg-upload-inner svg { width: 48px; height: 48px; color: #94a3b8; margin-bottom: 1rem; }
.bg-upload-inner h3 { margin: 0 0 0.5rem; font-size: 1.2rem; }
.bg-upload-inner p { color: #64748b; margin: 0 0 1.5rem; }

/* Loading Zone */
.bg-loading {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: #fff; z-index: 10;
}
.bg-loading .spinner {
  width: 40px; height: 40px; border: 4px solid #f1f5f9; border-top-color: #7c5cff;
  border-radius: 50%; animation: spin 1s linear infinite; margin-bottom: 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Editor Zone */
.bg-editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
}
.bg-toolbar {
  padding: 1rem;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  gap: 2rem;
  align-items: center;
  background: #fdfdfd;
}
.tool-group { display: flex; align-items: center; gap: 0.75rem; }
.tool-label { font-size: 0.9rem; color: #64748b; font-weight: 500; }
.tool-val {
  font-size: 0.9rem; font-weight: 600; color: #7c5cff;
  min-width: 2.5rem; text-align: right; font-variant-numeric: tabular-nums;
}
.tool-radio { display: inline-flex; cursor: pointer; }
.tool-radio input { display: none; }
.tool-btn {
  padding: 0.4rem 0.8rem; border-radius: 6px; font-size: 0.9rem; font-weight: 500;
  color: #64748b; background: #f1f5f9; transition: 0.2s;
}
.tool-radio input:checked + .tool-btn { background: #7c5cff; color: #fff; }

.tool-icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 8px;
  border: 1px solid #e2e8f0; background: #fff; color: #334155;
  cursor: pointer; transition: 0.15s; padding: 0;
}
.tool-icon-btn svg { width: 18px; height: 18px; }
.tool-icon-btn:hover:not(:disabled) { background: #f1f5f9; border-color: #cbd5e1; }
.tool-icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.bg-canvas-container {
  flex: 1;
  overflow: auto;
  padding: 2rem;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background: #f1f5f9;
}

.canvas-stage {
  position: relative;
  transform-origin: top center;
  line-height: 0;
}

canvas#bgCanvas {
  display: block;
  max-width: 100%;
  height: auto;
  background-image: 
    linear-gradient(45deg, #e2e8f0 25%, transparent 25%),
    linear-gradient(-45deg, #e2e8f0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e2e8f0 75%),
    linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  background-color: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  cursor: none;
}

/* Круг-курсор, показывающий реальный размер кисти на экране */
.brush-cursor {
  position: absolute;
  top: 0; left: 0;
  border: 2px solid #7c5cff;
  background: rgba(124, 92, 255, 0.12);
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  display: none;
  z-index: 5;
}
.canvas-stage.show-cursor .brush-cursor { display: block; }
